From 8a9a34363fc37af8b141047bae2a0fb3605247d5 Mon Sep 17 00:00:00 2001 From: Jamie Banks Date: Tue, 9 Jun 2026 12:51:43 +0100 Subject: [PATCH] feat: implement Linux auto-installation and update Windows build process to use NSIS installer --- .gitea/workflows/build.yml | 6 ++-- Dockerfile.build | 1 + main.go | 62 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index c5af372..b72582e 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -30,8 +30,8 @@ jobs: cp build/bin/goexplore dist/goexplore-linux-amd64 # Windows amd64 - wails build -platform windows/amd64 -clean - cp build/bin/goexplore.exe dist/goexplore-windows-amd64.exe + wails build -platform windows/amd64 -clean -nsis + cp build/bin/goexplore-amd64-installer.exe dist/goexplore-windows-installer.exe " @@ -44,7 +44,7 @@ jobs: R2_ENDPOINT: ${{ secrets.R2_ENDPOINT_URL }} run: | aws s3 cp dist/goexplore-linux-amd64 s3://apps/goexplore/goexplore-linux-amd64 --endpoint-url "$R2_ENDPOINT" - aws s3 cp dist/goexplore-windows-amd64.exe s3://apps/goexplore/goexplore-windows-amd64.exe --endpoint-url "$R2_ENDPOINT" + aws s3 cp dist/goexplore-windows-installer.exe s3://apps/goexplore/goexplore-windows-installer.exe --endpoint-url "$R2_ENDPOINT" - name: Clean up run: sudo rm -rf dist build/bin/* diff --git a/Dockerfile.build b/Dockerfile.build index cdba756..9e504c3 100644 --- a/Dockerfile.build +++ b/Dockerfile.build @@ -5,6 +5,7 @@ RUN apt-get update && apt-get install -y \ curl \ gcc \ mingw-w64 \ + nsis \ libgtk-3-dev \ libwebkit2gtk-4.1-dev \ && rm -rf /var/lib/apt/lists/* diff --git a/main.go b/main.go index df49852..f7ba87d 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,11 @@ package main import ( "embed" + "fmt" + "os" + "os/exec" + "path/filepath" + "runtime" "github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2/pkg/options" @@ -15,7 +20,64 @@ var assets embed.FS //go:embed build/appicon.png var icon []byte +func installLinux() { + if runtime.GOOS != "linux" { + return + } + + exe, err := os.Executable() + if err != nil { + return + } + + home, err := os.UserHomeDir() + if err != nil { + return + } + + targetDir := filepath.Join(home, ".local", "bin") + targetExe := filepath.Join(targetDir, "goexplore") + + // If we are already running from the target path, do nothing. + if exe == targetExe { + return + } + + // Ensure target directories exist + os.MkdirAll(targetDir, 0755) + + // Copy the executable + data, err := os.ReadFile(exe) + if err == nil { + os.WriteFile(targetExe, data, 0755) + } + + // Write the application icon + iconDir := filepath.Join(home, ".local", "share", "icons", "hicolor", "512x512", "apps") + os.MkdirAll(iconDir, 0755) + os.WriteFile(filepath.Join(iconDir, "goexplore.png"), icon, 0644) + + // Write the desktop shortcut file + appDir := filepath.Join(home, ".local", "share", "applications") + os.MkdirAll(appDir, 0755) + desktopContent := fmt.Sprintf(`[Desktop Entry] +Name=GoExplore +Exec=%s +Icon=goexplore +Type=Application +Terminal=false +Categories=Utility;FileTools;`, targetExe) + os.WriteFile(filepath.Join(appDir, "goexplore.desktop"), []byte(desktopContent), 0644) + + // Execute the newly installed binary and exit the current running process + cmd := exec.Command(targetExe) + cmd.Start() + os.Exit(0) +} + func main() { + installLinux() + // Create an instance of the app structure app := NewApp()