mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-02 18:10:18 +05:30
fix(ipc): re-type wrapper signatures to match handler return shapes
Many IPC handlers were returning useful data but the wrappers typed
'void', silently dropping the response. Re-type all affected wrappers:
- file.write: returns { path } (resolved after security validation)
- file.delete/ensureDir/exists/isDirectory/copy/move: full wrappers
(previously only on window.electronAPI.file.*)
- crash.read: typed as Array<{...}> so callers can trust the shape
- crash.delete: returns boolean
- gitStage: returns { files, error? } so callers can detect failure
- gitCommit: returns { summary } | { error }
- updater.check/getState: returns { state }
This commit is contained in:
+40
-7
@@ -62,10 +62,28 @@ export const ipc = {
|
|||||||
// Callers needing a file picker should use ipc.file.pickFile() directly.
|
// Callers needing a file picker should use ipc.file.pickFile() directly.
|
||||||
read: (path: string): Promise<IpcResult<string | ChannelMissing>> =>
|
read: (path: string): Promise<IpcResult<string | ChannelMissing>> =>
|
||||||
safeCall('file', 'read', path),
|
safeCall('file', 'read', path),
|
||||||
write: (path: string, content: string): Promise<IpcResult<void | ChannelMissing>> =>
|
write: (path: string, content: string): Promise<IpcResult<{ path: string } | ChannelMissing>> =>
|
||||||
safeCall('file', 'write', path, content),
|
safeCall('file', 'write', path, content),
|
||||||
list: (dir: string): Promise<IpcResult<FileEntry[] | ChannelMissing>> =>
|
list: (dir: string): Promise<IpcResult<FileEntry[] | ChannelMissing>> =>
|
||||||
safeCall('file', 'list', dir),
|
safeCall('file', 'list', dir),
|
||||||
|
delete: (path: string): Promise<IpcResult<boolean | ChannelMissing>> =>
|
||||||
|
safeCall('file', 'delete', path),
|
||||||
|
ensureDir: (path: string): Promise<IpcResult<string | ChannelMissing>> =>
|
||||||
|
safeCall('file', 'ensureDir', path),
|
||||||
|
exists: (path: string): Promise<IpcResult<boolean | ChannelMissing>> =>
|
||||||
|
safeCall('file', 'exists', path),
|
||||||
|
isDirectory: (path: string): Promise<IpcResult<boolean | ChannelMissing>> =>
|
||||||
|
safeCall('file', 'isDirectory', path),
|
||||||
|
copy: (
|
||||||
|
source: string,
|
||||||
|
destination: string
|
||||||
|
): Promise<IpcResult<{ source: string; destination: string } | ChannelMissing>> =>
|
||||||
|
safeCall('file', 'copy', source, destination),
|
||||||
|
move: (
|
||||||
|
source: string,
|
||||||
|
destination: string
|
||||||
|
): Promise<IpcResult<{ source: string; destination: string } | ChannelMissing>> =>
|
||||||
|
safeCall('file', 'move', source, destination),
|
||||||
pickFolder: (): Promise<IpcResult<string | null | ChannelMissing>> =>
|
pickFolder: (): Promise<IpcResult<string | null | ChannelMissing>> =>
|
||||||
safeCall('file', 'pickFolder'),
|
safeCall('file', 'pickFolder'),
|
||||||
pickFile: (): Promise<IpcResult<string | null | ChannelMissing>> =>
|
pickFile: (): Promise<IpcResult<string | null | ChannelMissing>> =>
|
||||||
@@ -103,11 +121,13 @@ export const ipc = {
|
|||||||
gitStage: (args: {
|
gitStage: (args: {
|
||||||
rootPath: string;
|
rootPath: string;
|
||||||
files: string[];
|
files: string[];
|
||||||
}): Promise<IpcResult<void | ChannelMissing>> => safeCall('git', 'stage', args),
|
}): Promise<IpcResult<{ files: unknown[]; error?: string } | ChannelMissing>> =>
|
||||||
|
safeCall('git', 'stage', args),
|
||||||
gitCommit: (args: {
|
gitCommit: (args: {
|
||||||
rootPath: string;
|
rootPath: string;
|
||||||
message: string;
|
message: string;
|
||||||
}): Promise<IpcResult<void | ChannelMissing>> => safeCall('git', 'commit', args),
|
}): Promise<IpcResult<{ summary: string } | { error: string } | ChannelMissing>> =>
|
||||||
|
safeCall('git', 'commit', args),
|
||||||
setCurrent: (path: string | null): void => {
|
setCurrent: (path: string | null): void => {
|
||||||
if (typeof window !== 'undefined' && window.electronAPI?.file?.setCurrent) {
|
if (typeof window !== 'undefined' && window.electronAPI?.file?.setCurrent) {
|
||||||
window.electronAPI.file.setCurrent(path);
|
window.electronAPI.file.setCurrent(path);
|
||||||
@@ -161,9 +181,11 @@ export const ipc = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
updater: {
|
updater: {
|
||||||
check: (): Promise<IpcResult<void | ChannelMissing>> => safeCall('updater', 'check'),
|
check: (): Promise<IpcResult<{ state: string } | ChannelMissing>> =>
|
||||||
|
safeCall('updater', 'check'),
|
||||||
install: (): Promise<IpcResult<void | ChannelMissing>> => safeCall('updater', 'install'),
|
install: (): Promise<IpcResult<void | ChannelMissing>> => safeCall('updater', 'install'),
|
||||||
getState: (): Promise<IpcResult<unknown | ChannelMissing>> => safeCall('updater', 'getState'),
|
getState: (): Promise<IpcResult<{ state: string } | ChannelMissing>> =>
|
||||||
|
safeCall('updater', 'getState'),
|
||||||
onStatus: (cb: (payload: unknown) => void): (() => void) => {
|
onStatus: (cb: (payload: unknown) => void): (() => void) => {
|
||||||
if (typeof window === 'undefined' || !window.electronAPI?.updater?.onStatus) {
|
if (typeof window === 'undefined' || !window.electronAPI?.updater?.onStatus) {
|
||||||
return () => {};
|
return () => {};
|
||||||
@@ -172,9 +194,20 @@ export const ipc = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
crash: {
|
crash: {
|
||||||
read: (): Promise<IpcResult<unknown | ChannelMissing>> => safeCall('crash', 'read'),
|
read: (): Promise<
|
||||||
|
IpcResult<
|
||||||
|
| Array<{
|
||||||
|
filename: string;
|
||||||
|
kind: string;
|
||||||
|
message?: string;
|
||||||
|
stack?: string;
|
||||||
|
timestamp: string;
|
||||||
|
}>
|
||||||
|
| ChannelMissing
|
||||||
|
>
|
||||||
|
> => safeCall('crash', 'read'),
|
||||||
openDir: (): Promise<IpcResult<void | ChannelMissing>> => safeCall('crash', 'openDir'),
|
openDir: (): Promise<IpcResult<void | ChannelMissing>> => safeCall('crash', 'openDir'),
|
||||||
delete: (filename: string): Promise<IpcResult<void | ChannelMissing>> =>
|
delete: (filename: string): Promise<IpcResult<boolean | ChannelMissing>> =>
|
||||||
safeCall('crash', 'delete', filename),
|
safeCall('crash', 'delete', filename),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user