Skip to content

Commit

Permalink
add disable check update for feature
Browse files Browse the repository at this point in the history
  • Loading branch information
cage1016 committed Nov 30, 2022
1 parent 6ac6927 commit 09128c2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 56 deletions.
8 changes: 7 additions & 1 deletion .workflow/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
## Usage
CHECK_FOR_UPDATE - 檢查更新
ENABLED_S2T - 簡體到繁體
ENABLED_T2S - 繁體到簡體
ENABLED_S2TW - 簡體到臺灣正體
Expand All @@ -225,6 +226,9 @@ for more information, please go to:
https://github.com/cage1016/alfred-opencc
## Change Log
0.3.0
- configuration add enable/disable check for update
0.2.1
- fix multiline text</string>
<key>uidata</key>
Expand Down Expand Up @@ -269,6 +273,8 @@ https://github.com/cage1016/alfred-opencc
<array/>
<key>variables</key>
<dict>
<key>CHECK_FOR_UPDATE</key>
<string>1</string>
<key>ENABLED_HK2S</key>
<string>1</string>
<key>ENABLED_S2HK</key>
Expand All @@ -287,7 +293,7 @@ https://github.com/cage1016/alfred-opencc
<string>1</string>
</dict>
<key>version</key>
<string>0.2.1</string>
<string>0.3.0</string>
<key>webaddress</key>
<string>https://github.com/cage1016/alfred-opencc</string>
</dict>
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
[![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://lbesson.mit-license.org/)
![GitHub all releases](https://img.shields.io/github/downloads/cage1016/alfred-opencc/total)

## Mention

- The prerequisite for alfred-opencc v1.x.x is alfred5. Please use v0.x.x for alfred4 and mark configuration `CHECK_UPDATE` as `0` to avoid update for check.

## Introduction

由於 MacOS 在 12.3 終於移除對 Python2 的支援,導至 Alfred 4 版本中原先使用的 [amowu/alfred-chinese-converter](https://github.com/amowu/alfred-chinese-converter) 已經無法再使,作者也沒有更新。所以透過 Golang 自己造一個也省去了對 Python 的依賴。
Expand All @@ -16,6 +20,7 @@

| ENV | Enabled | |
|----------------|---|---|
| CHECK_FOR_UPDATE | 1 | 檢查更新 |
| ENABLED_S2T | 1 | 簡體到繁體 |
| ENABLED_T2S | 1 | 繁體到簡體 |
| ENABLED_S2TW | 1 | 簡體到臺灣正體 |
Expand Down
69 changes: 21 additions & 48 deletions alfred/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,76 +5,49 @@ import (
)

const (
ENABLED_S2T = "ENABLED_S2T"
ENABLED_T2S = "ENABLED_T2S"
ENABLED_S2TW = "ENABLED_S2TW"
ENABLED_TW2S = "ENABLED_TW2S"
ENABLED_S2HK = "ENABLED_S2HK"
ENABLED_HK2S = "ENABLED_HK2S"
ENABLED_S2TWP = "ENABLED_S2TWP"
ENABLED_TW2SP = "ENABLED_TW2SP"
ENABLED_S2T = "ENABLED_S2T"
ENABLED_T2S = "ENABLED_T2S"
ENABLED_S2TW = "ENABLED_S2TW"
ENABLED_TW2S = "ENABLED_TW2S"
ENABLED_S2HK = "ENABLED_S2HK"
ENABLED_HK2S = "ENABLED_HK2S"
ENABLED_S2TWP = "ENABLED_S2TWP"
ENABLED_TW2SP = "ENABLED_TW2SP"
CHECK_FOR_UPDATE = "CHECK_FOR_UPDATE"
)

func GetENABLED_S2T(wf *aw.Workflow) bool {
b := wf.Config.Get(ENABLED_S2T)
if b == "1" {
return true
}
return false
return wf.Config.Get(ENABLED_S2T) == "1"
}

func GetENABLED_T2S(wf *aw.Workflow) bool {
b := wf.Config.Get(ENABLED_T2S)
if b == "1" {
return true
}
return false
return wf.Config.Get(ENABLED_T2S) == "1"
}

func GetENABLED_S2TW(wf *aw.Workflow) bool {
b := wf.Config.Get(ENABLED_S2TW)
if b == "1" {
return true
}
return false
return wf.Config.Get(ENABLED_S2TW) == "1"
}

func GetENABLED_TW2S(wf *aw.Workflow) bool {
b := wf.Config.Get(ENABLED_TW2S)
if b == "1" {
return true
}
return false
return wf.Config.Get(ENABLED_TW2S) == "1"
}

func GetENABLED_S2HK(wf *aw.Workflow) bool {
b := wf.Config.Get(ENABLED_S2HK)
if b == "1" {
return true
}
return false
return wf.Config.Get(ENABLED_S2HK) == "1"
}

func GetENABLED_HK2S(wf *aw.Workflow) bool {
b := wf.Config.Get(ENABLED_HK2S)
if b == "1" {
return true
}
return false
return wf.Config.Get(ENABLED_HK2S) == "1"
}

func GetENABLED_S2TWP(wf *aw.Workflow) bool {
b := wf.Config.Get(ENABLED_S2TWP)
if b == "1" {
return true
}
return false
return wf.Config.Get(ENABLED_S2TWP) == "1"
}

func GetENABLED_TW2SP(wf *aw.Workflow) bool {
b := wf.Config.Get(ENABLED_TW2SP)
if b == "1" {
return true
}
return false
return wf.Config.Get(ENABLED_TW2SP) == "1"
}

func GetCHECK_UPDATE(wf *aw.Workflow) bool {
return wf.Config.Get(CHECK_FOR_UPDATE) == "1"
}
16 changes: 9 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ func run() {
}

if wf.UpdateAvailable() {
wf.Configure(aw.SuppressUIDs(true))
log.Println("Update available!")
wf.NewItem("An update is available!").
Subtitle("⇥ or ↩ to install update").
Valid(false).
Autocomplete("workflow:update").
Icon(&aw.Icon{Value: "update-available.png"})
if alfred.GetCHECK_UPDATE(wf) {
wf.Configure(aw.SuppressUIDs(true))
log.Println("Update available!")
wf.NewItem("An update is available!").
Subtitle("⇥ or ↩ to install update").
Valid(false).
Autocomplete("workflow:update").
Icon(&aw.Icon{Value: "update-available.png"})
}
}

h, found := handlers[args[0]]
Expand Down

0 comments on commit 09128c2

Please sign in to comment.