Skip to content

Commit

Permalink
增加多次检测为空时,是否安装依赖提示
Browse files Browse the repository at this point in the history
  • Loading branch information
cnbattle committed Jun 29, 2020
1 parent dc54323 commit f26cb84
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@
- [ ] 增加测试代码

## 使用
### 依赖
- Linux `xsel``xclip`
```
// Manjaro/Arch:
sudo pacman -S xsel xclip
// Debian/Ubuntu
sudo apt-get install xsel xclip
// Fedora
sudo dnf install xsel xclip
```
- Windows 10 `PowerShell`

### Linux or Mac
```
nohup ./aitranslate -c [Google|YouDao] &
Expand Down
4 changes: 2 additions & 2 deletions aitranslate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ var (
text string
// 通知logo
path string
// 监听时间间隔
monitoringInterval int = 100
// 监听时间间隔 毫秒
monitoringInterval = 100
)

func init() {
Expand Down
13 changes: 13 additions & 0 deletions aitranslate.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=aitranslate
After=network.target

[Service]
Type=simple
Restart=always
RestartSec=1s
ExecStart=/usr/bin/aitranslate
WorkingDirectory=/usr/bin/

[Install]
WantedBy=multi-user.target
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/abadojack/whatlanggo v1.0.1
github.com/atotto/clipboard v0.1.2
github.com/gen2brain/beeep v0.0.0-20200420150314-13046a26d502
github.com/go-bindata/go-bindata v3.1.2+incompatible // indirect
github.com/stretchr/testify v1.5.1 // indirect
github.com/tidwall/gjson v1.6.0
)
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gen2brain/beeep v0.0.0-20200420150314-13046a26d502 h1:e+btj9i/zyL7a2WrgOeKl2rTMMYkzGJIuVzziFu3fi0=
github.com/gen2brain/beeep v0.0.0-20200420150314-13046a26d502/go.mod h1:KvEoJUYimgK9VGK9RZu1RvlPHfdwtGw1+m6rnfPK+lI=
github.com/go-bindata/go-bindata v1.0.0 h1:DZ34txDXWn1DyWa+vQf7V9ANc2ILTtrEjtlsdJRF26M=
github.com/go-bindata/go-bindata v3.1.2+incompatible h1:5vjJMVhowQdPzjE1LdxyFF7YFTXg5IgGVW4gBr5IbvE=
github.com/go-bindata/go-bindata v3.1.2+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo=
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 h1:qZNfIGkIANxGv/OqtnntR4DfOY2+BgwR60cAcu/i3SE=
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4/go.mod h1:kW3HQ4UdaAyrUCSSDR4xUzBKW6O2iA4uHhk7AtyYp10=
github.com/godbus/dbus v4.1.0+incompatible h1:WqqLRTsQic3apZUK9qC5sGNfXthmPXzUZ7nQPrNITa4=
Expand Down
7 changes: 7 additions & 0 deletions translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import (

// translates Translate and Notify
func translates() {
emptyTimes := 0
beeep.Alert("", "自动翻译运行中...", "")
text = getClipboardString()
for {
time.Sleep(time.Millisecond * time.Duration(monitoringInterval))
newText := getClipboardString()
if strings.EqualFold("", newText) {
emptyTimes++
}
if !strings.EqualFold(text, newText) {
text = newText
translateText, err := translate.Trans(channel, text)
Expand All @@ -23,5 +27,8 @@ func translates() {
}
beeep.Alert(channel+" Translate", translateText, getImagePath("logo"))
}
if emptyTimes == 30 {
beeep.Alert("Error", "多次未检查到内容,请确定依赖包已经安装", getImagePath("warning"))
}
}
}

0 comments on commit f26cb84

Please sign in to comment.