Fix unsolicited radial menu activation by retiring global drag detection
This commit is contained in:
1 parent
569f0324d6
commit
e3c9581f3e
19 files changed
+112
-88
No files matched your search
@@ -1,4 +0,0 @@
|
||||
const {WindowsBridge}=require('../src/main/windows.cjs');
|
||||
const fs=require('node:fs'),path=require('node:path');
|
||||
const root=path.resolve(__dirname,'..'),log=path.join(root,'test-results/native-drag.json');
|
||||
(async()=>{const bridge=new WindowsBridge(root);const events=[];await bridge.startFileDragMonitor(event=>{events.push(event);fs.writeFileSync(log,JSON.stringify(events,null,2));});console.log('Monitor ready');setTimeout(()=>bridge.close(),60000);})().catch(error=>{console.error(error);process.exitCode=1;});
|
||||
@@ -0,0 +1,15 @@
|
||||
const assert = require('node:assert/strict');
|
||||
const path = require('node:path');
|
||||
const { WindowsBridge } = require('../src/main/windows.cjs');
|
||||
const root = path.resolve(process.argv[2] || path.join(__dirname, '..'));
|
||||
(async () => {
|
||||
const bridge = new WindowsBridge(root);
|
||||
try {
|
||||
await bridge.ready;
|
||||
await assert.rejects(bridge.request('monitor', { enabled: true }), /Unknown command/);
|
||||
const identity = await bridge.request('identity');
|
||||
assert.equal(typeof identity.packaged, 'boolean');
|
||||
assert.ok(Array.isArray(await bridge.getExplorerSelection()));
|
||||
console.log('Native integration passed: retired monitor rejected, identity and selection available.');
|
||||
} finally { bridge.close(); }
|
||||
})().catch(error => { console.error(error); process.exitCode = 1; });
|
||||
@@ -10,6 +10,8 @@ const root=path.resolve(__dirname,'..'),out=path.join(root,'test-results');
|
||||
(async()=>{
|
||||
await fs.mkdir(out,{recursive:true});
|
||||
const profile=await fs.mkdtemp(path.join(out,'profile-'));
|
||||
// An upgraded profile must not restore the retired automatic drag trigger.
|
||||
await fs.writeFile(path.join(profile,'settings.json'),JSON.stringify({dragWheel:true}));
|
||||
const app=await electron.launch({executablePath:process.env.FILEBOW_EXECUTABLE||require('electron'),args:process.env.FILEBOW_EXECUTABLE?[]:[root],env:{...process.env,FILEBOW_TEST:'1',FILEBOW_USER_DATA:profile},timeout:30000});
|
||||
const errors=[];app.on('window',window=>window.on('pageerror',error=>errors.push(error.message)));
|
||||
app.process().stderr.on('data',data=>{const text=data.toString();if(/Error|Exception/.test(text))process.stderr.write(text);});
|
||||
@@ -19,6 +21,11 @@ const root=path.resolve(__dirname,'..'),out=path.join(root,'test-results');
|
||||
assert.equal(await page.locator('html').getAttribute('lang'),'en');
|
||||
assert.equal(await app.evaluate(({app})=>app.getLocale()),'en-US');
|
||||
const state=await page.evaluate(()=>window.orbit.state());assert.equal(state.name,'FileBow');assert.ok(state.native.available,state.native.error);
|
||||
assert.equal(Object.hasOwn(state.settings,'dragWheel'),false);
|
||||
assert.equal(await page.locator('[data-setting="dragWheel"]').count(),0);
|
||||
const legacySettings=await page.evaluate(()=>window.orbit.settings({dragWheel:true}));
|
||||
assert.equal(Object.hasOwn(legacySettings.settings,'dragWheel'),false);
|
||||
assert.equal(Object.hasOwn(JSON.parse(await fs.readFile(path.join(profile,'settings.json'),'utf8')),'dragWheel'),false);
|
||||
const textFile=path.join(out,'Beispiel.txt');await fs.writeFile(textFile,'FileBow\nGrüße aus Köln.\nLokale Dateikonvertierung.');
|
||||
await page.evaluate(file=>window.orbit.selectFiles([file]),textFile);
|
||||
await page.locator('[data-action="convert-pdf"]').click();
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
Reference in new issue
Block a user