diff --git a/cmd/desktop/main.go b/cmd/desktop/main.go index 99778f95..f4925451 100644 --- a/cmd/desktop/main.go +++ b/cmd/desktop/main.go @@ -7,6 +7,8 @@ import ( "net/http" "os" "os/signal" + "path/filepath" + "strings" "syscall" "time" @@ -23,12 +25,24 @@ import ( "github.com/Tencent/WeKnora/internal/logger" "github.com/Tencent/WeKnora/internal/runtime" "github.com/Tencent/WeKnora/internal/tracing" - wailsruntime "github.com/wailsapp/wails/v2/pkg/runtime" "github.com/Tencent/WeKnora/internal/types/interfaces" + "github.com/joho/godotenv" + wailsruntime "github.com/wailsapp/wails/v2/pkg/runtime" "golang.org/x/sys/unix" ) func main() { + // For macOS .app bundle, the working directory is usually "/" or the MacOS folder. + // We need to change the working directory to the Resources folder where our configs are. + execPath, errPath := os.Executable() + if errPath == nil && strings.Contains(execPath, ".app/Contents/MacOS") { + resPath := filepath.Join(filepath.Dir(filepath.Dir(execPath)), "Resources") + _ = os.Chdir(resPath) + } + + // Load .env explicitly for the desktop app so DB_DRIVER gets loaded + _ = godotenv.Load() + // Set Gin mode if os.Getenv("GIN_MODE") == "release" { gin.SetMode(gin.ReleaseMode) @@ -137,13 +151,16 @@ func main() { EditMenu.AddText("Select All", keys.CmdOrCtrl("a"), func(_ *menu.CallbackData) {}) // Start Wails application + // We use a dummy handler for AssetServer to prevent wails from complaining err := wails.Run(&options.App{ Title: "WeKnora Lite", Width: 1280, Height: 800, Menu: AppMenu, AssetServer: &assetserver.Options{ - Assets: nil, + Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusNotFound) + }), }, StartHidden: false, // Show window on startup OnStartup: app.startup, diff --git a/scripts/package-mac-app.sh b/scripts/package-mac-app.sh index d4ab225f..7f4971c2 100755 --- a/scripts/package-mac-app.sh +++ b/scripts/package-mac-app.sh @@ -72,6 +72,12 @@ fi if [ -d migrations/sqlite ]; then cp -r migrations/sqlite/* "${RESOURCES_DIR}/migrations/sqlite/" fi +if [ -d config ]; then + cp -r config/* "${RESOURCES_DIR}/config/" +fi +if [ -d web ]; then + cp -r web "${RESOURCES_DIR}/" +fi # 注意:Wails build 生成的二进制文件工作目录默认是 app 的 Contents/MacOS 目录 # 后续可能需要调整代码中对配置文件的路径读取逻辑。