Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions login/login_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
)

const (
plistName = "com.zee.app.plist"
appBundle = "/Applications/Zee.app/Contents/MacOS/zee"
bundleSig = ".app/Contents/MacOS/"
plistNameApp = "com.zee.app.plist" // installed /Applications/Zee.app
plistNameDev = "com.zee.app.dev.plist" // local dev build
bundleSig = ".app/Contents/MacOS/"
)

func xmlEscape(s string) string {
Expand All @@ -23,12 +23,31 @@ func xmlEscape(s string) string {
return b.String()
}

// isRunningFromApp reports whether this binary is the installed Zee.app bundle
// rather than a local dev build. The login item (plist filename, launchd Label,
// and target binary) is keyed off this so a dev build never clobbers — or gets
// clobbered by — the installed app's entry.
func isRunningFromApp() bool {
exe, err := os.Executable()
if err != nil {
return false
}
return strings.Contains(exe, bundleSig)
}

func plistName() string {
if isRunningFromApp() {
return plistNameApp
}
return plistNameDev
}

func plistPath() (string, error) {
home, err := os.UserHomeDir()
if err != nil {
return "", err
}
return filepath.Join(home, "Library", "LaunchAgents", plistName), nil
return filepath.Join(home, "Library", "LaunchAgents", plistName()), nil
}

func Enabled() bool {
Expand All @@ -40,24 +59,10 @@ func Enabled() bool {
return err == nil
}

func bundleExe() (string, error) {
exe, err := os.Executable()
if err != nil {
return "", fmt.Errorf("resolve executable: %w", err)
}
if strings.Contains(exe, bundleSig) {
return exe, nil
}
if _, err := os.Stat(appBundle); err == nil {
return appBundle, nil
}
return "", fmt.Errorf("Zee.app not found in /Applications — install it first")
}

func Enable() error {
exe, err := bundleExe()
exe, err := os.Executable()
if err != nil {
return err
return fmt.Errorf("resolve executable: %w", err)
}

var env strings.Builder
Expand Down Expand Up @@ -86,7 +91,7 @@ func Enable() error {
%s </dict>
</dict>
</plist>
`, plistName, xmlEscape(exe), env.String())
`, plistName(), xmlEscape(exe), env.String())

path, err := plistPath()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions tray/tray_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func updateRecordingIcon(rec bool) {
mRecord.SetTitle("● Stop Recording (Shift+Control+Space)")
}
} else {
systray.SetTemplateIcon(iconIdleHi, iconIdle)
systray.SetIcon(iconIdleHi)
if mRecord != nil {
mRecord.SetTitle("○ Start Recording (Shift+Control+Space)")
}
Expand Down Expand Up @@ -155,7 +155,7 @@ func RefreshDevices(names []string, selected string) {
}

func onReady() {
systray.SetTemplateIcon(iconIdleHi, iconIdle)
systray.SetIcon(iconIdleHi)
systray.SetTooltip("zee – push to talk")

mStatus = systray.AddMenuItem(statusText(), "")
Expand Down