-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from nao1215/notify
Added desktop notification
- Loading branch information
Showing
16 changed files
with
133 additions
and
3 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
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.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package assets | ||
|
||
import ( | ||
_ "embed" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/nao1215/gup/internal/config" | ||
"github.com/nao1215/gup/internal/file" | ||
"github.com/nao1215/gup/internal/print" | ||
) | ||
|
||
//go:embed information.png | ||
var inforIcon []byte | ||
|
||
//go:embed warning.png | ||
var warningIcon []byte | ||
|
||
// DeployIconIfNeeded make icon file for notification. | ||
func DeployIconIfNeeded() { | ||
if !file.IsDir(assetsDirPath()) { | ||
if err := os.MkdirAll(assetsDirPath(), 0775); err != nil { | ||
print.Err(fmt.Errorf("%s: %w", "can not make assets directory", err)) | ||
return | ||
} | ||
} | ||
|
||
if !file.IsFile(InfoIconPath()) { | ||
err := os.WriteFile(InfoIconPath(), inforIcon, 0664) | ||
if err != nil { | ||
print.Warn(err) | ||
} | ||
} | ||
if !file.IsFile(WarningIconPath()) { | ||
err := os.WriteFile(WarningIconPath(), warningIcon, 0664) | ||
if err != nil { | ||
print.Warn(err) | ||
} | ||
} | ||
} | ||
|
||
// InfoIconPath return absolute path of information.png | ||
func InfoIconPath() string { | ||
return filepath.Join(assetsDirPath(), "information.png") | ||
} | ||
|
||
// WarningIconPath return absolute path of information.png | ||
func WarningIconPath() string { | ||
return filepath.Join(assetsDirPath(), "warning.png") | ||
} | ||
|
||
// assetsDirPath return absolute path of assets directory | ||
func assetsDirPath() string { | ||
return filepath.Join(config.DirPath(), "assets") | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package config | ||
|
||
import ( | ||
_ "embed" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
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,23 @@ | ||
package notify | ||
|
||
import ( | ||
"github.com/gen2brain/beeep" | ||
"github.com/nao1215/gup/internal/assets" | ||
"github.com/nao1215/gup/internal/print" | ||
) | ||
|
||
// Info notify information message at desktop | ||
func Info(title, message string) { | ||
err := beeep.Notify(title, message, assets.InfoIconPath()) | ||
if err != nil { | ||
print.Warn(err) | ||
} | ||
} | ||
|
||
// Warn notify warning message at desktop | ||
func Warn(title, message string) { | ||
err := beeep.Notify(title, message, assets.WarningIconPath()) | ||
if err != nil { | ||
print.Warn(err) | ||
} | ||
} |