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
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)

View file

@ -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, [], {

View file

@ -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 {

View file

@ -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
},
"win": {
"target": [
"portable"
],
"icon": "build/icon.png"
},
"files": [
"dist/**/*",
"dist-electron/**/*",
"package.json"
],
"hardenedRuntime": false,
"extraResources": [
{
"from": "backend/dist/universal/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"
]
}
}