Fix select monerod file and folder in setings

This commit is contained in:
everoddandeven 2024-10-16 17:19:49 +02:00
parent 3edd9d52bc
commit 10d832a614
5 changed files with 51 additions and 43 deletions

View file

@ -491,14 +491,35 @@ try {
} }
}); });
ipcMain.handle('select-folder', async (event) => { ipcMain.handle('select-file', async (event: any) => {
const result = await dialog.showOpenDialog({ 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: any) => {
if (!win) {
return;
}
const result = await dialog.showOpenDialog(win, {
title: 'Select Folder',
properties: ['openDirectory'], // Specifica che vogliamo solo cartelle properties: ['openDirectory'], // Specifica che vogliamo solo cartelle
}); });
const path = result.canceled ? null : result.filePaths[0]; 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) => { ipcMain.handle('is-wifi-connected', async (event) => {

View file

@ -43,6 +43,12 @@ contextBridge.exposeInMainWorld('electronAPI', {
onSelectedFolder: (callback) => { onSelectedFolder: (callback) => {
ipcRenderer.on('selected-folder', callback); ipcRenderer.on('selected-folder', callback);
}, },
selectFile: () => {
ipcRenderer.invoke('select-file');
},
onSelectedFile: (callback) => {
ipcRenderer.on('selected-file', callback);
},
isWifiConnected: () => { isWifiConnected: () => {
ipcRenderer.invoke('is-wifi-connected'); ipcRenderer.invoke('is-wifi-connected');
}, },

View file

@ -41,7 +41,6 @@
<input id="general-monerod-path-control" type="text" class="form-control form-control-sm" placeholder="" aria-label="Monerod path" aria-describedby="basic-addon2" [value]="currentSettings.monerodPath" readonly> <input id="general-monerod-path-control" type="text" class="form-control form-control-sm" placeholder="" aria-label="Monerod path" aria-describedby="basic-addon2" [value]="currentSettings.monerodPath" readonly>
<span class="input-group-text" id="basic-addon2"><button type="button" class="btn btn-secondary btn-sm" (click)="chooseMonerodFile()">Choose file</button></span> <span class="input-group-text" id="basic-addon2"><button type="button" class="btn btn-secondary btn-sm" (click)="chooseMonerodFile()">Choose file</button></span>
</div> </div>
<input type="file" class="form-control d-none" id="general-monerod-path" (change)="onMonerodPathChange()">
<small class="text-body-secondary">Path to monerod executable</small> <small class="text-body-secondary">Path to monerod executable</small>
</div> </div>
@ -58,7 +57,6 @@
<input id="upgrade-download-path=" type="text" class="form-control form-control-sm" placeholder="" aria-label="Monerod path" aria-describedby="basic-addon2" [value]="currentSettings.downloadUpgradePath" readonly> <input id="upgrade-download-path=" type="text" class="form-control form-control-sm" placeholder="" aria-label="Monerod path" aria-describedby="basic-addon2" [value]="currentSettings.downloadUpgradePath" readonly>
<span class="input-group-text" id="basic-addon2"><button type="button" class="btn btn-secondary btn-sm" (click)="chooseMoneroDownloadPath()">Choose folder</button></span> <span class="input-group-text" id="basic-addon2"><button type="button" class="btn btn-secondary btn-sm" (click)="chooseMoneroDownloadPath()">Choose folder</button></span>
</div> </div>
<input type="file" class="form-control d-none" id="general-download-monerod-path" webkitdirectory multiple>
<small class="text-body-secondary">Folder where to save updates</small> <small class="text-body-secondary">Folder where to save updates</small>
</div> </div>

View file

@ -134,24 +134,6 @@ export class SettingsComponent {
} }
} }
public onMonerodPathChange(): void {
if (document) {
const element = <HTMLInputElement>document.getElementById('general-monerod-path');
if (element.files) {
this.currentSettings.monerodPath = element.files[0].path;
}
}
}
public onMonerodDownloadPathChange(): void {
if (document) {
const element = <HTMLInputElement>document.getElementById('general-download-monerod-path');
if (element.files) {
this.currentSettings.downloadUpgradePath = element.files[0].path;
}
}
}
public async OnSave(): Promise<void> { public async OnSave(): Promise<void> {
if (!this.modified) { if (!this.modified) {
return; return;
@ -181,39 +163,36 @@ export class SettingsComponent {
} }
public chooseMonerodFile(): void { public chooseMonerodFile(): void {
const input = document.getElementById('general-monerod-path'); if (!window.electronAPI) {
console.error("Not electron app");
if (!input) {
return; 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 { public chooseMoneroDownloadPath(): void {
/* if (window.electronAPI) {
const input = document.getElementById('general-download-monerod-path'); window.electronAPI.onSelectedFolder((event: any, folder: string) => {
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 (folder == '') { if (folder == '') {
return; return;
} }
this.ngZone.run(() => { this.ngZone.run(() => {
this.currentSettings.downloadUpgradePath = folder; this.currentSettings.downloadUpgradePath = folder;
}) });
}); });
wdw.electronAPI.selectFolder(); window.electronAPI.selectFolder();
} }
} }

View file

@ -64,6 +64,10 @@ declare global {
onMoneroClose: (callback: (event: any, code: number) => void) => void; onMoneroClose: (callback: (event: any, code: number) => void) => void;
isWifiConnected: () => void; isWifiConnected: () => void;
onIsWifiConnectedResponse: (callback: (event: any, connected: boolean) => void) => 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; getOsType: () => void;
gotOsType: (callback: (event: any, osType: { platform: string, arch: string }) => void) => void; gotOsType: (callback: (event: any, osType: { platform: string, arch: string }) => void) => void;
quit: () => void; quit: () => void;