mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-12-22 09:00:10 +00:00
add "autostart on login" option to tray
This commit is contained in:
parent
8cf9b1f905
commit
5dee414596
1
go.mod
1
go.mod
@ -12,6 +12,7 @@ replace github.com/hrfee/jfa-go/logger => ./logger
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||||
|
github.com/emersion/go-autostart v0.0.0-20210130080809-00ed301c8e9a // indirect
|
||||||
github.com/fatih/color v1.10.0
|
github.com/fatih/color v1.10.0
|
||||||
github.com/fsnotify/fsnotify v1.4.9
|
github.com/fsnotify/fsnotify v1.4.9
|
||||||
github.com/getlantern/systray v1.1.0 // indirect
|
github.com/getlantern/systray v1.1.0 // indirect
|
||||||
|
2
go.sum
2
go.sum
@ -26,6 +26,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumC
|
|||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||||
github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk=
|
github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk=
|
||||||
github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
|
github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
|
||||||
|
github.com/emersion/go-autostart v0.0.0-20210130080809-00ed301c8e9a h1:M88ob4TyDnEqNuL3PgsE/p3bDujfspnulR+0dQWNYZs=
|
||||||
|
github.com/emersion/go-autostart v0.0.0-20210130080809-00ed301c8e9a/go.mod h1:buzQsO8HHkZX2Q45fdfGH1xejPjuDQaXH8btcYMFzPM=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473 h1:4cmBvAEBNJaGARUEs3/suWRyfyBfhf7I60WBZq+bv2w=
|
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473 h1:4cmBvAEBNJaGARUEs3/suWRyfyBfhf7I60WBZq+bv2w=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
github.com/envoyproxy/protoc-gen-validate v0.1.0 h1:EQciDnbrYxy13PgWoY8AqoxGiPrpgBZ1R8UNe3ddc+A=
|
github.com/envoyproxy/protoc-gen-validate v0.1.0 h1:EQciDnbrYxy13PgWoY8AqoxGiPrpgBZ1R8UNe3ddc+A=
|
||||||
|
44
tray.go
44
tray.go
@ -3,11 +3,14 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"path/filepath"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/emersion/go-autostart"
|
||||||
"github.com/getlantern/systray"
|
"github.com/getlantern/systray"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,14 +33,34 @@ func onReady() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to load favicon: %v", err)
|
log.Fatalf("Failed to load favicon: %v", err)
|
||||||
}
|
}
|
||||||
|
command := os.Args
|
||||||
|
command[0], _ = filepath.Abs(command[0])
|
||||||
|
// Make sure to replace any relative paths with absolute ones
|
||||||
|
pathArgs := []string{"-d", "-data", "-c", "-config"}
|
||||||
|
for i := 1; i < len(command); i++ {
|
||||||
|
isPath := false
|
||||||
|
for _, p := range pathArgs {
|
||||||
|
if command[i-1] == p {
|
||||||
|
isPath = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if isPath {
|
||||||
|
command[i], _ = filepath.Abs(command[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
as := &autostart.App{
|
||||||
|
Name: "jfa-go",
|
||||||
|
DisplayName: "A user management system for Jellyfin",
|
||||||
|
Exec: command,
|
||||||
|
}
|
||||||
systray.SetIcon(icon)
|
systray.SetIcon(icon)
|
||||||
systray.SetTitle("jfa-go")
|
systray.SetTitle("jfa-go")
|
||||||
mStart := systray.AddMenuItem("Start", "Start jfa-go")
|
mStart := systray.AddMenuItem("Start", "Start jfa-go")
|
||||||
mStop := systray.AddMenuItem("Stop", "Stop jfa-go")
|
mStop := systray.AddMenuItem("Stop", "Stop jfa-go")
|
||||||
mRestart := systray.AddMenuItem("Restart", "Restart jfa-go")
|
mRestart := systray.AddMenuItem("Restart", "Restart jfa-go")
|
||||||
mQuit := systray.AddMenuItem("Quit", "Quit jfa-go")
|
mQuit := systray.AddMenuItem("Quit", "Quit jfa-go")
|
||||||
mOnBoot := systray.AddMenuItemCheckbox("Run on login", "Run jfa-go on user login.", false)
|
mOnLogin := systray.AddMenuItemCheckbox("Run on login", "Run jfa-go on user login.", as.IsEnabled())
|
||||||
|
|
||||||
c := make(chan os.Signal, 1)
|
c := make(chan os.Signal, 1)
|
||||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
@ -89,6 +112,23 @@ func onReady() {
|
|||||||
}
|
}
|
||||||
case <-mQuit.ClickedCh:
|
case <-mQuit.ClickedCh:
|
||||||
systray.Quit()
|
systray.Quit()
|
||||||
|
case <-mOnLogin.ClickedCh:
|
||||||
|
fmt.Printf("Checked: %t, Enabled: %t\n", mOnLogin.Checked(), as.IsEnabled())
|
||||||
|
if !mOnLogin.Checked() {
|
||||||
|
if err := as.Enable(); err != nil {
|
||||||
|
log.Printf("Failed to enable autostart on login: %v", err)
|
||||||
|
} else {
|
||||||
|
mOnLogin.Check()
|
||||||
|
log.Printf("Enabled autostart")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := as.Disable(); err != nil {
|
||||||
|
log.Printf("Failed to disable autostart on login: %v", err)
|
||||||
|
} else {
|
||||||
|
mOnLogin.Uncheck()
|
||||||
|
log.Printf("Disabled autostart")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user