Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
fix: resolve desktop app crash on launch by fixing working directory and loading resources
wizardchen0a964ac0b778
diff --git a/cmd/desktop/main.go b/cmd/desktop/main.goindex 99778f954..f49254511 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 modeif 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 complainingerr := 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 startupOnStartup: app.startup,diff --git a/scripts/package-mac-app.sh b/scripts/package-mac-app.shindex d4ab225fd..7f4971c2a 100755--- a/scripts/package-mac-app.sh+++ b/scripts/package-mac-app.sh@@ -72,6 +72,12 @@ fiif [ -d migrations/sqlite ]; thencp -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 目录# 后续可能需要调整代码中对配置文件的路径读取逻辑。