Fix unsolicited radial menu activation by retiring global drag detection

This commit is contained in:
nordik committed 2026-10-27 12:13:15 +01:00
1 parent 569f0324d6
commit e3c9581f3e
19 files changed
+112 -88

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { EventEmitter } = require('node:events');
const { PassThrough } = require('node:stream');
const vm = require('node:vm');
const fs = require('node:fs');
const path = require('node:path');
test('unsolicited legacy drag messages cannot activate the radial menu', async () => {
const child = new EventEmitter();
child.stdin = new PassThrough();
child.stdout = new PassThrough();
child.stderr = new PassThrough();
const module = { exports: {} };
vm.runInNewContext(fs.readFileSync(path.join(__dirname, '../src/main/windows.cjs'), 'utf8'), {
module, setTimeout, clearTimeout,
require: name => name === 'node:child_process' ? { spawn: () => child } : require(name),
});
const bridge = new module.exports.WindowsBridge('C:/FileBow');
let activations = 0;
// Old helpers may still emit these events; the bridge must ignore them.
bridge.onDrag = () => { activations++; };
child.stdout.write('{"type":"ready"}\n');
await bridge.ready;
for (const phase of ['start', 'drop', 'shortcut', 'end']) {
child.stdout.write(JSON.stringify({ type: 'drag', phase, files: ['C:/selected.png'], x: 500, y: 500 }) + '\n');
}
assert.equal(activations, 0);
// Explicit requests, used by the real keyboard shortcuts, still work.
const selection = bridge.getExplorerSelection();
await new Promise(resolve => setImmediate(resolve));
const request = JSON.parse(child.stdin.read().toString());
assert.equal(request.command, 'selection');
child.stdout.write(JSON.stringify({ id: request.id, result: ['C:/selected.png'] }) + '\n');
assert.equal((await selection)[0], 'C:/selected.png');
bridge.close();
});