diff --git a/src/main.ts b/src/main.ts index 3b7adc0..1ec9f80 100644 --- a/src/main.ts +++ b/src/main.ts @@ -19,9 +19,10 @@ import db from '@/utils/db' import { T } from '@/i18n/index' import { store } from '@/store' import { initTalkingData } from '@/utils/analytic' -import { getConfig, saveConfig, sendToMain, triggerRPC } from '@/utils/dataSender' +import { getConfig, saveConfig, triggerRPC } from '@/utils/dataSender' import { mainMixin } from '@/utils/mainMixin' import { dragMixin } from '@/utils/mixin' +import { sendToMain } from '@/utils/common' webFrame.setVisualZoomLevelLimits(1, 1) diff --git a/src/main/events/ipcList.ts b/src/main/events/ipcList.ts index 25ce27c..b7f1129 100644 --- a/src/main/events/ipcList.ts +++ b/src/main/events/ipcList.ts @@ -301,7 +301,7 @@ export default { ipcMain.on(GET_PICBEDS, (evt: IpcMainEvent) => { const picBeds = getPicBeds() evt.sender.send(GET_PICBEDS, picBeds) - evt.returnValue = picBeds + // evt.returnValue = picBeds }) ipcMain.on(TOGGLE_SHORTKEY_MODIFIED_MODE, (_: IpcMainEvent, val: boolean) => { diff --git a/src/main/events/picgoCoreIPC.ts b/src/main/events/picgoCoreIPC.ts index 08af014..9d22abe 100644 --- a/src/main/events/picgoCoreIPC.ts +++ b/src/main/events/picgoCoreIPC.ts @@ -38,7 +38,8 @@ import { OPEN_WINDOW, GET_LANGUAGE_LIST, SET_CURRENT_LANGUAGE, - GET_CURRENT_LANGUAGE + GET_CURRENT_LANGUAGE, + PICGO_GET_CONFIG_SYNC } from '#/events/constants' import { configPaths } from '#/utils/configPaths' import { IPasteStyle, IPicGoHelperType, IWindowList } from '#/types/enum' @@ -211,7 +212,7 @@ const handlePluginUpdate = async (fullName: string | string[]) => { } const handleUpdateAllPlugin = () => { - ipcMain.on('updateAllPlugin', async (event: IpcMainEvent, list: string[]) => { + ipcMain.on('updateAllPlugin', async (_: IpcMainEvent, list: string[]) => { handlePluginUpdate(list) }) } @@ -249,7 +250,7 @@ const handleGetPicBedConfig = () => { // TODO: remove it const handlePluginActions = () => { - ipcMain.on('pluginActions', (event: IpcMainEvent, name: string, label: string) => { + ipcMain.on('pluginActions', (_: IpcMainEvent, name: string, label: string) => { const plugin = picgo.pluginLoader.getPlugin(name) if (plugin?.guiMenu?.(picgo)?.length) { const menu: GuiMenuItem[] = plugin.guiMenu(picgo) @@ -263,7 +264,7 @@ const handlePluginActions = () => { } const handleRemoveFiles = () => { - ipcMain.on('removeFiles', (event: IpcMainEvent, files: ImgInfo[]) => { + ipcMain.on('removeFiles', (_: IpcMainEvent, files: ImgInfo[]) => { setTimeout(() => { picgo.emit('remove', files, GuiApi.getInstance()) }, 500) @@ -271,15 +272,21 @@ const handleRemoveFiles = () => { } const handlePicGoSaveConfig = () => { - ipcMain.on(PICGO_SAVE_CONFIG, (event: IpcMainEvent, data: IObj) => { + ipcMain.on(PICGO_SAVE_CONFIG, (_: IpcMainEvent, data: IObj) => { picgo.saveConfig(data) }) } const handlePicGoGetConfig = () => { - ipcMain.on(PICGO_GET_CONFIG, (event: IpcMainEvent, key: string | undefined, callbackId: string) => { + ipcMain.handle(PICGO_GET_CONFIG, (_, key: string | undefined) => { + return picgo.getConfig(key) + }) +} + +const handlePicGoGetConfigSync = () => { + ipcMain.on(PICGO_GET_CONFIG_SYNC, (event: IpcMainEvent, key: string | undefined) => { const result = picgo.getConfig(key) - event.sender.send(PICGO_GET_CONFIG, result, callbackId) + event.returnValue = result }) } @@ -436,6 +443,7 @@ export default { handleRemoveFiles() handlePicGoSaveConfig() handlePicGoGetConfig() + handlePicGoGetConfigSync() handlePicGoGalleryDB() handleImportLocalPlugin() handleUpdateAllPlugin() diff --git a/src/renderer/components/InputBoxDialog.vue b/src/renderer/components/InputBoxDialog.vue index af087d5..c06de3f 100644 --- a/src/renderer/components/InputBoxDialog.vue +++ b/src/renderer/components/InputBoxDialog.vue @@ -33,7 +33,7 @@ import { ref, reactive, onBeforeUnmount, onBeforeMount } from 'vue' import { T as $T } from '@/i18n/index' import $bus from '@/utils/bus' -import { sendToMain } from '@/utils/dataSender' +import { sendToMain } from '@/utils/common' import { SHOW_INPUT_BOX, diff --git a/src/renderer/layouts/Main.vue b/src/renderer/layouts/Main.vue index 1b99bec..857f5b4 100644 --- a/src/renderer/layouts/Main.vue +++ b/src/renderer/layouts/Main.vue @@ -246,8 +246,8 @@ import { onBeforeRouteUpdate, useRouter } from 'vue-router' import InputBoxDialog from '@/components/InputBoxDialog.vue' import { T as $T } from '@/i18n/index' import * as config from '@/router/config' -import { getConfig, saveConfig, sendToMain } from '@/utils/dataSender' -import { openURL } from '@/utils/common' +import { getConfig, saveConfig } from '@/utils/dataSender' +import { openURL, sendToMain } from '@/utils/common' import { MINIMIZE_WINDOW, diff --git a/src/renderer/manage/pages/manageMain.vue b/src/renderer/manage/pages/manageMain.vue index 6a6f3b5..61fa80c 100644 --- a/src/renderer/manage/pages/manageMain.vue +++ b/src/renderer/manage/pages/manageMain.vue @@ -287,11 +287,11 @@ import { ref, reactive, computed, onBeforeMount, watch } from 'vue' import { useRouter, useRoute } from 'vue-router' import { supportedPicBedList } from '@/manage/utils/constants' -import { invokeToMain } from '@/manage/utils/dataSender' import { useManageStore } from '@/manage/store/manageStore' import { newBucketConfig } from '@/manage/utils/newBucketConfig' import { T as $T } from '@/i18n' +import { invokeToMain } from '@/utils/common' const manageStore = useManageStore() as any const route = useRoute() diff --git a/src/renderer/manage/pages/manageSetting.vue b/src/renderer/manage/pages/manageSetting.vue index b00a8ea..241a2be 100644 --- a/src/renderer/manage/pages/manageSetting.vue +++ b/src/renderer/manage/pages/manageSetting.vue @@ -248,11 +248,12 @@ import { ref, onBeforeMount, watch } from 'vue' import DynamicSwitch from '@/manage/components/DynamicSwitch.vue' import { fileCacheDbInstance } from '@/manage/store/bucketFileDb' import { formatFileSize, customRenameFormatTable } from '@/manage/utils/common' -import { getConfig, saveConfig, invokeToMain } from '@/manage/utils/dataSender' +import { getConfig, saveConfig } from '@/manage/utils/dataSender' import { T as $T } from '@/i18n' import { selectDownloadFolder } from '#/utils/static' +import { invokeToMain } from '@/utils/common' const form = ref({ timestampRename: false, diff --git a/src/renderer/manage/utils/dataSender.ts b/src/renderer/manage/utils/dataSender.ts index a94f0d0..3cfce67 100644 --- a/src/renderer/manage/utils/dataSender.ts +++ b/src/renderer/manage/utils/dataSender.ts @@ -34,13 +34,3 @@ export function saveConfig (_config: IObj | string, value?: any) { export function removeConfig (key: string, propName: string) { ipcRenderer.send(PICLIST_MANAGE_REMOVE_CONFIG, key, propName) } - -export function sendToMain (channel: string, ...args: any[]) { - const data = getRawData(args) - ipcRenderer.send(channel, ...data) -} - -export function invokeToMain (channel: string, ...args: any[]) { - const data = getRawData(args) - return ipcRenderer.invoke(channel, ...data) -} diff --git a/src/renderer/pages/Gallery.vue b/src/renderer/pages/Gallery.vue index 8c63749..26a379a 100644 --- a/src/renderer/pages/Gallery.vue +++ b/src/renderer/pages/Gallery.vue @@ -475,7 +475,8 @@ import type { IResult } from '@picgo/store/dist/types' import ALLApi from '@/apis/allApi' import { T as $T } from '@/i18n/index' import { customRenameFormatTable, customStrMatch, customStrReplace } from '@/manage/utils/common' -import { getConfig, saveConfig, sendToMain } from '@/utils/dataSender' +import { sendToMain } from '@/utils/common' +import { getConfig, saveConfig } from '@/utils/dataSender' import $$db from '@/utils/db' import { PASTE_TEXT, GET_PICBEDS } from '#/events/constants' diff --git a/src/renderer/pages/MiniPage.vue b/src/renderer/pages/MiniPage.vue index 04665bb..1d89d5f 100644 --- a/src/renderer/pages/MiniPage.vue +++ b/src/renderer/pages/MiniPage.vue @@ -40,8 +40,8 @@ import { IConfig } from 'piclist' import { onBeforeUnmount, onBeforeMount, ref, watch } from 'vue' import { T as $T } from '@/i18n/index' -import { invokeToMain } from '@/manage/utils/dataSender' -import { getConfig, sendToMain } from '@/utils/dataSender' +import { sendToMain, invokeToMain } from '@/utils/common' +import { getConfig } from '@/utils/dataSender' import { SHOW_MINI_PAGE_MENU, SET_MINI_WINDOW_POS } from '#/events/constants' import { isUrl } from '#/utils/common' diff --git a/src/renderer/pages/PicGoSetting.vue b/src/renderer/pages/PicGoSetting.vue index b3e80da..f8aed3f 100644 --- a/src/renderer/pages/PicGoSetting.vue +++ b/src/renderer/pages/PicGoSetting.vue @@ -1388,9 +1388,8 @@ import { useRouter } from 'vue-router' import ImageProcessSetting from '@/components/ImageProcessSetting.vue' import { i18nManager, T as $T } from '@/i18n/index' import { buildInRenameFormatTable } from '@/manage/utils/common' -import { invokeToMain } from '@/manage/utils/dataSender' import { SHORTKEY_PAGE } from '@/router/config' -import { getConfig, saveConfig, sendRPC, sendToMain } from '@/utils/dataSender' +import { getConfig, saveConfig, sendRPC } from '@/utils/dataSender' import { PICGO_OPEN_FILE, PICGO_OPEN_DIRECTORY, OPEN_URL, GET_PICBEDS, HIDE_DOCK } from '#/events/constants' import { II18nLanguage, IRPCActionType, ISartMode } from '#/types/enum' @@ -1399,6 +1398,7 @@ import { configPaths, ISartModeValues } from '#/utils/configPaths' import { getLatestVersion } from '#/utils/getLatestVersion' import pkg from 'root/package.json' +import { invokeToMain, sendToMain } from '@/utils/common' const $router = useRouter() const activeName = ref<'system' | 'syncAndConfigure' | 'upload' | 'advanced' | 'upadte'>('system') @@ -1422,7 +1422,7 @@ const languageList = i18nManager.languageList.map(item => ({ })) const startModeList = Object.values(ISartMode).map(item => ({ - label: $T(`SETTINGS_START_MODE_${item.toUpperCase().replace(/_/g, '')}` as any), + label: $T(`SETTINGS_START_MODE_${item.toUpperCase().replace(/-/g, '_')}` as any), value: item })) diff --git a/src/renderer/pages/Plugin.vue b/src/renderer/pages/Plugin.vue index ef9ea1a..d801b48 100644 --- a/src/renderer/pages/Plugin.vue +++ b/src/renderer/pages/Plugin.vue @@ -241,7 +241,8 @@ import { computed, ref, onBeforeMount, onBeforeUnmount, watch, onMounted, reacti import ConfigForm from '@/components/ConfigFormForPlugin.vue' import { T as $T } from '@/i18n/index' -import { getConfig, saveConfig, sendRPC, sendToMain } from '@/utils/dataSender' +import { sendToMain } from '@/utils/common' +import { getConfig, saveConfig, sendRPC } from '@/utils/dataSender' import { OPEN_URL, diff --git a/src/renderer/pages/RenamePage.vue b/src/renderer/pages/RenamePage.vue index f43c9ba..e1e6f2a 100644 --- a/src/renderer/pages/RenamePage.vue +++ b/src/renderer/pages/RenamePage.vue @@ -60,7 +60,7 @@ import { onBeforeUnmount, onBeforeMount, ref, reactive } from 'vue' import { useIPCOn } from '@/hooks/useIPC' import { T as $T } from '@/i18n/index' -import { sendToMain } from '@/utils/dataSender' +import { sendToMain } from '@/utils/common' import { GET_RENAME_FILE_NAME, RENAME_FILE_NAME } from '#/events/constants' diff --git a/src/renderer/pages/ShortKey.vue b/src/renderer/pages/ShortKey.vue index 2edb204..d22a24d 100644 --- a/src/renderer/pages/ShortKey.vue +++ b/src/renderer/pages/ShortKey.vue @@ -122,7 +122,8 @@ import { ipcRenderer, IpcRendererEvent } from 'electron' import { onBeforeUnmount, onBeforeMount, ref, watch } from 'vue' import { T as $T } from '@/i18n' -import { getConfig, sendToMain } from '@/utils/dataSender' +import { sendToMain } from '@/utils/common' +import { getConfig } from '@/utils/dataSender' import keyBinding from '@/utils/key-binding' import { TOGGLE_SHORTKEY_MODIFIED_MODE } from '#/events/constants' diff --git a/src/renderer/pages/TrayPage.vue b/src/renderer/pages/TrayPage.vue index b7a2f37..bb764ee 100644 --- a/src/renderer/pages/TrayPage.vue +++ b/src/renderer/pages/TrayPage.vue @@ -67,7 +67,8 @@ import { reactive, ref, onBeforeUnmount, onBeforeMount } from 'vue' import { IResult } from '@picgo/store/dist/types' import { T as $T } from '@/i18n/index' -import { getConfig, sendToMain } from '@/utils/dataSender' +import { sendToMain } from '@/utils/common' +import { getConfig } from '@/utils/dataSender' import $$db from '@/utils/db' diff --git a/src/renderer/pages/Upload.vue b/src/renderer/pages/Upload.vue index 98fd5c9..a0ff1a5 100644 --- a/src/renderer/pages/Upload.vue +++ b/src/renderer/pages/Upload.vue @@ -164,7 +164,8 @@ import ImageProcessSetting from '@/components/ImageProcessSetting.vue' import { T as $T } from '@/i18n' import { PICBEDS_PAGE } from '@/router/config' import $bus from '@/utils/bus' -import { getConfig, saveConfig, sendToMain, triggerRPC } from '@/utils/dataSender' +import { sendToMain } from '@/utils/common' +import { getConfig, saveConfig, triggerRPC } from '@/utils/dataSender' import { SHOW_INPUT_BOX, diff --git a/src/renderer/pages/picbeds/index.vue b/src/renderer/pages/picbeds/index.vue index 9161443..d35525b 100644 --- a/src/renderer/pages/picbeds/index.vue +++ b/src/renderer/pages/picbeds/index.vue @@ -110,7 +110,8 @@ import { useRoute, useRouter } from 'vue-router' import ConfigForm from '@/components/ConfigForm.vue' import { T as $T } from '@/i18n/index' -import { getConfig, sendToMain, triggerRPC } from '@/utils/dataSender' +import { sendToMain } from '@/utils/common' +import { getConfig, triggerRPC } from '@/utils/dataSender' import { OPEN_URL } from '#/events/constants' import { II18nLanguage, IRPCActionType } from '#/types/enum' diff --git a/src/renderer/utils/common.ts b/src/renderer/utils/common.ts index a631816..dc5e9ec 100644 --- a/src/renderer/utils/common.ts +++ b/src/renderer/utils/common.ts @@ -5,6 +5,7 @@ import { OPEN_URL } from '#/events/constants' import { ILogType } from '#/types/enum' const isDevelopment = process.env.NODE_ENV !== 'production' + export const handleTalkingDataEvent = (data: ITalkingDataOptions) => { const { EventId, Label = '', MapKv = {} } = data MapKv.from = window.location.href @@ -31,11 +32,16 @@ export const getRawData = (args: any): any => { return args } -function sendToMain (channel: string, ...args: any[]) { +export function sendToMain (channel: string, ...args: any[]) { const data = getRawData(args) ipcRenderer.send(channel, ...data) } +export function invokeToMain (channel: string, ...args: any[]) { + const data = getRawData(args) + return ipcRenderer.invoke(channel, ...data) +} + export const openURL = (url: string) => { sendToMain(OPEN_URL, url) } diff --git a/src/renderer/utils/dataSender.ts b/src/renderer/utils/dataSender.ts index 0c24465..d3a57b0 100644 --- a/src/renderer/utils/dataSender.ts +++ b/src/renderer/utils/dataSender.ts @@ -3,7 +3,7 @@ import { v4 as uuid } from 'uuid' import { getRawData } from '@/utils/common' -import { PICGO_SAVE_CONFIG, PICGO_GET_CONFIG, RPC_ACTIONS } from '#/events/constants' +import { PICGO_SAVE_CONFIG, PICGO_GET_CONFIG, RPC_ACTIONS, PICGO_GET_CONFIG_SYNC } from '#/events/constants' import { IRPCActionType } from '#/types/enum' export function saveConfig (config: IObj | string, value?: any) { @@ -11,18 +11,12 @@ export function saveConfig (config: IObj | string, value?: any) { ipcRenderer.send(PICGO_SAVE_CONFIG, configObject) } -export function getConfig (key?: string): Promise { - return new Promise((resolve) => { - const callbackId = uuid() - const callback = (_event: IpcRendererEvent, config: T | undefined, returnCallbackId: string) => { - if (returnCallbackId === callbackId) { - resolve(config) - ipcRenderer.removeListener(PICGO_GET_CONFIG, callback) - } - } - ipcRenderer.on(PICGO_GET_CONFIG, callback) - ipcRenderer.send(PICGO_GET_CONFIG, key, callbackId) - }) +export async function getConfig (key?: string): Promise { + return await ipcRenderer.invoke(PICGO_GET_CONFIG, key) +} + +export async function getConfigSync (key?: string): Promise { + return await ipcRenderer.sendSync(PICGO_GET_CONFIG_SYNC, key) } /** @@ -53,8 +47,3 @@ export function sendRPC (action: IRPCActionType, ...args: any[]): void { const data = getRawData(args) ipcRenderer.send(RPC_ACTIONS, action, data) } - -export function sendToMain (channel: string, ...args: any[]) { - const data = getRawData(args) - ipcRenderer.send(channel, ...data) -} diff --git a/src/universal/events/constants.ts b/src/universal/events/constants.ts index 688ccb4..7fe4a2e 100644 --- a/src/universal/events/constants.ts +++ b/src/universal/events/constants.ts @@ -5,6 +5,7 @@ export const TALKING_DATA_APPID = 'B743C16E2989419A9B02EDE9D1E6A530' export const TALKING_DATA_EVENT = 'TALKING_DATA_EVENT' export const PICGO_SAVE_CONFIG = 'PICGO_SAVE_CONFIG' export const PICGO_GET_CONFIG = 'PICGO_GET_CONFIG' +export const PICGO_GET_CONFIG_SYNC = 'PICGO_GET_CONFIG_SYNC' export const PICGO_GET_DB = 'PICGO_GET_DB' export const PICGO_INSERT_DB = 'PICGO_INSERT_DB' export const PICGO_INSERT_MANY_DB = 'PICGO_INSERT_MANY_DB'