Skip to content

Commit

Permalink
Added command handler to enable/disable pen functionality (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
robgruen authored Jan 21, 2025
1 parent 7de2bc3 commit d5a0f0b
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import {
import { alwaysEnabledAgents } from "../../appAgentManager.js";
import { getCacheFactory } from "../../../utils/cacheFactory.js";
import { resolveCommand } from "../../../command/command.js";
import child_process from "node:child_process";
import { fileURLToPath } from "node:url";

const enum AgentToggle {
Schema,
Expand All @@ -49,6 +51,11 @@ const AgentToggleDescription = [
"agents",
] as const;

const penLauncherPath = new URL(
"../../../../../../../dotnet/penLauncher/bin/Debug/net9.0/penLauncher.exe",
import.meta.url,
);

function getAgentToggleOptions(
toggle: AgentToggle,
options: Record<string, boolean | null>,
Expand Down Expand Up @@ -1033,6 +1040,34 @@ export function getConfigCommandHandlers(): CommandHandlerTable {
),
},
},
pen: {
description: "Toggles click note pen handler.",
defaultSubCommand: "on",
commands: getToggleCommandHandlers(
"Surface Pen Click Handler",
async (isContext, enable) => {
if (enable) {
spawnPenLauncherProcess("--register");
} else {
spawnPenLauncherProcess("--unregister");
}
},
),
},
},
};
}

async function spawnPenLauncherProcess(args: string) {
return new Promise<child_process.ChildProcess>((resolve, reject) => {
const child = child_process.spawn(fileURLToPath(penLauncherPath), [
args,
]);
child.on("error", (err) => {
reject(err);
});
child.on("spawn", () => {
resolve(child);
});
});
}

0 comments on commit d5a0f0b

Please sign in to comment.