mirror of
https://forge.fsky.io/oneflux/omegafox.git
synced 2026-02-10 17:32:06 -08:00
Fix launcher not using abspath
- Gets the absolute path to the Camoufox binary - Other small refactoring
This commit is contained in:
parent
e8985d692a
commit
3dc4de7a80
3 changed files with 20 additions and 19 deletions
|
|
@ -16,11 +16,11 @@ func getExecutableName() string {
|
||||||
// Get the executable name based on the OS
|
// Get the executable name based on the OS
|
||||||
switch normalizeOS(runtime.GOOS) {
|
switch normalizeOS(runtime.GOOS) {
|
||||||
case "linux":
|
case "linux":
|
||||||
return "./camoufox-bin"
|
return getPath("camoufox-bin")
|
||||||
case "macos":
|
case "macos":
|
||||||
return "./Camoufox.app"
|
return getPath("Camoufox.app")
|
||||||
case "windows":
|
case "windows":
|
||||||
return "./camoufox.exe"
|
return getPath("camoufox.exe")
|
||||||
default:
|
default:
|
||||||
// This should never be reached due to the check in normalizeOS
|
// This should never be reached due to the check in normalizeOS
|
||||||
return ""
|
return ""
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,19 @@ func main() {
|
||||||
runCamoufox(execName, args, addonsList)
|
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
|
// Parses & removes an argument from the args list
|
||||||
func parseArgs(param string, defaultValue string, args *[]string, removeFromArgs bool) string {
|
func parseArgs(param string, defaultValue string, args *[]string, removeFromArgs bool) string {
|
||||||
for i := 0; i < len(*args); i++ {
|
for i := 0; i < len(*args); i++ {
|
||||||
|
|
|
||||||
|
|
@ -110,27 +110,15 @@ func contains(slice []string, item string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the absolute path to the target addon location
|
// Returns the absolute path to the target addon location
|
||||||
func getAddonPath(addonName string) (string, error) {
|
func getAddonPath(addonName string) string {
|
||||||
execPath, err := os.Executable()
|
return getPath(filepath.Join("addons", addonName))
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Downloads and extracts the addons
|
// Downloads and extracts the addons
|
||||||
func maybeDownloadAddons(addons map[string]string, addonsList *[]string) {
|
func maybeDownloadAddons(addons map[string]string, addonsList *[]string) {
|
||||||
for addonName, url := range addons {
|
for addonName, url := range addons {
|
||||||
// Get the addon path
|
// Get the addon path
|
||||||
addonPath, err := getAddonPath(addonName)
|
addonPath := getAddonPath(addonName)
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error getting addon path: %v\n", err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the addon is already extracted
|
// Check if the addon is already extracted
|
||||||
if _, err := os.Stat(addonPath); !os.IsNotExist(err) {
|
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
|
// Addon doesn't exist, create directory and download
|
||||||
err = os.MkdirAll(addonPath, 0755)
|
err := os.MkdirAll(addonPath, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to create directory for %s: %v\n", addonName, err)
|
fmt.Printf("Failed to create directory for %s: %v\n", addonName, err)
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue