3 Star 0 Fork 0

Gitee 极速下载 / clipman

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/yory8/clipman
克隆/下载
notify.go 857 Bytes
一键复制 编辑 原始数据 按行查看 历史
yory8 提交于 2020-02-25 22:24 . feat: add desktop notifications
package main
import (
"fmt"
"log"
"os/exec"
"time"
)
func smartLog(message, urgency string, alert bool) {
if alert {
if err := notify(message, urgency); err != nil {
log.Printf("failure sending notification: %s\n", err)
}
}
switch urgency {
case "critical", "normal":
log.Fatal(message)
default:
log.Println(message)
}
}
func notify(message string, urgency string) error {
var timeout time.Duration
switch urgency {
// cases accepted by notify-send: low, normal, critical
case "critical":
timeout = 5 * time.Second
case "low":
timeout = 2 * time.Second
default:
timeout = 3 * time.Second
}
// notify-send only accepts milliseconds
millisec := fmt.Sprintf("%v", timeout.Seconds()*1000)
args := []string{"-a", "Clipman", "-u", urgency, "-t", millisec, message}
return exec.Command("notify-send", args...).Run()
}
1
https://gitee.com/mirrors/clipman.git
git@gitee.com:mirrors/clipman.git
mirrors
clipman
clipman
master

搜索帮助