-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: factor out the touch notification for gpg signing too
- Loading branch information
Showing
3 changed files
with
41 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package notify | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/gen2brain/beeep" | ||
"go.uber.org/zap" | ||
) | ||
|
||
const waitTime = 6 * time.Second | ||
|
||
// Touch starts a goroutine, and waits for a short period. If the returned | ||
// CancelFunc has not been called it sends a notification to remind the user to | ||
// physically touch the Security Key. | ||
func Touch(log *zap.Logger) context.CancelFunc { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
timer := time.NewTimer(waitTime) | ||
go func() { | ||
select { | ||
case <-ctx.Done(): | ||
timer.Stop() | ||
case <-timer.C: | ||
err := beeep.Alert("Security Key Agent", "Waiting for touch...", "") | ||
if err != nil && log != nil { | ||
log.Warn("couldn't send touch notification", zap.Error(err)) | ||
} | ||
} | ||
}() | ||
return cancel | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters