Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
149 lines (136 loc) · 4.17 KB
/
Copy pathmain.go
File metadata and controls
149 lines (136 loc) · 4.17 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Command pausa is the macOS break-reminder application. It is a thin
// entry-point that wires together the configuration store, scheduler,
// macOS bridge, and Wails runtime.
package main
import (
"embed"
"log/slog"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/menu"
"github.com/wailsapp/wails/v2/pkg/menu/keys"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
"github.com/wailsapp/wails/v2/pkg/options/mac"
"pausa/internal/breakapp"
"pausa/internal/clock"
"pausa/internal/config"
plog "pausa/internal/log"
"pausa/internal/platform"
"pausa/internal/scheduler"
"pausa/internal/tips"
)
//go:embed all:frontend/dist
var assets embed.FS
func main() {
logFile := plog.Init(slog.LevelInfo)
if logFile != nil {
defer func() { _ = logFile.Close() }()
}
cfgPath, err := config.DefaultPath()
if err != nil {
slog.Error("locate config", "err", err)
return
}
cfgStore, err := config.Open(cfgPath)
if err != nil {
// Non-fatal; defaults are in use.
slog.Warn("open config", "err", err, "path", cfgPath)
}
cfgSub := cfgStore.Subscribe()
catalog := tips.NewCatalog()
busySrc := platform.NewBusySource()
sched := scheduler.New(
clock.New(),
cfgStore.Get(),
cfgSub,
platform.NewIdleSource(),
busySrc,
)
app := breakapp.New(cfgStore, sched, catalog, busySrc)
appMenu := buildAppMenu(app)
err = wails.Run(&options.App{
Title: "Pausa",
Width: 640,
Height: 720,
MinWidth: 560,
MinHeight: 640,
// macOS keeps running as a menu-bar app when the window closes, so the
// close button hides it. Without a tray to restore it from, closing
// must quit instead of stranding a hidden app.
HideWindowOnClose: platform.Caps.SystemTray,
StartHidden: false,
AssetServer: &assetserver.Options{
Assets: assets,
},
Menu: appMenu,
BackgroundColour: &options.RGBA{R: 17, G: 24, B: 39, A: 1},
OnStartup: app.Startup,
OnDomReady: app.DomReady,
OnShutdown: app.Shutdown,
// Prevent a second launch from spinning up a second status item,
// busy sampler, and scheduler. Instead, surface the existing window.
// UniqueId matches the bundle identifier so the lock and the app
// identity stay in sync.
SingleInstanceLock: &options.SingleInstanceLock{
UniqueId: "com.yuseferi.pausa",
OnSecondInstanceLaunch: func(_ options.SecondInstanceData) {
app.FocusExisting()
},
},
Bind: []interface{}{app},
Frameless: true,
Mac: &mac.Options{
TitleBar: &mac.TitleBar{
TitlebarAppearsTransparent: true,
HideTitle: true,
HideTitleBar: true,
FullSizeContent: true,
},
About: &mac.AboutInfo{
Title: "Pausa",
Message: "A mindful break reminder for macOS.",
},
},
})
if err != nil {
slog.Error("wails run", "err", err)
}
}
// buildAppMenu constructs the macOS menu bar (the one at the top of the
// screen, not the status item). Most operations live in the status bar; this
// menu provides standard shortcuts.
func buildAppMenu(app *breakapp.App) *menu.Menu {
m := menu.NewMenu()
m.Append(menu.AppMenu())
file := m.AddSubmenu("File")
file.AddText("Preferences…", keys.CmdOrCtrl(","), func(_ *menu.CallbackData) {
app.OpenPreferences()
})
file.AddSeparator()
file.AddText("Quit Pausa", keys.CmdOrCtrl("q"), func(_ *menu.CallbackData) {
app.QuitApp()
})
br := m.AddSubmenu("Breaks")
br.AddText("Take a Break Now", keys.CmdOrCtrl("b"), func(_ *menu.CallbackData) {
app.TakeBreakNow()
})
br.AddText("Skip Break", keys.Combo("s", keys.CmdOrCtrlKey, keys.ShiftKey), func(_ *menu.CallbackData) {
app.SkipBreak()
})
br.AddText("Postpone Break", keys.Combo("p", keys.CmdOrCtrlKey, keys.ShiftKey), func(_ *menu.CallbackData) {
app.PostponeBreak()
})
br.AddSeparator()
br.AddText("Pause Breaks", keys.CmdOrCtrl("p"), func(_ *menu.CallbackData) {
app.PauseBreaks()
})
br.AddText("Resume Breaks", keys.CmdOrCtrl("r"), func(_ *menu.CallbackData) {
app.ResumeBreaks()
})
br.AddSeparator()
br.AddText("Reset Schedule", nil, func(_ *menu.CallbackData) {
app.ResetBreaks()
})
m.Append(menu.EditMenu())
return m
}