add macos

This commit is contained in:
2026-07-01 10:06:31 +07:00
parent 248d3a6722
commit b702287cfb
10 changed files with 148 additions and 47 deletions

View File

@@ -124,9 +124,10 @@ type App struct {
lastSyncTime time.Time
isStreamingSc bool
streamScStop chan struct{}
statusMsg string
expectingLogin bool
backendOnline bool
statusMsg string
expectingLogin bool
needsClearPortalStorage bool
backendOnline bool
dashboard StudentDashboardSnapshot
wifiEnforce bool
acceptedWifi map[string]bool
@@ -209,6 +210,9 @@ func (a *App) startup(ctx context.Context) {
a.loadSession()
a.loadStats()
// Request Location Access (macOS)
winapi.RequestLocationAccess()
// Register blocker callbacks
blocker.Instance.OnBlocked = func(procName string, title string) {
go a.reportBlockedApp(procName, title)
@@ -534,7 +538,8 @@ func (a *App) NavigateToLogin() {
func (a *App) Logout() {
a.mu.Lock()
a.student = nil
a.expectingLogin = false
a.expectingLogin = true
a.needsClearPortalStorage = true
a.mu.Unlock()
_ = os.Remove(a.sessionPath)
@@ -552,7 +557,7 @@ func (a *App) Logout() {
a.stopScreenshotStream()
guard.SuppressFor(5 * time.Second)
runtime.WindowReloadApp(a.ctx)
runtime.WindowExecJS(a.ctx, "window.location.href = 'https://portal.rikkei.edu.vn/dangnhap'")
}
// GetStats trả về Wifi, thời gian online/offline và trạng thái giám sát
@@ -622,9 +627,23 @@ func (a *App) authStorageScanner() {
a.mu.Lock()
expecting := a.expectingLogin
needsClear := a.needsClearPortalStorage
loggedIn := a.student != nil
a.mu.Unlock()
if needsClear && expecting {
runtime.WindowExecJS(a.ctx, `
try {
localStorage.removeItem("student");
localStorage.removeItem("token");
} catch(e) {}
`)
a.mu.Lock()
a.needsClearPortalStorage = false
a.mu.Unlock()
continue
}
if loggedIn || !expecting {
continue
}
@@ -661,8 +680,16 @@ func (a *App) runMonitorTick() {
wifi := winapi.GetWifiConnection()
a.mu.Lock()
a.wifiSSID = wifi.SSID
a.wifiBSSID = wifi.BSSID
if strings.Contains(strings.ToLower(wifi.SSID), "redacted") {
a.wifiSSID = "Chưa cấp quyền Vị Trí (macOS)"
} else {
a.wifiSSID = wifi.SSID
}
if strings.Contains(strings.ToLower(wifi.BSSID), "redacted") {
a.wifiBSSID = "Chưa cấp quyền Vị Trí (macOS)"
} else {
a.wifiBSSID = wifi.BSSID
}
a.mu.Unlock()
backendOnline := a.pingBackend()
@@ -732,8 +759,16 @@ func (a *App) refreshNetworkStatus() {
wifi := winapi.GetWifiConnection()
backendOnline := a.pingBackend()
a.mu.Lock()
a.wifiSSID = wifi.SSID
a.wifiBSSID = wifi.BSSID
if strings.Contains(strings.ToLower(wifi.SSID), "redacted") {
a.wifiSSID = "Chưa cấp quyền Vị Trí (macOS)"
} else {
a.wifiSSID = wifi.SSID
}
if strings.Contains(strings.ToLower(wifi.BSSID), "redacted") {
a.wifiBSSID = "Chưa cấp quyền Vị Trí (macOS)"
} else {
a.wifiBSSID = wifi.BSSID
}
a.backendOnline = backendOnline
a.mu.Unlock()
if backendOnline {
@@ -923,6 +958,10 @@ func (a *App) isWifiAllowed(ssid, bssid string) bool {
if !enforce || len(allowed) == 0 {
return true
}
// Bypass Wi-Fi check if it's redacted by macOS privacy controls
if strings.Contains(strings.ToLower(ssid), "redacted") || strings.Contains(strings.ToLower(bssid), "redacted") {
return true
}
bKey := winapi.BSSIDKey(bssid)
if bKey == "" || len(bKey) != 12 {
return false