mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-08-27 11:10:50 +08:00
✨ Feature: click cancel in rename-window will use origin filename now
ISSUES CLOSED: #791
This commit is contained in:
@@ -12,7 +12,7 @@ import { IWindowList } from '#/types/enum'
|
|||||||
import util from 'util'
|
import util from 'util'
|
||||||
import { IPicGo } from 'picgo'
|
import { IPicGo } from 'picgo'
|
||||||
import { showNotification, calcDurationRange } from '~/main/utils/common'
|
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'
|
import logger from '@core/picgo/logger'
|
||||||
|
|
||||||
const waitForShow = (webcontent: WebContents) => {
|
const waitForShow = (webcontent: WebContents) => {
|
||||||
@@ -26,13 +26,13 @@ const waitForShow = (webcontent: WebContents) => {
|
|||||||
const waitForRename = (window: BrowserWindow, id: number): Promise<string|null> => {
|
const waitForRename = (window: BrowserWindow, id: number): Promise<string|null> => {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const windowId = window.id
|
const windowId = window.id
|
||||||
ipcMain.once(`rename${id}`, (evt: Event, newName: string) => {
|
ipcMain.once(`${RENAME_FILE_NAME}${id}`, (evt: Event, newName: string) => {
|
||||||
resolve(newName)
|
resolve(newName)
|
||||||
window.close()
|
window.close()
|
||||||
})
|
})
|
||||||
window.on('close', () => {
|
window.on('close', () => {
|
||||||
resolve(null)
|
resolve(null)
|
||||||
ipcMain.removeAllListeners(`rename${id}`)
|
ipcMain.removeAllListeners(`${RENAME_FILE_NAME}${id}`)
|
||||||
windowManager.deleteById(windowId)
|
windowManager.deleteById(windowId)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -93,7 +93,7 @@ class Uploader {
|
|||||||
if (rename) {
|
if (rename) {
|
||||||
const window = windowManager.create(IWindowList.RENAME_WINDOW)!
|
const window = windowManager.create(IWindowList.RENAME_WINDOW)!
|
||||||
await waitForShow(window.webContents)
|
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)
|
name = await waitForRename(window, window.webContents.id)
|
||||||
}
|
}
|
||||||
item.fileName = name || fileName
|
item.fileName = name || fileName
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { RENAME_FILE_NAME } from '#/events/constants'
|
||||||
import { Component, Vue } from 'vue-property-decorator'
|
import { Component, Vue } from 'vue-property-decorator'
|
||||||
import mixin from '@/utils/mixin'
|
import mixin from '@/utils/mixin'
|
||||||
import {
|
import {
|
||||||
@@ -34,20 +35,23 @@ import {
|
|||||||
})
|
})
|
||||||
export default class extends Vue {
|
export default class extends Vue {
|
||||||
fileName: string = ''
|
fileName: string = ''
|
||||||
|
originName: string = ''
|
||||||
id: string | null = null
|
id: string | null = null
|
||||||
created () {
|
created () {
|
||||||
ipcRenderer.on('rename', (event: IpcRendererEvent, name: string, id: string) => {
|
ipcRenderer.on(RENAME_FILE_NAME, (event: IpcRendererEvent, newName: string, originName: string, id: string) => {
|
||||||
this.fileName = name
|
this.fileName = newName
|
||||||
|
this.originName = originName
|
||||||
this.id = id
|
this.id = id
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
confirmName () {
|
confirmName () {
|
||||||
ipcRenderer.send(`rename${this.id}`, this.fileName)
|
ipcRenderer.send(`${RENAME_FILE_NAME}${this.id}`, this.fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
cancel () {
|
cancel () {
|
||||||
ipcRenderer.send(`rename${this.id}`, null)
|
// if cancel, use origin file name
|
||||||
|
ipcRenderer.send(`${RENAME_FILE_NAME}${this.id}`, this.originName)
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
|
|||||||
@@ -28,3 +28,4 @@ export const PICGO_HANDLE_PLUGIN_ING = 'PICGO_HANDLE_PLUGIN_ING'
|
|||||||
export const PICGO_TOGGLE_PLUGIN = 'PICGO_TOGGLE_PLUGIN'
|
export const PICGO_TOGGLE_PLUGIN = 'PICGO_TOGGLE_PLUGIN'
|
||||||
export const PASTE_TEXT = 'PASTE_TEXT'
|
export const PASTE_TEXT = 'PASTE_TEXT'
|
||||||
export const SET_MINI_WINDOW_POS = 'SET_MINI_WINDOW_POS'
|
export const SET_MINI_WINDOW_POS = 'SET_MINI_WINDOW_POS'
|
||||||
|
export const RENAME_FILE_NAME = 'RENAME_FILE_NAME'
|
||||||
|
|||||||
Reference in New Issue
Block a user