Feature: picbeds config can be reseted to empty now

This commit is contained in:
萌萌哒赫萝 2023-03-24 13:32:16 +08:00
parent f0daf97028
commit 086b2871e7
9 changed files with 72 additions and 8 deletions

View File

@ -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

View File

@ -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: 获取插件列表失败

View File

@ -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: 取得插件列表失敗

View File

@ -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()

View File

@ -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
})
}

View File

@ -27,14 +27,24 @@
type="uploader"
>
<el-form-item>
<el-button
class="confirm-btn"
type="primary"
round
@click="handleConfirm"
>
{{ $T('CONFIRM') }}
</el-button>
<el-button-group>
<el-button
class="confirm-btn"
type="info"
round
@click="handleReset"
>
{{ $T('RESET_PICBED_CONFIG') }}
</el-button>
<el-button
class="confirm-btn"
type="success"
round
@click="handleConfirm"
>
{{ $T('CONFIRM') }}
</el-button>
</el-button-group>
</el-form-item>
</config-form>
<div
@ -63,6 +73,7 @@ import {
} from 'electron'
import { OPEN_URL } from '~/universal/events/constants'
import { Link } from '@element-plus/icons-vue'
const type = ref('')
const config = ref<IPicGoPluginConfig[]>([])
const picBedName = ref('')
@ -90,6 +101,17 @@ const handleConfirm = async () => {
}
}
const handleReset = async () => {
await triggerRPC<void>(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 () {

View File

@ -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'
}

View File

@ -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

View File

@ -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]