Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
72 lines (61 loc) · 1.65 KB
/
Copy pathmain.go
File metadata and controls
72 lines (61 loc) · 1.65 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
68
69
70
71
72
package main
import (
"client/platform/autostart"
"client/platform/config"
"client/platform/singleinstance"
"client/platform/update"
"client/quic"
"client/ui"
"log"
"os"
"os/signal"
"syscall"
"time"
"fyne.io/systray"
)
func main() {
logPath, err := config.InitLogging()
if err != nil {
log.Println("file logging unavailable:", err)
} else if logPath != "" {
log.Println("logging to", logPath)
}
// Old versions stored Supabase tokens here; nothing uses them now.
config.RemoveLegacySession()
// Before anything with side effects: a second launch must not open its own
// QUIC session or add a second tray icon. It hands the reveal request to
// the running instance and exits — unless the service manager started it,
// in which case nobody asked to see anything and it just exits.
primary, err := singleinstance.Acquire(ui.RevealFromStealth, !autostart.StartedByService())
if err != nil {
log.Println("single instance:", err)
}
if !primary {
log.Println("Turbo is already running; asked it to show and exiting")
return
}
go quic.ConnectQuicServer()
go func() {
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
<-sigCh
systray.Quit()
// Fallback in case the native teardown hangs, so Ctrl+C is never a no-op.
time.Sleep(2 * time.Second)
os.Exit(0)
}()
runTray(onReady, nil)
}
func onReady() {
ui.SetupTray(iconData, systray.Quit)
if err := autostart.EnableAutoStart(); err != nil {
log.Println(err)
}
if err := update.AutoUpdate(); err != nil {
log.Println(err)
quic.SendMessage(&quic.Message{
Type: "stacktrace",
Data: "Auto-update failed: " + err.Error(),
})
}
}