This commit is contained in:
2026-06-30 13:25:48 +07:00
parent 1c2bfde005
commit 251c1b7573
8 changed files with 63 additions and 9 deletions

View File

@@ -113,6 +113,7 @@ type App struct {
monitoringTornDown bool
chatUnread int
replyStaffID uint
fetchAppsMu sync.Mutex
}
type LocalStats struct {
@@ -299,6 +300,7 @@ func (a *App) startLocalServer() {
go a.refreshStudentData()
// Chuyển hướng WebView về trang dashboard của app bằng cách reload app assets
guard.SuppressFor(5 * time.Second)
runtime.WindowReloadApp(a.ctx)
w.Write([]byte("ok"))
} else {
@@ -330,7 +332,10 @@ func (a *App) startLocalServer() {
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
return
}
go runtime.WindowReloadApp(a.ctx)
go func() {
guard.SuppressFor(5 * time.Second)
runtime.WindowReloadApp(a.ctx)
}()
w.Write([]byte("ok"))
})
@@ -495,6 +500,7 @@ func (a *App) NavigateToLogin() {
a.mu.Lock()
a.expectingLogin = true
a.mu.Unlock()
guard.SuppressFor(5 * time.Second)
runtime.WindowExecJS(a.ctx, "window.location.href = 'https://portal.rikkei.edu.vn/dangnhap'")
}
@@ -519,6 +525,7 @@ func (a *App) Logout() {
a.disconnectWS()
a.stopScreenshotStream()
guard.SuppressFor(5 * time.Second)
runtime.WindowReloadApp(a.ctx)
}
@@ -912,6 +919,9 @@ func (a *App) rejectUnauthorizedWifi(ssid, bssid string) {
}
func (a *App) fetchAllowedApps(classId int64) {
a.fetchAppsMu.Lock()
defer a.fetchAppsMu.Unlock()
a.mu.Lock()
studentID := int64(0)
if a.student != nil {
@@ -935,6 +945,12 @@ func (a *App) fetchAllowedApps(classId int64) {
}
if err := json.NewDecoder(resp.Body).Decode(&res); err == nil {
if res.Exit {
a.mu.Lock()
stillExam := a.dashboard.MonitorMode == "exam"
a.mu.Unlock()
if stillExam {
return
}
reason := res.Reason
if reason == "" {
reason = "Không đáp ứng điều kiện học tập (chưa cấu hình ứng dụng được phép hoặc ngoài giờ học)."
@@ -984,6 +1000,7 @@ func (a *App) fetchStudentStatus(studentID int64) {
}
a.mu.Lock()
prevMode := a.dashboard.MonitorMode
a.dashboard = res
if res.MonitorLabel != "" {
a.statusMsg = res.MonitorLabel
@@ -998,6 +1015,10 @@ func (a *App) fetchStudentStatus(studentID int64) {
a.statusMsg = res.MonitorLabel
}
a.mu.Unlock()
if prevMode != res.MonitorMode {
guard.SuppressFor(4 * time.Second)
}
}
func (a *App) connectWS() {
@@ -1292,6 +1313,7 @@ func (a *App) examStudentContext() (int64, *StudentExamSnapshot, error) {
// ReturnToDashboard quay lại giao diện chính của app (giữ cookie WebView2).
func (a *App) ReturnToDashboard() {
guard.SuppressFor(5 * time.Second)
runtime.WindowReloadApp(a.ctx)
}
@@ -1315,10 +1337,12 @@ func (a *App) openExamWebView(targetURL, title string) error {
url.QueryEscape(targetURL),
url.QueryEscape(title),
)
guard.SuppressFor(5 * time.Second)
runtime.WindowExecJS(a.ctx, fmt.Sprintf("window.location.href = %q", wrapper))
return nil
}
// Trang thi bên ngoài: mở trực tiếp trong WebView (first-party cookies → giữ phiên đăng nhập).
guard.SuppressFor(5 * time.Second)
runtime.WindowExecJS(a.ctx, fmt.Sprintf("window.location.href = %q", targetURL))
return nil
}
@@ -1481,6 +1505,7 @@ func uniqueFilePath(path string) string {
}
func openFolderInExplorer(filePath string) {
guard.SuppressFor(5 * time.Second)
dir := filepath.Dir(filePath)
_ = exec.Command("explorer", dir).Start()
}