From ed5a86dce0575475f33f538ad8208791fbd62194 Mon Sep 17 00:00:00 2001 From: santa Date: Thu, 8 Jan 2026 14:25:14 +0100 Subject: [PATCH] custom document backend implemented --- electron/main/custom_document.html | 111 +++++++++++++++++++++-------- electron/main/index.html | 2 +- electron/main/preload.js | 12 ++++ main.js | 25 ++++++- 4 files changed, 117 insertions(+), 33 deletions(-) diff --git a/electron/main/custom_document.html b/electron/main/custom_document.html index 6d58c1e..a12b429 100644 --- a/electron/main/custom_document.html +++ b/electron/main/custom_document.html @@ -58,6 +58,10 @@ margin-top: 25px; } + .hidden { + visibility: hidden; + } + button { padding: 10px 20px; font-size: 14px; @@ -92,19 +96,19 @@
-

Custom Document Generator

- - - +

Manage document types

- + +
+ + +
+ @@ -118,6 +122,7 @@
+ + + diff --git a/electron/main/index.html b/electron/main/index.html index 6d045ab..0fa59e0 100644 --- a/electron/main/index.html +++ b/electron/main/index.html @@ -19,7 +19,7 @@ diff --git a/electron/main/preload.js b/electron/main/preload.js index 356ada0..80c4140 100644 --- a/electron/main/preload.js +++ b/electron/main/preload.js @@ -30,6 +30,18 @@ try { file_download: () => {ipcRenderer.send("file_download")} }) + + + //documenttypes + + contextBridge.exposeInMainWorld('api', { + getTxtFiles: () => ipcRenderer.invoke('get-txt-files'), + saveTxtFile: (name, content) => + ipcRenderer.invoke('save-txt-file', name, content), + readTxtFile: (fileName) => + ipcRenderer.invoke('read-txt-file', fileName) + }); + ipcRenderer.on("error", (event, err) => {alert(err)}) } catch (error) { diff --git a/main.js b/main.js index 7e2dd9a..a2c7e34 100644 --- a/main.js +++ b/main.js @@ -262,4 +262,27 @@ let q1 = { {name:"abc", displayname:"ABC"}, {name:"qeg", displayname:"aqghegahu"} ] -} \ No newline at end of file +} + +//gibt Documentfiles an preload zurück + +electron.ipcMain.handle('get-txt-files', () => { + const storagePath = `${mainDir}/storage/documentType` + +return fs.readdirSync(storagePath) + .filter(f => f.endsWith('.txt')) +}); + +//speichern neuer document types + +electron.ipcMain.handle('save-txt-file', (event, fileName, content) => { + const filePath = `${mainDir}/storage/documentType/${fileName}.txt`; + fs.writeFileSync(filePath, content, 'utf8'); + return true; +}); + +// +electron.ipcMain.handle('read-txt-file', (event, fileName) => { + const filePath = `${mainDir}/storage/documentType/${fileName}`; + return fs.readFileSync(filePath, 'utf8'); +}); \ No newline at end of file