feat(windows): simplify tray controls and allow installer-user config edits
This commit is contained in:
1 parent
d59b2d5463
commit
ae5e979761
18 files changed
+611
-88
No files matched your search
@@ -0,0 +1,68 @@
|
||||
package windowstray
|
||||
|
||||
import "github.com/rvbox/rvbox/internal/client/windowsservice"
|
||||
|
||||
// MenuStatus contains only presentation facts, never configuration or spool data.
|
||||
type MenuStatus struct {
|
||||
Label string
|
||||
AutoStart bool
|
||||
StartupKnown bool
|
||||
CanStart bool
|
||||
CanStop bool
|
||||
}
|
||||
|
||||
func menuStatus(service windowsservice.Status, queryErr error, connection string) MenuStatus {
|
||||
result := MenuStatus{Label: "Status: unavailable"}
|
||||
if queryErr != nil {
|
||||
return result
|
||||
}
|
||||
result.StartupKnown = service.Installed && (service.Startup == windowsservice.StartupAutomatic || service.Startup == windowsservice.StartupManual)
|
||||
result.AutoStart = service.Startup == windowsservice.StartupAutomatic
|
||||
switch service.State {
|
||||
case windowsservice.StateStopped:
|
||||
result.Label = "Status: stopped"
|
||||
result.CanStart = service.Installed
|
||||
case windowsservice.StateStartPending:
|
||||
result.Label = "Status: starting"
|
||||
case windowsservice.StateStopPending:
|
||||
result.Label = "Status: stopping"
|
||||
case windowsservice.StatePaused:
|
||||
result.Label, result.CanStop = "Status: paused", true
|
||||
case windowsservice.StateRunning:
|
||||
result.Label, result.CanStop = "Status: disconnected", true
|
||||
if connection == "running" {
|
||||
result.Label = "Status: running"
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func automaticAction(automatic bool) Action {
|
||||
if automatic {
|
||||
return ActionSetManual
|
||||
}
|
||||
return ActionSetAutomatic
|
||||
}
|
||||
|
||||
type menuItem struct {
|
||||
Action Action
|
||||
Label string
|
||||
Disabled bool
|
||||
Checked bool
|
||||
Separator bool
|
||||
}
|
||||
|
||||
func trayMenu(status MenuStatus) []menuItem {
|
||||
return []menuItem{
|
||||
{Label: status.Label, Disabled: true},
|
||||
{Separator: true},
|
||||
{Action: ActionOpenConfig, Label: "Open config"},
|
||||
{Action: ActionOpenLog, Label: "Open log"},
|
||||
{Separator: true},
|
||||
{Action: ActionStartService, Label: "Start service", Disabled: !status.CanStart},
|
||||
{Action: ActionStopService, Label: "Stop service", Disabled: !status.CanStop},
|
||||
{Action: ActionSetAutomatic, Label: "Auto start", Disabled: !status.StartupKnown, Checked: status.AutoStart},
|
||||
{Separator: true},
|
||||
{Action: ActionExitTray, Label: "Exit"},
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user