Skip to content

Commit

Permalink
feat(systray): manually trigger a restart for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
aybabtme committed Feb 4, 2025
1 parent b64ba01 commit 11f28d0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmd/humanlog/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ type serviceClient interface {
DoLogout(ctx context.Context) error
DoLogin(ctx context.Context) error
DoUpdate(ctx context.Context) error
DoRestart(ctx context.Context) error
CheckUpdate(ctx context.Context) error
}

Expand Down Expand Up @@ -618,7 +619,12 @@ func (hdl *serviceHandler) DoUpdate(ctx context.Context) error {
return fmt.Errorf("applying self-update: %v", err)
}
// triggering self-shutdown
return hdl.shutdown()
return hdl.shutdown(ctx)
}

func (hdl *serviceHandler) DoRestart(ctx context.Context) error {
// triggering self-shutdown
return hdl.shutdown(ctx)
}

func (hdl *serviceHandler) CheckUpdate(ctx context.Context) error {
Expand Down
20 changes: 20 additions & 0 deletions cmd/humanlog/systray_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type systrayController struct {

mSettings *systray.MenuItem
mUpdate *systray.MenuItem
mRestart *systray.MenuItem
}

type systrayModel struct {
Expand Down Expand Up @@ -110,6 +111,10 @@ func newSystrayController(ctx context.Context, ll *slog.Logger, client serviceCl
fmt.Sprintf("%s (latest, click to check)", currentSV.String()),
fmt.Sprintf("Currently running humanlog version %s", currentSV.String()),
)
mRestart := systray.AddMenuItem(
"Restart",
"Cause humanlog's service to restart, for whatever reason",
)

mQuit := systray.AddMenuItem("Quit", "Quit the whole app")
_ = onClick(ctx, mQuit, func(ctx context.Context) {
Expand All @@ -130,12 +135,14 @@ func newSystrayController(ctx context.Context, ll *slog.Logger, client serviceCl
mQuery: mQuery,
mSettings: mSettings,
mUpdate: mUpdate,
mRestart: mRestart,
}
ctrl.registerClickUserSettings(ctx, mUserMenuItem_Sub_Settings)
ctrl.registerClickUserLogin(ctx, mUserMenuItem_Sub_Login)
ctrl.registerClickUserLogout(ctx, mUserMenuItem_Sub_Logout)
ctrl.registerClickQuery(ctx, mQuery)
ctrl.registerClickUpdate(ctx, mUpdate)
ctrl.registryClickRestart(ctx, mRestart)
ctrl.registerClickLocalhostSettings(ctx, mSettings)

return ctrl, nil
Expand Down Expand Up @@ -345,6 +352,19 @@ func (ctrl *systrayController) registerClickUpdate(ctx context.Context, mi *syst
})
}

func (ctrl *systrayController) registryClickRestart(ctx context.Context, mi *systray.MenuItem) context.CancelFunc {
return onClick(ctx, mi, func(ctx context.Context) {
if mi.Disabled() {
ctrl.ll.DebugContext(ctx, "clicked restart, but button disabled")
return
}
ctrl.ll.DebugContext(ctx, "clicked restart")
if err := ctrl.client.DoRestart(ctx); err != nil {
ctrl.NotifyError(ctx, err)
}
})
}

func (ctrl *systrayController) registerClickQuery(ctx context.Context, mi *systray.MenuItem) context.CancelFunc {
queryPath := ctrl.baseSiteURL.JoinPath("/localhost")
return onClick(ctx, mi, func(ctx context.Context) {
Expand Down

0 comments on commit 11f28d0

Please sign in to comment.