diff --git a/app/main.ts b/app/main.ts index c1ebbd0..28f021e 100644 --- a/app/main.ts +++ b/app/main.ts @@ -490,15 +490,36 @@ try { //throw new Error(`Error: ${error}`); } }); + + ipcMain.handle('select-file', async (event: any) => { + if (!win) + { + return; + } + + const result = await dialog.showOpenDialog(win, { + title: 'Select File', + properties: ['openFile'] + }); + + const path = result.canceled ? null : result.filePaths[0]; + + win.webContents.send('selected-file', path ? `${path}` : ''); + }); - ipcMain.handle('select-folder', async (event) => { - const result = await dialog.showOpenDialog({ + ipcMain.handle('select-folder', async (event: any) => { + if (!win) { + return; + } + + const result = await dialog.showOpenDialog(win, { + title: 'Select Folder', properties: ['openDirectory'], // Specifica che vogliamo solo cartelle }); const path = result.canceled ? null : result.filePaths[0]; - win?.webContents.send('selected-folder', path ? `${path}` : ''); + win.webContents.send('selected-folder', path ? `${path}` : ''); }); ipcMain.handle('is-wifi-connected', async (event) => { diff --git a/app/preload.js b/app/preload.js index 9e7ed8a..6bbff45 100644 --- a/app/preload.js +++ b/app/preload.js @@ -43,6 +43,12 @@ contextBridge.exposeInMainWorld('electronAPI', { onSelectedFolder: (callback) => { ipcRenderer.on('selected-folder', callback); }, + selectFile: () => { + ipcRenderer.invoke('select-file'); + }, + onSelectedFile: (callback) => { + ipcRenderer.on('selected-file', callback); + }, isWifiConnected: () => { ipcRenderer.invoke('is-wifi-connected'); }, diff --git a/src/app/pages/settings/settings.component.html b/src/app/pages/settings/settings.component.html index 51fb70a..7791e4f 100644 --- a/src/app/pages/settings/settings.component.html +++ b/src/app/pages/settings/settings.component.html @@ -41,7 +41,6 @@ - Path to monerod executable @@ -58,7 +57,6 @@ - Folder where to save updates diff --git a/src/app/pages/settings/settings.component.ts b/src/app/pages/settings/settings.component.ts index 274440d..d1b66b5 100644 --- a/src/app/pages/settings/settings.component.ts +++ b/src/app/pages/settings/settings.component.ts @@ -134,24 +134,6 @@ export class SettingsComponent { } } - public onMonerodPathChange(): void { - if (document) { - const element = document.getElementById('general-monerod-path'); - if (element.files) { - this.currentSettings.monerodPath = element.files[0].path; - } - } - } - - public onMonerodDownloadPathChange(): void { - if (document) { - const element = document.getElementById('general-download-monerod-path'); - if (element.files) { - this.currentSettings.downloadUpgradePath = element.files[0].path; - } - } - } - public async OnSave(): Promise { if (!this.modified) { return; @@ -181,39 +163,36 @@ export class SettingsComponent { } public chooseMonerodFile(): void { - const input = document.getElementById('general-monerod-path'); - - if (!input) { + if (!window.electronAPI) { + console.error("Not electron app"); return; } - input.click(); - + window.electronAPI.onSelectedFile((event: any, path: string) => { + if (path == '') { + return; + } + + this.ngZone.run(() => { + this.currentSettings.monerodPath = path; + }); + }); + + window.electronAPI.selectFile(); } public chooseMoneroDownloadPath(): void { - /* - const input = document.getElementById('general-download-monerod-path'); - - if (!input) { - return; - } - - input.click(); - */ - const wdw = (window as any); - - if (wdw.electronAPI && wdw.electronAPI.selectFolder && wdw.electronAPI.onSelectedFolder) { - wdw.electronAPI.onSelectedFolder((event: any, folder: string) => { + if (window.electronAPI) { + window.electronAPI.onSelectedFolder((event: any, folder: string) => { if (folder == '') { return; } this.ngZone.run(() => { this.currentSettings.downloadUpgradePath = folder; - }) + }); }); - wdw.electronAPI.selectFolder(); + window.electronAPI.selectFolder(); } } diff --git a/src/polyfills.ts b/src/polyfills.ts index 90f3350..94d655c 100644 --- a/src/polyfills.ts +++ b/src/polyfills.ts @@ -64,6 +64,10 @@ declare global { onMoneroClose: (callback: (event: any, code: number) => void) => void; isWifiConnected: () => void; onIsWifiConnectedResponse: (callback: (event: any, connected: boolean) => void) => void; + selectFolder: () => void; + selectFile: () => void; + onSelectedFolder: (callback: (event: any, path: string) => void) => void; + onSelectedFile: (callback: (event: any, path: string) => void) => void; getOsType: () => void; gotOsType: (callback: (event: any, osType: { platform: string, arch: string }) => void) => void; quit: () => void;