7 Commits
v ... master

Author SHA1 Message Date
idk
c8b4dcdc74 Prompt to download 2020-05-11 22:28:37 -04:00
idk
c4225f76da Prompt to download 2020-05-11 22:28:08 -04:00
idk
818dd5b71e fmt and bump 2020-05-11 20:01:55 -04:00
idk
6561ff52f7 Make messageboxes public 2020-05-11 19:57:58 -04:00
idk
e5a77ddf79 add purebrowser, firefox portable support 2020-05-11 19:51:56 -04:00
idk
869f222718 add purebrowser, firefox portable support 2020-05-11 19:51:45 -04:00
idk
431b8c5109 add waterfox and palemoon when installed to /usr/bin/ on Linux 2020-05-11 18:23:06 -04:00
7 changed files with 76 additions and 3 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
check/firefox/*

7
Makefile Normal file
View File

@@ -0,0 +1,7 @@
VERSION=0.0.03
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

Binary file not shown.

10
check/main.go Normal file
View File

@@ -0,0 +1,10 @@
package main
import (
"log"
"github.com/eyedeekay/go-fpw"
)
func main() {
log.Println(fcw.PortablePath())
}

View File

@@ -34,7 +34,7 @@ import (
"syscall"
)
func messageBox(title, text string) bool {
func MessageBox(title, text string) bool {
if runtime.GOOS == "linux" {
err := exec.Command("zenity", "--question", "--title", title, "--text", text).Run()
if err != nil {

View File

@@ -31,7 +31,7 @@ import (
"unsafe"
)
func messageBox(title, text string) bool {
func MessageBox(title, text string) bool {
user32 := syscall.NewLazyDLL("user32.dll")
messageBoxW := user32.NewProc("MessageBoxW")
mbYesNo := 0x00000004

57
ui.go
View File

@@ -30,6 +30,7 @@ import (
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
@@ -45,6 +46,49 @@ type UI interface {
// executable file.
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
// Firefox installation is not found.
func LocateFirefox() string {
@@ -56,6 +100,11 @@ func LocateFirefox() string {
}
}
portable := PortablePath()
if portable != "false" {
return portable
}
var paths []string
switch runtime.GOOS {
case "darwin":
@@ -79,7 +128,9 @@ func LocateFirefox() string {
paths = []string{
"/usr/bin/firefox-esr",
"/usr/bin/firefox",
"/usr/bin/waterfox",
"/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?"
// Ask user for confirmation
if !messageBox(title, text) {
if !MessageBox(title, text) {
return
}
@@ -197,6 +248,10 @@ func (c *firefox) kill() error {
func newFirefoxWithArgs(firefoxBinary string, args ...string) (*firefox, error) {
// The first two IDs are used internally during the initialization
if firefoxBinary == "" {
PromptDownload()
return nil, fmt.Errorf("Firefox not found.")
}
c := &firefox{
id: 2,
}