mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-01-23 02:36:05 +00:00
feat(pfapi): make removing files work for local file sync
This commit is contained in:
parent
0c307dff35
commit
d7def289f5
6 changed files with 37 additions and 10 deletions
2
electron/electronAPI.d.ts
vendored
2
electron/electronAPI.d.ts
vendored
|
|
@ -39,6 +39,8 @@ export interface ElectronAPI {
|
|||
localRev: string | null;
|
||||
}): Promise<{ rev: string; dataStr: string | undefined } | Error>;
|
||||
|
||||
fileSyncRemove(args: { filePath: string }): Promise<unknown | Error>;
|
||||
|
||||
checkDirExists(args: { dirPath: string }): Promise<true | Error>;
|
||||
|
||||
pickDirectory(): Promise<string | undefined>;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
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 { readdirSync, readFileSync, statSync, writeFileSync, unlinkSync } from 'fs';
|
||||
import { error, log } from 'electron-log/main';
|
||||
import { dialog, ipcMain } from 'electron';
|
||||
import { getWin } from './main-window';
|
||||
|
|
@ -92,6 +92,28 @@ export const initLocalFileSyncAdapter = (): void => {
|
|||
},
|
||||
);
|
||||
|
||||
ipcMain.handle(
|
||||
IPC.FILE_SYNC_REMOVE,
|
||||
(
|
||||
ev,
|
||||
{
|
||||
filePath,
|
||||
}: {
|
||||
filePath: string;
|
||||
},
|
||||
): void | Error => {
|
||||
try {
|
||||
console.log(IPC.FILE_SYNC_REMOVE, filePath);
|
||||
unlinkSync(filePath);
|
||||
return;
|
||||
} catch (e) {
|
||||
log('ERR: Sync error while loading file from ' + filePath);
|
||||
error(e);
|
||||
return new Error(e as string);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
ipcMain.handle(
|
||||
IPC.CHECK_DIR_EXISTS,
|
||||
(
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ const ea: ElectronAPI = {
|
|||
rev: string;
|
||||
dataStr: string | undefined;
|
||||
}>,
|
||||
fileSyncRemove: (filePath) => _invoke('FILE_SYNC_REMOVE', filePath) as Promise<void>,
|
||||
checkDirExists: (dirPath) =>
|
||||
_invoke('CHECK_DIR_EXISTS', dirPath) as Promise<true | Error>,
|
||||
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ export enum IPC {
|
|||
|
||||
FILE_SYNC_LOAD = 'FILE_SYNC_LOAD',
|
||||
FILE_SYNC_SAVE = 'FILE_SYNC_SAVE',
|
||||
FILE_SYNC_REMOVE = 'FILE_SYNC_REMOVE',
|
||||
FILE_SYNC_GET_REV_AND_CLIENT_UPDATE = 'FILE_SYNC_GET_REV_AND_CLIENT_UPDATE',
|
||||
|
||||
CHECK_DIR_EXISTS = 'CHECK_DIR_EXISTS',
|
||||
|
|
|
|||
|
|
@ -113,14 +113,12 @@ export class LocalFileSyncElectron
|
|||
}
|
||||
|
||||
async removeFile(targetPath: string): Promise<void> {
|
||||
// TODO
|
||||
alert('Not implemented');
|
||||
// try {
|
||||
// await this._api.remove(this._getPath(targetPath));
|
||||
// } catch (e) {
|
||||
// throw e;
|
||||
// }
|
||||
// TODO error handling
|
||||
const r = await (window as any).ea.fileSyncRemove({
|
||||
filePath: await this._getFilePath(targetPath),
|
||||
});
|
||||
if (r instanceof Error) {
|
||||
throw r;
|
||||
}
|
||||
}
|
||||
|
||||
async checkDirAndOpenPickerIfNotExists(): Promise<void> {
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import { isDataRepairPossible } from '../core/data-repair/is-data-repair-possibl
|
|||
import { isValidAppData } from '../imex/sync/is-valid-app-data.util';
|
||||
import { dataRepair } from '../core/data-repair/data-repair.util';
|
||||
import { LocalFileSyncElectron } from './api/sync/providers/local-file-sync/local-file-sync-electron';
|
||||
import { IS_ELECTRON } from '../app.constants';
|
||||
|
||||
export const CROSS_MODEL_VERSION = 1 as const;
|
||||
|
||||
|
|
@ -151,7 +152,9 @@ export const PFAPI_SYNC_PROVIDERS = [
|
|||
basePath: `/`,
|
||||
}),
|
||||
new Webdav({}),
|
||||
fileSyncElectron,
|
||||
...(IS_ELECTRON ? [fileSyncElectron] : []),
|
||||
// TODO android
|
||||
// ...(IS_ELECTRON ? [fileSyncElectron] : []),
|
||||
];
|
||||
|
||||
export const PFAPI_CFG: PfapiBaseCfg<PfapiAllModelCfg> = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue