From bc2e92836c16a1c9c6b631c983d763cba4bf48ed Mon Sep 17 00:00:00 2001 From: PiEgg Date: Sun, 9 Jul 2023 14:19:01 +0800 Subject: [PATCH] :bug: Fix: rename page bug ISSUES CLOSED: #1130 --- src/main/apis/app/uploader/index.ts | 21 ++++---- src/renderer/pages/Gallery.vue | 2 +- src/renderer/pages/RenamePage.vue | 74 ++++++++++++++++++++--------- src/universal/events/constants.ts | 1 + 4 files changed, 64 insertions(+), 34 deletions(-) diff --git a/src/main/apis/app/uploader/index.ts b/src/main/apis/app/uploader/index.ts index 667bcd6..ea01551 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 'picgo' import { showNotification, calcDurationRange, getClipboardFilePath } from '~/main/utils/common' -import { RENAME_FILE_NAME, TALKING_DATA_EVENT } from '~/universal/events/constants' +import { GET_RENAME_FILE_NAME, RENAME_FILE_NAME, TALKING_DATA_EVENT } 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 @@ -99,8 +91,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('wait for rename window ready...') + 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 @@ -177,6 +174,8 @@ class Uploader { }) }, 500) return false + } finally { + ipcMain.removeAllListeners(GET_RENAME_FILE_NAME) } } } diff --git a/src/renderer/pages/Gallery.vue b/src/renderer/pages/Gallery.vue index 10323e7..f8c89e1 100644 --- a/src/renderer/pages/Gallery.vue +++ b/src/renderer/pages/Gallery.vue @@ -659,7 +659,7 @@ export default { transform scale(1.1) &-img width 100% - object-fit fill + object-fit contain &__tool-panel color #ddd margin-bottom 4px diff --git a/src/renderer/pages/RenamePage.vue b/src/renderer/pages/RenamePage.vue index e5e9148..7bb62da 100644 --- a/src/renderer/pages/RenamePage.vue +++ b/src/renderer/pages/RenamePage.vue @@ -1,20 +1,37 @@ @@ -73,10 +107,6 @@ export default { } diff --git a/src/universal/events/constants.ts b/src/universal/events/constants.ts index 1a56a9f..daa9ad6 100644 --- a/src/universal/events/constants.ts +++ b/src/universal/events/constants.ts @@ -29,6 +29,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'