diff --git a/backend/main.go b/backend/main.go index be41de8..f0f1d22 100644 --- a/backend/main.go +++ b/backend/main.go @@ -1,11 +1,8 @@ package main import ( - "embed" "encoding/json" "fmt" - "io" - "io/fs" "net/http" "os" "os/exec" @@ -19,9 +16,6 @@ import ( "github.com/kv/clearnup/backend/internal/scanner" ) -//go:embed all:dist -var distFS embed.FS - const Port = ":36969" func enableCors(w *http.ResponseWriter) { @@ -53,42 +47,8 @@ func main() { http.HandleFunc("/api/apps/action", handleAppAction) http.HandleFunc("/api/apps/uninstall", handleAppUninstall) - // Static File Serving (SPA Support) - // Check if we are running with embedded files or local dist - // Priority: Embedded (Production) -> Local dist (Dev/Preview) - - // Try to get a sub-fs for "dist" from the embedded FS - distRoot, err := fs.Sub(distFS, "dist") - if err == nil { - fmt.Println("📂 Serving embedded static files") - // Check if it's actually populated (sanity check) - if _, err := distRoot.Open("index.html"); err == nil { - fsrv := http.FileServer(http.FS(distRoot)) - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - if filepath.Ext(r.URL.Path) == "" { - // Read index.html from embedded - index, _ := distRoot.Open("index.html") - stat, _ := index.Stat() - http.ServeContent(w, r, "index.html", stat.ModTime(), index.(io.ReadSeeker)) - return - } - fsrv.ServeHTTP(w, r) - }) - } else { - // Fallback to local ./dist if embedded is empty (e.g. dev mode without build) - if _, err := os.Stat("dist"); err == nil { - fmt.Println("📂 Serving static files from local ./dist") - fs := http.FileServer(http.Dir("dist")) - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - if filepath.Ext(r.URL.Path) == "" { - http.ServeFile(w, r, "dist/index.html") - return - } - fs.ServeHTTP(w, r) - }) - } - } - } + // Static File Serving is handled directly by Electron. + // Backend only needs to provide API routes. fmt.Printf("🚀 Antigravity Backend running on http://localhost%s\n", Port) diff --git a/dist-electron/main.cjs b/dist-electron/main.cjs index 0fb1cef..a66aabd 100644 --- a/dist-electron/main.cjs +++ b/dist-electron/main.cjs @@ -292,7 +292,8 @@ var startBackend = () => { console.log("Development mode: Backend should be running via start-go.sh"); return; } - const backendPath = import_path3.default.join(process.resourcesPath, "backend"); + const backendExec = process.platform === "win32" ? "backend.exe" : "backend"; + const backendPath = import_path3.default.join(process.resourcesPath, backendExec); console.log("Starting backend from:", backendPath); try { backendProcess = (0, import_child_process3.spawn)(backendPath, [], { diff --git a/electron/main.ts b/electron/main.ts index 89769e0..49ea0de 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -22,7 +22,8 @@ const startBackend = () => { return; } - const backendPath = path.join(process.resourcesPath, 'backend'); + const backendExec = process.platform === 'win32' ? 'backend.exe' : 'backend'; + const backendPath = path.join(process.resourcesPath, backendExec); console.log('Starting backend from:', backendPath); try { diff --git a/package.json b/package.json index d963295..946c410 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "Lumina", + "name": "lumina", "private": true, "version": "1.0.0", "type": "module", @@ -10,7 +10,9 @@ "electron:build": "node scripts/build-electron.mjs", "build": "tsc -b && vite build", "build:go:mac": "sh scripts/build-go.sh", + "build:go:win": "GOOS=windows GOARCH=amd64 go build -ldflags=\"-s -w\" -o backend/dist/windows/backend.exe backend/main.go", "build:mac": "pnpm run build:go:mac && pnpm run build && pnpm run electron:build && electron-builder --mac --universal", + "build:win": "pnpm run build:go:win && pnpm run build && pnpm run electron:build && electron-builder --win portable --x64", "lint": "eslint .", "preview": "vite preview", "preinstall": "node scripts/check-pnpm.js" @@ -64,24 +66,30 @@ ], "icon": "build/icon.png", "category": "public.app-category.utilities", - "hardenedRuntime": false + "hardenedRuntime": false, + "extraResources": [ + { + "from": "backend/dist/universal/backend", + "to": "backend" + } + ] }, "win": { "target": [ "portable" ], - "icon": "build/icon.png" + "icon": "build/icon.png", + "extraResources": [ + { + "from": "backend/dist/windows/backend.exe", + "to": "backend.exe" + } + ] }, "files": [ "dist/**/*", "dist-electron/**/*", "package.json" - ], - "extraResources": [ - { - "from": "backend/dist/universal/backend", - "to": "backend" - } ] } } \ No newline at end of file