Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
wasn't sending up snooze duration after all
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Sanders committed Sep 5, 2018
1 parent 01685e5 commit 9241f0f
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 30 deletions.
2 changes: 1 addition & 1 deletion keybase/platform_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (c context) BeforeUpdatePrompt(update updater.Update, options updater.Updat
if err != nil {
c.log.Warningf("Error running notify-send: %s (%s)", err, result.CombinedOutput())
}
c.ReportAction(updater.UpdateActionSnooze, &update, options)
c.ReportAction(UpdateActionResponse{updater.UpdateActionSnooze, false, 0}, &update, options)
return updater.CancelErr(fmt.Errorf("Linux uses system package manager"))
}

Expand Down
10 changes: 6 additions & 4 deletions keybase/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ type updaterPromptInput struct {
}

type updaterPromptInputResult struct {
Action string `json:"action"`
AutoUpdate bool `json:"autoUpdate"`
Action string `json:"action"`
AutoUpdate bool `json:"autoUpdate"`
SnoozeDuration int `json:"snooze_duration"`
}

func (c context) promptInput(update updater.Update, options updater.UpdateOptions, promptOptions updater.UpdatePromptOptions) (string, error) {
Expand Down Expand Up @@ -69,8 +70,9 @@ func (c context) responseForResult(result updaterPromptInputResult) (*updater.Up
}

return &updater.UpdatePromptResponse{
Action: updateAction,
AutoUpdate: autoUpdate,
Action: updateAction,
AutoUpdate: autoUpdate,
SnoozeDuration: result.SnoozeDuration,
}, nil
}

Expand Down
14 changes: 9 additions & 5 deletions keybase/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"net/http"
"net/url"
"strconv"
"time"

"github.com/keybase/go-updater"
Expand Down Expand Up @@ -37,17 +38,20 @@ func (c context) reportError(err error, update *updater.Update, options updater.
}

// ReportAction notifies the API server of a client updater action
func (c context) ReportAction(action updater.UpdateAction, update *updater.Update, options updater.UpdateOptions) {
if err := c.reportAction(action, update, options, defaultEndpoints.action, time.Minute); err != nil {
c.log.Warningf("Error notifying about an action (%s): %s", action, err)
func (c context) ReportAction(actionResponse updater.UpdatePromptResponse, update *updater.Update, options updater.UpdateOptions) {
if err := c.reportAction(actionResponse, update, options, defaultEndpoints.action, time.Minute); err != nil {
c.log.Warningf("Error notifying about an action (%s): %s", actionResponse.Action, err)
}
}

func (c context) reportAction(action updater.UpdateAction, update *updater.Update, options updater.UpdateOptions, uri string, timeout time.Duration) error {
func (c context) reportAction(actionResponse updater.UpdatePromptResponse, update *updater.Update, options updater.UpdateOptions, uri string, timeout time.Duration) error {
data := url.Values{}
data.Add("action", action.String())
data.Add("action", actionResponse.Action.String())
autoUpdate, _ := c.config.GetUpdateAuto()
data.Add("auto_update", util.URLValueForBool(autoUpdate))
if actionResponse.SnoozeDuration > 0 {
data.Add("snooze_duration", strconv.Itoa(actionResponse.SnoozeDuration))
}
return c.report(data, update, options, uri, timeout)
}

Expand Down
6 changes: 4 additions & 2 deletions keybase/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ func TestReportActionApply(t *testing.T) {
defer server.Close()

ctx := testContext(t)
err := ctx.reportAction(updater.UpdateActionApply, &testUpdate, testOptions, server.URL, testReportTimeout)
actionResponse := UpdatActionResponse{updater.UpdateActionApply, false, 0}
err := ctx.reportAction(actionResponse, &testUpdate, testOptions, server.URL, testReportTimeout)
assert.NoError(t, err)
}

Expand All @@ -81,7 +82,8 @@ func TestReportActionEmpty(t *testing.T) {
defer server.Close()

ctx := testContext(t)
err := ctx.reportAction("", &testUpdate, testOptions, server.URL, testReportTimeout)
actionResponse := UpdatActionResponse{"", false, 0}
err := ctx.reportAction(actionResponse, &testUpdate, testOptions, server.URL, testReportTimeout)
assert.NoError(t, err)
}

Expand Down
5 changes: 3 additions & 2 deletions protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ type UpdatePromptOptions struct {

// UpdatePromptResponse is the result for UpdatePrompt
type UpdatePromptResponse struct {
Action UpdateAction `json:"action"`
AutoUpdate bool `json:"autoUpdate"`
Action UpdateAction `json:"action"`
AutoUpdate bool `json:"autoUpdate"`
SnoozeDuration int `json:"snooze_duration"`
}

// UpdateUI is a UI interface
Expand Down
2 changes: 1 addition & 1 deletion update_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (u testUpdateCheckUI) UpdateOptions() UpdateOptions {
return newDefaultTestUpdateOptions()
}

func (u testUpdateCheckUI) ReportAction(_ UpdateAction, _ *Update, _ UpdateOptions) {}
func (u testUpdateCheckUI) ReportAction(_ UpdateActionResponse, _ *Update, _ UpdateOptions) {}

func (u testUpdateCheckUI) ReportError(_ error, _ *Update, _ UpdateOptions) {}

Expand Down
26 changes: 13 additions & 13 deletions updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Context interface {
Apply(update Update, options UpdateOptions, tmpDir string) error
AfterApply(update Update) error
ReportError(err error, update *Update, options UpdateOptions)
ReportAction(action UpdateAction, update *Update, options UpdateOptions)
ReportAction(updatePromptResponse UpdatePromptResponse, update *Update, options UpdateOptions)
ReportSuccess(update *Update, options UpdateOptions)
AfterUpdateCheck(update *Update)
GetAppStatePath() string
Expand Down Expand Up @@ -113,20 +113,20 @@ func (u *Updater) update(ctx Context, options UpdateOptions) (*Update, error) {
}

// Prompt for update
updateAction, err := u.promptForUpdateAction(ctx, *update, options)
updatePromptResponse, err := u.promptForUpdateAction(ctx, *update, options)
if err != nil {
return update, promptErr(err)
}
switch updateAction {
switch updatePromptResponse.Action {
case UpdateActionApply:
ctx.ReportAction(UpdateActionApply, update, options)
ctx.ReportAction(updatePromptResponse, update, options)
case UpdateActionAuto:
ctx.ReportAction(UpdateActionAuto, update, options)
ctx.ReportAction(updatePromptResponse, update, options)
case UpdateActionSnooze:
ctx.ReportAction(UpdateActionSnooze, update, options)
ctx.ReportAction(updatePromptResponse, update, options)
return update, CancelErr(fmt.Errorf("Snoozed update"))
case UpdateActionCancel:
ctx.ReportAction(UpdateActionCancel, update, options)
ctx.ReportAction(updatePromptResponse, update, options)
return update, CancelErr(fmt.Errorf("Canceled"))
case UpdateActionError:
return update, promptErr(fmt.Errorf("Unknown prompt error"))
Expand Down Expand Up @@ -242,7 +242,7 @@ func (u *Updater) NeedUpdate(ctx Context) (upToDate bool, err error) {
}

// promptForUpdateAction prompts the user for permission to apply an update
func (u *Updater) promptForUpdateAction(ctx Context, update Update, options UpdateOptions) (UpdateAction, error) {
func (u *Updater) promptForUpdateAction(ctx Context, update Update, options UpdateOptions) (UpdatePromptResponse, error) {
u.log.Debug("Prompt for update")

auto, autoSet := u.config.GetUpdateAuto()
Expand All @@ -253,11 +253,11 @@ func (u *Updater) promptForUpdateAction(ctx Context, update Update, options Upda
// If there's an error getting active status, we'll just update
isActive, err := u.checkUserActive(ctx)
if err == nil && isActive {
return UpdateActionUIBusy, nil
return UpdatePromptResponse{UpdateActionUIBusy, false, 0}, nil
}
u.guiBusyCount = 0
}
return UpdateActionAuto, nil
return UpdatePromptResponse{UpdateActionAuto, false, 0}, nil
}

updateUI := ctx.GetUpdateUI()
Expand All @@ -267,10 +267,10 @@ func (u *Updater) promptForUpdateAction(ctx Context, update Update, options Upda
promptOptions := UpdatePromptOptions{AutoUpdate: autoUpdate}
updatePromptResponse, err := updateUI.UpdatePrompt(update, options, promptOptions)
if err != nil {
return UpdateActionError, err
return UpdatePromptResponse{UpdateActionError, false, 0}, err
}
if updatePromptResponse == nil {
return UpdateActionError, fmt.Errorf("No response")
return UpdatePromptResponse{UpdateActionError, false, 0}, fmt.Errorf("No response")
}

if updatePromptResponse.Action != UpdateActionContinue {
Expand All @@ -281,7 +281,7 @@ func (u *Updater) promptForUpdateAction(ctx Context, update Update, options Upda
}
}

return updatePromptResponse.Action, nil
return *updatePromptResponse, nil
}

type guiAppState struct {
Expand Down
4 changes: 2 additions & 2 deletions updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ func (u *testUpdateUI) ReportError(err error, update *Update, options UpdateOpti
u.errReported = err
}

func (u *testUpdateUI) ReportAction(action UpdateAction, update *Update, options UpdateOptions) {
u.actionReported = action
func (u *testUpdateUI) ReportAction(actionResponse UpdateActionResponse, update *Update, options UpdateOptions) {
u.actionReported = actionResponse.action
autoUpdate, _ := u.cfg.GetUpdateAuto()
u.autoUpdateReported = autoUpdate
u.updateReported = update
Expand Down

0 comments on commit 9241f0f

Please sign in to comment.