diff --git a/package-lock.json b/package-lock.json index 6c2cebb..5621770 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "Final2x", - "version": "1.1.3", + "version": "1.1.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "Final2x", - "version": "1.1.3", + "version": "1.1.4", "hasInstallScript": true, "dependencies": { "@intlify/unplugin-vue-i18n": "^0.12.2", diff --git a/package.json b/package.json index 371a4e9..29e43ca 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "Final2x", "productName": "Final2x", - "version": "1.1.3", + "version": "1.1.4", "description": "A cross-platform image super-resolution tool.", "main": "./out/main/index.js", "author": "Tohrusky", diff --git a/src/main/openDirectory.ts b/src/main/openDirectory.ts index d5c2318..b9db5ed 100644 --- a/src/main/openDirectory.ts +++ b/src/main/openDirectory.ts @@ -1,12 +1,20 @@ import { dialog } from 'electron' -export function openDirectory(event, p): void { +/** + * @description Open a directory or file/multiple files + * @param event The event that triggered the function + * @param p The properties of the dialog + */ +export function openDirectory(event, p: Array): void { dialog .showOpenDialog({ - properties: [p] + properties: p }) .then((result) => { console.log(result) - event.sender.send('selectedItem', result.filePaths[0]) + event.sender.send('selectedItem', result.filePaths) + }) + .catch((err) => { + console.log(err) }) } diff --git a/src/renderer/src/locales/en.ts b/src/renderer/src/locales/en.ts index 57c4a95..9accd6b 100644 --- a/src/renderer/src/locales/en.ts +++ b/src/renderer/src/locales/en.ts @@ -19,7 +19,7 @@ export const en = { }, Final2xHome: { text0: 'Removal successful', - text1: 'Drag and drop images or folders here to upload' + text1: 'Click or drag and drop images or folders here to upload' }, Final2xSettings: { text0: 'When the GPU display order is incorrect for the loaded device, choose another one', diff --git a/src/renderer/src/locales/ja.ts b/src/renderer/src/locales/ja.ts index 7e8d8ad..f062e0c 100644 --- a/src/renderer/src/locales/ja.ts +++ b/src/renderer/src/locales/ja.ts @@ -19,7 +19,7 @@ export const ja = { }, Final2xHome: { text0: '削除が成功しました', - text1: 'ここにファイルをおいてアップロードしてください' + text1: '画像やフォルダをここにクリックまたはドラッグ&ドロップしてアップロードしてください' }, Final2xSettings: { text0: 'デバイスの負荷。GPUの表示順が正しくない場合は、別のものを選択してください', diff --git a/src/renderer/src/locales/zh.ts b/src/renderer/src/locales/zh.ts index 6341425..d167835 100644 --- a/src/renderer/src/locales/zh.ts +++ b/src/renderer/src/locales/zh.ts @@ -19,7 +19,7 @@ export const zh = { }, Final2xHome: { text0: '移除成功', - text1: '将图片或文件夹拖拽到此处上传' + text1: '点击或拖拽图片或文件夹到此处上传' }, Final2xSettings: { text0: '负载的设备,GPU显示顺序错误时,选择另一个即可', diff --git a/src/renderer/src/utils/IOPath.ts b/src/renderer/src/utils/IOPath.ts index 1ee5162..4a08176 100644 --- a/src/renderer/src/utils/IOPath.ts +++ b/src/renderer/src/utils/IOPath.ts @@ -24,6 +24,15 @@ class ioPATH { inputpathMap.value.delete(id) } + /** + * @description 检查 id 是否存在,因为 naive-ui 生成的 id 长度较短,所以这里只检查 inputpathMap 即可 + * @param id inputpath id + */ + static checkID(id: string): boolean { + const { inputpathMap } = storeToRefs(useIOPathStore()) + return inputpathMap.value.get(id) != undefined + } + /** * @description Get an inputpath from inputpathMap by id * @param id inputpath id diff --git a/src/renderer/src/utils/index.ts b/src/renderer/src/utils/index.ts index 1e9881d..a7fcc45 100644 --- a/src/renderer/src/utils/index.ts +++ b/src/renderer/src/utils/index.ts @@ -36,6 +36,13 @@ class Utils { /* empty */ } } + + /** + * @description 生成超长随机字符串 + */ + static getRandString(): string { + return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15) + } } -export const { getCurrentLocale, getLanguage, sleep, DeepDeepSleep } = Utils +export const { getCurrentLocale, getLanguage, sleep, DeepDeepSleep, getRandString } = Utils diff --git a/src/renderer/src/utils/pathFormat.ts b/src/renderer/src/utils/pathFormat.ts index 818b7cc..b656100 100644 --- a/src/renderer/src/utils/pathFormat.ts +++ b/src/renderer/src/utils/pathFormat.ts @@ -37,6 +37,14 @@ class PathFormat { static checkPath(path: string): boolean { return path.startsWith('/') || path.includes('\\') } + + /** + * @description 返回文件名 + */ + static getFileName(path: string): string { + const segments = path.split(/[/\\]/) + return segments[segments.length - 1] + } } export default PathFormat diff --git a/src/renderer/src/views/Final2xHome.vue b/src/renderer/src/views/Final2xHome.vue index e179a92..9f734e6 100644 --- a/src/renderer/src/views/Final2xHome.vue +++ b/src/renderer/src/views/Final2xHome.vue @@ -7,6 +7,7 @@ import { FileImageOutlined } from '@vicons/antd' import PathFormat from '../utils/pathFormat' import ioPATH from '../utils/IOPath' +import { getRandString } from '../utils' import { useIOPathStore } from '../store/ioPathStore' const { t } = useI18n() @@ -26,6 +27,45 @@ class Final2xHomeNotifications { } } +function handleClickUpload(): void { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + const handleSelected = (e, path): void => { + if (path != undefined) { + path.forEach((p: string) => { + // 生成随机id + let pathid = getRandString() + while (ioPATH.checkID(pathid)) { + pathid = getRandString() + } + // console.log(pathid) + // 插入 inputpathMap + ioPATH.add(pathid, p) + // 插入 inputFileList + inputFileList.value.push({ + fullPath: p, + id: pathid, + name: PathFormat.getFileName(p), + percentage: 0, + status: 'pending', + thumbnailUrl: null, + type: 'image/png', + url: null + }) + }) + } + } + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + window.electron.ipcRenderer.removeAllListeners('selectedItem') // 取消监听,防止多次触发 + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + window.electron.ipcRenderer.send('open-directory-dialog', ['openFile', 'multiSelections']) + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + window.electron.ipcRenderer.on('selectedItem', handleSelected) +} + onMounted(() => { const dragWrapper = document.getElementById('file_drag') dragWrapper?.addEventListener('drop', (e) => { @@ -82,7 +122,7 @@ function handleRemove(options: { file: UploadFileInfo; fileList: Array - +
diff --git a/src/renderer/src/views/Final2xSettings.vue b/src/renderer/src/views/Final2xSettings.vue index e5d36d2..d215c44 100644 --- a/src/renderer/src/views/Final2xSettings.vue +++ b/src/renderer/src/views/Final2xSettings.vue @@ -144,16 +144,21 @@ class MyPopoverMessages { function getPath(): void { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - window.electron.ipcRenderer.send('open-directory-dialog', 'openDirectory') - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - window.electron.ipcRenderer.on('selectedItem', function (e, path) { - // console.log(path === undefined) - if (path != undefined) { + const handleSelected = (e, path): void => { + if (path[0] != undefined) { // console.log(ioPath.getoutputpath()) - ioPath.setoutputpathManual(path) + ioPath.setoutputpathManual(path[0]) } - }) + } + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + window.electron.ipcRenderer.removeAllListeners('selectedItem') // 取消监听,防止多次触发 + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + window.electron.ipcRenderer.send('open-directory-dialog', ['openDirectory']) + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + window.electron.ipcRenderer.on('selectedItem', handleSelected) } // ----------------------------------------------------------------------------------------- diff --git a/test/utils/IOPath.test.ts b/test/utils/IOPath.test.ts index f917d5d..0ea9194 100644 --- a/test/utils/IOPath.test.ts +++ b/test/utils/IOPath.test.ts @@ -14,9 +14,12 @@ describe('IOPath', () => { it('test_ioPath', () => { const { outputpath } = storeToRefs(useIOPathStore()) - + // checkID + expect(ioPath.checkID('114514')).toBe(false) // test inputpath ioPath.add('114514', 'test') + // checkID + expect(ioPath.checkID('114514')).toBe(true) expect(ioPath.getByID('114514')).toBe('test') ioPath.add('114514', 'test2') expect(ioPath.getByID('114514')).toBe('test2') diff --git a/test/utils/index.test.ts b/test/utils/index.test.ts index 1803d3d..3a36f0d 100644 --- a/test/utils/index.test.ts +++ b/test/utils/index.test.ts @@ -2,7 +2,7 @@ * @vitest-environment jsdom */ -import { sleep, DeepDeepSleep, getCurrentLocale } from '../../src/renderer/src/utils' +import { sleep, DeepDeepSleep, getCurrentLocale, getRandString } from '../../src/renderer/src/utils' import { describe, expect, it } from 'vitest' describe('Utils', () => { @@ -23,4 +23,8 @@ describe('Utils', () => { const end = new Date().getTime() expect(end - start).toBeGreaterThanOrEqual(1000) }) + + it('getRandString', () => { + expect(getRandString()) + }) }) diff --git a/test/utils/pathFormat.test.ts b/test/utils/pathFormat.test.ts index 33ece2c..1ae671f 100644 --- a/test/utils/pathFormat.test.ts +++ b/test/utils/pathFormat.test.ts @@ -19,7 +19,7 @@ describe('PathFormat', () => { ]) }) - it('checkpath', () => { + it('check_path', () => { const check: Array = [ PathFormat.checkPath('/Users/test/Downloads/unix'), PathFormat.checkPath('C:\\Users\\test\\Downloads\\win'), @@ -28,4 +28,11 @@ describe('PathFormat', () => { ] expect(check).toStrictEqual([true, true, false, false]) }) + + it('get_file_name', () => { + expect(PathFormat.getFileName('/Users/test/Downloads/unix/114514.txt')).toBe('114514.txt') + expect(PathFormat.getFileName('C:\\Users\\test\\Downloads\\win\\genshin.png')).toBe( + 'genshin.png' + ) + }) })