mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-01-23 02:36:05 +00:00
Improve local file sync directory picker
This commit is contained in:
parent
5db60bbf43
commit
9600ca906c
4 changed files with 33 additions and 14 deletions
9
electron/electronAPI.d.ts
vendored
9
electron/electronAPI.d.ts
vendored
|
|
@ -51,7 +51,7 @@ export interface ElectronAPI {
|
|||
|
||||
checkDirExists(args: { dirPath: string }): Promise<true | Error>;
|
||||
|
||||
pickDirectory(): Promise<string | undefined>;
|
||||
pickDirectory(options?: DirectoryDialogOptions): Promise<string | undefined>;
|
||||
|
||||
// checkDirExists(dirPath: string): Promise<true | Error>;
|
||||
|
||||
|
|
@ -152,3 +152,10 @@ export interface ElectronAPI {
|
|||
request: PluginNodeScriptRequest,
|
||||
): Promise<PluginNodeScriptResult>;
|
||||
}
|
||||
|
||||
export interface DirectoryDialogOptions {
|
||||
defaultPath?: string | null;
|
||||
title?: string;
|
||||
message?: string;
|
||||
buttonLabel?: string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,14 @@ import { IPC } from './shared-with-frontend/ipc-events.const';
|
|||
import { SyncGetRevResult } from '../src/app/imex/sync/sync.model';
|
||||
import { readdirSync, readFileSync, statSync, writeFileSync, unlinkSync } from 'fs';
|
||||
import { error, log } from 'electron-log/main';
|
||||
import { dialog, ipcMain } from 'electron';
|
||||
import { dialog, ipcMain, OpenDialogOptions } from 'electron';
|
||||
import { getWin } from './main-window';
|
||||
|
||||
type DirectoryDialogOptions = Pick<
|
||||
OpenDialogOptions,
|
||||
'defaultPath' | 'title' | 'message' | 'buttonLabel'
|
||||
>;
|
||||
|
||||
export const initLocalFileSyncAdapter = (): void => {
|
||||
ipcMain.handle(
|
||||
IPC.FILE_SYNC_SAVE,
|
||||
|
|
@ -136,16 +141,19 @@ 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 {
|
||||
ipcMain.handle(
|
||||
IPC.PICK_DIRECTORY,
|
||||
async (_ev, options?: DirectoryDialogOptions): Promise<string | undefined> => {
|
||||
const { canceled, filePaths } = await dialog.showOpenDialog(getWin(), {
|
||||
properties: ['openDirectory'],
|
||||
...options,
|
||||
});
|
||||
if (canceled) {
|
||||
return undefined;
|
||||
}
|
||||
return filePaths[0];
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const getRev = (filePath: string): string => {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { ipcRenderer, IpcRendererEvent, webFrame, contextBridge } from 'electron';
|
||||
import { ElectronAPI } from './electronAPI.d';
|
||||
import { DirectoryDialogOptions, ElectronAPI } from './electronAPI.d';
|
||||
import { IPCEventValue } from './shared-with-frontend/ipc-events.const';
|
||||
import { LocalBackupMeta } from '../src/app/imex/local-backup/local-backup.model';
|
||||
import { SyncGetRevResult } from '../src/app/imex/sync/sync.model';
|
||||
|
|
@ -48,7 +48,8 @@ const ea: ElectronAPI = {
|
|||
checkDirExists: (dirPath) =>
|
||||
_invoke('CHECK_DIR_EXISTS', dirPath) as Promise<true | Error>,
|
||||
|
||||
pickDirectory: () => _invoke('PICK_DIRECTORY') as Promise<string | undefined>,
|
||||
pickDirectory: (options?: DirectoryDialogOptions) =>
|
||||
_invoke('PICK_DIRECTORY', options) as Promise<string | undefined>,
|
||||
|
||||
// STANDARD
|
||||
// --------
|
||||
|
|
|
|||
|
|
@ -86,7 +86,10 @@ export class LocalFileSyncElectron extends LocalFileSyncBase {
|
|||
PFLog.normal(`${LocalFileSyncElectron.L}.pickDirectory()`);
|
||||
|
||||
try {
|
||||
const dir = await (window as any).ea.pickDirectory();
|
||||
const privateCfg = await this.privateCfg.load();
|
||||
const dir = await (window as any).ea.pickDirectory({
|
||||
defaultPath: privateCfg?.syncFolderPath || undefined,
|
||||
});
|
||||
if (dir) {
|
||||
await this.privateCfg.upsertPartial({ syncFolderPath: dir });
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue