🎨 Optimize multi-window services

This commit is contained in:
2025-11-05 00:10:26 +08:00
parent e9b6fef3cd
commit 1f0254822f
15 changed files with 220 additions and 239 deletions

View File

@@ -1,6 +1,8 @@
package services
import (
"strconv"
"github.com/wailsapp/wails/v3/pkg/application"
"voidraft/internal/common/constant"
)
@@ -77,3 +79,45 @@ func (wh *WindowHelper) AutoShowMainWindow() {
window.Show()
}
}
// GetDocumentWindow 根据文档ID获取窗口利用 Wails3 的 WindowManager
func (wh *WindowHelper) GetDocumentWindow(documentID int64) (application.Window, bool) {
app := application.Get()
windowName := strconv.FormatInt(documentID, 10)
return app.Window.GetByName(windowName)
}
// GetAllDocumentWindows 获取所有文档窗口(排除主窗口)
func (wh *WindowHelper) GetAllDocumentWindows() []application.Window {
app := application.Get()
allWindows := app.Window.GetAll()
var docWindows []application.Window
for _, window := range allWindows {
// 跳过主窗口
if window.Name() != constant.VOIDRAFT_MAIN_WINDOW_NAME {
docWindows = append(docWindows, window)
}
}
return docWindows
}
// FocusDocumentWindow 聚焦指定文档的窗口
func (wh *WindowHelper) FocusDocumentWindow(documentID int64) bool {
if window, exists := wh.GetDocumentWindow(documentID); exists {
window.Show()
window.Restore()
window.Focus()
return true
}
return false
}
// CloseDocumentWindow 关闭指定文档的窗口
func (wh *WindowHelper) CloseDocumentWindow(documentID int64) bool {
if window, exists := wh.GetDocumentWindow(documentID); exists {
window.Close()
return true
}
return false
}