Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ jobs:

- name: Build
run: npm run build

- name: Build native cursor overlay helper
run: npm run native:build-overlay

- name: Smoke native cursor overlay helper
run: npm run native:smoke-overlay
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ jobs:
- name: Build native cursor overlay helper
run: npm run native:build-overlay

- name: Smoke native cursor overlay helper
run: npm run native:smoke-overlay

- name: Package Windows installer
run: npm run package:win

Expand Down
4 changes: 2 additions & 2 deletions native/cursor-overlay-helper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ private static void HandleCommandLine(OverlayForm overlayForm, SynchronizationCo
switch (command.Type)
{
case "show":
if (command.Event is not ("move" or "click"))
if (command.Event is not ("move" or "click" or "drag"))
{
WriteError("invalid_command", "Show command event must be move or click.");
WriteError("invalid_command", "Show command event must be move, click, or drag.");
return;
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"build": "electron-vite build",
"native:build": "node scripts/build-cursor-overlay-helper.cjs",
"native:build-overlay": "npm run native:build",
"native:smoke-overlay": "node scripts/smoke-cursor-overlay-helper.cjs",
"package:win": "npm run build && npm run native:build && electron-builder --win --x64 --publish never && node scripts/sign-win-artifacts.cjs --update-latest-yml",
"package:win:verify-uiaccess": "node scripts/verify-win-uiaccess-package.cjs",
"signing:create-dev-cert": "node scripts/create-dev-signing-cert.cjs",
Expand Down
136 changes: 136 additions & 0 deletions scripts/smoke-cursor-overlay-helper.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
const { spawn } = require('node:child_process');
const { existsSync } = require('node:fs');
const { join, resolve } = require('node:path');

const projectRoot = resolve(__dirname, '..');
const helperPath = join(
projectRoot,
'build',
'native',
'cursor-overlay-helper',
'win-x64',
'SwitchifyCursorOverlay.exe'
);

const timeoutMs = 5_000;
let stdoutBuffer = '';
let stderrBuffer = '';
let settled = false;
let sawReady = false;
let shutdownSent = false;
let timeout = null;
let helper = null;

if (!existsSync(helperPath)) {
fail(`Cursor overlay helper was not found: ${helperPath}`);
}

helper = spawn(helperPath, [], {
stdio: ['pipe', 'pipe', 'pipe'],
windowsHide: true
});

timeout = setTimeout(() => {
fail(`Cursor overlay helper smoke test timed out.${stderrBuffer ? ` stderr: ${stderrBuffer.trim()}` : ''}`);
}, timeoutMs);

helper.once('error', (error) => {
fail(`Cursor overlay helper failed to start: ${error.message}`);
});

helper.once('exit', (code, signal) => {
if (!settled && !shutdownSent) {
fail(`Cursor overlay helper exited before shutdown: ${signal ?? code ?? 'unknown'}`);
}
});

helper.stdout.on('data', (chunk) => {
stdoutBuffer += String(chunk);
readStdoutLines();
});

helper.stderr.on('data', (chunk) => {
stderrBuffer += String(chunk);
});

function readStdoutLines() {
while (stdoutBuffer.includes('\n')) {
const newlineIndex = stdoutBuffer.indexOf('\n');
const line = stdoutBuffer.slice(0, newlineIndex).trim();
stdoutBuffer = stdoutBuffer.slice(newlineIndex + 1);
if (line) {
handleMessage(line);
}
}
}

function handleMessage(line) {
let message;
try {
message = JSON.parse(line);
} catch (error) {
fail(`Cursor overlay helper returned malformed output: ${line}`);
return;
}

if (message.type === 'error') {
fail(`Cursor overlay helper reported ${message.code ?? 'error'}: ${message.message ?? 'unknown error'}`);
return;
}

if (message.type === 'ready' && !sawReady) {
sawReady = true;
smokeEvents();
}
}

function smokeEvents() {
for (const event of ['move', 'click', 'drag']) {
writeCommand({
type: 'show',
event,
x: 100,
y: 100,
size: 96,
durationMs: 50,
crosshairs: false,
persistent: false,
color: {
red: 211,
green: 47,
blue: 47
}
});
}

setTimeout(() => {
shutdownSent = true;
writeCommand({ type: 'shutdown' });
helper.stdin.end();
clearTimeout(timeout);
settled = true;
console.log('Cursor overlay helper smoke test passed.');
setTimeout(() => {
if (helper && !helper.killed) {
helper.kill();
}
}, 1_000).unref();
}, 100);
}

function writeCommand(command) {
helper.stdin.write(`${JSON.stringify(command)}\n`);
}

function fail(message) {
if (settled) return;
settled = true;
if (timeout) {
clearTimeout(timeout);
}
if (helper && !helper.killed) {
helper.kill();
}
console.error(message);
process.exitCode = 1;
}