diff --git a/public/i18n/en.yml b/public/i18n/en.yml index 862b455..d962577 100644 --- a/public/i18n/en.yml +++ b/public/i18n/en.yml @@ -48,6 +48,7 @@ COPY_PICBED_CONFIG_SUCCEED: Copy Picbed Config Succeed INPUT: Input CANCEL: Cancel CONFIRM: Confirm +RESET_PICBED_CONFIG: Reset CHOOSE_SHOWED_PICBED: Choose Showed Picbed CHOOSE_PASTE_FORMAT: Choose Paste Format SEARCH: Search @@ -222,6 +223,7 @@ TIPS_NETWORK_ERROR: Network Error TIPS_NEED_RELOAD: Need Reload App TIPS_PLEASE_CHOOSE_LOG_LEVEL: Please choose log level TIPS_SET_SUCCEED: Set successfully +TIPS_RESET_SUCCEED: Reset successfully TIPS_PLUGIN_NOT_GUI_IMPLEMENT: This plugin is not optimized for the GUI, continue? TIPS_CLICK_NOTIFICATION_TO_RELOAD: Click notification to reload app TIPS_GET_PLUGIN_LIST_FAILED: Get plugin list failed diff --git a/public/i18n/zh-CN.yml b/public/i18n/zh-CN.yml index 0526917..97888bf 100644 --- a/public/i18n/zh-CN.yml +++ b/public/i18n/zh-CN.yml @@ -48,6 +48,7 @@ COPY_PICBED_CONFIG_SUCCEED: 复制图床配置成功 INPUT: 输入框 CANCEL: 取消 CONFIRM: 确定 +RESET_PICBED_CONFIG: 重置 CHOOSE_SHOWED_PICBED: 请选择显示的图床 CHOOSE_PASTE_FORMAT: 请选择粘贴的格式 SEARCH: 搜索 @@ -222,6 +223,7 @@ TIPS_NETWORK_ERROR: 网络错误暂时无法获取 TIPS_NEED_RELOAD: 需要重启生效 TIPS_PLEASE_CHOOSE_LOG_LEVEL: 请选择日志记录等级 TIPS_SET_SUCCEED: 设置成功 +TIPS_RESET_SUCCEED: 重置成功 TIPS_PLUGIN_NOT_GUI_IMPLEMENT: 该插件未对可视化界面进行优化, 是否继续安装? TIPS_CLICK_NOTIFICATION_TO_RELOAD: 请点击此通知重启应用以生效 TIPS_GET_PLUGIN_LIST_FAILED: 获取插件列表失败 diff --git a/public/i18n/zh-TW.yml b/public/i18n/zh-TW.yml index 929cd6b..01d6921 100644 --- a/public/i18n/zh-TW.yml +++ b/public/i18n/zh-TW.yml @@ -48,6 +48,7 @@ COPY_PICBED_CONFIG_SUCCEED: 複製圖床設定成功 INPUT: 輸入框 CANCEL: 取消 CONFIRM: 確定 +RESET_PICBED_CONFIG: 重置 CHOOSE_SHOWED_PICBED: 請選擇顯示的圖床 CHOOSE_PASTE_FORMAT: 請選擇貼上的格式 SEARCH: 搜尋 @@ -222,6 +223,7 @@ TIPS_NETWORK_ERROR: 網路錯誤,暫時無法取得 TIPS_NEED_RELOAD: 需要重新啟動生效 TIPS_PLEASE_CHOOSE_LOG_LEVEL: 請選擇記錄等級 TIPS_SET_SUCCEED: 設定成功 +TIPS_RESET_SUCCEED: 重置成功 TIPS_PLUGIN_NOT_GUI_IMPLEMENT: 該插件未對GUI進行優化,是否繼續安裝? TIPS_CLICK_NOTIFICATION_TO_RELOAD: 請點擊此通知重新啟動程式以生效 TIPS_GET_PLUGIN_LIST_FAILED: 取得插件列表失敗 diff --git a/src/main/events/rpc/index.ts b/src/main/events/rpc/index.ts index 8024907..1854f4d 100644 --- a/src/main/events/rpc/index.ts +++ b/src/main/events/rpc/index.ts @@ -4,6 +4,7 @@ import { RPC_ACTIONS } from '#/events/constants' import { deleteUploaderConfig, getUploaderConfigList, + resetUploaderConfig, selectUploaderConfig, updateUploaderConfig } from '~/main/utils/handleUploaderConfig' @@ -33,6 +34,11 @@ class RPCServer { this.sendBack(event, action, true, callbackId) break } + case IRPCActionType.RESET_UPLOADER_CONFIG: { + this.resetUploaderConfig(args as IResetUploaderConfigArgs) + this.sendBack(event, action, true, callbackId) + break + } default: { this.sendBack(event, action, null, callbackId) break @@ -74,6 +80,12 @@ class RPCServer { const res = updateUploaderConfig(type, id, config) return res } + + private resetUploaderConfig (args: IResetUploaderConfigArgs) { + const [type, id] = args + const res = resetUploaderConfig(type, id) + return res + } } const rpcServer = new RPCServer() diff --git a/src/main/utils/handleUploaderConfig.ts b/src/main/utils/handleUploaderConfig.ts index 079daab..1fc63f7 100644 --- a/src/main/utils/handleUploaderConfig.ts +++ b/src/main/utils/handleUploaderConfig.ts @@ -167,3 +167,23 @@ export const updateUploaderConfig = (type: string, id: string, config: IStringKe [`picBed.${type}`]: updatedConfig }) } + +/** + * Reset selected congfig id to default + */ + +export const resetUploaderConfig = (type: string, id: string) => { + const { configList } = getUploaderConfigList(type) + configList.forEach((item: IStringKeyMap) => { + if (item._id === id) { + Object.keys(item).forEach(key => { + if (!['_configName', '_id', '_createdAt', '_updatedAt'].includes(key)) { + delete item[key] + } + }) + } + }) + picgo.saveConfig({ + [`uploader.${type}.configList`]: configList + }) +} diff --git a/src/renderer/pages/picbeds/index.vue b/src/renderer/pages/picbeds/index.vue index 8fab36c..16a24a4 100644 --- a/src/renderer/pages/picbeds/index.vue +++ b/src/renderer/pages/picbeds/index.vue @@ -27,14 +27,24 @@ type="uploader" > - - {{ $T('CONFIRM') }} - + + + {{ $T('RESET_PICBED_CONFIG') }} + + + {{ $T('CONFIRM') }} + +
([]) const picBedName = ref('') @@ -90,6 +101,17 @@ const handleConfirm = async () => { } } +const handleReset = async () => { + await triggerRPC(IRPCActionType.RESET_UPLOADER_CONFIG, type.value, $route.params.configId) + const successNotification = new Notification($T('SETTINGS_RESULT'), { + body: $T('TIPS_RESET_SUCCEED') + }) + successNotification.onclick = () => { + return true + } + $router.back() +} + const linkToLogInList = ['github', 'tcyun', 'aliyun', 'smms', 'qiniu', 'imgur', 'upyun', 'githubPlus'] function handelNameClick () { diff --git a/src/universal/types/enum.ts b/src/universal/types/enum.ts index a56485f..1613f81 100644 --- a/src/universal/types/enum.ts +++ b/src/universal/types/enum.ts @@ -63,4 +63,5 @@ export enum IRPCActionType { CHANGE_CURRENT_UPLOADER = 'CHANGE_CURRENT_UPLOADER', SELECT_UPLOADER = 'SELECT_UPLOADER', UPDATE_UPLOADER_CONFIG = 'UPDATE_UPLOADER_CONFIG', + RESET_UPLOADER_CONFIG = 'RESET_UPLOADER_CONFIG' } diff --git a/src/universal/types/i18n.d.ts b/src/universal/types/i18n.d.ts index 2085ef1..7967979 100644 --- a/src/universal/types/i18n.d.ts +++ b/src/universal/types/i18n.d.ts @@ -46,6 +46,7 @@ interface ILocales { INPUT: string CANCEL: string CONFIRM: string + RESET_PICBED_CONFIG: string CHOOSE_SHOWED_PICBED: string CHOOSE_PASTE_FORMAT: string SEARCH: string @@ -201,6 +202,7 @@ interface ILocales { TIPS_NEED_RELOAD: string TIPS_PLEASE_CHOOSE_LOG_LEVEL: string TIPS_SET_SUCCEED: string + TIPS_RESET_SUCCEED: string TIPS_PLUGIN_NOT_GUI_IMPLEMENT: string TIPS_CLICK_NOTIFICATION_TO_RELOAD: string TIPS_GET_PLUGIN_LIST_FAILED: string diff --git a/src/universal/types/rpc.d.ts b/src/universal/types/rpc.d.ts index 39a50fa..48d7789 100644 --- a/src/universal/types/rpc.d.ts +++ b/src/universal/types/rpc.d.ts @@ -2,3 +2,4 @@ type IGetUploaderConfigListArgs = [type: string] type IDeleteUploaderConfigArgs = [type: string, id: string] type ISelectUploaderConfigArgs = [type: string, id: string] type IUpdateUploaderConfigArgs = [type: string, id: string, config: IStringKeyMap] +type IResetUploaderConfigArgs = [type: string, id: string]