diff --git a/splitargs.py b/splitargs.py index 85c9ec0..ffba913 100755 --- a/splitargs.py +++ b/splitargs.py @@ -27,8 +27,16 @@ def get_args(wf): operation = arg_array[5] # 是否有更新 - if operation == 'update': + if operation == 'update_now': wf.start_update() + return + elif operation == 'update_with_url': + import webbrowser + url = "https://github.com/whyliam/whyliam.workflows.youdao/releases" + webbrowser.open(url) + return + elif operation == 'update_next_time': + return # 是否有错误 elif operation == 'error': @@ -91,5 +99,8 @@ def get_args(wf): if __name__ == '__main__': - wf = Workflow3() + wf = Workflow3(update_settings={ + 'github_slug': 'whyliam/whyliam.workflows.youdao', + 'frequency': 0 + }) sys.exit(wf.run(get_args)) diff --git a/whyliam.workflows.youdao.alfred3workflow b/whyliam.workflows.youdao.alfred3workflow index e4d7a78..9c76e51 100644 Binary files a/whyliam.workflows.youdao.alfred3workflow and b/whyliam.workflows.youdao.alfred3workflow differ diff --git a/whyliam.workflows.youdao.alfredworkflow b/whyliam.workflows.youdao.alfredworkflow index 4366a08..9c76e51 100644 Binary files a/whyliam.workflows.youdao.alfredworkflow and b/whyliam.workflows.youdao.alfredworkflow differ diff --git a/youdao.py b/youdao.py index ca4aecf..4e1d5a8 100755 --- a/youdao.py +++ b/youdao.py @@ -8,6 +8,7 @@ import hashlib import time import sys +import random reload(sys) sys.setdefaultencoding('utf8') @@ -93,8 +94,6 @@ def sentry_message(errorCode, msg): def get_youdao_url(query): # 构建有道翻译URL - import random - zhiyun_id = os.getenv('zhiyun_id', '').strip() zhiyun_key = os.getenv('zhiyun_key', '').strip() if zhiyun_id and zhiyun_key: @@ -194,17 +193,24 @@ def get_history_data(): def is_expired(): - # 检查更新 - if wf.update_available: - arg = get_arg_str('', '', operation='update') + # 检查更新,随机检测 + if random.random() < 0.01 and wf.update_available: + arg = get_arg_str('', '', operation='update_now') wf.add_item( - title='马上更新', subtitle='有新版本更新', arg=arg, + title='马上更新(点击后请打开 Alfred 的 Preference 完成更新)', + subtitle='有新版本更新', arg=arg, valid=True, icon=ICON_UPDATE) - arg = get_arg_str('', '', operation='not_update') + arg = get_arg_str('', '', operation='update_with_url') + wf.add_item( + title='手动更新', subtitle='有新版本更新', arg=arg, + valid=True, icon=ICON_ERROR) + + arg = get_arg_str('', '', operation='update_next_time') wf.add_item( title='暂不更新', subtitle='有新版本更新', arg=arg, valid=True, icon=ICON_ERROR) + wf.send_feedback() return True return False