diff --git a/src/main/apis/app/uploader/index.ts b/src/main/apis/app/uploader/index.ts index 07e1168..4472e1f 100644 --- a/src/main/apis/app/uploader/index.ts +++ b/src/main/apis/app/uploader/index.ts @@ -13,7 +13,7 @@ import { IWindowList } from '#/types/enum' import util from 'util' import { IPicGo } from 'piclist' import { showNotification, getClipboardFilePath } from '~/main/utils/common' -import { RENAME_FILE_NAME } from '~/universal/events/constants' +import { GET_RENAME_FILE_NAME, RENAME_FILE_NAME } from '~/universal/events/constants' import logger from '@core/picgo/logger' import { T } from '~/main/i18n' import fse from 'fs-extra' @@ -22,14 +22,6 @@ import { privacyManager } from '~/main/utils/privacyManager' import writeFile from 'write-file-atomic' import { CLIPBOARD_IMAGE_FOLDER } from '~/universal/utils/static' -const waitForShow = (webcontent: WebContents) => { - return new Promise((resolve) => { - webcontent.on('did-finish-load', () => { - resolve() - }) - }) -} - const waitForRename = (window: BrowserWindow, id: number): Promise => { return new Promise((resolve) => { const windowId = window.id @@ -85,8 +77,13 @@ class Uploader { } if (rename) { const window = windowManager.create(IWindowList.RENAME_WINDOW)! - await waitForShow(window.webContents) - window.webContents.send(RENAME_FILE_NAME, fileName, item.fileName, window.webContents.id) + logger.info('create rename window') + ipcMain.on(GET_RENAME_FILE_NAME, (evt) => { + if (evt.sender.id === window.webContents.id) { + logger.info('rename window ready, wait for rename...') + window.webContents.send(RENAME_FILE_NAME, fileName, item.fileName, window.webContents.id) + } + }) name = await waitForRename(window, window.webContents.id) } item.fileName = name || fileName @@ -157,6 +154,8 @@ class Uploader { }) }, 500) return false + } finally { + ipcMain.removeAllListeners(GET_RENAME_FILE_NAME) } } } diff --git a/src/renderer/pages/RenamePage.vue b/src/renderer/pages/RenamePage.vue index fbc0208..ce37ecf 100644 --- a/src/renderer/pages/RenamePage.vue +++ b/src/renderer/pages/RenamePage.vue @@ -1,16 +1,33 @@ diff --git a/src/universal/events/constants.ts b/src/universal/events/constants.ts index 464bdcc..e92b8cc 100644 --- a/src/universal/events/constants.ts +++ b/src/universal/events/constants.ts @@ -30,6 +30,7 @@ export const PICGO_TOGGLE_PLUGIN = 'PICGO_TOGGLE_PLUGIN' export const PASTE_TEXT = 'PASTE_TEXT' export const SET_MINI_WINDOW_POS = 'SET_MINI_WINDOW_POS' export const RENAME_FILE_NAME = 'RENAME_FILE_NAME' +export const GET_RENAME_FILE_NAME = 'GET_RENAME_FILE_NAME' export const SHOW_MAIN_PAGE_QRCODE = 'SHOW_MAIN_PAGE_QRCODE' export const SHOW_MAIN_PAGE_DONATION = 'SHOW_MAIN_PAGE_DONATION' export const FORCE_UPDATE = 'FORCE_UPDATE'