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:
Johannes Millan 2026-04-14 21:37:55 +02:00
parent 23c729bd9c
commit 46e0fa2d01
5 changed files with 35 additions and 5 deletions

View file

@ -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>;

View file

@ -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));
}

View file

@ -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>,

View file

@ -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',

View file

@ -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[]>;
}