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
+7 -1
View File
@@ -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)
}
+7 -18
View File
@@ -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<T> (key?: string): Promise<T | undefined> {
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<T> (key?: string): Promise<T | undefined> {
return await ipcRenderer.invoke(PICGO_GET_CONFIG, key)
}
export async function getConfigSync<T> (key?: string): Promise<T | undefined> {
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)
}