merge: integrate remote learning module safely
Some checks failed
Electron E2E / Electron E2E (macos-latest) (push) Has been cancelled
Electron E2E / Electron E2E (ubuntu-latest) (push) Has been cancelled
Electron E2E / Electron E2E (windows-latest) (push) Has been cancelled

This commit is contained in:
2026-08-17 01:05:49 +08:00
125 changed files with 11451 additions and 12132 deletions

View File

@@ -57,6 +57,12 @@ const UNIFIED_CHANNELS = new Set<string>([
'update:cancelAutoInstall',
]);
const ALLOWED_EVENT_CHANNELS = new Set([
'learning:runtime-event',
] as const);
export type AllowedIpcEventChannel = 'learning:runtime-event';
function toUnifiedRequest(channel: string, args: unknown[]): UnifiedRequest {
const splitIndex = channel.indexOf(':');
return {
@@ -112,6 +118,31 @@ export async function invokeIpc<T>(channel: string, ...args: unknown[]): Promise
return invokeApi<T>(channel, ...args);
}
export function subscribeIpcEvent(
channel: AllowedIpcEventChannel,
listener: (payload: unknown) => void,
): () => void {
if (!ALLOWED_EVENT_CHANNELS.has(channel)) {
throw new AppError('PERMISSION', 'IPC event channel is not allowed', {
transport: 'ipc',
channel,
source: 'renderer-event-subscription',
});
}
const unsubscribe = window.electron.ipcRenderer.on(channel, listener);
let active = true;
return () => {
if (!active) return;
active = false;
if (typeof unsubscribe === 'function') {
unsubscribe();
return;
}
window.electron.ipcRenderer.off(channel, listener);
};
}
export async function invokeIpcWithRetry<T>(
channel: string,
args: unknown[] = [],