adb-toolkit/app.go
jegly 26d82c68d5 Add GSI Loader, APK Audit, Firmware, Intent Lab, Screen Mirror, Magisk, and App Lock features; bump to v1.2.0
- New sidebar views: GSI Loader (DSU + permanent fastboot flash), APK Audit,
  Firmware, Intent Lab, Screen Mirror
- New backend modules: backend_gsi.go, backend_apkaudit*.go, backend_firmware.go,
  backend_intent.go, backend_magisk.go, backend_applock.go, backend_scrcpy.go,
  backend_payload.go, backend_privacy.go, backend_overview.go, backend_bootinfo.go,
  backend_flasher.go, backend_transfer.go, backend_filehttp.go
- App Lock / danger-gate infrastructure (DangerGate, LockGate, applock.ts)
- Privileged uninstall via embedded Android helper dex (android-helper/)
- nfpm packaging version bump to 1.2.0
2026-07-06 15:17:59 +10:00

114 lines
3.1 KiB
Go

package main
import (
"context"
"sync"
"time"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
// DeviceMode represents whether a device is in ADB or Fastboot mode
type DeviceMode string
const (
DeviceModeUnknown DeviceMode = "unknown"
DeviceModeADB DeviceMode = "adb"
DeviceModeFastboot DeviceMode = "fastboot"
)
// Device represents a connected ADB device
type Device struct {
Serial string `json:"serial"`
Status string `json:"status"`
}
// DeviceInfo holds detailed information about a connected device
type DeviceInfo struct {
Model string `json:"model"`
AndroidVersion string `json:"androidVersion"`
BuildNumber string `json:"buildNumber"`
BatteryLevel string `json:"batteryLevel"`
Serial string `json:"serial"`
IPAddress string `json:"ipAddress"`
RootStatus string `json:"rootStatus"`
Codename string `json:"codename"`
RamTotal string `json:"ramTotal"`
StorageInfo string `json:"storageInfo"`
Brand string `json:"brand"`
DeviceName string `json:"deviceName"`
SecurityPatch string `json:"securityPatch"`
Uptime string `json:"uptime"`
BootloaderStatus string `json:"bootloaderStatus"`
ScreenResolution string `json:"screenResolution"`
BasebandVersion string `json:"basebandVersion"`
KernelVersion string `json:"kernelVersion"`
CPUArch string `json:"cpuArch"`
}
// FileEntry represents a file or directory on the device
type FileEntry struct {
Name string `json:"name"`
Type string `json:"type"`
Size string `json:"size"`
Permissions string `json:"permissions"`
Date string `json:"date"`
Time string `json:"time"`
}
// PackageInfo represents an installed app package
type PackageInfo struct {
PackageName string `json:"packageName"`
IsEnabled bool `json:"isEnabled"`
}
// AdbConfig holds user-configurable ADB settings
type AdbConfig struct {
AdbPath string `json:"adbPath"`
FastbootPath string `json:"fastbootPath"`
}
// App is the main application struct
type App struct {
ctx context.Context
config AdbConfig
// binary path cache
binaryCache map[string]string
cacheMutex sync.RWMutex
// cancellation for long-running ops
currentCancel context.CancelFunc
opMutex sync.Mutex
// app-lock "require password for destructive actions" session window
dangerMu sync.Mutex
dangerUntil time.Time
}
// NewApp creates a new App instance
func NewApp() *App {
return &App{
binaryCache: make(map[string]string),
config: AdbConfig{},
}
}
// Startup is called when the app starts
func (a *App) Startup(ctx context.Context) {
a.ctx = ctx
// Frameless windows can open off-centre on some WMs; centre on launch.
runtime.WindowCenter(ctx)
}
// Shutdown is called when the app is closing — tidy up spawned child processes
// (e.g. a scrcpy mirror) so they don't outlive the app as orphan windows.
// Exception: a mirror started in "detached" mode is left running on purpose.
func (a *App) Shutdown(ctx context.Context) {
scrcpyMu.Lock()
detached := scrcpyDetached
scrcpyMu.Unlock()
if !detached {
a.StopScrcpy()
}
}