fix: Electron desktop app startup and add install script
- tryElectronApp() now finds the project directory via LAZY_UPDATE_MANAGER_DIR env, CWD, binary path, or $HOME - Launches node_modules/.bin/electron directly instead of npm start (avoids recompiling the Go backend on every launch) - Add install.sh with Electron fallback, desktop launcher, and prefer_electron config - Desktop entry points to electron launcher for wofi support - Update electron to v41.7.1
This commit is contained in:
@@ -288,20 +288,64 @@ func defaultConfigPath() string {
|
||||
}
|
||||
|
||||
func tryElectronApp() error {
|
||||
// Try to find and launch the Electron app
|
||||
cmd := exec.Command("npm", "start")
|
||||
projectDir := electronProjectDir()
|
||||
if projectDir == "" {
|
||||
return errors.New("LazyUpdateManager project directory not found – set LAZY_UPDATE_MANAGER_DIR or run from the project folder")
|
||||
}
|
||||
|
||||
electronBin := filepath.Join(projectDir, "node_modules", ".bin", "electron")
|
||||
if _, err := os.Stat(electronBin); err != nil {
|
||||
electronBin = "electron"
|
||||
}
|
||||
|
||||
cmd := exec.Command(electronBin, projectDir)
|
||||
cmd.Dir = projectDir
|
||||
cmd.Stdout = nil
|
||||
cmd.Stderr = nil
|
||||
cmd.Stdin = nil
|
||||
if err := cmd.Run(); err != nil {
|
||||
// Try electron directly
|
||||
cmd = exec.Command("electron", ".")
|
||||
cmd.Stdout = nil
|
||||
cmd.Stderr = nil
|
||||
cmd.Stdin = nil
|
||||
return cmd.Run()
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
func electronProjectDir() string {
|
||||
if d := os.Getenv("LAZY_UPDATE_MANAGER_DIR"); d != "" {
|
||||
if hasElectronMain(d) {
|
||||
return d
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
if d, err := os.Getwd(); err == nil && hasElectronMain(d) {
|
||||
return d
|
||||
}
|
||||
|
||||
exe, err := os.Executable()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
exeDir := filepath.Dir(exe)
|
||||
|
||||
// binary in ~/Projekte/LazyUpdateManager/bin/
|
||||
if p := filepath.Dir(exeDir); hasElectronMain(p) {
|
||||
return p
|
||||
}
|
||||
|
||||
// binary in ~/.local/bin/, project is at configured location
|
||||
if p := filepath.Join(exeDir, "..", "Projekte", "LazyUpdateManager"); hasElectronMain(p) {
|
||||
return p
|
||||
}
|
||||
|
||||
// relative to $HOME
|
||||
if home, err := os.UserHomeDir(); err == nil {
|
||||
if p := filepath.Join(home, "Projekte", "LazyUpdateManager"); hasElectronMain(p) {
|
||||
return p
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func hasElectronMain(dir string) bool {
|
||||
info, err := os.Stat(filepath.Join(dir, "electron", "main.cjs"))
|
||||
return err == nil && !info.IsDir()
|
||||
}
|
||||
|
||||
func usage() {
|
||||
|
||||
Reference in New Issue
Block a user