mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-07-18 00:46:45 +00:00
fix(sync): add FILE_SYNC_LIST_FILES electron IPC handler and fix preload args
Add missing IPC handler for file listing used by local-file sync, and fix
preload.ts passing bare dirPath string instead of the expected { dirPath }
object — causing IPC handler to destructure undefined.
This commit is contained in:
parent
23c729bd9c
commit
46e0fa2d01
5 changed files with 35 additions and 5 deletions
2
electron/electronAPI.d.ts
vendored
2
electron/electronAPI.d.ts
vendored
|
|
@ -48,7 +48,7 @@ export interface ElectronAPI {
|
|||
|
||||
fileSyncRemove(args: { filePath: string }): Promise<unknown | Error>;
|
||||
|
||||
fileSyncListFiles(args: { dirPath: string }): Promise<string[] | Error>; // NEW
|
||||
fileSyncListFiles(args: { dirPath: string }): Promise<string[] | Error>;
|
||||
|
||||
checkDirExists(args: { dirPath: string }): Promise<true | Error>;
|
||||
|
||||
|
|
|
|||
|
|
@ -112,6 +112,36 @@ export const initLocalFileSyncAdapter = (): void => {
|
|||
return true;
|
||||
} catch (e) {
|
||||
log('ERR: error while checking dir ' + dirPath);
|
||||
if ((e as NodeJS.ErrnoException).code === 'EACCES') {
|
||||
log(
|
||||
'ERR: Permission denied. If running as a snap, ensure the "home" or "removable-media" interface is connected.',
|
||||
);
|
||||
}
|
||||
error(e);
|
||||
return e instanceof Error ? e : new Error(String(e));
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
ipcMain.handle(
|
||||
IPC.FILE_SYNC_LIST_FILES,
|
||||
(
|
||||
ev,
|
||||
{
|
||||
dirPath,
|
||||
}: {
|
||||
dirPath: string;
|
||||
},
|
||||
): string[] | Error => {
|
||||
try {
|
||||
return readdirSync(dirPath);
|
||||
} catch (e) {
|
||||
log('ERR: Sync error while listing files in ' + dirPath);
|
||||
if ((e as NodeJS.ErrnoException).code === 'EACCES') {
|
||||
log(
|
||||
'ERR: Permission denied. If running as a snap, ensure the "home" or "removable-media" interface is connected.',
|
||||
);
|
||||
}
|
||||
error(e);
|
||||
return e instanceof Error ? e : new Error(String(e));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,8 +49,8 @@ const ea: ElectronAPI = {
|
|||
dataStr: string | undefined;
|
||||
}>,
|
||||
fileSyncRemove: (filePath) => _invoke('FILE_SYNC_REMOVE', filePath) as Promise<void>,
|
||||
fileSyncListFiles: ({ dirPath }) =>
|
||||
_invoke('FILE_SYNC_LIST_FILES', dirPath) as Promise<string[] | Error>,
|
||||
fileSyncListFiles: (args) =>
|
||||
_invoke('FILE_SYNC_LIST_FILES', args) as Promise<string[] | Error>,
|
||||
checkDirExists: (dirPath) =>
|
||||
_invoke('CHECK_DIR_EXISTS', dirPath) as Promise<true | Error>,
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ export enum IPC {
|
|||
FILE_SYNC_LOAD = 'FILE_SYNC_LOAD',
|
||||
FILE_SYNC_SAVE = 'FILE_SYNC_SAVE',
|
||||
FILE_SYNC_REMOVE = 'FILE_SYNC_REMOVE',
|
||||
FILE_SYNC_LIST_FILES = 'FILE_SYNC_LIST_FILES', // NEW
|
||||
FILE_SYNC_LIST_FILES = 'FILE_SYNC_LIST_FILES',
|
||||
FILE_SYNC_GET_REV_AND_CLIENT_UPDATE = 'FILE_SYNC_GET_REV_AND_CLIENT_UPDATE',
|
||||
|
||||
CHECK_DIR_EXISTS = 'CHECK_DIR_EXISTS',
|
||||
|
|
|
|||
|
|
@ -3,5 +3,5 @@ export interface FileAdapter {
|
|||
writeFile(filePath: string, dataStr: string): Promise<void>;
|
||||
deleteFile(filePath: string): Promise<void>;
|
||||
checkDirExists?(dirPath: string): Promise<boolean>;
|
||||
listFiles?(dirPath: string): Promise<string[]>; // NEW
|
||||
listFiles?(dirPath: string): Promise<string[]>;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue