Skip to content

Commit 04701d4

Browse files
committed
✨ Feature: click cancel in rename-window will use origin filename now
ISSUES CLOSED: #791
1 parent bcaf255 commit 04701d4

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/main/apis/app/uploader/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { IWindowList } from '#/types/enum'
1212
import util from 'util'
1313
import { IPicGo } from 'picgo'
1414
import { showNotification, calcDurationRange } from '~/main/utils/common'
15-
import { TALKING_DATA_EVENT } from '~/universal/events/constants'
15+
import { RENAME_FILE_NAME, TALKING_DATA_EVENT } from '~/universal/events/constants'
1616
import logger from '@core/picgo/logger'
1717

1818
const waitForShow = (webcontent: WebContents) => {
@@ -26,13 +26,13 @@ const waitForShow = (webcontent: WebContents) => {
2626
const waitForRename = (window: BrowserWindow, id: number): Promise<string|null> => {
2727
return new Promise((resolve) => {
2828
const windowId = window.id
29-
ipcMain.once(`rename${id}`, (evt: Event, newName: string) => {
29+
ipcMain.once(`${RENAME_FILE_NAME}${id}`, (evt: Event, newName: string) => {
3030
resolve(newName)
3131
window.close()
3232
})
3333
window.on('close', () => {
3434
resolve(null)
35-
ipcMain.removeAllListeners(`rename${id}`)
35+
ipcMain.removeAllListeners(`${RENAME_FILE_NAME}${id}`)
3636
windowManager.deleteById(windowId)
3737
})
3838
})
@@ -93,7 +93,7 @@ class Uploader {
9393
if (rename) {
9494
const window = windowManager.create(IWindowList.RENAME_WINDOW)!
9595
await waitForShow(window.webContents)
96-
window.webContents.send('rename', fileName, window.webContents.id)
96+
window.webContents.send(RENAME_FILE_NAME, fileName, item.fileName, window.webContents.id)
9797
name = await waitForRename(window, window.webContents.id)
9898
}
9999
item.fileName = name || fileName

src/renderer/pages/RenamePage.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
</div>
2323
</template>
2424
<script lang="ts">
25+
import { RENAME_FILE_NAME } from '#/events/constants'
2526
import { Component, Vue } from 'vue-property-decorator'
2627
import mixin from '@/utils/mixin'
2728
import {
@@ -34,20 +35,23 @@ import {
3435
})
3536
export default class extends Vue {
3637
fileName: string = ''
38+
originName: string = ''
3739
id: string | null = null
3840
created () {
39-
ipcRenderer.on('rename', (event: IpcRendererEvent, name: string, id: string) => {
40-
this.fileName = name
41+
ipcRenderer.on(RENAME_FILE_NAME, (event: IpcRendererEvent, newName: string, originName: string, id: string) => {
42+
this.fileName = newName
43+
this.originName = originName
4144
this.id = id
4245
})
4346
}
4447
4548
confirmName () {
46-
ipcRenderer.send(`rename${this.id}`, this.fileName)
49+
ipcRenderer.send(`${RENAME_FILE_NAME}${this.id}`, this.fileName)
4750
}
4851
4952
cancel () {
50-
ipcRenderer.send(`rename${this.id}`, null)
53+
// if cancel, use origin file name
54+
ipcRenderer.send(`${RENAME_FILE_NAME}${this.id}`, this.originName)
5155
}
5256
5357
beforeDestroy () {

src/universal/events/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ export const PICGO_HANDLE_PLUGIN_ING = 'PICGO_HANDLE_PLUGIN_ING'
2828
export const PICGO_TOGGLE_PLUGIN = 'PICGO_TOGGLE_PLUGIN'
2929
export const PASTE_TEXT = 'PASTE_TEXT'
3030
export const SET_MINI_WINDOW_POS = 'SET_MINI_WINDOW_POS'
31+
export const RENAME_FILE_NAME = 'RENAME_FILE_NAME'

0 commit comments

Comments
 (0)