-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
67 lines (56 loc) · 1.54 KB
/
main.go
File metadata and controls
67 lines (56 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
_ "embed"
"encoding/json"
"fmt"
"os"
"golang.org/x/sys/windows"
"github.com/getlantern/systray"
)
//go:embed assets/icon_active.ico
var iconActive []byte
//go:embed assets/icon_inactive.ico
var iconInactive []byte
type Config struct {
TailscalePath string `json:"tailscalePath"`
TrustedSSIDs []string `json:"trustedSSIDs"`
ExitNodes []string `json:"exitNodes"`
}
var config Config
var tailscalePath string
var currentVersion = "v2.1.3"
var startupDir = os.Getenv("APPDATA") + `\Microsoft\Windows\Start Menu\Programs\Startup`
var mutexHandle windows.Handle
func main() {
mutexName, _ := windows.UTF16PtrFromString("Global\\AutoExitNodeMutex")
handle, err := windows.CreateMutex(nil, false, mutexName)
if err != nil {
fmt.Println("Failed to create mutex:", err)
os.Exit(1)
}
mutexHandle = handle
lastErr := windows.GetLastError()
if lastErr == windows.ERROR_ALREADY_EXISTS {
fmt.Println("Only one instance is allowed.")
os.Exit(0)
}
defer windows.ReleaseMutex(mutexHandle)
defer windows.CloseHandle(mutexHandle)
loadConfig()
tailscaleAvailable = isValidTailscalePath(tailscalePath)
systray.Run(autoExitNote, nil)
}
func loadConfig() {
// Default config
config = Config{
TailscalePath: "C:\\Program Files\\Tailscale\\tailscale.exe",
TrustedSSIDs: []string{"Yoda-Fi", "R2D2-Fi"},
ExitNodes: []string{"homeassistant", "router", "vpn-node"},
}
f, err := os.Open("config.json")
if err == nil {
defer f.Close()
_ = json.NewDecoder(f).Decode(&config)
}
tailscalePath = config.TailscalePath
}