Feature: click cancel in rename-window will use origin filename now

ISSUES CLOSED: #791
This commit is contained in:
PiEgg
2022-01-09 11:20:56 +08:00
parent bcaf255a9c
commit 04701d4202
3 changed files with 13 additions and 8 deletions

View File

@@ -12,7 +12,7 @@ import { IWindowList } from '#/types/enum'
import util from 'util'
import { IPicGo } from 'picgo'
import { showNotification, calcDurationRange } from '~/main/utils/common'
import { TALKING_DATA_EVENT } from '~/universal/events/constants'
import { RENAME_FILE_NAME, TALKING_DATA_EVENT } from '~/universal/events/constants'
import logger from '@core/picgo/logger'
const waitForShow = (webcontent: WebContents) => {
@@ -26,13 +26,13 @@ const waitForShow = (webcontent: WebContents) => {
const waitForRename = (window: BrowserWindow, id: number): Promise<string|null> => {
return new Promise((resolve) => {
const windowId = window.id
ipcMain.once(`rename${id}`, (evt: Event, newName: string) => {
ipcMain.once(`${RENAME_FILE_NAME}${id}`, (evt: Event, newName: string) => {
resolve(newName)
window.close()
})
window.on('close', () => {
resolve(null)
ipcMain.removeAllListeners(`rename${id}`)
ipcMain.removeAllListeners(`${RENAME_FILE_NAME}${id}`)
windowManager.deleteById(windowId)
})
})
@@ -93,7 +93,7 @@ class Uploader {
if (rename) {
const window = windowManager.create(IWindowList.RENAME_WINDOW)!
await waitForShow(window.webContents)
window.webContents.send('rename', fileName, window.webContents.id)
window.webContents.send(RENAME_FILE_NAME, fileName, item.fileName, window.webContents.id)
name = await waitForRename(window, window.webContents.id)
}
item.fileName = name || fileName

View File

@@ -22,6 +22,7 @@
</div>
</template>
<script lang="ts">
import { RENAME_FILE_NAME } from '#/events/constants'
import { Component, Vue } from 'vue-property-decorator'
import mixin from '@/utils/mixin'
import {
@@ -34,20 +35,23 @@ import {
})
export default class extends Vue {
fileName: string = ''
originName: string = ''
id: string | null = null
created () {
ipcRenderer.on('rename', (event: IpcRendererEvent, name: string, id: string) => {
this.fileName = name
ipcRenderer.on(RENAME_FILE_NAME, (event: IpcRendererEvent, newName: string, originName: string, id: string) => {
this.fileName = newName
this.originName = originName
this.id = id
})
}
confirmName () {
ipcRenderer.send(`rename${this.id}`, this.fileName)
ipcRenderer.send(`${RENAME_FILE_NAME}${this.id}`, this.fileName)
}
cancel () {
ipcRenderer.send(`rename${this.id}`, null)
// if cancel, use origin file name
ipcRenderer.send(`${RENAME_FILE_NAME}${this.id}`, this.originName)
}
beforeDestroy () {

View File

@@ -28,3 +28,4 @@ export const PICGO_HANDLE_PLUGIN_ING = 'PICGO_HANDLE_PLUGIN_ING'
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'