mirror of
https://github.com/everoddandeven/monerod-gui.git
synced 2024-12-22 11:39:25 +00:00
Fix select monerod file and folder in setings
This commit is contained in:
parent
3edd9d52bc
commit
10d832a614
5 changed files with 51 additions and 43 deletions
27
app/main.ts
27
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) => {
|
||||
|
|
|
@ -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');
|
||||
},
|
||||
|
|
|
@ -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>
|
||||
<span class="input-group-text" id="basic-addon2"><button type="button" class="btn btn-secondary btn-sm" (click)="chooseMonerodFile()">Choose file</button></span>
|
||||
</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>
|
||||
</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>
|
||||
<span class="input-group-text" id="basic-addon2"><button type="button" class="btn btn-secondary btn-sm" (click)="chooseMoneroDownloadPath()">Choose folder</button></span>
|
||||
</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>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -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> {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue