Skip to content

Commit

Permalink
feat: expand browser support
Browse files Browse the repository at this point in the history
Add support for Edge, Waterfox, IceDragon and others.
  • Loading branch information
dessant committed Feb 9, 2020
1 parent c159b03 commit 5b8ace7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ of the browser extension.

## License

Copyright (c) 2019 Armin Sebastian
Copyright (c) 2019-2020 Armin Sebastian

This software is released under the terms of the GNU General Public License v3.0.
See the [LICENSE](LICENSE) file for further information.
Expand Down
28 changes: 17 additions & 11 deletions cmd/setup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ func getLocation(browser, targetEnv string) (map[string]string, error) {
home := usr.HomeDir

manifestDir := map[string]string{
"chrome": filepath.Join(home, ".config/google-chrome/NativeMessagingHosts"),
"firefox": filepath.Join(home, ".mozilla/native-messaging-hosts"),
"opera": filepath.Join(home, ".config/google-chrome/NativeMessagingHosts"),
// targets
"chrome": filepath.Join(home, ".config/google-chrome/NativeMessagingHosts"),
"firefox": filepath.Join(home, ".mozilla/native-messaging-hosts"),
"opera": filepath.Join(home, ".config/google-chrome/NativeMessagingHosts"),
//browsers
"chromium": filepath.Join(home, ".config/chromium/NativeMessagingHosts"),
}
manifest := manifestDir[browser]
Expand All @@ -130,10 +132,14 @@ func getLocation(browser, targetEnv string) (map[string]string, error) {
home := usr.HomeDir

manifestDir := map[string]string{
"chrome": filepath.Join(home, "Library/Application Support/Google/Chrome/NativeMessagingHosts"),
"firefox": filepath.Join(home, "Library/Application Support/Mozilla/NativeMessagingHosts"),
"opera": filepath.Join(home, "Library/Application Support/Google/Chrome/NativeMessagingHosts"),
"chromium": filepath.Join(home, "Library/Application Support/Chromium/NativeMessagingHosts"),
// targets
"chrome": filepath.Join(home, "Library/Application Support/Google/Chrome/NativeMessagingHosts"),
"edge": filepath.Join(home, "Library/Application Support/Microsoft Edge/NativeMessagingHosts"),
"firefox": filepath.Join(home, "Library/Application Support/Mozilla/NativeMessagingHosts"),
"opera": filepath.Join(home, "Library/Application Support/Google/Chrome/NativeMessagingHosts"),
//browsers
"chromium": filepath.Join(home, "Library/Application Support/Chromium/NativeMessagingHosts"),
"microsoft edge": filepath.Join(home, "Library/Application Support/Microsoft Edge/NativeMessagingHosts"),
}
manifest := manifestDir[browser]
if manifest == "" {
Expand All @@ -151,7 +157,7 @@ func getLocation(browser, targetEnv string) (map[string]string, error) {
return location, nil
}

func install(manifestDir, appDir, targetEnv, extension string) error {
func install(manifestDir, appDir, browser, targetEnv, extension string) error {
execName := utils.GetExecName("buster-client")
execPath := filepath.Join(appDir, execName)
if err := restoreAsset(execPath, execName); err != nil {
Expand Down Expand Up @@ -220,7 +226,7 @@ func install(manifestDir, appDir, targetEnv, extension string) error {
}

if runtime.GOOS == "windows" {
if err := setManifestRegistry(targetEnv, manifestPath); err != nil {
if err := setManifestRegistry(browser, targetEnv, manifestPath); err != nil {
log.Println(err)
return errors.New("cannot set registry value")
}
Expand Down Expand Up @@ -265,7 +271,6 @@ func update() error {
return nil
}


func writeError(res http.ResponseWriter, error error) {
response, _ := json.Marshal(map[string]string{"error": error.Error()})
res.Header().Set("Content-Type", "application/json")
Expand Down Expand Up @@ -316,11 +321,12 @@ func installHandler(res http.ResponseWriter, req *http.Request) {
if isValidSession(req.FormValue("session")) {
appDir := req.FormValue("appDir")
manifestDir := req.FormValue("manifestDir")
browser := req.FormValue("browser")
targetEnv := req.FormValue("targetEnv")
extension := req.FormValue("extension")

log.Println("Installing client")
if err := install(manifestDir, appDir, targetEnv, extension); err != nil {
if err := install(manifestDir, appDir, browser, targetEnv, extension); err != nil {
writeError(res, err)
return
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/setup/main_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

package main

func setManifestRegistry(targetEnv, manifestPath string) error {
func setManifestRegistry(browser, targetEnv, manifestPath string) error {
return nil
}
10 changes: 8 additions & 2 deletions cmd/setup/main_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import (
"golang.org/x/sys/windows/registry"
)

func setManifestRegistry(targetEnv, manifestPath string) error {
func setManifestRegistry(browser, targetEnv, manifestPath string) error {
var key string
if targetEnv == "firefox" {
if browser == "waterfox" {
key = `SOFTWARE\Waterfox\NativeMessagingHosts\`
} else if browser == "icedragon" {
key = `SOFTWARE\ComodoGroup\NativeMessagingHosts\`
} else if browser == "cliqz" {
key = `SOFTWARE\Cliqz\NativeMessagingHosts\`
} else if targetEnv == "firefox" {
key = `SOFTWARE\Mozilla\NativeMessagingHosts\`
} else {
key = `SOFTWARE\Google\Chrome\NativeMessagingHosts\`
Expand Down

0 comments on commit 5b8ace7

Please sign in to comment.