-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e87088
commit bf95657
Showing
7 changed files
with
174 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
This is a running list of things that need to taken care of at some point: | ||
|
||
- [ ] Long subtract function too complex | ||
- [ ] Manifest requires registry key on Windows | ||
- [ ] There has got to be a way to figure out which XCode version is installed | ||
- [ ] The native messaging is broken on browsers installed by snap | ||
- this is an issue with the Firefox Snapcraft in particular: https://forum.snapcraft.io/t/firefox-snapcraft-native-messaging-behavior/40437 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,8 @@ | ||
package manifest | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
const name = "armaria" | ||
const description = "Armaria is a fast local-first bookmarks manager." | ||
const hostType = "stdio" | ||
const FirefoxExtension = "[email protected]" | ||
const ChromeExtension1 = "chrome-extension://cahkgigfdplmhgjbioakkgennhncioli/" | ||
const ChromeExtension2 = "chrome-extension://fbnilfpngakppdkddndcnckolmlpghdf/" | ||
//go:build !windows | ||
|
||
// TODO: Windows needs registry entiries. | ||
package manifest | ||
|
||
// InstallManifest installs the app manifest. | ||
func InstallManifest(path string, hostPath string, manifestType ManifestType) error { | ||
var err error | ||
var buffer []byte | ||
|
||
if manifestType == ManifestChrome || manifestType == ManifestChromium { | ||
manifest := chromeManifest{ | ||
Name: name, | ||
Description: description, | ||
Path: hostPath, | ||
HostType: hostType, | ||
AllowedOrigins: []string{ | ||
ChromeExtension1, | ||
ChromeExtension2, | ||
}, | ||
} | ||
|
||
buffer, err = json.Marshal(manifest) | ||
if err != nil { | ||
return fmt.Errorf("error marshalling manifest while installing manifest: %w", err) | ||
} | ||
} else if manifestType == ManifestFirefox { | ||
manifest := firefoxManifest{ | ||
Name: name, | ||
Description: description, | ||
Path: hostPath, | ||
HostType: hostType, | ||
AllowedExtensions: []string{FirefoxExtension}, | ||
} | ||
|
||
buffer, err = json.Marshal(manifest) | ||
if err != nil { | ||
return fmt.Errorf("error marshalling manifest while installing manifest: %w", err) | ||
} | ||
} | ||
|
||
handle, err := os.Create(path) | ||
if err != nil { | ||
return fmt.Errorf("error creating manifest file while installing manifest: %w", err) | ||
} | ||
defer handle.Close() | ||
|
||
_, err = handle.Write(buffer) | ||
if err != nil { | ||
return fmt.Errorf("error writing manfiest file contents while installing manifest: %w", err) | ||
} | ||
|
||
return nil | ||
return installManifest(path, hostPath, manifestType) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package manifest | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
const name = "armaria" | ||
const description = "Armaria is a fast local-first bookmarks manager." | ||
const hostType = "stdio" | ||
const FirefoxExtension = "[email protected]" | ||
const ChromeExtension1 = "chrome-extension://cahkgigfdplmhgjbioakkgennhncioli/" | ||
const ChromeExtension2 = "chrome-extension://fbnilfpngakppdkddndcnckolmlpghdf/" | ||
|
||
// installManifest installs the app manifest. | ||
func installManifest(path string, hostPath string, manifestType ManifestType) error { | ||
var err error | ||
var buffer []byte | ||
|
||
if manifestType == ManifestChrome || manifestType == ManifestChromium { | ||
manifest := chromeManifest{ | ||
Name: name, | ||
Description: description, | ||
Path: hostPath, | ||
HostType: hostType, | ||
AllowedOrigins: []string{ | ||
ChromeExtension1, | ||
ChromeExtension2, | ||
}, | ||
} | ||
|
||
buffer, err = json.Marshal(manifest) | ||
if err != nil { | ||
return fmt.Errorf("error marshalling manifest while installing manifest: %w", err) | ||
} | ||
} else if manifestType == ManifestFirefox { | ||
manifest := firefoxManifest{ | ||
Name: name, | ||
Description: description, | ||
Path: hostPath, | ||
HostType: hostType, | ||
AllowedExtensions: []string{FirefoxExtension}, | ||
} | ||
|
||
buffer, err = json.Marshal(manifest) | ||
if err != nil { | ||
return fmt.Errorf("error marshalling manifest while installing manifest: %w", err) | ||
} | ||
} | ||
|
||
handle, err := os.Create(path) | ||
if err != nil { | ||
return fmt.Errorf("error creating manifest file while installing manifest: %w", err) | ||
} | ||
defer handle.Close() | ||
|
||
_, err = handle.Write(buffer) | ||
if err != nil { | ||
return fmt.Errorf("error writing manfiest file contents while installing manifest: %w", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
//go:build windows | ||
|
||
package manifest | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"golang.org/x/sys/windows/registry" | ||
) | ||
|
||
// InstallManifest installs the app manifest. | ||
func InstallManifest(path string, hostPath string, manifestType ManifestType) error { | ||
err := installManifest(path, hostPath, manifestType) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Windows (unfortunately) requires registry entries here. | ||
if manifestType == ManifestChrome || manifestType == ManifestChromium { | ||
if err := writeKey(`Software\Google\Chrome\NativeMessagingHosts\armaria`, path); err != nil { | ||
return err | ||
} | ||
} else if manifestType == ManifestFirefox { | ||
if err := writeKey(`Software\Mozilla\NativeMessagingHosts\armaria`, path); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// writeKey writes value to registry key. | ||
// It gets written to both local machine and current user. | ||
func writeKey(path string, value string) error { | ||
localMachineKey, err := openKey(registry.LOCAL_MACHINE, path) | ||
if err != nil { | ||
return fmt.Errorf("error opening local machine key while installing manifest: %w", err) | ||
} | ||
defer localMachineKey.Close() | ||
|
||
if err := localMachineKey.SetStringValue("", value); err != nil { | ||
return fmt.Errorf("error writing local machine key while installing manifest: %w", err) | ||
} | ||
|
||
userKey, err := openKey(registry.CURRENT_USER, path) | ||
if err != nil { | ||
return fmt.Errorf("error opening current user key while installing manifest: %w", err) | ||
} | ||
defer userKey.Close() | ||
|
||
if err := userKey.SetStringValue("", value); err != nil { | ||
return fmt.Errorf("error writing current user key while installing manifest: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// openKey opens a key for writing. | ||
// It will create any parent keys necessary. | ||
func openKey(root registry.Key, path string) (registry.Key, error) { | ||
tokens := strings.Split(path, `\`) | ||
keys := []registry.Key{root} | ||
for _, token := range tokens { | ||
key, _, err := registry.CreateKey(keys[len(keys)-1], token, registry.WRITE) | ||
if err != nil { | ||
return key, err | ||
} | ||
keys = append(keys, key) | ||
} | ||
|
||
for i, key := range keys { | ||
if i != 0 && i != len(keys)-1 { | ||
key.Close() | ||
} | ||
} | ||
|
||
return keys[len(keys)-1], nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters