mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-01-23 02:36:05 +00:00
feat: add folder picker when there is no valid selected #3473
This commit is contained in:
parent
552b25074d
commit
866df0c493
5 changed files with 43 additions and 5 deletions
2
electron/electronAPI.d.ts
vendored
2
electron/electronAPI.d.ts
vendored
|
|
@ -40,6 +40,8 @@ export interface ElectronAPI {
|
|||
|
||||
checkDirExists(args: { dirPath: string }): Promise<true | Error>;
|
||||
|
||||
pickDirectory(): Promise<string | undefined>;
|
||||
|
||||
// checkDirExists(dirPath: string): Promise<true | Error>;
|
||||
|
||||
// STANDARD
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ import { IPC } from './shared-with-frontend/ipc-events.const';
|
|||
import { SyncGetRevResult } from '../src/app/imex/sync/sync.model';
|
||||
import { readdirSync, readFileSync, statSync, writeFileSync } from 'fs';
|
||||
import { error, log } from 'electron-log/main';
|
||||
import { ipcMain } from 'electron';
|
||||
import { dialog, ipcMain } from 'electron';
|
||||
import { getWin } from './main-window';
|
||||
|
||||
export const initLocalFileSyncAdapter = (): void => {
|
||||
ipcMain.handle(
|
||||
|
|
@ -112,6 +113,17 @@ export const initLocalFileSyncAdapter = (): void => {
|
|||
}
|
||||
},
|
||||
);
|
||||
|
||||
ipcMain.handle(IPC.PICK_DIRECTORY, async (): Promise<string | undefined> => {
|
||||
const { canceled, filePaths } = await dialog.showOpenDialog(getWin(), {
|
||||
properties: ['openDirectory'],
|
||||
});
|
||||
if (canceled) {
|
||||
return undefined;
|
||||
} else {
|
||||
return filePaths[0];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const getRev = (filePath: string): string => {
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ const ea: ElectronAPI = {
|
|||
checkDirExists: (dirPath) =>
|
||||
_invoke('CHECK_DIR_EXISTS', dirPath) as Promise<true | Error>,
|
||||
|
||||
pickDirectory: () => _invoke('PICK_DIRECTORY') as Promise<string | undefined>,
|
||||
|
||||
// STANDARD
|
||||
// --------
|
||||
setZoomFactor: (zoomFactor: number) => {
|
||||
|
|
|
|||
|
|
@ -50,9 +50,11 @@ export enum IPC {
|
|||
|
||||
FILE_SYNC_LOAD = 'FILE_SYNC_LOAD',
|
||||
FILE_SYNC_SAVE = 'FILE_SYNC_SAVE',
|
||||
CHECK_DIR_EXISTS = 'CHECK_DIR_EXISTS',
|
||||
FILE_SYNC_GET_REV_AND_CLIENT_UPDATE = 'FILE_SYNC_GET_REV_AND_CLIENT_UPDATE',
|
||||
|
||||
CHECK_DIR_EXISTS = 'CHECK_DIR_EXISTS',
|
||||
PICK_DIRECTORY = 'PICK_DIRECTORY',
|
||||
|
||||
ANY_FILE_DOWNLOADED = 'ANY_FILE_DOWNLOADED',
|
||||
|
||||
FULL_SCREEN_BLOCKER = 'FULL_SCREEN_BLOCKER',
|
||||
|
|
|
|||
|
|
@ -40,9 +40,18 @@ export class LocalFileSyncElectronService implements SyncProviderServiceInterfac
|
|||
};
|
||||
} catch (e) {
|
||||
const folderPath = await this._folderPathOnce$.toPromise();
|
||||
const isDirExists = await this._checkDirExists(folderPath as string);
|
||||
if (!isDirExists) {
|
||||
alert(`Directory ${folderPath} does not exist`);
|
||||
try {
|
||||
const isDirExists = await this._checkDirExists(folderPath as string);
|
||||
if (!isDirExists) {
|
||||
alert('No valid folder selected for local file sync. Please select one.');
|
||||
this._pickDirectory();
|
||||
throw new Error('No valid folder selected');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
alert('No valid folder selected for local file sync. Please select one.');
|
||||
this._pickDirectory();
|
||||
throw new Error('No valid folder selected');
|
||||
}
|
||||
|
||||
if (e?.toString?.().includes('ENOENT')) {
|
||||
|
|
@ -115,4 +124,15 @@ export class LocalFileSyncElectronService implements SyncProviderServiceInterfac
|
|||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
private async _pickDirectory(): Promise<void> {
|
||||
const dir = await window.ea.pickDirectory();
|
||||
if (dir) {
|
||||
this._globalConfigService.updateSection('sync', {
|
||||
localFileSync: {
|
||||
syncFolderPath: dir,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue