Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ let appWin = null;
let notifier = null;
let androidSet = null;
let updater = null;
// 按键映射引擎:whenReady 里创建,registerIpc 里的 keymap:* 处理要用,所以放模块级
let keymapEngine = null;
let updateBusy = false;
let updateInfo = null;

Expand Down Expand Up @@ -3054,7 +3056,7 @@ if (!gotLock) {
androidSet = new AndroidSettings(runtime);

// ---- 按键映射引擎 ----
const keymapEngine = new KeymapEngine({
keymapEngine = new KeymapEngine({
execInput: (cmd) => runtime.client().shell(cmd, { timeout: 4000 }),
getSize: () => {
// 用当前面板尺寸(横屏 1280x720 / 竖屏 720x1280)
Expand Down
13 changes: 13 additions & 0 deletions test/run-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,5 +239,18 @@ test('读取注册表值能识别模式(兼容大小写与多键串)', () =>
assert(gpupref.parseValue('') === 'auto');
});

console.log('\n[main.js 按键映射]');
test('按键映射 IPC 用到的 keymapEngine 必须是模块级变量(否则每次调用都抛 ReferenceError)', () => {
const mainJs = fs.readFileSync(path.join(__dirname, '..', 'src', 'main.js'), 'utf8');
const at = mainJs.indexOf('function registerIpc(');
assert(at > 0, '找不到 registerIpc');
const ipc = mainJs.slice(at, mainJs.indexOf('\n}\n', at));
assert(/keymapEngine/.test(ipc), 'registerIpc 里应有按键映射处理');
// registerIpc 是独立的顶层函数,看不到 whenReady 回调里的块级 const
const decls = mainJs.match(/\b(?:const|let|var)\s+keymapEngine\b/g) || [];
assert(decls.length === 1 && /^let keymapEngine\b/m.test(mainJs),
`keymapEngine 应只在模块级声明一次,实际声明:${decls.join(', ') || '无'}`);
});

console.log(`\n结果:${passed} 通过,${failed} 失败\n`);
process.exit(failed ? 1 : 0);