Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
818dd5b71e | ||
![]() |
6561ff52f7 | ||
![]() |
e5a77ddf79 | ||
![]() |
869f222718 | ||
![]() |
431b8c5109 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
check/firefox/*
|
7
Makefile
Normal file
7
Makefile
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
VERSION=0.0.02
|
||||||
|
|
||||||
|
fmt:
|
||||||
|
gofmt -w -s *.go
|
||||||
|
|
||||||
|
release: fmt
|
||||||
|
gothub release -p -u eyedeekay -r "go-fpw" -t v$(VERSION) -n "lib" -d "tag for release"
|
BIN
check/check
Executable file
BIN
check/check
Executable file
Binary file not shown.
10
check/main.go
Normal file
10
check/main.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"github.com/eyedeekay/go-fpw"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
log.Println(fcw.PortablePath())
|
||||||
|
}
|
@@ -34,7 +34,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
func messageBox(title, text string) bool {
|
func MessageBox(title, text string) bool {
|
||||||
if runtime.GOOS == "linux" {
|
if runtime.GOOS == "linux" {
|
||||||
err := exec.Command("zenity", "--question", "--title", title, "--text", text).Run()
|
err := exec.Command("zenity", "--question", "--title", title, "--text", text).Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -31,7 +31,7 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
func messageBox(title, text string) bool {
|
func MessageBox(title, text string) bool {
|
||||||
user32 := syscall.NewLazyDLL("user32.dll")
|
user32 := syscall.NewLazyDLL("user32.dll")
|
||||||
messageBoxW := user32.NewProc("MessageBoxW")
|
messageBoxW := user32.NewProc("MessageBoxW")
|
||||||
mbYesNo := 0x00000004
|
mbYesNo := 0x00000004
|
||||||
|
53
ui.go
53
ui.go
@@ -30,6 +30,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -45,6 +46,49 @@ type UI interface {
|
|||||||
// executable file.
|
// executable file.
|
||||||
var FirefoxExecutable = LocateFirefox
|
var FirefoxExecutable = LocateFirefox
|
||||||
|
|
||||||
|
func PortablePath() string {
|
||||||
|
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
|
||||||
|
if err != nil {
|
||||||
|
log.Println("An error was encountered detecting the portable path", err)
|
||||||
|
}
|
||||||
|
listing, err := ioutil.ReadDir(dir)
|
||||||
|
for _, appdir := range listing {
|
||||||
|
if appdir.IsDir() {
|
||||||
|
for _, exe := range portableFiles() {
|
||||||
|
path := filepath.Join(dir, appdir.Name(), exe)
|
||||||
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
log.Println(path)
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "false"
|
||||||
|
}
|
||||||
|
|
||||||
|
func portableFiles() []string {
|
||||||
|
var paths []string
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "windows":
|
||||||
|
paths = []string{
|
||||||
|
"firefox.exe",
|
||||||
|
"icecat.exe",
|
||||||
|
"waterfox.exe",
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
paths = []string{
|
||||||
|
"firefox-esr",
|
||||||
|
"firefox",
|
||||||
|
"waterfox",
|
||||||
|
"icecat",
|
||||||
|
"purebrowser",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return paths
|
||||||
|
}
|
||||||
|
|
||||||
// LocateFirefox returns a path to the Firefox binary, or an empty string if
|
// LocateFirefox returns a path to the Firefox binary, or an empty string if
|
||||||
// Firefox installation is not found.
|
// Firefox installation is not found.
|
||||||
func LocateFirefox() string {
|
func LocateFirefox() string {
|
||||||
@@ -56,6 +100,11 @@ func LocateFirefox() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
portable := PortablePath()
|
||||||
|
if portable != "false" {
|
||||||
|
return portable
|
||||||
|
}
|
||||||
|
|
||||||
var paths []string
|
var paths []string
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "darwin":
|
case "darwin":
|
||||||
@@ -79,7 +128,9 @@ func LocateFirefox() string {
|
|||||||
paths = []string{
|
paths = []string{
|
||||||
"/usr/bin/firefox-esr",
|
"/usr/bin/firefox-esr",
|
||||||
"/usr/bin/firefox",
|
"/usr/bin/firefox",
|
||||||
|
"/usr/bin/waterfox",
|
||||||
"/usr/bin/icecat",
|
"/usr/bin/icecat",
|
||||||
|
"/usr/bin/purebrowser",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +150,7 @@ func PromptDownload() {
|
|||||||
text := "No Firefox installation was found. Would you like to download and install it now?"
|
text := "No Firefox installation was found. Would you like to download and install it now?"
|
||||||
|
|
||||||
// Ask user for confirmation
|
// Ask user for confirmation
|
||||||
if !messageBox(title, text) {
|
if !MessageBox(title, text) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user