Frameless Window

This commit is contained in:
2025-06-09 01:00:15 +08:00
parent 8522a47b5f
commit 7f97b4a937
12 changed files with 999 additions and 17 deletions

View File

@@ -29,15 +29,8 @@ func RegisterTrayEvents(app *application.App, systray *application.SystemTray, m
trayService.HandleWindowClose()
})
// 处理窗口最小化事件 - 根据配置决定是隐藏到托盘还是正常最小化
mainWindow.RegisterHook(wailsevents.Common.WindowMinimise, func(event *application.WindowEvent) {
if trayService.ShouldMinimizeToTray() {
// 取消默认最小化行为,隐藏到托盘
event.Cancel()
trayService.HandleWindowMinimize()
}
// 如果不启用托盘,允许正常最小化(不取消事件)
})
// 不再拦截窗口最小化事件,让任务栏点击保持正常行为
// 最小化到托盘的逻辑由前端标题栏按钮直接处理
}
// RegisterTrayMenuEvents 注册系统托盘菜单事件

View File

@@ -17,6 +17,7 @@ type ServiceManager struct {
dialogService *DialogService
websocketService *WebSocketService
httpService *HTTPService
trayService *TrayService
logger *log.LoggerService
}
@@ -49,6 +50,9 @@ func NewServiceManager() *ServiceManager {
// 初始化 HTTP 服务
httpService := NewHTTPService(logger, websocketService)
// 初始化托盘服务
trayService := NewTrayService(logger, configService)
// 设置迁移服务的WebSocket广播
migrationService.SetProgressBroadcaster(func(progress MigrationProgress) {
websocketService.BroadcastMigrationProgress(progress)
@@ -95,6 +99,7 @@ func NewServiceManager() *ServiceManager {
dialogService: dialogService,
websocketService: websocketService,
httpService: httpService,
trayService: trayService,
logger: logger,
}
}
@@ -108,6 +113,7 @@ func (sm *ServiceManager) GetServices() []application.Service {
application.NewService(sm.systemService),
application.NewService(sm.hotkeyService),
application.NewService(sm.dialogService),
application.NewService(sm.trayService),
}
}
@@ -130,3 +136,8 @@ func (sm *ServiceManager) GetLogger() *log.LoggerService {
func (sm *ServiceManager) GetConfigService() *ConfigService {
return sm.configService
}
// GetTrayService 获取托盘服务实例
func (sm *ServiceManager) GetTrayService() *TrayService {
return sm.trayService
}

View File

@@ -77,3 +77,10 @@ func (ts *TrayService) ShowWindow() {
ts.logger.Info("TrayService: Window shown from system tray")
}
}
// MinimizeButtonClicked 处理标题栏最小化按钮点击
func (ts *TrayService) MinimizeButtonClicked() {
// 最小化按钮总是执行正常最小化到任务栏,不隐藏到托盘
ts.mainWindow.Minimise()
ts.logger.Info("TrayService: Window minimized to taskbar via titlebar button")
}