Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c8b4dcdc74 | ||
![]() |
c4225f76da | ||
![]() |
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.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
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"
|
||||
)
|
||||
|
||||
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 {
|
||||
|
@@ -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
57
ui.go
@@ -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,
|
||||
}
|
||||
|
Reference in New Issue
Block a user