Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(service): click to check updates right away #174

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cmd/humanlog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ func newApp() *cli.App {

if cfg.ExperimentalFeatures != nil {
if cfg.ExperimentalFeatures.SendLogsToCloud != nil && *cfg.ExperimentalFeatures.SendLogsToCloud {
// TODO(antoine): remove this codepath, it's redundant with the localhost port path
ll := getLogger(cctx)
apiURL := getAPIUrl(cctx)
notifyUnableToIngest := func(err error) {
Expand Down
32 changes: 23 additions & 9 deletions cmd/humanlog/service_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ type serviceClient interface {
DoLogout(ctx context.Context) error
DoLogin(ctx context.Context) error
DoUpdate(ctx context.Context) error
CheckUpdate(ctx context.Context) error
}

var _ serviceClient = (*serviceHandler)(nil)
Expand Down Expand Up @@ -564,6 +565,14 @@ func (hdl *serviceHandler) DoUpdate(ctx context.Context) error {
return selfupdate.UpgradeInPlace(ctx, baseSiteURL, channelName, os.Stdout, os.Stderr, os.Stdin)
}

func (hdl *serviceHandler) CheckUpdate(ctx context.Context) error {
var channelName *string
if hdl.config.ExperimentalFeatures != nil {
channelName = hdl.config.ExperimentalFeatures.ReleaseChannel
}
return hdl.checkUpdate(ctx, channelName)
}

func (hdl *serviceHandler) registerClient(client systrayClient) {
ctx := hdl.ctx
ll := hdl.ll
Expand Down Expand Up @@ -609,7 +618,7 @@ func (hdl *serviceHandler) notifyUpdateAvailable(ctx context.Context, oldV, newV
if hdl.client == nil {
return nil
}
return hdl.client.NotifyUpdateAvailable(ctx, newV, newV)
return hdl.client.NotifyUpdateAvailable(ctx, oldV, newV)
}

var _ systrayClient = (*systrayController)(nil)
Expand Down Expand Up @@ -673,10 +682,9 @@ func newSystrayController(ctx context.Context, ll *slog.Logger, client serviceCl

mSettings := systray.AddMenuItem("Settings...", "Configure humanlog on your machine")
mUpdate := systray.AddMenuItem(
currentSV.String(),
fmt.Sprintf("%s (latest, click to check)", currentSV.String()),
fmt.Sprintf("Currently running humanlog version %s", currentSV.String()),
)
mUpdate.Disable()

mQuit := systray.AddMenuItem("Quit", "Quit the whole app")
_ = onClick(ctx, mQuit, func(ctx context.Context) {
Expand Down Expand Up @@ -814,8 +822,8 @@ func (ctrl *systrayController) renderUpdateMenuItem(ctx context.Context) error {
current := ctrl.model.currentVersionSV
mi := ctrl.mUpdate
if !hasUpdate {
mi.SetTitle(fmt.Sprintf("%s (latest)", current.String()))
mi.Disable()

mi.SetTitle(fmt.Sprintf("%s (latest, click to check)", current.String()))
} else {
nextVersion := ctrl.model.nextVersionSV
mi.SetTitle(fmt.Sprintf("Update available! (%s)", nextVersion.String()))
Expand Down Expand Up @@ -865,12 +873,18 @@ func (ctrl *systrayController) registerClickUserLogout(ctx context.Context, mi *
func (ctrl *systrayController) registerClickUpdate(ctx context.Context, mi *systray.MenuItem) context.CancelFunc {
return onClick(ctx, mi, func(ctx context.Context) {
if mi.Disabled() {
ctrl.ll.DebugContext(ctx, "clicked updated, but button disabled")
ctrl.ll.DebugContext(ctx, "clicked update, but button disabled")
return
}
ctrl.ll.DebugContext(ctx, "clicked updated")
if err := ctrl.client.DoUpdate(ctx); err != nil {
ctrl.NotifyError(ctx, err)
ctrl.ll.DebugContext(ctx, "clicked update")
if ctrl.model.hasUpdate {
if err := ctrl.client.DoUpdate(ctx); err != nil {
ctrl.NotifyError(ctx, err)
}
} else {
if err := ctrl.client.CheckUpdate(ctx); err != nil {
ctrl.NotifyError(ctx, err)
}
}
})
}
Expand Down
Loading