fix: resolve blank page in Windows/Mac releases by removing Go embed

This commit is contained in:
vndangkhoa 2026-03-10 08:12:05 +07:00
parent d674c89c47
commit 9a7b3dd723
4 changed files with 23 additions and 53 deletions

View file

@ -1,11 +1,8 @@
package main package main
import ( import (
"embed"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"io/fs"
"net/http" "net/http"
"os" "os"
"os/exec" "os/exec"
@ -19,9 +16,6 @@ import (
"github.com/kv/clearnup/backend/internal/scanner" "github.com/kv/clearnup/backend/internal/scanner"
) )
//go:embed all:dist
var distFS embed.FS
const Port = ":36969" const Port = ":36969"
func enableCors(w *http.ResponseWriter) { func enableCors(w *http.ResponseWriter) {
@ -53,42 +47,8 @@ func main() {
http.HandleFunc("/api/apps/action", handleAppAction) http.HandleFunc("/api/apps/action", handleAppAction)
http.HandleFunc("/api/apps/uninstall", handleAppUninstall) http.HandleFunc("/api/apps/uninstall", handleAppUninstall)
// Static File Serving (SPA Support) // Static File Serving is handled directly by Electron.
// Check if we are running with embedded files or local dist // Backend only needs to provide API routes.
// 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)
})
}
}
}
fmt.Printf("🚀 Antigravity Backend running on http://localhost%s\n", Port) fmt.Printf("🚀 Antigravity Backend running on http://localhost%s\n", Port)

View file

@ -292,7 +292,8 @@ var startBackend = () => {
console.log("Development mode: Backend should be running via start-go.sh"); console.log("Development mode: Backend should be running via start-go.sh");
return; 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); console.log("Starting backend from:", backendPath);
try { try {
backendProcess = (0, import_child_process3.spawn)(backendPath, [], { backendProcess = (0, import_child_process3.spawn)(backendPath, [], {

View file

@ -22,7 +22,8 @@ const startBackend = () => {
return; 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); console.log('Starting backend from:', backendPath);
try { try {

View file

@ -1,5 +1,5 @@
{ {
"name": "Lumina", "name": "lumina",
"private": true, "private": true,
"version": "1.0.0", "version": "1.0.0",
"type": "module", "type": "module",
@ -10,7 +10,9 @@
"electron:build": "node scripts/build-electron.mjs", "electron:build": "node scripts/build-electron.mjs",
"build": "tsc -b && vite build", "build": "tsc -b && vite build",
"build:go:mac": "sh scripts/build-go.sh", "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: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 .", "lint": "eslint .",
"preview": "vite preview", "preview": "vite preview",
"preinstall": "node scripts/check-pnpm.js" "preinstall": "node scripts/check-pnpm.js"
@ -64,24 +66,30 @@
], ],
"icon": "build/icon.png", "icon": "build/icon.png",
"category": "public.app-category.utilities", "category": "public.app-category.utilities",
"hardenedRuntime": false "hardenedRuntime": false,
},
"win": {
"target": [
"portable"
],
"icon": "build/icon.png"
},
"files": [
"dist/**/*",
"dist-electron/**/*",
"package.json"
],
"extraResources": [ "extraResources": [
{ {
"from": "backend/dist/universal/backend", "from": "backend/dist/universal/backend",
"to": "backend" "to": "backend"
} }
] ]
},
"win": {
"target": [
"portable"
],
"icon": "build/icon.png",
"extraResources": [
{
"from": "backend/dist/windows/backend.exe",
"to": "backend.exe"
}
]
},
"files": [
"dist/**/*",
"dist-electron/**/*",
"package.json"
]
} }
} }