diff --git a/launcher/exec.go b/launcher/exec.go index 98c9bca..b07c337 100644 --- a/launcher/exec.go +++ b/launcher/exec.go @@ -16,11 +16,11 @@ func getExecutableName() string { // Get the executable name based on the OS switch normalizeOS(runtime.GOOS) { case "linux": - return "./camoufox-bin" + return getPath("camoufox-bin") case "macos": - return "./Camoufox.app" + return getPath("Camoufox.app") case "windows": - return "./camoufox.exe" + return getPath("camoufox.exe") default: // This should never be reached due to the check in normalizeOS return "" diff --git a/launcher/main.go b/launcher/main.go index 8706858..745461b 100644 --- a/launcher/main.go +++ b/launcher/main.go @@ -60,6 +60,19 @@ func main() { runCamoufox(execName, args, addonsList) } +// Returns the absolute path relative to the launcher +func getPath(path string) string { + execPath, err := os.Executable() + if err != nil { + fmt.Printf("Error getting executable path: %v\n", err) + os.Exit(1) + } + execDir := filepath.Dir(execPath) + + addonPath := filepath.Join(execDir, path) + return addonPath +} + // Parses & removes an argument from the args list func parseArgs(param string, defaultValue string, args *[]string, removeFromArgs bool) string { for i := 0; i < len(*args); i++ { diff --git a/launcher/xpi-dl.go b/launcher/xpi-dl.go index 30c2233..66d74b9 100644 --- a/launcher/xpi-dl.go +++ b/launcher/xpi-dl.go @@ -110,27 +110,15 @@ func contains(slice []string, item string) bool { } // Returns the absolute path to the target addon location -func getAddonPath(addonName string) (string, error) { - execPath, err := os.Executable() - if err != nil { - fmt.Printf("Error getting executable path: %v\n", err) - return "", err - } - execDir := filepath.Dir(execPath) - - addonPath := filepath.Join(execDir, "addons", addonName) - return addonPath, nil +func getAddonPath(addonName string) string { + return getPath(filepath.Join("addons", addonName)) } // Downloads and extracts the addons func maybeDownloadAddons(addons map[string]string, addonsList *[]string) { for addonName, url := range addons { // Get the addon path - addonPath, err := getAddonPath(addonName) - if err != nil { - fmt.Printf("Error getting addon path: %v\n", err) - continue - } + addonPath := getAddonPath(addonName) // Check if the addon is already extracted if _, err := os.Stat(addonPath); !os.IsNotExist(err) { @@ -140,7 +128,7 @@ func maybeDownloadAddons(addons map[string]string, addonsList *[]string) { } // Addon doesn't exist, create directory and download - err = os.MkdirAll(addonPath, 0755) + err := os.MkdirAll(addonPath, 0755) if err != nil { fmt.Printf("Failed to create directory for %s: %v\n", addonName, err) continue