-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Desktop Notifications, the sequel (#109)
* added logo for notification window and added notification library dependency * Added desktop notifications * Addressing feedback on env var and commenting * add version clarification since we use version in the notification title * go fmt * added --quiet flag tied to ROG_NOTIFY_QUIET
- Loading branch information
Showing
7 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,57 @@ | ||
package util | ||
|
||
/** | ||
* urfave/cli Notify "Extension" | ||
* | ||
* This sub-package of rig is intended for potential separation into a | ||
* standalone package or PR to the main framework. As such, it should not have | ||
* any built-in assumptions or identifiers about Rig, nor depend on anything in | ||
* the rig codebase. | ||
*/ | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/martinlindhe/notify" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
var config *NotifyConfig | ||
|
||
// NotifyConfig holds configuration for notification support | ||
type NotifyConfig struct { | ||
// The label for the app to be displayed in notifications. | ||
Label string | ||
|
||
// Relative path to notification logo. | ||
Icon string | ||
} | ||
|
||
// NotifyInit initializes notification config | ||
func NotifyInit(label string) error { | ||
config = &NotifyConfig{ | ||
Icon: "util/logo.png", | ||
Label: label, | ||
} | ||
return nil | ||
} | ||
|
||
// NotifySuccess send a notification for a successful command run | ||
func NotifySuccess(ctx *cli.Context, message string) { | ||
if shouldNotify(ctx) { | ||
notify.Notify(config.Label, fmt.Sprintf("Success: %s", ctx.Command.Name), message, config.Icon) | ||
} | ||
} | ||
|
||
// NotifyError send a notification for a failed command run | ||
func NotifyError(ctx *cli.Context, message string) error { | ||
if shouldNotify(ctx) { | ||
notify.Notify(config.Label, fmt.Sprintf("Error: %s", ctx.Command.Name), message, config.Icon) | ||
} | ||
return nil | ||
} | ||
|
||
// shouldNotify returns a boolean if notifications are enabled | ||
func shouldNotify(ctx *cli.Context) bool { | ||
return !ctx.GlobalBool("quiet") | ||
} |