Feature(custom): optimize get config speed

This commit is contained in:
Kuingsmile 2024-06-09 21:05:30 +08:00
parent 19c12b6b02
commit 106290f868
20 changed files with 57 additions and 55 deletions

View File

@ -19,9 +19,10 @@ import db from '@/utils/db'
import { T } from '@/i18n/index' import { T } from '@/i18n/index'
import { store } from '@/store' import { store } from '@/store'
import { initTalkingData } from '@/utils/analytic' 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 { mainMixin } from '@/utils/mainMixin'
import { dragMixin } from '@/utils/mixin' import { dragMixin } from '@/utils/mixin'
import { sendToMain } from '@/utils/common'
webFrame.setVisualZoomLevelLimits(1, 1) webFrame.setVisualZoomLevelLimits(1, 1)

View File

@ -301,7 +301,7 @@ export default {
ipcMain.on(GET_PICBEDS, (evt: IpcMainEvent) => { ipcMain.on(GET_PICBEDS, (evt: IpcMainEvent) => {
const picBeds = getPicBeds() const picBeds = getPicBeds()
evt.sender.send(GET_PICBEDS, picBeds) evt.sender.send(GET_PICBEDS, picBeds)
evt.returnValue = picBeds // evt.returnValue = picBeds
}) })
ipcMain.on(TOGGLE_SHORTKEY_MODIFIED_MODE, (_: IpcMainEvent, val: boolean) => { ipcMain.on(TOGGLE_SHORTKEY_MODIFIED_MODE, (_: IpcMainEvent, val: boolean) => {

View File

@ -38,7 +38,8 @@ import {
OPEN_WINDOW, OPEN_WINDOW,
GET_LANGUAGE_LIST, GET_LANGUAGE_LIST,
SET_CURRENT_LANGUAGE, SET_CURRENT_LANGUAGE,
GET_CURRENT_LANGUAGE GET_CURRENT_LANGUAGE,
PICGO_GET_CONFIG_SYNC
} from '#/events/constants' } from '#/events/constants'
import { configPaths } from '#/utils/configPaths' import { configPaths } from '#/utils/configPaths'
import { IPasteStyle, IPicGoHelperType, IWindowList } from '#/types/enum' import { IPasteStyle, IPicGoHelperType, IWindowList } from '#/types/enum'
@ -211,7 +212,7 @@ const handlePluginUpdate = async (fullName: string | string[]) => {
} }
const handleUpdateAllPlugin = () => { const handleUpdateAllPlugin = () => {
ipcMain.on('updateAllPlugin', async (event: IpcMainEvent, list: string[]) => { ipcMain.on('updateAllPlugin', async (_: IpcMainEvent, list: string[]) => {
handlePluginUpdate(list) handlePluginUpdate(list)
}) })
} }
@ -249,7 +250,7 @@ const handleGetPicBedConfig = () => {
// TODO: remove it // TODO: remove it
const handlePluginActions = () => { 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) const plugin = picgo.pluginLoader.getPlugin(name)
if (plugin?.guiMenu?.(picgo)?.length) { if (plugin?.guiMenu?.(picgo)?.length) {
const menu: GuiMenuItem[] = plugin.guiMenu(picgo) const menu: GuiMenuItem[] = plugin.guiMenu(picgo)
@ -263,7 +264,7 @@ const handlePluginActions = () => {
} }
const handleRemoveFiles = () => { const handleRemoveFiles = () => {
ipcMain.on('removeFiles', (event: IpcMainEvent, files: ImgInfo[]) => { ipcMain.on('removeFiles', (_: IpcMainEvent, files: ImgInfo[]) => {
setTimeout(() => { setTimeout(() => {
picgo.emit('remove', files, GuiApi.getInstance()) picgo.emit('remove', files, GuiApi.getInstance())
}, 500) }, 500)
@ -271,15 +272,21 @@ const handleRemoveFiles = () => {
} }
const handlePicGoSaveConfig = () => { const handlePicGoSaveConfig = () => {
ipcMain.on(PICGO_SAVE_CONFIG, (event: IpcMainEvent, data: IObj) => { ipcMain.on(PICGO_SAVE_CONFIG, (_: IpcMainEvent, data: IObj) => {
picgo.saveConfig(data) picgo.saveConfig(data)
}) })
} }
const handlePicGoGetConfig = () => { 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) const result = picgo.getConfig(key)
event.sender.send(PICGO_GET_CONFIG, result, callbackId) event.returnValue = result
}) })
} }
@ -436,6 +443,7 @@ export default {
handleRemoveFiles() handleRemoveFiles()
handlePicGoSaveConfig() handlePicGoSaveConfig()
handlePicGoGetConfig() handlePicGoGetConfig()
handlePicGoGetConfigSync()
handlePicGoGalleryDB() handlePicGoGalleryDB()
handleImportLocalPlugin() handleImportLocalPlugin()
handleUpdateAllPlugin() handleUpdateAllPlugin()

View File

@ -33,7 +33,7 @@ import { ref, reactive, onBeforeUnmount, onBeforeMount } from 'vue'
import { T as $T } from '@/i18n/index' import { T as $T } from '@/i18n/index'
import $bus from '@/utils/bus' import $bus from '@/utils/bus'
import { sendToMain } from '@/utils/dataSender' import { sendToMain } from '@/utils/common'
import { import {
SHOW_INPUT_BOX, SHOW_INPUT_BOX,

View File

@ -246,8 +246,8 @@ import { onBeforeRouteUpdate, useRouter } from 'vue-router'
import InputBoxDialog from '@/components/InputBoxDialog.vue' import InputBoxDialog from '@/components/InputBoxDialog.vue'
import { T as $T } from '@/i18n/index' import { T as $T } from '@/i18n/index'
import * as config from '@/router/config' import * as config from '@/router/config'
import { getConfig, saveConfig, sendToMain } from '@/utils/dataSender' import { getConfig, saveConfig } from '@/utils/dataSender'
import { openURL } from '@/utils/common' import { openURL, sendToMain } from '@/utils/common'
import { import {
MINIMIZE_WINDOW, MINIMIZE_WINDOW,

View File

@ -287,11 +287,11 @@ import { ref, reactive, computed, onBeforeMount, watch } from 'vue'
import { useRouter, useRoute } from 'vue-router' import { useRouter, useRoute } from 'vue-router'
import { supportedPicBedList } from '@/manage/utils/constants' import { supportedPicBedList } from '@/manage/utils/constants'
import { invokeToMain } from '@/manage/utils/dataSender'
import { useManageStore } from '@/manage/store/manageStore' import { useManageStore } from '@/manage/store/manageStore'
import { newBucketConfig } from '@/manage/utils/newBucketConfig' import { newBucketConfig } from '@/manage/utils/newBucketConfig'
import { T as $T } from '@/i18n' import { T as $T } from '@/i18n'
import { invokeToMain } from '@/utils/common'
const manageStore = useManageStore() as any const manageStore = useManageStore() as any
const route = useRoute() const route = useRoute()

View File

@ -248,11 +248,12 @@ import { ref, onBeforeMount, watch } from 'vue'
import DynamicSwitch from '@/manage/components/DynamicSwitch.vue' import DynamicSwitch from '@/manage/components/DynamicSwitch.vue'
import { fileCacheDbInstance } from '@/manage/store/bucketFileDb' import { fileCacheDbInstance } from '@/manage/store/bucketFileDb'
import { formatFileSize, customRenameFormatTable } from '@/manage/utils/common' 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 { T as $T } from '@/i18n'
import { selectDownloadFolder } from '#/utils/static' import { selectDownloadFolder } from '#/utils/static'
import { invokeToMain } from '@/utils/common'
const form = ref<IStringKeyMap>({ const form = ref<IStringKeyMap>({
timestampRename: false, timestampRename: false,

View File

@ -34,13 +34,3 @@ export function saveConfig (_config: IObj | string, value?: any) {
export function removeConfig (key: string, propName: string) { export function removeConfig (key: string, propName: string) {
ipcRenderer.send(PICLIST_MANAGE_REMOVE_CONFIG, key, propName) 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)
}

View File

@ -475,7 +475,8 @@ import type { IResult } from '@picgo/store/dist/types'
import ALLApi from '@/apis/allApi' import ALLApi from '@/apis/allApi'
import { T as $T } from '@/i18n/index' import { T as $T } from '@/i18n/index'
import { customRenameFormatTable, customStrMatch, customStrReplace } from '@/manage/utils/common' 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 $$db from '@/utils/db'
import { PASTE_TEXT, GET_PICBEDS } from '#/events/constants' import { PASTE_TEXT, GET_PICBEDS } from '#/events/constants'

View File

@ -40,8 +40,8 @@ import { IConfig } from 'piclist'
import { onBeforeUnmount, onBeforeMount, ref, watch } from 'vue' import { onBeforeUnmount, onBeforeMount, ref, watch } from 'vue'
import { T as $T } from '@/i18n/index' import { T as $T } from '@/i18n/index'
import { invokeToMain } from '@/manage/utils/dataSender' import { sendToMain, invokeToMain } from '@/utils/common'
import { getConfig, sendToMain } from '@/utils/dataSender' import { getConfig } from '@/utils/dataSender'
import { SHOW_MINI_PAGE_MENU, SET_MINI_WINDOW_POS } from '#/events/constants' import { SHOW_MINI_PAGE_MENU, SET_MINI_WINDOW_POS } from '#/events/constants'
import { isUrl } from '#/utils/common' import { isUrl } from '#/utils/common'

View File

@ -1388,9 +1388,8 @@ import { useRouter } from 'vue-router'
import ImageProcessSetting from '@/components/ImageProcessSetting.vue' import ImageProcessSetting from '@/components/ImageProcessSetting.vue'
import { i18nManager, T as $T } from '@/i18n/index' import { i18nManager, T as $T } from '@/i18n/index'
import { buildInRenameFormatTable } from '@/manage/utils/common' import { buildInRenameFormatTable } from '@/manage/utils/common'
import { invokeToMain } from '@/manage/utils/dataSender'
import { SHORTKEY_PAGE } from '@/router/config' 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 { PICGO_OPEN_FILE, PICGO_OPEN_DIRECTORY, OPEN_URL, GET_PICBEDS, HIDE_DOCK } from '#/events/constants'
import { II18nLanguage, IRPCActionType, ISartMode } from '#/types/enum' import { II18nLanguage, IRPCActionType, ISartMode } from '#/types/enum'
@ -1399,6 +1398,7 @@ import { configPaths, ISartModeValues } from '#/utils/configPaths'
import { getLatestVersion } from '#/utils/getLatestVersion' import { getLatestVersion } from '#/utils/getLatestVersion'
import pkg from 'root/package.json' import pkg from 'root/package.json'
import { invokeToMain, sendToMain } from '@/utils/common'
const $router = useRouter() const $router = useRouter()
const activeName = ref<'system' | 'syncAndConfigure' | 'upload' | 'advanced' | 'upadte'>('system') 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 => ({ 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 value: item
})) }))

View File

@ -241,7 +241,8 @@ import { computed, ref, onBeforeMount, onBeforeUnmount, watch, onMounted, reacti
import ConfigForm from '@/components/ConfigFormForPlugin.vue' import ConfigForm from '@/components/ConfigFormForPlugin.vue'
import { T as $T } from '@/i18n/index' 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 { import {
OPEN_URL, OPEN_URL,

View File

@ -60,7 +60,7 @@ import { onBeforeUnmount, onBeforeMount, ref, reactive } from 'vue'
import { useIPCOn } from '@/hooks/useIPC' import { useIPCOn } from '@/hooks/useIPC'
import { T as $T } from '@/i18n/index' 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' import { GET_RENAME_FILE_NAME, RENAME_FILE_NAME } from '#/events/constants'

View File

@ -122,7 +122,8 @@ import { ipcRenderer, IpcRendererEvent } from 'electron'
import { onBeforeUnmount, onBeforeMount, ref, watch } from 'vue' import { onBeforeUnmount, onBeforeMount, ref, watch } from 'vue'
import { T as $T } from '@/i18n' 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 keyBinding from '@/utils/key-binding'
import { TOGGLE_SHORTKEY_MODIFIED_MODE } from '#/events/constants' import { TOGGLE_SHORTKEY_MODIFIED_MODE } from '#/events/constants'

View File

@ -67,7 +67,8 @@ import { reactive, ref, onBeforeUnmount, onBeforeMount } from 'vue'
import { IResult } from '@picgo/store/dist/types' import { IResult } from '@picgo/store/dist/types'
import { T as $T } from '@/i18n/index' 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' import $$db from '@/utils/db'

View File

@ -164,7 +164,8 @@ import ImageProcessSetting from '@/components/ImageProcessSetting.vue'
import { T as $T } from '@/i18n' import { T as $T } from '@/i18n'
import { PICBEDS_PAGE } from '@/router/config' import { PICBEDS_PAGE } from '@/router/config'
import $bus from '@/utils/bus' 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 { import {
SHOW_INPUT_BOX, SHOW_INPUT_BOX,

View File

@ -110,7 +110,8 @@ import { useRoute, useRouter } from 'vue-router'
import ConfigForm from '@/components/ConfigForm.vue' import ConfigForm from '@/components/ConfigForm.vue'
import { T as $T } from '@/i18n/index' 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 { OPEN_URL } from '#/events/constants'
import { II18nLanguage, IRPCActionType } from '#/types/enum' import { II18nLanguage, IRPCActionType } from '#/types/enum'

View File

@ -5,6 +5,7 @@ import { OPEN_URL } from '#/events/constants'
import { ILogType } from '#/types/enum' import { ILogType } from '#/types/enum'
const isDevelopment = process.env.NODE_ENV !== 'production' const isDevelopment = process.env.NODE_ENV !== 'production'
export const handleTalkingDataEvent = (data: ITalkingDataOptions) => { export const handleTalkingDataEvent = (data: ITalkingDataOptions) => {
const { EventId, Label = '', MapKv = {} } = data const { EventId, Label = '', MapKv = {} } = data
MapKv.from = window.location.href MapKv.from = window.location.href
@ -31,11 +32,16 @@ export const getRawData = (args: any): any => {
return args return args
} }
function sendToMain (channel: string, ...args: any[]) { export function sendToMain (channel: string, ...args: any[]) {
const data = getRawData(args) const data = getRawData(args)
ipcRenderer.send(channel, ...data) 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) => { export const openURL = (url: string) => {
sendToMain(OPEN_URL, url) sendToMain(OPEN_URL, url)
} }

View File

@ -3,7 +3,7 @@ import { v4 as uuid } from 'uuid'
import { getRawData } from '@/utils/common' 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' import { IRPCActionType } from '#/types/enum'
export function saveConfig (config: IObj | string, value?: any) { 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) ipcRenderer.send(PICGO_SAVE_CONFIG, configObject)
} }
export function getConfig<T> (key?: string): Promise<T | undefined> { export async function getConfig<T> (key?: string): Promise<T | undefined> {
return new Promise((resolve) => { return await ipcRenderer.invoke(PICGO_GET_CONFIG, key)
const callbackId = uuid() }
const callback = (_event: IpcRendererEvent, config: T | undefined, returnCallbackId: string) => {
if (returnCallbackId === callbackId) { export async function getConfigSync<T> (key?: string): Promise<T | undefined> {
resolve(config) return await ipcRenderer.sendSync(PICGO_GET_CONFIG_SYNC, key)
ipcRenderer.removeListener(PICGO_GET_CONFIG, callback)
}
}
ipcRenderer.on(PICGO_GET_CONFIG, callback)
ipcRenderer.send(PICGO_GET_CONFIG, key, callbackId)
})
} }
/** /**
@ -53,8 +47,3 @@ export function sendRPC (action: IRPCActionType, ...args: any[]): void {
const data = getRawData(args) const data = getRawData(args)
ipcRenderer.send(RPC_ACTIONS, action, data) ipcRenderer.send(RPC_ACTIONS, action, data)
} }
export function sendToMain (channel: string, ...args: any[]) {
const data = getRawData(args)
ipcRenderer.send(channel, ...data)
}

View File

@ -5,6 +5,7 @@ export const TALKING_DATA_APPID = 'B743C16E2989419A9B02EDE9D1E6A530'
export const TALKING_DATA_EVENT = 'TALKING_DATA_EVENT' export const TALKING_DATA_EVENT = 'TALKING_DATA_EVENT'
export const PICGO_SAVE_CONFIG = 'PICGO_SAVE_CONFIG' export const PICGO_SAVE_CONFIG = 'PICGO_SAVE_CONFIG'
export const PICGO_GET_CONFIG = 'PICGO_GET_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_GET_DB = 'PICGO_GET_DB'
export const PICGO_INSERT_DB = 'PICGO_INSERT_DB' export const PICGO_INSERT_DB = 'PICGO_INSERT_DB'
export const PICGO_INSERT_MANY_DB = 'PICGO_INSERT_MANY_DB' export const PICGO_INSERT_MANY_DB = 'PICGO_INSERT_MANY_DB'