@codingfrees/uap-device-control 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/uap-device-control.mjs +77 -12
- package/package.json +1 -1
|
@@ -407,7 +407,7 @@ import path4 from "node:path";
|
|
|
407
407
|
// package.json
|
|
408
408
|
var package_default = {
|
|
409
409
|
name: "@codingfrees/uap-device-control",
|
|
410
|
-
version: "0.1.
|
|
410
|
+
version: "0.1.9",
|
|
411
411
|
description: "Cross-platform outbound UAP Device Control client",
|
|
412
412
|
type: "module",
|
|
413
413
|
bin: {
|
|
@@ -1167,7 +1167,18 @@ async function windowsAdapter(run) {
|
|
|
1167
1167
|
const monitors = monitorId ? JSON.parse(asText((await invoke2(WINDOWS_MONITORS)).stdout)) : [];
|
|
1168
1168
|
const monitor = monitorId ? monitors.find((item) => item.id === monitorId) : void 0;
|
|
1169
1169
|
if (monitorId && !monitor) throw new TypeError("screen monitor is unavailable");
|
|
1170
|
-
await invoke2(
|
|
1170
|
+
await invoke2(
|
|
1171
|
+
WINDOWS_POINTER,
|
|
1172
|
+
pointerArguments(
|
|
1173
|
+
monitor ? {
|
|
1174
|
+
...input,
|
|
1175
|
+
x: integer2(input.x, 0, 1e5, "x") + monitor.x,
|
|
1176
|
+
y: integer2(input.y, 0, 1e5, "y") + monitor.y,
|
|
1177
|
+
toX: integer2(input.toX ?? input.x, 0, 1e5, "toX") + monitor.x,
|
|
1178
|
+
toY: integer2(input.toY ?? input.y, 0, 1e5, "toY") + monitor.y
|
|
1179
|
+
} : input
|
|
1180
|
+
)
|
|
1181
|
+
);
|
|
1171
1182
|
},
|
|
1172
1183
|
keyboard: async (input) => {
|
|
1173
1184
|
await invoke2(WINDOWS_KEYBOARD, [windowsKeyboardSequence(input)]);
|
|
@@ -1184,7 +1195,10 @@ async function windowsInteropScreenAdapter(run) {
|
|
|
1184
1195
|
const version = await run(executable, ["-NoProfile", "-NonInteractive", "-Command", "$PSVersionTable.PSVersion.ToString()"], { ...commandOptions(), timeout: 2e3 });
|
|
1185
1196
|
if (!/^\d+(?:\.\d+)+/.test(asText(version.stdout).trim())) continue;
|
|
1186
1197
|
const invoke2 = (script, args = []) => powershellInvoke(run, executable, script, args);
|
|
1187
|
-
return {
|
|
1198
|
+
return {
|
|
1199
|
+
monitors: async () => JSON.parse(asText((await invoke2(WINDOWS_MONITORS)).stdout)),
|
|
1200
|
+
captureScreen: async (monitorId, options) => JSON.parse(asText((await invoke2(WINDOWS_CAPTURE, [monitorId ?? "0", options?.format ?? "png", String(options?.quality ?? 100)])).stdout))
|
|
1201
|
+
};
|
|
1188
1202
|
} catch {
|
|
1189
1203
|
}
|
|
1190
1204
|
}
|
|
@@ -1203,7 +1217,11 @@ async function linuxAdapter(run) {
|
|
|
1203
1217
|
const monitors = parseXrandrGeometry(asText((await run("xrandr", ["--query"], commandOptions())).stdout));
|
|
1204
1218
|
const monitor2 = monitorId ? monitors.find((item) => item.id === monitorId) : monitors.find((item) => item.primary) ?? monitors[0];
|
|
1205
1219
|
if (!monitor2) throw new TypeError("screen monitor is unavailable");
|
|
1206
|
-
const output2 = await run(
|
|
1220
|
+
const output2 = await run(
|
|
1221
|
+
"import",
|
|
1222
|
+
["-window", "root", "-crop", `${monitor2.width}x${monitor2.height}+${monitor2.x}+${monitor2.y}`, ...options.format === "jpeg" ? ["-quality", String(options.quality)] : [], `${options.format}:-`],
|
|
1223
|
+
binaryOptions()
|
|
1224
|
+
);
|
|
1207
1225
|
const bytes2 = screenImage(asBuffer(output2.stdout), options.format);
|
|
1208
1226
|
return { contentType: `image/${options.format}`, contentBase64: bytes2.toString("base64"), width: monitor2.width, height: monitor2.height, monitorId: monitor2.id };
|
|
1209
1227
|
}
|
|
@@ -1273,10 +1291,11 @@ function windowsKeyboardSequence(input) {
|
|
|
1273
1291
|
}
|
|
1274
1292
|
const key = text3(input.key, 64, "keyboard key");
|
|
1275
1293
|
if (/^F(?:[1-9]|1[0-2])$/.test(key)) return "{" + key + "}";
|
|
1276
|
-
const token = WINDOWS_KEY_TOKENS[key];
|
|
1277
|
-
if (!token) throw new TypeError("keyboard key is invalid");
|
|
1278
1294
|
const modifiers = modifierList(input.modifiers);
|
|
1279
|
-
|
|
1295
|
+
if (modifiers.includes("Meta")) throw new TypeError("Meta keyboard modifier is unavailable on Windows");
|
|
1296
|
+
const token = WINDOWS_KEY_TOKENS[key] ?? (/^[a-zA-Z0-9]$/.test(key) ? key.toLowerCase() : null);
|
|
1297
|
+
if (!token) throw new TypeError("keyboard key is invalid; use a named key, F1-F12, or a single letter/digit");
|
|
1298
|
+
return (modifiers.includes("Control") ? "^" : "") + (modifiers.includes("Alt") ? "%" : "") + (modifiers.includes("Shift") || /^[A-Z]$/.test(key) && modifiers.length === 0 ? "+" : "") + token;
|
|
1280
1299
|
}
|
|
1281
1300
|
function linuxKeySequence(key, rawModifiers) {
|
|
1282
1301
|
const aliases = { Control: "ctrl", Alt: "alt", Shift: "shift", Meta: "super" };
|
|
@@ -1717,7 +1736,11 @@ async function runRemote(options) {
|
|
|
1717
1736
|
options.log?.(event);
|
|
1718
1737
|
if (event.event === "browser.bridge" && (event.status === "paired" || event.status === "unpaired")) refreshSession();
|
|
1719
1738
|
};
|
|
1720
|
-
const browser = options.browserControl === false ? void 0 : await createBrowserBridge(options.stateDirectory, options.browserPort ?? 8800, browserLog)
|
|
1739
|
+
const browser = options.browserControl === false ? void 0 : await createBrowserBridge(options.stateDirectory, options.browserPort ?? 8800, browserLog).catch((error) => {
|
|
1740
|
+
if (!optionalBrowserBridgeFailure(error)) throw error;
|
|
1741
|
+
options.log?.({ event: "browser.bridge", status: "unavailable" });
|
|
1742
|
+
return void 0;
|
|
1743
|
+
});
|
|
1721
1744
|
if (browser) {
|
|
1722
1745
|
options.log?.({ event: "browser.bridge", status: "ready", port: browser.port, paired: browser.paired });
|
|
1723
1746
|
if (browser.pairingCode) options.log?.({ event: "browser.bridge", status: "pairing-required", port: browser.port, pairingCode: browser.pairingCode });
|
|
@@ -1770,6 +1793,10 @@ async function runRemote(options) {
|
|
|
1770
1793
|
engine.close();
|
|
1771
1794
|
}
|
|
1772
1795
|
}
|
|
1796
|
+
function optionalBrowserBridgeFailure(error) {
|
|
1797
|
+
if (!error || typeof error !== "object" || !("code" in error)) return false;
|
|
1798
|
+
return ["EADDRINUSE", "EACCES", "EAFNOSUPPORT", "EPROTONOSUPPORT"].includes(String(error.code));
|
|
1799
|
+
}
|
|
1773
1800
|
async function remoteSession(origin, stateDirectory, engine, fetcher = fetch, signal, log) {
|
|
1774
1801
|
const deviceId = engine.options.deviceId;
|
|
1775
1802
|
const invoke2 = (pathname, body, requestSignal = signal, timeoutMs = 15e3, requestLog = log) => authorizedRequest(fetcher, origin, stateDirectory, pathname, body, requestSignal, timeoutMs, requestLog, deviceId);
|
|
@@ -1995,8 +2022,8 @@ function xml(value) {
|
|
|
1995
2022
|
// src/cli.ts
|
|
1996
2023
|
var DEFAULT_DEVICE_CONTROL_ORIGIN = "https://device-control.aemdpc.ro";
|
|
1997
2024
|
function parseDeviceControlArguments(args, cwd = process.cwd()) {
|
|
1998
|
-
const command = args[0];
|
|
1999
|
-
if (!["remote", "status", "login", "logout", "install-service"].includes(command ?? "")) throw new TypeError("command
|
|
2025
|
+
const command = !args.length || args.includes("--help") || args.includes("-h") || args[0] === "help" ? "help" : args[0];
|
|
2026
|
+
if (!["help", "remote", "status", "login", "logout", "install-service"].includes(command ?? "")) throw new TypeError("unknown command; run uap-device-control help");
|
|
2000
2027
|
let origin = process.env.UAP_DEVICE_CONTROL_ORIGIN;
|
|
2001
2028
|
let stateDirectory = defaultDeviceControlStateDirectory();
|
|
2002
2029
|
const roots = [];
|
|
@@ -2006,7 +2033,7 @@ function parseDeviceControlArguments(args, cwd = process.cwd()) {
|
|
|
2006
2033
|
let browserControl = true;
|
|
2007
2034
|
let browserPort = 8800;
|
|
2008
2035
|
let json2 = false;
|
|
2009
|
-
for (let index = 1; index < args.length; index++) {
|
|
2036
|
+
for (let index = command === "help" ? args.length : 1; index < args.length; index++) {
|
|
2010
2037
|
const option = args[index];
|
|
2011
2038
|
const value = args[index + 1];
|
|
2012
2039
|
if (option === "--origin") origin = required(value, option), index++;
|
|
@@ -2039,6 +2066,10 @@ function parseDeviceControlArguments(args, cwd = process.cwd()) {
|
|
|
2039
2066
|
}
|
|
2040
2067
|
async function runDeviceControlCli(args = process.argv.slice(2)) {
|
|
2041
2068
|
const config = parseDeviceControlArguments(args);
|
|
2069
|
+
if (config.command === "help") {
|
|
2070
|
+
process.stdout.write(deviceControlHelp());
|
|
2071
|
+
return;
|
|
2072
|
+
}
|
|
2042
2073
|
const existingAuth = await loadRemoteAuth(config.stateDirectory);
|
|
2043
2074
|
const resolvedOrigin = resolveConfiguredOrigin(config.origin, existingAuth?.origin);
|
|
2044
2075
|
const output = (event) => process.stdout.write(formatCliEvent(event, config.json) + "\n");
|
|
@@ -2100,7 +2131,8 @@ function formatCliEvent(event, json2 = false) {
|
|
|
2100
2131
|
}
|
|
2101
2132
|
if (event.event === "browser.bridge") {
|
|
2102
2133
|
if (status === "ready") return "\u{1F310} Browser bridge ready \xB7 127.0.0.1:" + String(event.port) + (event.paired ? " \xB7 paired" : " \xB7 waiting for pairing");
|
|
2103
|
-
if (status === "pairing-required") return "\
|
|
2134
|
+
if (status === "pairing-required") return "\u26A0\uFE0F Browser extension not connected; remote control continues without browser tools \xB7 pairing code " + String(event.pairingCode) + " \xB7 port " + String(event.port);
|
|
2135
|
+
if (status === "unavailable") return "\u26A0\uFE0F Browser control unavailable; remote control continues with files, terminal and processes";
|
|
2104
2136
|
if (status === "paired") return "\u2705 UAP Browser Extension paired";
|
|
2105
2137
|
if (status === "connected") return "\u{1F310} UAP Browser Extension connected";
|
|
2106
2138
|
if (status === "unpaired") return "\u{1F50C} UAP Browser Extension unpaired";
|
|
@@ -2119,6 +2151,39 @@ function formatCliEvent(event, json2 = false) {
|
|
|
2119
2151
|
if ("authenticated" in event) return (event.authenticated ? "\u2705" : "\u26A0\uFE0F") + " Device " + String(event.deviceId) + " \xB7 " + String(event.origin) + " \xB7 remote=" + JSON.stringify(event.remote);
|
|
2120
2152
|
return "\u2139\uFE0F " + JSON.stringify(event);
|
|
2121
2153
|
}
|
|
2154
|
+
function deviceControlHelp() {
|
|
2155
|
+
return `UAP Device Control
|
|
2156
|
+
|
|
2157
|
+
Usage:
|
|
2158
|
+
uap-device-control <command> [options]
|
|
2159
|
+
|
|
2160
|
+
Commands:
|
|
2161
|
+
remote Connect this computer to Device Control
|
|
2162
|
+
status Show authentication, device and connection status
|
|
2163
|
+
login Authorize this computer in your browser
|
|
2164
|
+
logout Remove the saved authorization
|
|
2165
|
+
install-service Install the authenticated Remote as a system service
|
|
2166
|
+
help Show this help
|
|
2167
|
+
|
|
2168
|
+
Remote options:
|
|
2169
|
+
--root <id=path> Add a writable filesystem root
|
|
2170
|
+
--read-only-root <id=path> Add a read-only filesystem root
|
|
2171
|
+
--allow-executable <path> Allow an executable for terminal commands
|
|
2172
|
+
--allow-service <name> Allow a native service
|
|
2173
|
+
--browser-port <port> Browser extension bridge port (default: 8800)
|
|
2174
|
+
--no-browser-control Run without browser integration
|
|
2175
|
+
--state-dir <path> Override the local state directory
|
|
2176
|
+
--origin <https-origin> Override the Device Control service origin
|
|
2177
|
+
--json Emit machine-readable JSON events
|
|
2178
|
+
-h, --help Show this help
|
|
2179
|
+
|
|
2180
|
+
Examples:
|
|
2181
|
+
npx @codingfrees/uap-device-control@latest
|
|
2182
|
+
npx @codingfrees/uap-device-control@latest login
|
|
2183
|
+
npx @codingfrees/uap-device-control@latest remote
|
|
2184
|
+
npx @codingfrees/uap-device-control@latest remote --no-browser-control
|
|
2185
|
+
`;
|
|
2186
|
+
}
|
|
2122
2187
|
function httpDetail(event) {
|
|
2123
2188
|
const status = Number(event.httpStatus);
|
|
2124
2189
|
const pathname = typeof event.pathname === "string" && /^\/[A-Za-z0-9._~!$&'()*+,;=:@%/-]{1,255}$/.test(event.pathname) ? event.pathname : "";
|