mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-06-12 09:29:43 +08:00
⚡️ perf(webview): 降低首屏加载与 WebView2 内存占用
- Monaco Editor 改为首次使用时按需初始化 - AI 面板改为懒加载,延后加载 Markdown 和图表渲染依赖 - 增加 Windows 低内存视觉模式,支持关闭透明 WebView 和 Acrylic - 补充低内存启动说明与模式解析测试
This commit is contained in:
26
main.go
26
main.go
@@ -2,6 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
aiservice "GoNavi-Wails/internal/ai/service"
|
||||
"GoNavi-Wails/internal/app"
|
||||
@@ -18,6 +20,13 @@ func main() {
|
||||
// Create an instance of the app structure
|
||||
application := app.NewApp()
|
||||
aiService := aiservice.NewService()
|
||||
lowMemoryMode := isLowMemoryMode()
|
||||
backgroundColour := &options.RGBA{R: 0, G: 0, B: 0, A: 0}
|
||||
windowsBackdrop := windows.Acrylic
|
||||
if lowMemoryMode {
|
||||
backgroundColour = &options.RGBA{R: 255, G: 255, B: 255, A: 255}
|
||||
windowsBackdrop = windows.None
|
||||
}
|
||||
|
||||
// Create application with options
|
||||
err := wails.Run(&options.App{
|
||||
@@ -28,7 +37,7 @@ func main() {
|
||||
AssetServer: &assetserver.Options{
|
||||
Assets: assets,
|
||||
},
|
||||
BackgroundColour: &options.RGBA{R: 0, G: 0, B: 0, A: 0},
|
||||
BackgroundColour: backgroundColour,
|
||||
OnStartup: func(ctx context.Context) {
|
||||
app.InitializeLifecycle(application, ctx)
|
||||
aiservice.InitializeLifecycle(aiService, ctx)
|
||||
@@ -39,9 +48,9 @@ func main() {
|
||||
aiService,
|
||||
},
|
||||
Windows: &windows.Options{
|
||||
WebviewIsTransparent: true,
|
||||
WindowIsTranslucent: true,
|
||||
BackdropType: windows.Acrylic,
|
||||
WebviewIsTransparent: !lowMemoryMode,
|
||||
WindowIsTranslucent: !lowMemoryMode,
|
||||
BackdropType: windowsBackdrop,
|
||||
DisableWindowIcon: false,
|
||||
DisableFramelessWindowDecorations: false,
|
||||
WebviewUserDataPath: resolveWindowsWebviewUserDataPath(),
|
||||
@@ -56,3 +65,12 @@ func main() {
|
||||
logger.Error(err, "应用启动失败")
|
||||
}
|
||||
}
|
||||
|
||||
func isLowMemoryMode() bool {
|
||||
switch strings.ToLower(strings.TrimSpace(os.Getenv("GONAVI_LOW_MEMORY_MODE"))) {
|
||||
case "1", "true", "yes", "on":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user