Skip to content

Commit

Permalink
✨ Feature: click cancel in rename-window will use origin filename now
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #791
  • Loading branch information
Molunerfinn committed Jan 9, 2022
1 parent bcaf255 commit 04701d4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/main/apis/app/uploader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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)
})
})
Expand Down Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions src/renderer/pages/RenamePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 () {
Expand Down
1 change: 1 addition & 0 deletions src/universal/events/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 04701d4

Please sign in to comment.