mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-13 00:13:33 +08:00
- 新增 web-server 运行模式与浏览器端运行时桥接 - 支持管理员密码、会话策略、Google Authenticator 与恢复码 - 设置中心补充浏览器访问认证状态与改密入口 - 优化初始化向导,未启用 2FA 时跳过验证器步骤 Refs #618
82 lines
2.2 KiB
Go
82 lines
2.2 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
|
|
"GoNavi-Wails/internal/connection"
|
|
"GoNavi-Wails/internal/uievents"
|
|
wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime"
|
|
)
|
|
|
|
const applicationBeforeCloseRequestEvent = "app:before-close-request"
|
|
|
|
var (
|
|
emitApplicationBeforeCloseRequest = uievents.Emit
|
|
quitApplicationRuntime = wailsRuntime.Quit
|
|
)
|
|
|
|
// NewBeforeCloseHandler exposes the Wails close guard without binding the
|
|
// lifecycle callback itself as a frontend RPC method.
|
|
func NewBeforeCloseHandler(a *App) func(context.Context) bool {
|
|
return func(ctx context.Context) bool {
|
|
if a == nil {
|
|
return false
|
|
}
|
|
return a.beforeClose(ctx)
|
|
}
|
|
}
|
|
|
|
func (a *App) beforeClose(ctx context.Context) bool {
|
|
a.applicationQuitMu.Lock()
|
|
if a.allowApplicationQuit {
|
|
a.allowApplicationQuit = false
|
|
a.applicationQuitPromptInFlight = false
|
|
a.applicationQuitMu.Unlock()
|
|
return false
|
|
}
|
|
if a.applicationQuitPromptInFlight {
|
|
a.applicationQuitMu.Unlock()
|
|
return true
|
|
}
|
|
a.applicationQuitPromptInFlight = true
|
|
a.applicationQuitMu.Unlock()
|
|
|
|
emitCtx := ctx
|
|
if emitCtx == nil {
|
|
emitCtx = a.ctx
|
|
}
|
|
if emitCtx != nil {
|
|
emitApplicationBeforeCloseRequest(emitCtx, applicationBeforeCloseRequestEvent)
|
|
}
|
|
return true
|
|
}
|
|
|
|
// CancelApplicationQuit resets a previously intercepted close request after
|
|
// the frontend dialog is cancelled or cannot complete a save.
|
|
func (a *App) CancelApplicationQuit() connection.QueryResult {
|
|
if a == nil {
|
|
return connection.QueryResult{Success: false, Message: "application is not initialized"}
|
|
}
|
|
a.applicationQuitMu.Lock()
|
|
a.applicationQuitPromptInFlight = false
|
|
a.allowApplicationQuit = false
|
|
a.applicationQuitMu.Unlock()
|
|
return connection.QueryResult{Success: true}
|
|
}
|
|
|
|
// ForceQuitApplication is called only after the frontend has confirmed that
|
|
// discarding or saving pending SQL edits is acceptable.
|
|
func (a *App) ForceQuitApplication() connection.QueryResult {
|
|
if a == nil {
|
|
return connection.QueryResult{Success: false, Message: "application is not initialized"}
|
|
}
|
|
a.applicationQuitMu.Lock()
|
|
a.allowApplicationQuit = true
|
|
a.applicationQuitPromptInFlight = false
|
|
a.applicationQuitMu.Unlock()
|
|
if a.ctx != nil {
|
|
quitApplicationRuntime(a.ctx)
|
|
}
|
|
return connection.QueryResult{Success: true}
|
|
}
|