mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-09-06 07:56:56 +08:00
🔨 Refactor: move guiApi to singleton
This commit is contained in:
@@ -130,8 +130,7 @@ class ShortKeyHandler {
|
|||||||
} else if (command.includes('picgo-plugin-')) {
|
} else if (command.includes('picgo-plugin-')) {
|
||||||
const handler = shortKeyService.getShortKeyHandler(command)
|
const handler = shortKeyService.getShortKeyHandler(command)
|
||||||
if (handler) {
|
if (handler) {
|
||||||
const guiApi = new GuiApi()
|
return handler(picgo, GuiApi.getInstance())
|
||||||
return handler(picgo, guiApi)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.warn(`can not find command: ${command}`)
|
logger.warn(`can not find command: ${command}`)
|
||||||
|
|||||||
@@ -18,8 +18,18 @@ import {
|
|||||||
|
|
||||||
// Cross-process support may be required in the future
|
// Cross-process support may be required in the future
|
||||||
class GuiApi implements IGuiApi {
|
class GuiApi implements IGuiApi {
|
||||||
|
private static instance: GuiApi
|
||||||
private windowId: number = -1
|
private windowId: number = -1
|
||||||
private settingWindowId: number = -1
|
private settingWindowId: number = -1
|
||||||
|
private constructor () {
|
||||||
|
console.log('init guiapi')
|
||||||
|
}
|
||||||
|
public static getInstance (): GuiApi {
|
||||||
|
if (!GuiApi.instance) {
|
||||||
|
GuiApi.instance = new GuiApi()
|
||||||
|
}
|
||||||
|
return GuiApi.instance
|
||||||
|
}
|
||||||
private async showSettingWindow () {
|
private async showSettingWindow () {
|
||||||
this.settingWindowId = await getSettingWindowId()
|
this.settingWindowId = await getSettingWindowId()
|
||||||
const settingWindow = BrowserWindow.fromId(this.settingWindowId)
|
const settingWindow = BrowserWindow.fromId(this.settingWindowId)
|
||||||
|
|||||||
@@ -210,12 +210,11 @@ const handleGetPicBedConfig = () => {
|
|||||||
const handlePluginActions = () => {
|
const handlePluginActions = () => {
|
||||||
ipcMain.on('pluginActions', (event: IpcMainEvent, name: string, label: string) => {
|
ipcMain.on('pluginActions', (event: IpcMainEvent, name: string, label: string) => {
|
||||||
const plugin = picgo.pluginLoader.getPlugin(name)
|
const plugin = picgo.pluginLoader.getPlugin(name)
|
||||||
const guiApi = new GuiApi()
|
|
||||||
if (plugin?.guiMenu?.(picgo)?.length) {
|
if (plugin?.guiMenu?.(picgo)?.length) {
|
||||||
const menu: GuiMenuItem[] = plugin.guiMenu(picgo)
|
const menu: GuiMenuItem[] = plugin.guiMenu(picgo)
|
||||||
menu.forEach(item => {
|
menu.forEach(item => {
|
||||||
if (item.label === label) {
|
if (item.label === label) {
|
||||||
item.handle(picgo, guiApi)
|
item.handle(picgo, GuiApi.getInstance())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -224,9 +223,8 @@ const handlePluginActions = () => {
|
|||||||
|
|
||||||
const handleRemoveFiles = () => {
|
const handleRemoveFiles = () => {
|
||||||
ipcMain.on('removeFiles', (event: IpcMainEvent, files: ImgInfo[]) => {
|
ipcMain.on('removeFiles', (event: IpcMainEvent, files: ImgInfo[]) => {
|
||||||
const guiApi = new GuiApi()
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
picgo.emit('remove', files, guiApi)
|
picgo.emit('remove', files, GuiApi.getInstance())
|
||||||
}, 500)
|
}, 500)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user