Skip to content

Commit 8d442ac

Browse files
authored
✨ add batch update scripts (#219)
1 parent f1527b0 commit 8d442ac

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

src/locales/en-US/translation.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ confirm_delete_subscription: Are You Sure You Want to Delete This Subscription?
108108
# Script List ScriptList
109109
list:
110110
confirm_delete: Are You Sure You Want to Delete? Please Note That This and pasted the remaining text.
111+
confirm_update: Are You Sure You Want to Update? Please Note That This is an irreversible operation.
111112
enable: Enable
112113
disable: Disable
113114
name: Name
@@ -135,10 +136,12 @@ update_not_supported: This script does not support update checks
135136
checking_for_updates: Checking for updates...
136137
new_version_available: New version available
137138
latest_version: Latest Version
139+
checked_for_all_selected: Checked updates for all selected
138140
update_check_failed: Update Check Failed
139141
stopping_script: Stopping script
140142
script_stopped: Script Stopped
141143
starting_script: Starting script...
144+
starting_updates: Starting Batch Updates...
142145
script_started: Script Started
143146
batch_operations: Batch Operations
144147
export: Export

src/locales/zh-CN/translation.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ backup_list: 备份列表
6060
open_backup_dir: 打开备份目录
6161
confirm_delete: 确认删除
6262
confirm_delete_backup_file: 确认删除备份文件
63+
confirm_update: 确认更新
6364
delete_success: 删除成功
6465
backup_strategy: 备份策略
6566
under_construction: 建设中
@@ -108,6 +109,7 @@ confirm_delete_subscription: 确定要删除此订阅吗? 相关的脚本也会
108109
# 脚本列表 ScriptList
109110
list:
110111
confirm_delete: 确定要删除吗?请注意这个操作无法恢复!
112+
confirm_update: 确认要更新吗?请注意此操作不可逆!
111113
enable: 开启
112114
disable: 关闭
113115
name: 名称
@@ -135,10 +137,12 @@ update_not_supported: 该脚本不支持检查更新
135137
checking_for_updates: 检查更新中...
136138
new_version_available: 存在新版本
137139
latest_version: 已是最新版本
140+
checked_for_all_selected: 所选脚本皆已检查更新
138141
update_check_failed: 检查更新失败
139142
stopping_script: 正在停止脚本
140143
script_stopped: 脚本已停止
141144
starting_script: 正在启动脚本...
145+
starting_updates: 正在批量更新...
142146
script_started: 脚本已启动
143147
batch_operations: 批量操作
144148
export: 导出

src/pages/options/routes/ScriptList.tsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ function ScriptList() {
714714
<Select.Option value="disable">{t("disable")}</Select.Option>
715715
<Select.Option value="export">{t("export")}</Select.Option>
716716
<Select.Option value="delete">{t("delete")}</Select.Option>
717+
<Select.Option value="update">{t("update")}</Select.Option>
717718
</Select>
718719
<Button
719720
type="primary"
@@ -767,6 +768,57 @@ function ScriptList() {
767768
});
768769
}
769770
break;
771+
// 批量更新
772+
case "update":
773+
// eslint-disable-next-line no-restricted-globals, no-alert
774+
if (confirm(t("list.confirm_update")!)) {
775+
select.forEach((item, index, array) => {
776+
Message.warning({
777+
id: "checkupdateStart",
778+
content: t("starting_updates"),
779+
});
780+
scriptCtrl
781+
.checkUpdate(item.id)
782+
.then((res) => {
783+
if (res) {
784+
// 需要更新
785+
Message.warning({
786+
id: "checkupdate",
787+
content: t("new_version_available"),
788+
});
789+
} else {
790+
// 已是最新,不弹出了,不然脚本数目太多会一直显示很久
791+
// Message.success({
792+
// id: "checkupdate",
793+
// content: t("latest_version"),
794+
// });
795+
}
796+
if (index === array.length - 1) {
797+
// 当前元素是最后一个
798+
Message.success({
799+
id: "checkupdateEnd",
800+
content: t("checked_for_all_selected"),
801+
});
802+
}
803+
})
804+
.catch((e) => {
805+
Message.error({
806+
id: "checkupdate",
807+
content: `${t("update_check_failed")}: ${
808+
e.message
809+
}`,
810+
});
811+
});
812+
const list = scriptList.map((script) => {
813+
if (script.id === item.id) {
814+
script.updatetime = item.updatetime;
815+
}
816+
return script;
817+
});
818+
setScriptList(list);
819+
});
820+
}
821+
break;
770822
default:
771823
Message.error(t("unknown_operation")!);
772824
break;

0 commit comments

Comments
 (0)