Skip to content

Commit ad29419

Browse files
committed
feat(window-recognition): 记忆IPC通道与评分boost接入
1 parent b5b083b commit ad29419

3 files changed

Lines changed: 45 additions & 2 deletions

File tree

‎client/electron/ipc/channels.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export const IPC_CHANNELS = {
3939
SCREEN_WATCH_WINDOWS_START: 'screen_watch_windows_start',
4040
SCREEN_WATCH_WINDOWS_STOP: 'screen_watch_windows_stop',
4141
SCREEN_WINDOWS_CHANGED: 'screen_windows_changed',
42+
// 窗口选择记忆
43+
WINDOW_MEMORY_RECORD: 'window_memory_record',
44+
WINDOW_MEMORY_CLEAR: 'window_memory_clear',
4245
SCREEN_CAPTURE_START: 'screen_capture_start',
4346
SCREEN_CAPTURE_STOP: 'screen_capture_stop',
4447
SCREEN_CAPTURE_FRAME: 'screen_capture_frame',

‎client/electron/preload.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ const ALLOWED_CHANNELS = [
5353
'screen_list_windows',
5454
'screen_watch_windows_start',
5555
'screen_watch_windows_stop',
56+
'window_memory_record',
57+
'window_memory_clear',
5658
'screen_capture_start',
5759
'screen_capture_stop',
5860
'audio_list_sources',

‎client/electron/screenCaptureHandlers.ts‎

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { getCaptureRateScale, onPerformanceModeChange } from './performanceMode.
1919
import { loadProcessAudioNative } from './audio/processAudioNative.js';
2020
import { parseHwndFromSourceId, buildNativeIndex, resolveGeometrySignals } from './windowSignals.js';
2121
import type { NativeWindowSignal } from './windowSignals.js';
22+
import { recordChoice, clearMemory, lookupMemory, computeMemoryBoost } from './windowHistory.js';
2223

2324
// ================================================================
2425
// 模块级状态
@@ -259,7 +260,18 @@ export function registerScreenCaptureHandlers(): void {
259260
});
260261

261262
// 智能评分、过滤与排序(阶段一:空信号映射,纯标题评分)
262-
return scoreAndFilterWindows(rawWindows, { signalsBySourceId: buildSignalMap(sources) });
263+
const scored = scoreAndFilterWindows(rawWindows, {
264+
signalsBySourceId: buildSignalMap(sources),
265+
memoryLookup: (processName: string, title: string) => {
266+
const entry = lookupMemory(processName, title);
267+
if (!entry) return null;
268+
return {
269+
courseName: entry.courseName,
270+
boost: computeMemoryBoost(entry, Date.now()),
271+
};
272+
},
273+
});
274+
return scored;
263275
} catch (err) {
264276
logger.error('[IPC] screen_list_windows failed:', err);
265277
return [];
@@ -295,7 +307,17 @@ export function registerScreenCaptureHandlers(): void {
295307
return { id: src.id, title: src.name, thumbnail: thumb.toDataURL() };
296308
});
297309

298-
const scored = scoreAndFilterWindows(rawWindows, { signalsBySourceId: buildSignalMap(sources) });
310+
const scored = scoreAndFilterWindows(rawWindows, {
311+
signalsBySourceId: buildSignalMap(sources),
312+
memoryLookup: (processName: string, title: string) => {
313+
const entry = lookupMemory(processName, title);
314+
if (!entry) return null;
315+
return {
316+
courseName: entry.courseName,
317+
boost: computeMemoryBoost(entry, Date.now()),
318+
};
319+
},
320+
});
299321

300322
// 推送到渲染进程
301323
const mainWindowId = getMainWindowId();
@@ -323,6 +345,22 @@ export function registerScreenCaptureHandlers(): void {
323345
}
324346
return { success: true };
325347
});
348+
349+
safeHandle('window_memory_record', async (_event, payload: { processName?: string; title?: string; courseName?: string }) => {
350+
const processName = typeof payload?.processName === 'string' ? payload.processName : '';
351+
const title = typeof payload?.title === 'string' ? payload.title : '';
352+
if (!processName || !title) {
353+
return { success: false };
354+
}
355+
const courseName = typeof payload?.courseName === 'string' ? payload.courseName : undefined;
356+
recordChoice(processName, title, courseName);
357+
return { success: true };
358+
});
359+
360+
safeHandle('window_memory_clear', async () => {
361+
clearMemory();
362+
return { success: true };
363+
});
326364
}
327365

328366
/**

0 commit comments

Comments
 (0)