From c1e58eb695de78fbf1d2b26c608692f0962373df Mon Sep 17 00:00:00 2001 From: bagusindrayana Date: Sat, 6 Apr 2024 15:34:42 +0800 Subject: [PATCH] feat: open,save, and save as file in query tab --- src/main/ipc-handlers/application.ts | 28 ++++ src/renderer/components/Workspace.vue | 2 +- src/renderer/components/WorkspaceTabQuery.vue | 127 +++++++++++++++++- src/renderer/ipc-api/Application.ts | 12 ++ src/renderer/stores/workspaces.ts | 37 ++--- 5 files changed, 188 insertions(+), 18 deletions(-) diff --git a/src/main/ipc-handlers/application.ts b/src/main/ipc-handlers/application.ts index ac3817bb..1cba4057 100644 --- a/src/main/ipc-handlers/application.ts +++ b/src/main/ipc-handlers/application.ts @@ -1,5 +1,6 @@ import { app, dialog, ipcMain, safeStorage } from 'electron'; import * as Store from 'electron-store'; +import * as fs from 'fs'; import { validateSender } from '../libs/misc/validateSender'; import { ShortcutRegister } from '../libs/ShortcutRegister'; @@ -52,6 +53,11 @@ export default () => { return dialog.showOpenDialog(options); }); + ipcMain.handle('show-save-dialog', (event, options) => { + if (!validateSender(event.senderFrame)) return { status: 'error', response: 'Unauthorized process' }; + return dialog.showSaveDialog(options); + }); + ipcMain.handle('get-download-dir-path', (event) => { if (!validateSender(event.senderFrame)) return { status: 'error', response: 'Unauthorized process' }; return app.getPath('downloads'); @@ -80,4 +86,26 @@ export default () => { const shortCutRegister = ShortcutRegister.getInstance(); shortCutRegister.unregister(); }); + + ipcMain.handle('read-file', (event, filePath) => { + if (!validateSender(event.senderFrame)) return { status: 'error', response: 'Unauthorized process' }; + try { + const content = fs.readFileSync(filePath, 'utf-8'); + return content; + } + catch (error) { + return { status: 'error', response: error.toString() }; + } + }); + + ipcMain.handle('write-file', (event, filePath, content) => { + if (!validateSender(event.senderFrame)) return { status: 'error', response: 'Unauthorized process' }; + try { + fs.writeFileSync(filePath, content, 'utf-8'); + return { status: 'success' }; + } + catch (error) { + return { status: 'error', response: error.toString() }; + } + }); }; diff --git a/src/renderer/components/Workspace.vue b/src/renderer/components/Workspace.vue index 5ec20e0d..c54ae495 100644 --- a/src/renderer/components/Workspace.vue +++ b/src/renderer/components/Workspace.vue @@ -46,7 +46,7 @@ :size="18" /> - {{ cutText(element.content || 'Query', 20, true) }} #{{ element.index }} + {{ cutText(element.elementName || element.content || 'Query', 20, true) }} #{{ element.index }} +
+ + + +