diff --git a/README.md b/README.md index 3da5ac9..236c013 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ https://github.com/user-attachments/assets/c4a50d2f-5bbb-48ac-9425-30ecc20ada7c - [X] Linux - [X] Windows - [X] MacOS -- [ ] Import/export `monerod.conf` node configuration +- [X] Import/export `monerod.conf` node configuration - [X] Synchronization in a specific time slot - [ ] Installers - [X] Linux diff --git a/app/main.ts b/app/main.ts index ba0edb9..3ad7d1b 100644 --- a/app/main.ts +++ b/app/main.ts @@ -759,6 +759,44 @@ try { } }); + ipcMain.handle('read-file', (event: IpcMainInvokeEvent, filePath: string) => { + fs.readFile(filePath, 'utf-8', (err, data) => { + if (err != null) { + win?.webContents.send('on-read-file-error', `${err}`); + return; + } + + win?.webContents.send('on-read-file', data); + }); + }); + + ipcMain.handle('save-file', async (event: IpcMainInvokeEvent, defaultPath: string, content: string) => { + if (!win) { + return; + } + + const result = await dialog.showSaveDialog(win, { + title: 'Save File', + defaultPath: defaultPath, + properties: [ + 'showOverwriteConfirmation' + ] + }); + + if (result.canceled) { + win.webContents.send('on-save-file', ''); + return; + } + try { + fs.writeFileSync(result.filePath, content); + + win.webContents.send('on-save-file', result.filePath); + } + catch(error: any) { + win.webContents.send('on-save-file-error', `${error}`); + } + }); + ipcMain.handle('select-file', async (event: IpcMainInvokeEvent, extensions?: string[]) => { if (!win) { @@ -794,6 +832,10 @@ try { win.webContents.send('selected-folder', path ? `${path}` : ''); }); + ipcMain.handle('get-path', (event: IpcMainInvokeEvent, path: 'home' | 'appData' | 'userData' | 'sessionData' | 'temp' | 'exe' | 'module' | 'desktop' | 'documents' | 'downloads' | 'music' | 'pictures' | 'videos' | 'recent' | 'logs' | 'crashDumps') => { + win?.webContents.send('on-get-path', app.getPath(path)); + }); + ipcMain.handle('is-wifi-connected', async (event: IpcMainInvokeEvent) => { isWifiConnected(); }); diff --git a/app/preload.js b/app/preload.js index 09402c0..1ee7050 100644 --- a/app/preload.js +++ b/app/preload.js @@ -69,9 +69,35 @@ contextBridge.exposeInMainWorld('electronAPI', { onSelectedFolder: (callback) => { ipcRenderer.on('selected-folder', callback); }, + readFile: (filePath) => { + ipcRenderer.invoke('read-file', filePath); + }, + onReadFile: (callback) => { + ipcRenderer.on('on-read-file', callback); + }, + onReadFileError: (callback) => { + ipcRenderer.on('on-read-file-error', callback); + }, + unregisterOnReadFile: () => { + ipcRenderer.removeAllListeners('on-read-file'); + ipcRenderer.removeAllListeners('on-read-file-error'); + }, unregisterOnSelectedFolder: () => { ipcRenderer.removeAllListeners('selected-folder'); }, + saveFile: (defaultPath, content) => { + ipcRenderer.invoke('save-file', defaultPath, content); + }, + onSaveFileError: (callback) => { + ipcRenderer.on('on-save-file-error', callback); + }, + onSaveFile: (callback) => { + ipcRenderer.on('on-save-file', callback); + }, + unregisterOnSaveFile: () => { + ipcRenderer.removeAllListeners('on-save-file-error'); + ipcRenderer.removeAllListeners('on-save-file'); + }, selectFile: (extensions = undefined) => { ipcRenderer.invoke('select-file', extensions); }, @@ -90,6 +116,15 @@ contextBridge.exposeInMainWorld('electronAPI', { unregisterOnIsWifiConnectedResponse: () => { ipcRenderer.removeAllListeners('is-wifi-connected-result'); }, + getPath: (path) => { + ipcRenderer.invoke('get-path', path); + }, + onGetPath: (callback) => { + ipcRenderer.on('on-get-path', callback); + }, + unregisterOnGetPath: () => { + ipcRenderer.removeAllListeners('on-get-path'); + }, getOsType: () => { ipcRenderer.invoke('get-os-type'); }, diff --git a/src/app/core/services/electron/electron.service.ts b/src/app/core/services/electron/electron.service.ts index 5987a4a..9b37984 100644 --- a/src/app/core/services/electron/electron.service.ts +++ b/src/app/core/services/electron/electron.service.ts @@ -227,6 +227,42 @@ export class ElectronService { return await selectPromise; } + public async readFile(filePath: string): Promise { + const promise = new Promise((resolve, reject) => { + window.electronAPI.onReadFileError((event: any, error: string) => { + window.electronAPI.unregisterOnReadFile(); + reject(error); + }); + + window.electronAPI.onReadFile((event: any, data: string) => { + window.electronAPI.unregisterOnReadFile(); + resolve(data); + }); + }); + + window.electronAPI.readFile(filePath); + + return await promise; + } + + public async saveFile(defaultPath: string, content: string): Promise { + const promise = new Promise((resolve, reject) => { + window.electronAPI.onSaveFileError((event: any, error: string) => { + window.electronAPI.unregisterOnSaveFile(); + reject(error); + }); + + window.electronAPI.onSaveFile((event: any, filePath: string) => { + window.electronAPI.unregisterOnSaveFile(); + resolve(filePath); + }) + }); + + window.electronAPI.saveFile(defaultPath, content); + + return await promise; + } + public async selectFolder(): Promise { const selectPromise = new Promise((resolve) => { window.electronAPI.onSelectedFolder((event: any, folder: string) => { @@ -240,6 +276,18 @@ export class ElectronService { return await selectPromise; } + public async getPath(path: 'home' | 'appData' | 'userData' | 'sessionData' | 'temp' | 'exe' | 'module' | 'desktop' | 'documents' | 'downloads' | 'music' | 'pictures' | 'videos' | 'recent' | 'logs' | 'crashDumps'): Promise { + const promise = new Promise((resolve) => { + window.electronAPI.onGetPath((event: any, result: string) => { + window.electronAPI.unregisterOnGetPath(); + resolve(result); + }) + }); + + window.electronAPI.getPath(path); + + return await promise; + } public async getOsType(): Promise<{ platform: string, arch: string }> { const promise = new Promise<{ platform: string, arch: string }>((resolve) => { diff --git a/src/app/pages/settings/settings.component.html b/src/app/pages/settings/settings.component.html index 5191e01..185d9c8 100644 --- a/src/app/pages/settings/settings.component.html +++ b/src/app/pages/settings/settings.component.html @@ -21,14 +21,55 @@ -