screen-relay 0.1.0 → 0.1.1
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/README.md +19 -19
- package/dist/cli/client.d.ts +1 -1
- package/dist/cli/config.d.ts +1 -1
- package/dist/cli/host/common.d.ts +1 -1
- package/dist/cli/host/state.d.ts +1 -1
- package/dist/cli/host/supervisor.d.ts +4 -1
- package/dist/cli/host/windows.d.ts +82 -0
- package/dist/cli/relay.mjs +563 -179
- package/dist/protocol/index.d.ts +2 -2
- package/dist/sdk/index.d.ts +2 -1
- package/dist/sdk/index.js +131 -21
- package/dist/sdk/transport.d.ts +20 -0
- package/dist/viewer/index.html +1 -1
- package/dist/viewer/viewer.js +40 -13
- package/package.json +2 -2
- package/skills/core/SKILL.md +7 -5
- package/skills/core/references/cli.md +13 -13
- package/skills/core/references/config.md +3 -3
- package/skills/core/references/sdk.md +1 -1
- package/skills/core/references/troubleshooting.md +2 -2
- package/skills/screen-relay/SKILL.md +1 -1
- package/src/engine/server/server.cpp +15 -11
- package/src/engine/server/server.hpp +3 -2
- package/src/engine/server/wire.cpp +5 -0
- package/src/engine/server/wire.hpp +2 -0
package/dist/cli/relay.mjs
CHANGED
|
@@ -64,7 +64,7 @@ var require_dist = __commonJS({
|
|
|
64
64
|
});
|
|
65
65
|
module.exports = __toCommonJS(src_exports);
|
|
66
66
|
var import_promises4 = __require("node:fs/promises");
|
|
67
|
-
var
|
|
67
|
+
var import_node_fs13 = __require("node:fs");
|
|
68
68
|
var DEVIN_LOCAL_PATH = "/opt/.devin";
|
|
69
69
|
var CURSOR = "cursor";
|
|
70
70
|
var CURSOR_CLI = "cursor-cli";
|
|
@@ -155,7 +155,7 @@ var require_dist = __commonJS({
|
|
|
155
155
|
return { isAgent: true, agent: { name: GITHUB_COPILOT } };
|
|
156
156
|
}
|
|
157
157
|
try {
|
|
158
|
-
await (0, import_promises4.access)(DEVIN_LOCAL_PATH,
|
|
158
|
+
await (0, import_promises4.access)(DEVIN_LOCAL_PATH, import_node_fs13.constants.F_OK);
|
|
159
159
|
return { isAgent: true, agent: { name: DEVIN } };
|
|
160
160
|
} catch (_error) {
|
|
161
161
|
}
|
|
@@ -7499,10 +7499,17 @@ import { readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "
|
|
|
7499
7499
|
import { resolve as resolve2 } from "node:path";
|
|
7500
7500
|
|
|
7501
7501
|
// src/sdk/index.ts
|
|
7502
|
-
import { readFileSync } from "node:fs";
|
|
7503
7502
|
import { request as httpRequest } from "node:http";
|
|
7504
7503
|
import { request as httpsRequest } from "node:https";
|
|
7505
7504
|
|
|
7505
|
+
// src/sdk/transport.ts
|
|
7506
|
+
import { X509Certificate } from "node:crypto";
|
|
7507
|
+
import { readFileSync } from "node:fs";
|
|
7508
|
+
import { Agent as HttpAgent } from "node:http";
|
|
7509
|
+
import { Agent as HttpsAgent } from "node:https";
|
|
7510
|
+
import { isIP } from "node:net";
|
|
7511
|
+
import { checkServerIdentity } from "node:tls";
|
|
7512
|
+
|
|
7506
7513
|
// src/protocol/errors.ts
|
|
7507
7514
|
var ERROR_REASONS = {
|
|
7508
7515
|
invalid_input: { class: "usage", code: "INVALID_ARGUMENT", exitCode: 2 },
|
|
@@ -7795,9 +7802,123 @@ function baseUrl(url, token) {
|
|
|
7795
7802
|
return parsed;
|
|
7796
7803
|
}
|
|
7797
7804
|
|
|
7805
|
+
// src/sdk/transport.ts
|
|
7806
|
+
var PEM_CERTIFICATE = /-----BEGIN CERTIFICATE-----[\s\S]*?-----END CERTIFICATE-----/;
|
|
7807
|
+
function readCertificates(path2) {
|
|
7808
|
+
try {
|
|
7809
|
+
return readFileSync(path2);
|
|
7810
|
+
} catch (error) {
|
|
7811
|
+
throw new RelayError("io_error", `Cannot read certificate ${path2}: ${error instanceof Error ? error.message : String(error)}`);
|
|
7812
|
+
}
|
|
7813
|
+
}
|
|
7814
|
+
function leafCertificate(pem, path2) {
|
|
7815
|
+
const block2 = PEM_CERTIFICATE.exec(pem.toString())?.[0];
|
|
7816
|
+
if (!block2) throw new RelayError("io_error", `Cannot read certificate ${path2}: the file contains no certificate`);
|
|
7817
|
+
try {
|
|
7818
|
+
const certificate = new X509Certificate(block2);
|
|
7819
|
+
return {
|
|
7820
|
+
der: certificate.raw,
|
|
7821
|
+
validFrom: Date.parse(certificate.validFrom),
|
|
7822
|
+
validTo: Date.parse(certificate.validTo)
|
|
7823
|
+
};
|
|
7824
|
+
} catch (error) {
|
|
7825
|
+
throw new RelayError("io_error", `Cannot read certificate ${path2}: ${error instanceof Error ? error.message : String(error)}`);
|
|
7826
|
+
}
|
|
7827
|
+
}
|
|
7828
|
+
function trust(target2) {
|
|
7829
|
+
if (target2.certificate) {
|
|
7830
|
+
return { kind: "certificate", certificate: leafCertificate(readCertificates(target2.certificate), target2.certificate) };
|
|
7831
|
+
}
|
|
7832
|
+
if (target2.ca) return { kind: "authority", bundle: readCertificates(target2.ca) };
|
|
7833
|
+
return { kind: "system" };
|
|
7834
|
+
}
|
|
7835
|
+
function verifyPin(pin, peer) {
|
|
7836
|
+
if (!peer.raw || !peer.raw.equals(pin.der)) return new Error("The server certificate does not match the pinned certificate.");
|
|
7837
|
+
const now = Date.now();
|
|
7838
|
+
if (!Number.isFinite(pin.validFrom) || !Number.isFinite(pin.validTo) || now < pin.validFrom || now > pin.validTo) {
|
|
7839
|
+
return new Error("The pinned certificate is not valid.");
|
|
7840
|
+
}
|
|
7841
|
+
return void 0;
|
|
7842
|
+
}
|
|
7843
|
+
var PinnedAgent = class extends HttpsAgent {
|
|
7844
|
+
constructor(pin, options, timeout2, signal) {
|
|
7845
|
+
super(options);
|
|
7846
|
+
this.timeout = timeout2;
|
|
7847
|
+
this.signal = signal;
|
|
7848
|
+
this.pin = pin;
|
|
7849
|
+
}
|
|
7850
|
+
timeout;
|
|
7851
|
+
signal;
|
|
7852
|
+
pin;
|
|
7853
|
+
createConnection(options, callback) {
|
|
7854
|
+
const socket = super.createConnection({ ...options, rejectUnauthorized: false });
|
|
7855
|
+
if (!socket || !callback) return socket;
|
|
7856
|
+
let state = "handshaking";
|
|
7857
|
+
const finish2 = (error) => {
|
|
7858
|
+
if (state !== "handshaking") return;
|
|
7859
|
+
state = error ? "failed" : "verified";
|
|
7860
|
+
clearTimeout(timer);
|
|
7861
|
+
socket.removeListener("error", fail);
|
|
7862
|
+
socket.removeListener("close", close);
|
|
7863
|
+
socket.removeListener("secureConnect", verify);
|
|
7864
|
+
this.signal?.removeEventListener("abort", abort);
|
|
7865
|
+
if (error) socket.destroy();
|
|
7866
|
+
callback(error, socket);
|
|
7867
|
+
};
|
|
7868
|
+
const fail = (error) => finish2(error);
|
|
7869
|
+
const close = () => finish2(new RelayError("unreachable", "The connection was closed."));
|
|
7870
|
+
const abort = () => finish2(new RelayError("canceled", "Request canceled."));
|
|
7871
|
+
const verify = () => finish2(verifyPin(this.pin, socket.getPeerCertificate()) ?? null);
|
|
7872
|
+
const timer = setTimeout(() => finish2(new RelayError("timeout", "The request timed out.")), this.timeout);
|
|
7873
|
+
socket.once("error", fail);
|
|
7874
|
+
socket.once("close", close);
|
|
7875
|
+
socket.once("secureConnect", verify);
|
|
7876
|
+
this.signal?.addEventListener("abort", abort, { once: true });
|
|
7877
|
+
if (this.signal?.aborted) abort();
|
|
7878
|
+
return void 0;
|
|
7879
|
+
}
|
|
7880
|
+
};
|
|
7881
|
+
function route(target2) {
|
|
7882
|
+
const identity2 = target2.url.hostname.replace(/^\[|\]$/g, "");
|
|
7883
|
+
return { dial: target2.connect ?? identity2, identity: identity2, ...isIP(identity2) ? {} : { servername: identity2 } };
|
|
7884
|
+
}
|
|
7885
|
+
function httpsAgent(where, trust2, timeout2, signal) {
|
|
7886
|
+
const servername = where.servername ? { servername: where.servername } : {};
|
|
7887
|
+
if (trust2.kind === "certificate") {
|
|
7888
|
+
return new PinnedAgent(trust2.certificate, { keepAlive: true, rejectUnauthorized: false, ...servername }, timeout2, signal);
|
|
7889
|
+
}
|
|
7890
|
+
const verify = (_dialed, certificate) => checkServerIdentity(where.identity, certificate);
|
|
7891
|
+
return new HttpsAgent({
|
|
7892
|
+
keepAlive: true,
|
|
7893
|
+
...servername,
|
|
7894
|
+
checkServerIdentity: verify,
|
|
7895
|
+
...trust2.kind === "authority" ? { ca: trust2.bundle } : {}
|
|
7896
|
+
});
|
|
7897
|
+
}
|
|
7898
|
+
function plan(target2) {
|
|
7899
|
+
if (!target2.ca && !target2.certificate && !target2.connect) return { kind: "fetch" };
|
|
7900
|
+
const where = route(target2);
|
|
7901
|
+
if (target2.url.protocol !== "https:") return { kind: "node", dial: where.dial, agent: new HttpAgent({ keepAlive: true }) };
|
|
7902
|
+
return { kind: "node", dial: where.dial, agent: httpsAgent(where, trust(target2), target2.timeout, target2.signal) };
|
|
7903
|
+
}
|
|
7904
|
+
|
|
7798
7905
|
// src/sdk/index.ts
|
|
7799
|
-
function target({ url = "http://127.0.0.1:8080", timeout: timeout2 = 1e4, token, ca, connect, signal }) {
|
|
7800
|
-
|
|
7906
|
+
function target({ url = "http://127.0.0.1:8080", timeout: timeout2 = 1e4, token, ca, certificate, connect, signal }) {
|
|
7907
|
+
if (ca && certificate) throw new RelayError("invalid_option", "Pass ca or certificate, not both.");
|
|
7908
|
+
return {
|
|
7909
|
+
base: baseUrl(url, token),
|
|
7910
|
+
timeout: integer(timeout2, 1, 2147483647, "timeout"),
|
|
7911
|
+
token,
|
|
7912
|
+
ca,
|
|
7913
|
+
certificate,
|
|
7914
|
+
connect,
|
|
7915
|
+
signal,
|
|
7916
|
+
transport: void 0
|
|
7917
|
+
};
|
|
7918
|
+
}
|
|
7919
|
+
function transportPlan(server) {
|
|
7920
|
+
server.transport ??= plan({ url: server.base, ca: server.ca, certificate: server.certificate, connect: server.connect, timeout: server.timeout, signal: server.signal });
|
|
7921
|
+
return server.transport;
|
|
7801
7922
|
}
|
|
7802
7923
|
function headers(server, body) {
|
|
7803
7924
|
const result = server.token ? { Authorization: `Bearer ${server.token}` } : {};
|
|
@@ -7812,34 +7933,22 @@ function decode(data, binary) {
|
|
|
7812
7933
|
throw new RelayError("protocol_error", "Invalid JSON response");
|
|
7813
7934
|
}
|
|
7814
7935
|
}
|
|
7815
|
-
function nodeRequest(server, path2, binary, body) {
|
|
7936
|
+
function nodeRequest(server, where, path2, binary, body) {
|
|
7816
7937
|
const base = server.base;
|
|
7817
|
-
let ca;
|
|
7818
|
-
if (server.ca) {
|
|
7819
|
-
try {
|
|
7820
|
-
ca = readFileSync(server.ca);
|
|
7821
|
-
} catch (error) {
|
|
7822
|
-
return Promise.reject(new RelayError("io_error", `Cannot read certificate ${server.ca}: ${error instanceof Error ? error.message : String(error)}`));
|
|
7823
|
-
}
|
|
7824
|
-
}
|
|
7825
|
-
const hostname = server.connect ?? base.hostname.replace(/^\[|\]$/g, "");
|
|
7826
7938
|
const requestHeaders = headers(server, body);
|
|
7827
7939
|
if (body !== void 0) requestHeaders["Content-Length"] = String(body.length);
|
|
7828
7940
|
if (server.connect) requestHeaders.Host = base.host;
|
|
7829
7941
|
const options = {
|
|
7830
7942
|
protocol: base.protocol,
|
|
7831
|
-
hostname,
|
|
7943
|
+
hostname: where.dial,
|
|
7832
7944
|
port: Number(base.port || (base.protocol === "https:" ? 443 : 80)),
|
|
7833
7945
|
path: `${base.pathname === "/" ? "" : base.pathname}${path2}`,
|
|
7834
7946
|
method: body === void 0 ? "GET" : "POST",
|
|
7835
7947
|
headers: requestHeaders,
|
|
7836
7948
|
timeout: server.timeout,
|
|
7837
|
-
signal: server.signal
|
|
7949
|
+
signal: server.signal,
|
|
7950
|
+
agent: where.agent
|
|
7838
7951
|
};
|
|
7839
|
-
if (ca) {
|
|
7840
|
-
options.ca = ca;
|
|
7841
|
-
options.checkServerIdentity = () => void 0;
|
|
7842
|
-
}
|
|
7843
7952
|
return new Promise((resolve6, reject) => {
|
|
7844
7953
|
const transport = base.protocol === "https:" ? httpsRequest : httpRequest;
|
|
7845
7954
|
const sent = transport(options, (response) => {
|
|
@@ -7888,7 +7997,8 @@ function nodeRequest(server, path2, binary, body) {
|
|
|
7888
7997
|
}
|
|
7889
7998
|
async function request(server, path2, binary = false, body) {
|
|
7890
7999
|
if (server.signal?.aborted) throw new RelayError("canceled", "Request canceled.");
|
|
7891
|
-
|
|
8000
|
+
const transport = transportPlan(server);
|
|
8001
|
+
if (transport.kind === "node") return nodeRequest(server, transport, path2, binary, body);
|
|
7892
8002
|
const controller = new AbortController();
|
|
7893
8003
|
let timer;
|
|
7894
8004
|
const deadline = new Promise((_, reject) => {
|
|
@@ -8027,7 +8137,7 @@ function createClient(options = {}) {
|
|
|
8027
8137
|
import { spawn, spawnSync } from "node:child_process";
|
|
8028
8138
|
import { accessSync, constants, statSync } from "node:fs";
|
|
8029
8139
|
import { homedir } from "node:os";
|
|
8030
|
-
import { delimiter, dirname, join } from "node:path";
|
|
8140
|
+
import { delimiter, dirname, extname, join } from "node:path";
|
|
8031
8141
|
import { fileURLToPath } from "node:url";
|
|
8032
8142
|
|
|
8033
8143
|
// src/cli/mode.ts
|
|
@@ -8251,7 +8361,7 @@ function printFailure(failure, jsonMode, args = {}) {
|
|
|
8251
8361
|
var DEFAULT_PORT = 8080;
|
|
8252
8362
|
var COMPONENTS = ["display", "dbus", "desktop", "engine", "apps"];
|
|
8253
8363
|
var LAUNCHER_DIR = dirname(fileURLToPath(import.meta.url));
|
|
8254
|
-
var VERSION = true ? "0.1.
|
|
8364
|
+
var VERSION = true ? "0.1.1" : "0.0.0";
|
|
8255
8365
|
function engineDirectory() {
|
|
8256
8366
|
return join(process.env.XDG_DATA_HOME || join(homedir(), ".local", "share"), "screen-relay", "engine", VERSION);
|
|
8257
8367
|
}
|
|
@@ -8259,16 +8369,16 @@ function isLinux() {
|
|
|
8259
8369
|
return process.platform.startsWith("linux");
|
|
8260
8370
|
}
|
|
8261
8371
|
function requireHost() {
|
|
8262
|
-
if (!isLinux() && process.platform !== "darwin") {
|
|
8372
|
+
if (!isLinux() && process.platform !== "darwin" && process.platform !== "win32") {
|
|
8263
8373
|
throw new Failure(
|
|
8264
8374
|
"unsupported_platform",
|
|
8265
|
-
"Host commands run on Linux or
|
|
8266
|
-
"Run this on the Linux or
|
|
8375
|
+
"Host commands run on Linux, macOS, or Windows only",
|
|
8376
|
+
"Run this on the Linux, macOS, or Windows machine; client commands (status, screenshot, click, ...) work anywhere with --url."
|
|
8267
8377
|
);
|
|
8268
8378
|
}
|
|
8269
8379
|
}
|
|
8270
8380
|
function which(program) {
|
|
8271
|
-
if (program.includes("/")) {
|
|
8381
|
+
if (program.includes("/") || process.platform === "win32" && program.includes("\\")) {
|
|
8272
8382
|
try {
|
|
8273
8383
|
if (statSync(program).isFile()) {
|
|
8274
8384
|
accessSync(program, constants.X_OK);
|
|
@@ -8278,20 +8388,24 @@ function which(program) {
|
|
|
8278
8388
|
}
|
|
8279
8389
|
return void 0;
|
|
8280
8390
|
}
|
|
8391
|
+
const names = process.platform === "win32" && !extname(program) ? [`${program}.exe`] : [program];
|
|
8281
8392
|
for (const directory of (process.env.PATH ?? "").split(delimiter)) {
|
|
8282
|
-
|
|
8283
|
-
|
|
8284
|
-
|
|
8285
|
-
|
|
8286
|
-
|
|
8393
|
+
if (process.platform === "win32" && !directory) continue;
|
|
8394
|
+
for (const name of names) {
|
|
8395
|
+
const candidate = join(directory || ".", name);
|
|
8396
|
+
try {
|
|
8397
|
+
if (statSync(candidate).isFile()) {
|
|
8398
|
+
accessSync(candidate, constants.X_OK);
|
|
8399
|
+
return candidate;
|
|
8400
|
+
}
|
|
8401
|
+
} catch {
|
|
8287
8402
|
}
|
|
8288
|
-
} catch {
|
|
8289
8403
|
}
|
|
8290
8404
|
}
|
|
8291
8405
|
return void 0;
|
|
8292
8406
|
}
|
|
8293
8407
|
function clearedCommand(command) {
|
|
8294
|
-
if (process.platform === "darwin") return command;
|
|
8408
|
+
if (process.platform === "darwin" || process.platform === "win32") return command;
|
|
8295
8409
|
return ["setpriv", "--inh-caps=-all", "--ambient-caps=-all", ...command];
|
|
8296
8410
|
}
|
|
8297
8411
|
function spawnCleared(command, options = {}) {
|
|
@@ -8305,8 +8419,8 @@ function run(command, options = {}) {
|
|
|
8305
8419
|
// src/cli/host/supervisor.ts
|
|
8306
8420
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
8307
8421
|
import { randomBytes } from "node:crypto";
|
|
8308
|
-
import { accessSync as accessSync2, closeSync as closeSync2, constants as constants2, existsSync, fchmodSync, mkdirSync, mkdtempSync, openSync as openSync2, readdirSync as readdirSync2, readFileSync as readFileSync4, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
8309
|
-
import { dirname as
|
|
8422
|
+
import { accessSync as accessSync2, closeSync as closeSync2, constants as constants2, existsSync as existsSync2, fchmodSync, mkdirSync, mkdtempSync, openSync as openSync2, readdirSync as readdirSync2, readFileSync as readFileSync4, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
8423
|
+
import { dirname as dirname3, join as join5, resolve } from "node:path";
|
|
8310
8424
|
|
|
8311
8425
|
// src/cli/config.ts
|
|
8312
8426
|
var import_yaml = __toESM(require_dist2(), 1);
|
|
@@ -8314,7 +8428,7 @@ import { readFileSync as readFileSync2, statSync as statSync2 } from "node:fs";
|
|
|
8314
8428
|
import { homedir as homedir2 } from "node:os";
|
|
8315
8429
|
import { join as join2 } from "node:path";
|
|
8316
8430
|
import { inspect, TextDecoder } from "node:util";
|
|
8317
|
-
var BACKENDS = ["x11", "wayland", "macos"];
|
|
8431
|
+
var BACKENDS = ["x11", "wayland", "macos", "windows"];
|
|
8318
8432
|
var COMPOSITORS = ["auto", "on", "off"];
|
|
8319
8433
|
var SECTIONS = {
|
|
8320
8434
|
display: ["resolution", "compositor"],
|
|
@@ -8637,26 +8751,174 @@ function applyTo(args, settings2, present) {
|
|
|
8637
8751
|
import { closeSync, fstatSync, linkSync, openSync, readFileSync as readFileSync3, readdirSync, readSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
8638
8752
|
import { execFileSync, spawn as spawn2 } from "node:child_process";
|
|
8639
8753
|
import { homedir as homedir3 } from "node:os";
|
|
8640
|
-
import { join as
|
|
8754
|
+
import { join as join4 } from "node:path";
|
|
8641
8755
|
import { setTimeout as delay } from "node:timers/promises";
|
|
8756
|
+
|
|
8757
|
+
// src/cli/host/windows.ts
|
|
8758
|
+
import { existsSync } from "node:fs";
|
|
8759
|
+
import { dirname as dirname2, join as join3 } from "node:path";
|
|
8760
|
+
var MSYS2_ROOT = "C:\\msys64";
|
|
8761
|
+
var MSYS2_SHELL = `${MSYS2_ROOT}\\usr\\bin\\bash.exe`;
|
|
8762
|
+
var MSYS2_LIBRARIES = `${MSYS2_ROOT}\\ucrt64\\bin`;
|
|
8763
|
+
var MSYS2_SEARCH = ["usr/local/bin", "usr/bin", "ucrt64/bin"];
|
|
8764
|
+
var MSYS2_PATH = MSYS2_SEARCH.map((directory) => `/${directory}`).join(":");
|
|
8765
|
+
var MSYS2_LOGIN_FILES = ["etc\\profile", "etc\\bash.bashrc"].map((file) => `${MSYS2_ROOT}\\${file}`);
|
|
8766
|
+
var MSYS2_CHECKED = [.../* @__PURE__ */ new Set([
|
|
8767
|
+
MSYS2_ROOT,
|
|
8768
|
+
`${MSYS2_ROOT}\\etc`,
|
|
8769
|
+
`${MSYS2_ROOT}\\etc\\profile.d`,
|
|
8770
|
+
MSYS2_SHELL,
|
|
8771
|
+
...MSYS2_LOGIN_FILES,
|
|
8772
|
+
...MSYS2_SEARCH.flatMap((directory) => directory.split("/").map((_, index, parts) => `${MSYS2_ROOT}\\${parts.slice(0, index + 1).join("\\")}`))
|
|
8773
|
+
])];
|
|
8774
|
+
var TRUSTED_SIDS = /* @__PURE__ */ new Set(["S-1-5-18", "S-1-5-32-544", "S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464"]);
|
|
8775
|
+
var REPLACE_RIGHTS = 2 | 64 | 65536 | 262144 | 524288 | 268435456 | 1073741824;
|
|
8776
|
+
var WRITE_RIGHTS = { file: REPLACE_RIGHTS | 4, directory: REPLACE_RIGHTS };
|
|
8777
|
+
var CREATOR_SIDS = /* @__PURE__ */ new Set(["S-1-3-0", "S-1-3-1", "S-1-3-4"]);
|
|
8778
|
+
var installation;
|
|
8779
|
+
function engineEnvironment(env = process.env) {
|
|
8780
|
+
if (process.platform !== "win32" || msys2Installation().state !== "trusted") return env;
|
|
8781
|
+
const key = Object.keys(env).find((name) => name.toUpperCase() === "PATH") ?? "PATH";
|
|
8782
|
+
return { ...env, [key]: [MSYS2_LIBRARIES, env[key]].filter(Boolean).join(";") };
|
|
8783
|
+
}
|
|
8784
|
+
function engineWorkingDirectory(engine) {
|
|
8785
|
+
return process.platform === "win32" ? dirname2(engine) : void 0;
|
|
8786
|
+
}
|
|
8787
|
+
function msys2Installation() {
|
|
8788
|
+
installation ??= detectMsys2();
|
|
8789
|
+
return installation;
|
|
8790
|
+
}
|
|
8791
|
+
function forgetMsys2Installation() {
|
|
8792
|
+
installation = void 0;
|
|
8793
|
+
}
|
|
8794
|
+
function msys2Shell() {
|
|
8795
|
+
const found = msys2Installation();
|
|
8796
|
+
if (found.state === "trusted") return found.shell;
|
|
8797
|
+
throw msys2Failure(found);
|
|
8798
|
+
}
|
|
8799
|
+
function msys2Failure(found) {
|
|
8800
|
+
if (found.state === "untrusted") return new Failure("missing_dependency", `MSYS2 at ${found.root} is not a trusted installation`, msys2Fix(found));
|
|
8801
|
+
return new Failure("missing_dependency", "MSYS2 is not installed", "Install MSYS2 from https://www.msys2.org, then run screen-relay install again.");
|
|
8802
|
+
}
|
|
8803
|
+
function msys2Fix(found) {
|
|
8804
|
+
const reinstall = `delete ${found.root} and run screen-relay install again`;
|
|
8805
|
+
if (!found.repair) return `${found.reason} To fix it, ${reinstall}.`;
|
|
8806
|
+
const command = found.repair.map((part, index) => index > 0 && /[()*]/.test(part) ? `"${part}"` : part).join(" ");
|
|
8807
|
+
return `${found.reason} If you installed MSYS2 there and only you use it, remove the rights it inherits from C:\\ with: ${command}. Otherwise ${reinstall}.`;
|
|
8808
|
+
}
|
|
8809
|
+
function repairMsys2() {
|
|
8810
|
+
const found = msys2Installation();
|
|
8811
|
+
if (found.state !== "untrusted" || !found.repair) return false;
|
|
8812
|
+
const [, ...args] = found.repair;
|
|
8813
|
+
const ok = run([systemTool("icacls.exe"), ...args], { timeout: 12e4 }).status === 0;
|
|
8814
|
+
forgetMsys2Installation();
|
|
8815
|
+
return ok;
|
|
8816
|
+
}
|
|
8817
|
+
function trustedAcl(probe) {
|
|
8818
|
+
const trusted = (sid) => Boolean(sid) && (sid === probe.current || TRUSTED_SIDS.has(sid));
|
|
8819
|
+
for (const object of probe.objects) {
|
|
8820
|
+
if (!trusted(object.owner)) return { trusted: false, reason: `${object.path} is owned by ${object.ownerName}.`, owned: false };
|
|
8821
|
+
for (const rule of object.rules) {
|
|
8822
|
+
if (!(rule.rights & WRITE_RIGHTS[object.kind]) || trusted(rule.sid) || CREATOR_SIDS.has(rule.sid)) continue;
|
|
8823
|
+
return { trusted: false, reason: `${object.path} lets ${rule.name} write to it.`, owned: true };
|
|
8824
|
+
}
|
|
8825
|
+
}
|
|
8826
|
+
return { trusted: true };
|
|
8827
|
+
}
|
|
8828
|
+
function detectMsys2() {
|
|
8829
|
+
if (!existsSync(MSYS2_SHELL)) return { state: "missing", root: MSYS2_ROOT };
|
|
8830
|
+
const probe = aclProbe();
|
|
8831
|
+
if (!probe) return { state: "untrusted", root: MSYS2_ROOT, reason: `screen-relay could not read who owns ${MSYS2_ROOT}.` };
|
|
8832
|
+
const verdict = trustedAcl(probe);
|
|
8833
|
+
if (verdict.trusted) return { state: "trusted", root: MSYS2_ROOT, shell: MSYS2_SHELL };
|
|
8834
|
+
return { state: "untrusted", root: MSYS2_ROOT, reason: verdict.reason, repair: msys2Repair(verdict.owned, probe.current) };
|
|
8835
|
+
}
|
|
8836
|
+
function msys2Repair(owned, account) {
|
|
8837
|
+
return owned && /^S-\d+(-\d+)+$/.test(account) ? repairCommand(account) : void 0;
|
|
8838
|
+
}
|
|
8839
|
+
function repairCommand(account) {
|
|
8840
|
+
return ["icacls", MSYS2_ROOT, "/inheritance:r", "/grant:r", "*S-1-5-18:(OI)(CI)F", "*S-1-5-32-544:(OI)(CI)F", `*${account}:(OI)(CI)F`, "*S-1-5-32-545:(OI)(CI)RX"];
|
|
8841
|
+
}
|
|
8842
|
+
function aclProbe() {
|
|
8843
|
+
const script = [
|
|
8844
|
+
"$ErrorActionPreference = 'Stop'",
|
|
8845
|
+
"[Console]::OutputEncoding = [System.Text.Encoding]::UTF8",
|
|
8846
|
+
`$paths = @(${MSYS2_CHECKED.map((path2) => `'${path2}'`).join(", ")})`,
|
|
8847
|
+
"$objects = @(foreach ($path in $paths) {",
|
|
8848
|
+
" if (-not (Test-Path -LiteralPath $path)) { continue }",
|
|
8849
|
+
" $isDirectory = Test-Path -LiteralPath $path -PathType Container",
|
|
8850
|
+
" $acl = if ($isDirectory) { [System.IO.Directory]::GetAccessControl($path) } else { [System.IO.File]::GetAccessControl($path) }",
|
|
8851
|
+
" $owner = $acl.GetOwner([System.Security.Principal.SecurityIdentifier])",
|
|
8852
|
+
" $ownerName = try { $owner.Translate([System.Security.Principal.NTAccount]).Value } catch { $owner.Value }",
|
|
8853
|
+
" $rules = @($acl.Access | Where-Object { $_.AccessControlType -eq [System.Security.AccessControl.AccessControlType]::Allow } | ForEach-Object {",
|
|
8854
|
+
" $sid = if ($_.IdentityReference -is [System.Security.Principal.SecurityIdentifier]) { $_.IdentityReference } else { $_.IdentityReference.Translate([System.Security.Principal.SecurityIdentifier]) }",
|
|
8855
|
+
" $name = try { $sid.Translate([System.Security.Principal.NTAccount]).Value } catch { $sid.Value }",
|
|
8856
|
+
" [pscustomobject]@{ sid = $sid.Value; name = $name; rights = [int]$_.FileSystemRights }",
|
|
8857
|
+
" })",
|
|
8858
|
+
" [pscustomobject]@{ path = $path; directory = $isDirectory; owner = $owner.Value; ownerName = $ownerName; rules = $rules }",
|
|
8859
|
+
"})",
|
|
8860
|
+
"$current = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value",
|
|
8861
|
+
"[pscustomobject]@{ current = $current; objects = $objects } | ConvertTo-Json -Depth 5 -Compress"
|
|
8862
|
+
].join("\n");
|
|
8863
|
+
const result = run([systemTool("WindowsPowerShell", "v1.0", "powershell.exe"), "-NoProfile", "-NonInteractive", "-Command", script], { timeout: 2e4 });
|
|
8864
|
+
if (result.status !== 0 || !result.stdout) return null;
|
|
8865
|
+
try {
|
|
8866
|
+
const decoded = JSON.parse(result.stdout.replace(/^\uFEFF/, "").trim());
|
|
8867
|
+
const objects = (Array.isArray(decoded.objects) ? decoded.objects : decoded.objects ? [decoded.objects] : []).map((object) => ({
|
|
8868
|
+
path: String(object.path ?? ""),
|
|
8869
|
+
kind: object.directory === true ? "directory" : "file",
|
|
8870
|
+
owner: String(object.owner ?? ""),
|
|
8871
|
+
ownerName: String(object.ownerName ?? object.owner ?? ""),
|
|
8872
|
+
rules: (Array.isArray(object.rules) ? object.rules : object.rules ? [object.rules] : []).map((rule) => ({
|
|
8873
|
+
sid: String(rule.sid ?? ""),
|
|
8874
|
+
name: String(rule.name ?? rule.sid ?? ""),
|
|
8875
|
+
rights: Number(rule.rights ?? 0)
|
|
8876
|
+
}))
|
|
8877
|
+
}));
|
|
8878
|
+
return { current: String(decoded.current ?? ""), objects };
|
|
8879
|
+
} catch {
|
|
8880
|
+
return null;
|
|
8881
|
+
}
|
|
8882
|
+
}
|
|
8883
|
+
function systemTool(...parts) {
|
|
8884
|
+
return join3(process.env.SystemRoot || "C:\\Windows", "System32", ...parts);
|
|
8885
|
+
}
|
|
8886
|
+
function wingetPath() {
|
|
8887
|
+
return process.env.LOCALAPPDATA ? join3(process.env.LOCALAPPDATA, "Microsoft", "WindowsApps", "winget.exe") : null;
|
|
8888
|
+
}
|
|
8889
|
+
function windowsSessionId() {
|
|
8890
|
+
const result = run([systemTool("WindowsPowerShell", "v1.0", "powershell.exe"), "-NoProfile", "-NonInteractive", "-Command", "[System.Diagnostics.Process]::GetCurrentProcess().SessionId"], { timeout: 15e3 });
|
|
8891
|
+
const text = result.stdout?.trim() ?? "";
|
|
8892
|
+
return result.status === 0 && /^\d+$/.test(text) ? Number(text) : null;
|
|
8893
|
+
}
|
|
8894
|
+
function windowsStartTime(pid) {
|
|
8895
|
+
const result = run([systemTool("WindowsPowerShell", "v1.0", "powershell.exe"), "-NoProfile", "-NonInteractive", "-Command", `(Get-Process -Id ${pid}).StartTime.ToFileTimeUtc()`], { timeout: 15e3 });
|
|
8896
|
+
const text = result.stdout?.trim() ?? "";
|
|
8897
|
+
return result.status === 0 && /^\d+$/.test(text) ? text : null;
|
|
8898
|
+
}
|
|
8899
|
+
function killTree(pid) {
|
|
8900
|
+
run([systemTool("taskkill.exe"), "/PID", String(pid), "/T", "/F"], { timeout: 1e4 });
|
|
8901
|
+
}
|
|
8902
|
+
|
|
8903
|
+
// src/cli/host/state.ts
|
|
8642
8904
|
function stateDir(name) {
|
|
8643
8905
|
if (!/^[A-Za-z0-9_-][A-Za-z0-9_.-]{0,63}$/.test(name)) {
|
|
8644
8906
|
throw new Failure("invalid_input", `Invalid session name "${name}"`, 'Use letters, digits, ".", "_" or "-".');
|
|
8645
8907
|
}
|
|
8646
|
-
return
|
|
8908
|
+
return join4(process.env.XDG_STATE_HOME || join4(homedir3(), ".local", "state"), "screen-relay", name);
|
|
8647
8909
|
}
|
|
8648
8910
|
function readSession(name) {
|
|
8649
8911
|
try {
|
|
8650
|
-
return JSON.parse(readFileSync3(
|
|
8912
|
+
return JSON.parse(readFileSync3(join4(stateDir(name), "session.json"), "utf8"));
|
|
8651
8913
|
} catch {
|
|
8652
8914
|
return null;
|
|
8653
8915
|
}
|
|
8654
8916
|
}
|
|
8655
8917
|
function writeSession(directory, data) {
|
|
8656
|
-
const temporary =
|
|
8918
|
+
const temporary = join4(directory, "session.json.tmp");
|
|
8657
8919
|
writeFileSync(temporary, `${JSON.stringify(data, null, 2)}
|
|
8658
8920
|
`);
|
|
8659
|
-
renameSync(temporary,
|
|
8921
|
+
renameSync(temporary, join4(directory, "session.json"));
|
|
8660
8922
|
}
|
|
8661
8923
|
function tail(path2, lines = 20) {
|
|
8662
8924
|
try {
|
|
@@ -8687,6 +8949,7 @@ function darwinStartTime(pid) {
|
|
|
8687
8949
|
}
|
|
8688
8950
|
}
|
|
8689
8951
|
function startTime(pid) {
|
|
8952
|
+
if (process.platform === "win32") return windowsStartTime(pid);
|
|
8690
8953
|
if (process.platform === "darwin") return darwinStartTime(pid);
|
|
8691
8954
|
try {
|
|
8692
8955
|
const stat = readFileSync3(`/proc/${pid}/stat`, "utf8");
|
|
@@ -8699,6 +8962,7 @@ function startTime(pid) {
|
|
|
8699
8962
|
function alive(record) {
|
|
8700
8963
|
if (!record || typeof record !== "object") return false;
|
|
8701
8964
|
const value = record;
|
|
8965
|
+
if (process.platform === "win32" && value.start === null) return false;
|
|
8702
8966
|
return typeof value.pid === "number" && value.start !== void 0 && startTime(value.pid) === value.start;
|
|
8703
8967
|
}
|
|
8704
8968
|
function identity(pid) {
|
|
@@ -8725,7 +8989,7 @@ function lockOwnerAlive(file) {
|
|
|
8725
8989
|
}
|
|
8726
8990
|
}
|
|
8727
8991
|
async function sweep(directory, signal) {
|
|
8728
|
-
if (process.platform === "darwin") return;
|
|
8992
|
+
if (process.platform === "darwin" || process.platform === "win32") return;
|
|
8729
8993
|
const marker = Buffer.from(`SCREEN_RELAY_SESSION=${directory}`);
|
|
8730
8994
|
for (const killSignal of ["SIGTERM", "SIGKILL"]) {
|
|
8731
8995
|
signal?.throwIfAborted();
|
|
@@ -8757,7 +9021,8 @@ async function reap(directory, session, signal) {
|
|
|
8757
9021
|
for (const record of Object.values(session?.components ?? {})) {
|
|
8758
9022
|
if (alive(record)) {
|
|
8759
9023
|
try {
|
|
8760
|
-
process.
|
|
9024
|
+
if (process.platform === "win32") killTree(record.pid);
|
|
9025
|
+
else process.kill(-Number(record.pid), "SIGKILL");
|
|
8761
9026
|
} catch {
|
|
8762
9027
|
}
|
|
8763
9028
|
}
|
|
@@ -8765,12 +9030,22 @@ async function reap(directory, session, signal) {
|
|
|
8765
9030
|
await sweep(directory, signal);
|
|
8766
9031
|
}
|
|
8767
9032
|
async function lock(name, directory) {
|
|
8768
|
-
const file =
|
|
9033
|
+
const file = join4(directory, "lock");
|
|
8769
9034
|
const busy = () => new Failure(
|
|
8770
9035
|
"already_running",
|
|
8771
9036
|
`Session "${name}" is already running`,
|
|
8772
9037
|
"Stop it with `screen-relay down --name " + name + "` or pick another --name."
|
|
8773
9038
|
);
|
|
9039
|
+
if (process.platform === "win32") {
|
|
9040
|
+
while (!claimLock(file)) {
|
|
9041
|
+
if (lockOwnerAlive(file)) throw busy();
|
|
9042
|
+
rmSync(file, { force: true });
|
|
9043
|
+
}
|
|
9044
|
+
return { close: () => {
|
|
9045
|
+
rmSync(file, { force: true });
|
|
9046
|
+
return Promise.resolve();
|
|
9047
|
+
} };
|
|
9048
|
+
}
|
|
8774
9049
|
const [command, args] = process.platform === "darwin" ? ["lockf", ["-k", "-s", "-t", "0", file, "sh", "-c", "printf .; cat"]] : ["flock", ["--exclusive", "--nonblock", "--conflict-exit-code", "75", file, "sh", "-c", "printf .; cat"]];
|
|
8775
9050
|
const child = spawn2(command, args, { detached: true, stdio: ["pipe", "pipe", "ignore"] });
|
|
8776
9051
|
const acquired = new Promise((resolve6, reject) => {
|
|
@@ -8804,7 +9079,8 @@ async function lock(name, directory) {
|
|
|
8804
9079
|
var BACKEND_PROGRAMS = {
|
|
8805
9080
|
x11: ["Xvfb", "xauth", "xprop", "xwininfo", "xdpyinfo", "setxkbmap"],
|
|
8806
9081
|
wayland: ["sway", "Xwayland", "swaymsg", "foot"],
|
|
8807
|
-
macos: []
|
|
9082
|
+
macos: [],
|
|
9083
|
+
windows: []
|
|
8808
9084
|
};
|
|
8809
9085
|
var HINTS = {
|
|
8810
9086
|
display: "Check Xvfb and /tmp/.X11-unix with `screen-relay doctor`.",
|
|
@@ -8913,13 +9189,14 @@ var Session = class {
|
|
|
8913
9189
|
writeSession(this.dir, this.data);
|
|
8914
9190
|
}
|
|
8915
9191
|
spawn(name, command, options = {}) {
|
|
8916
|
-
const log = openSync2(
|
|
9192
|
+
const log = openSync2(join5(this.dir, `${name}.log`), name === "apps" ? "a" : "w", 384);
|
|
8917
9193
|
this.logs.push(log);
|
|
8918
9194
|
let child;
|
|
8919
9195
|
try {
|
|
8920
9196
|
child = spawnCleared(command, {
|
|
8921
9197
|
env: this.env,
|
|
8922
9198
|
detached: true,
|
|
9199
|
+
windowsHide: true,
|
|
8923
9200
|
signal: this.args.signal,
|
|
8924
9201
|
...options,
|
|
8925
9202
|
stdio: ["ignore", log, log, ...(options.stdio ?? []).slice(3)]
|
|
@@ -8939,8 +9216,8 @@ var Session = class {
|
|
|
8939
9216
|
failure(name, code, message) {
|
|
8940
9217
|
const recovery = code === "component_failed" || code === "timeout" ? { next: nextFor(sessionCommand(`logs ${name}`, this.args.name)), label: "Read the logs" } : {};
|
|
8941
9218
|
const hint = name === "display" && this.data.backend === "wayland" ? "Read `screen-relay logs display`, then run `SCREEN_RELAY_BACKEND=wayland screen-relay doctor`." : HINTS[name] ?? "";
|
|
8942
|
-
const log = tail(
|
|
8943
|
-
const detail2 = name === "engine" && this.data.backend
|
|
9219
|
+
const log = tail(join5(this.dir, `${name}.log`));
|
|
9220
|
+
const detail2 = name === "engine" && attaches(this.data.backend) && code === "component_failed" ? log.trim().replace(/\r?\n/g, "; ") : "";
|
|
8944
9221
|
return new Failure(code, detail2 ? `${message}: ${detail2}` : message, hint, { component: name, log, logs: this.dir }, recovery);
|
|
8945
9222
|
}
|
|
8946
9223
|
checkChildren() {
|
|
@@ -8982,8 +9259,8 @@ var Session = class {
|
|
|
8982
9259
|
delete this.env.SWAYSOCK;
|
|
8983
9260
|
delete this.env.XAUTHORITY;
|
|
8984
9261
|
this.save({ backend: "wayland", runtimeDir: this.runtimeDir });
|
|
8985
|
-
const config =
|
|
8986
|
-
const displayFile =
|
|
9262
|
+
const config = join5(this.dir, "sway.conf");
|
|
9263
|
+
const displayFile = join5(this.dir, "wayland-display");
|
|
8987
9264
|
writeFileSync2(config, `output * mode --custom ${this.args.resolution}@${this.args.fps}Hz
|
|
8988
9265
|
xwayland force
|
|
8989
9266
|
`);
|
|
@@ -9002,7 +9279,7 @@ xwayland force
|
|
|
9002
9279
|
const sockets = readdirSync2(this.runtimeDir, { withFileTypes: true }).filter((entry) => entry.isSocket()).map((entry) => entry.name);
|
|
9003
9280
|
this.env.WAYLAND_DISPLAY = sockets.find((name) => /^wayland-\d+$/.test(name));
|
|
9004
9281
|
const swaySocket = sockets.find((name) => /^sway-ipc\.\d+\.\d+\.sock$/.test(name));
|
|
9005
|
-
if (swaySocket) this.env.SWAYSOCK =
|
|
9282
|
+
if (swaySocket) this.env.SWAYSOCK = join5(this.runtimeDir, swaySocket);
|
|
9006
9283
|
if (this.env.WAYLAND_DISPLAY && this.env.SWAYSOCK) break;
|
|
9007
9284
|
if (Date.now() > deadline) throw this.failure("display", "timeout", "Sway did not report a Wayland display");
|
|
9008
9285
|
await sleep(200);
|
|
@@ -9019,13 +9296,13 @@ xwayland force
|
|
|
9019
9296
|
}
|
|
9020
9297
|
async start() {
|
|
9021
9298
|
this.args.signal?.throwIfAborted();
|
|
9022
|
-
const runtime =
|
|
9299
|
+
const runtime = join5(this.dir, "runtime");
|
|
9023
9300
|
rmSync2(runtime, { recursive: true, force: true });
|
|
9024
9301
|
mkdirSync(runtime, { mode: 448 });
|
|
9025
9302
|
const backend = resolveBackend(this.args.backend, this.args.display);
|
|
9026
|
-
const attached = backend
|
|
9027
|
-
this.env = attached ? { ...process.env, SCREEN_RELAY_SESSION: this.dir } : desktopEnv(this.dir);
|
|
9028
|
-
if (backend
|
|
9303
|
+
const attached = attaches(backend) || Boolean(this.args.display);
|
|
9304
|
+
this.env = attached ? engineEnvironment({ ...process.env, SCREEN_RELAY_SESSION: this.dir }) : desktopEnv(this.dir);
|
|
9305
|
+
if (attaches(backend)) {
|
|
9029
9306
|
delete this.env.DISPLAY;
|
|
9030
9307
|
delete this.env.WAYLAND_DISPLAY;
|
|
9031
9308
|
delete this.env.XAUTHORITY;
|
|
@@ -9044,7 +9321,7 @@ xwayland force
|
|
|
9044
9321
|
if (desktopCommand.length && !this.args.display && !ownBus && which("dbus-run-session")) desktopCommand = ["dbus-run-session", "--", ...desktopCommand];
|
|
9045
9322
|
if (missing2.length) throw new Failure("missing_dependency", `Missing ${missing2.join(", ")}`, `Run \`${installCommand(backend)}\`, or check with \`${backend === "wayland" ? "SCREEN_RELAY_BACKEND=wayland " : ""}screen-relay doctor\`.`);
|
|
9046
9323
|
let resolution2;
|
|
9047
|
-
if (backend
|
|
9324
|
+
if (attaches(backend)) {
|
|
9048
9325
|
resolution2 = null;
|
|
9049
9326
|
} else if (backend === "wayland") {
|
|
9050
9327
|
resolution2 = await this.startWaylandDisplay(layout);
|
|
@@ -9052,7 +9329,7 @@ xwayland force
|
|
|
9052
9329
|
this.env.DISPLAY = this.args.display;
|
|
9053
9330
|
resolution2 = displaySize(this.env);
|
|
9054
9331
|
} else {
|
|
9055
|
-
const auth =
|
|
9332
|
+
const auth = join5(this.dir, "Xauthority");
|
|
9056
9333
|
writeFileSync2(auth, "");
|
|
9057
9334
|
const fd = openSync2(auth, "r+");
|
|
9058
9335
|
fchmodSync(fd, 384);
|
|
@@ -9083,12 +9360,12 @@ xwayland force
|
|
|
9083
9360
|
let token = null;
|
|
9084
9361
|
const engineCommand = [engine, "--bind", bind, "--port", String(this.args.port), "--fps", String(this.args.fps), "--bitrate-min", String(this.args.bitrateMin), "--bitrate-start", String(this.args.bitrateStart), "--bitrate-max", String(this.args.bitrateMax)];
|
|
9085
9362
|
engineCommand.push("--backend", backend);
|
|
9086
|
-
const viewer =
|
|
9087
|
-
if (!
|
|
9363
|
+
const viewer = join5(LAUNCHER_DIR, "..", "viewer");
|
|
9364
|
+
if (!existsSync2(join5(dirname3(engine), "viewer")) && existsSync2(join5(viewer, "viewer.js"))) engineCommand.push("--viewer-dir", viewer);
|
|
9088
9365
|
if (this.args.output) engineCommand.push("--output", this.args.output);
|
|
9089
|
-
if (bind !== "127.0.0.1" || this.args.public || backend
|
|
9366
|
+
if (bind !== "127.0.0.1" || this.args.public || attaches(backend)) {
|
|
9090
9367
|
token = randomBytes(32).toString("hex");
|
|
9091
|
-
const tokenFile =
|
|
9368
|
+
const tokenFile = join5(this.dir, "token");
|
|
9092
9369
|
const descriptor = openSync2(tokenFile, "w", 384);
|
|
9093
9370
|
fchmodSync(descriptor, 384);
|
|
9094
9371
|
writeFileSync2(descriptor, `${token}
|
|
@@ -9098,14 +9375,16 @@ xwayland force
|
|
|
9098
9375
|
this.data.tokenFile = tokenFile;
|
|
9099
9376
|
}
|
|
9100
9377
|
if (this.args.public) engineCommand.push("--public-origin", this.args.public);
|
|
9101
|
-
if (this.args["tls-cert"])
|
|
9102
|
-
|
|
9378
|
+
if (this.args["tls-cert"]) {
|
|
9379
|
+
const absolute = (file) => process.platform === "win32" && file ? resolve(file) : file;
|
|
9380
|
+
engineCommand.push("--tls-cert", absolute(this.args["tls-cert"]), "--tls-key", absolute(this.args["tls-key"] ?? ""));
|
|
9381
|
+
} else if (this.args.public) engineCommand.push("--behind-tls-proxy");
|
|
9103
9382
|
const scheme = this.args["tls-cert"] ? "https" : "http";
|
|
9104
9383
|
const localUrl = `${scheme}://127.0.0.1:${this.args.port}`;
|
|
9105
9384
|
this.save({ bind, localUrl, url: this.args.public || localUrl, tlsCert: this.args["tls-cert"] ? resolve(String(this.args["tls-cert"])) : null });
|
|
9106
|
-
const engineChild = this.spawn("engine", engineCommand);
|
|
9385
|
+
const engineChild = this.spawn("engine", engineCommand, { cwd: engineWorkingDirectory(engine) });
|
|
9107
9386
|
await waitSpawn(engineChild);
|
|
9108
|
-
await this.waitReady(engineChild.pid, { url: localUrl, token,
|
|
9387
|
+
await this.waitReady(engineChild.pid, { url: localUrl, token, certificate: this.data.tlsCert, connect: connectHost(bind) }, desktop);
|
|
9109
9388
|
this.save({ state: "ready", ready: Date.now() / 1e3 });
|
|
9110
9389
|
const url = this.data.url;
|
|
9111
9390
|
return {
|
|
@@ -9128,7 +9407,7 @@ xwayland force
|
|
|
9128
9407
|
};
|
|
9129
9408
|
}
|
|
9130
9409
|
async engineReady(pid, where) {
|
|
9131
|
-
for (const line of tail(
|
|
9410
|
+
for (const line of tail(join5(this.dir, "engine.log"), 50).split(/\r?\n/)) {
|
|
9132
9411
|
if (!line.startsWith("{")) continue;
|
|
9133
9412
|
try {
|
|
9134
9413
|
const message = JSON.parse(line);
|
|
@@ -9136,13 +9415,13 @@ xwayland force
|
|
|
9136
9415
|
const image = Buffer.from(await createClient({
|
|
9137
9416
|
url: where.url,
|
|
9138
9417
|
token: where.token ?? void 0,
|
|
9139
|
-
|
|
9418
|
+
certificate: where.certificate ?? void 0,
|
|
9140
9419
|
connect: where.connect ?? void 0,
|
|
9141
9420
|
timeout: 3e3,
|
|
9142
9421
|
signal: this.args.signal
|
|
9143
9422
|
}).screenshot());
|
|
9144
9423
|
if (!image.subarray(0, 8).equals(PNG)) return false;
|
|
9145
|
-
if (this.args.display || this.data.backend
|
|
9424
|
+
if (this.args.display || attaches(this.data.backend)) {
|
|
9146
9425
|
if (image.length < 24) return false;
|
|
9147
9426
|
this.save({ resolution: `${image.readUInt32BE(16)}x${image.readUInt32BE(20)}` });
|
|
9148
9427
|
}
|
|
@@ -9225,10 +9504,10 @@ xwayland force
|
|
|
9225
9504
|
function desktopEnv(directory) {
|
|
9226
9505
|
const env = {
|
|
9227
9506
|
...process.env,
|
|
9228
|
-
XDG_RUNTIME_DIR:
|
|
9229
|
-
XDG_CONFIG_HOME:
|
|
9230
|
-
XDG_CACHE_HOME:
|
|
9231
|
-
ICEAUTHORITY:
|
|
9507
|
+
XDG_RUNTIME_DIR: join5(directory, "runtime"),
|
|
9508
|
+
XDG_CONFIG_HOME: join5(directory, "config"),
|
|
9509
|
+
XDG_CACHE_HOME: join5(directory, "cache"),
|
|
9510
|
+
ICEAUTHORITY: join5(directory, "ICEauthority"),
|
|
9232
9511
|
SCREEN_RELAY_SESSION: directory
|
|
9233
9512
|
};
|
|
9234
9513
|
delete env.DBUS_SESSION_BUS_ADDRESS;
|
|
@@ -9239,8 +9518,8 @@ function compositing(setting, fps) {
|
|
|
9239
9518
|
}
|
|
9240
9519
|
function writeCompositing(configHome, enabled) {
|
|
9241
9520
|
if (!configHome) return;
|
|
9242
|
-
const dir =
|
|
9243
|
-
const file =
|
|
9521
|
+
const dir = join5(configHome, "xfce4", "xfconf", "xfce-perchannel-xml");
|
|
9522
|
+
const file = join5(dir, "xfwm4.xml");
|
|
9244
9523
|
const wanted = `<property name="use_compositing" type="bool" value="${enabled}"/>`;
|
|
9245
9524
|
const general = ` <property name="general" type="empty">
|
|
9246
9525
|
${wanted}
|
|
@@ -9262,39 +9541,44 @@ ${general}</channel>
|
|
|
9262
9541
|
writeFileSync2(file, next);
|
|
9263
9542
|
}
|
|
9264
9543
|
function findEngine() {
|
|
9265
|
-
|
|
9544
|
+
const name = process.platform === "win32" ? "relay-engine.exe" : "relay-engine";
|
|
9545
|
+
for (const candidate of [join5(LAUNCHER_DIR, name), join5(LAUNCHER_DIR, "..", name), join5(engineDirectory(), name)]) {
|
|
9266
9546
|
try {
|
|
9267
9547
|
accessSync2(candidate, constants2.X_OK);
|
|
9268
9548
|
return candidate;
|
|
9269
9549
|
} catch {
|
|
9270
9550
|
}
|
|
9271
9551
|
}
|
|
9272
|
-
return which(
|
|
9552
|
+
return which(name) ?? null;
|
|
9553
|
+
}
|
|
9554
|
+
function attaches(backend) {
|
|
9555
|
+
return backend === "macos" || backend === "windows";
|
|
9273
9556
|
}
|
|
9274
9557
|
function compiledBackends(engine = findEngine()) {
|
|
9275
|
-
const compiled = engine ? /^Compiled backends: (.+)$/m.exec(run([engine, "--help"]).stdout ?? "")?.[1] : void 0;
|
|
9558
|
+
const compiled = engine ? /^Compiled backends: (.+)$/m.exec(run([engine, "--help"], { env: engineEnvironment(), cwd: engineWorkingDirectory(engine) }).stdout ?? "")?.[1] : void 0;
|
|
9276
9559
|
return compiled ? compiled.split(", ") : [];
|
|
9277
9560
|
}
|
|
9278
9561
|
function installCommand(backend) {
|
|
9279
9562
|
return `screen-relay install${backend === "wayland" ? " --backend wayland" : ""}`;
|
|
9280
9563
|
}
|
|
9281
9564
|
function sessionNeeds(backend, args) {
|
|
9282
|
-
const desktop = backend
|
|
9565
|
+
const desktop = attaches(backend) ? "none" : args.desktop || (args.display ? "none" : backend === "wayland" ? "foot" : "xfce");
|
|
9283
9566
|
const desktopCommand = desktop === "xfce" ? ["xfce4-session"] : desktop === "none" ? [] : splitCommand(desktop);
|
|
9284
9567
|
const layout = args.keyboardLayout ?? "us";
|
|
9285
|
-
const needed = backend
|
|
9568
|
+
const needed = attaches(backend) ? [] : backend === "wayland" ? ["setpriv", ...args.display ? [] : BACKEND_PROGRAMS.wayland.filter((program) => program !== "foot"), ...desktopCommand.length ? [desktopCommand[0]] : []] : ["setpriv", ...args.display ? [] : ["Xvfb", "xauth"], ...desktopCommand.length ? ["xprop", "xwininfo", desktopCommand[0]] : [], ...!args.display && layout !== "us" ? ["setxkbmap"] : []];
|
|
9286
9569
|
const missing2 = needed.filter((program) => !which(program));
|
|
9287
9570
|
const ownBus = Boolean(desktopCommand.length && !args.display && which("dbus-daemon"));
|
|
9288
9571
|
if (desktop === "xfce" && !args.display && !ownBus && !which("dbus-run-session")) missing2.push("dbus-run-session");
|
|
9289
9572
|
return { desktop, desktopCommand, layout, missing: missing2, ownBus };
|
|
9290
9573
|
}
|
|
9291
9574
|
function requestedBackend(explicit, display) {
|
|
9292
|
-
const requested = explicit !== void 0 ? backendValue(explicit, "SCREEN_RELAY_BACKEND") : process.platform === "darwin" ? "macos" : display !== void 0 && !display.includes(":") ? "wayland" : void 0;
|
|
9293
|
-
|
|
9575
|
+
const requested = explicit !== void 0 ? backendValue(explicit, "SCREEN_RELAY_BACKEND") : process.platform === "darwin" ? "macos" : process.platform === "win32" ? "windows" : display !== void 0 && !display.includes(":") ? "wayland" : void 0;
|
|
9576
|
+
const owner = requested === "macos" ? "darwin" : requested === "windows" ? "win32" : "linux";
|
|
9577
|
+
if (requested && !process.platform.startsWith(owner)) {
|
|
9294
9578
|
throw new Failure(
|
|
9295
9579
|
"invalid_input",
|
|
9296
|
-
`The ${requested} backend is only supported on ${requested === "macos" ? "macOS" : "Linux"}`,
|
|
9297
|
-
process.platform === "darwin" ? "Use --backend macos on macOS." : "Use --backend x11 or --backend wayland on Linux."
|
|
9580
|
+
`The ${requested} backend is only supported on ${requested === "macos" ? "macOS" : requested === "windows" ? "Windows" : "Linux"}`,
|
|
9581
|
+
process.platform === "darwin" ? "Use --backend macos on macOS." : process.platform === "win32" ? "Use --backend windows on Windows." : "Use --backend x11 or --backend wayland on Linux."
|
|
9298
9582
|
);
|
|
9299
9583
|
}
|
|
9300
9584
|
if (requested === "x11" && display !== void 0 && !display.includes(":")) {
|
|
@@ -9310,7 +9594,7 @@ function resolveBackend(explicit, display) {
|
|
|
9310
9594
|
const available = compiledBackends();
|
|
9311
9595
|
const backend = requested ?? (!available.length || available.includes("x11") ? "x11" : "wayland");
|
|
9312
9596
|
if (available.length && !available.includes(backend)) {
|
|
9313
|
-
const hint = backend === "macos" ? "Rebuild relay-engine with the macos backend." : `Run \`screen-relay install --backend ${backend}\``;
|
|
9597
|
+
const hint = backend === "macos" ? "Rebuild relay-engine with the macos backend." : backend === "windows" ? "Run `screen-relay install`." : `Run \`screen-relay install --backend ${backend}\``;
|
|
9314
9598
|
throw new Failure("missing_dependency", `relay-engine was built without the ${backend} backend (compiled: ${available.join(", ")})`, hint);
|
|
9315
9599
|
}
|
|
9316
9600
|
return backend;
|
|
@@ -9396,12 +9680,12 @@ function resolveTarget(args) {
|
|
|
9396
9680
|
if (!url && process.env.SCREEN_RELAY_URL) url = process.env.SCREEN_RELAY_URL;
|
|
9397
9681
|
const explicit = Boolean(url);
|
|
9398
9682
|
let tokenFile = typeof args["token-file"] === "string" ? args["token-file"] : process.env.SCREEN_RELAY_TOKEN_FILE;
|
|
9399
|
-
let
|
|
9683
|
+
let certificate, connect;
|
|
9400
9684
|
if (!url) {
|
|
9401
9685
|
const session = readSession(String(args.name));
|
|
9402
9686
|
if (session?.state === "ready" && alive(session.supervisor)) {
|
|
9403
9687
|
url = String(session.localUrl);
|
|
9404
|
-
|
|
9688
|
+
certificate = session.tlsCert ?? void 0;
|
|
9405
9689
|
connect = connectHost(session.bind) ?? void 0;
|
|
9406
9690
|
tokenFile = tokenFile || session.tokenFile;
|
|
9407
9691
|
} else if (!session && args.name === "default" && args.nameExplicit === false) {
|
|
@@ -9424,7 +9708,7 @@ function resolveTarget(args) {
|
|
|
9424
9708
|
throw new Failure("invalid_input", `Cannot read token file: ${detail(error)}`, "Check --token-file.");
|
|
9425
9709
|
}
|
|
9426
9710
|
}
|
|
9427
|
-
return { url: checkUrl(url, token), token,
|
|
9711
|
+
return { url: checkUrl(url, token), token, certificate, connect, timeout: Number(args.timeout ?? 10), signal: args.signal, explicit };
|
|
9428
9712
|
}
|
|
9429
9713
|
var RECOVERY = {
|
|
9430
9714
|
busy: "Close the other viewer or client, then retry.",
|
|
@@ -9452,7 +9736,7 @@ function remoteRecovery(target2) {
|
|
|
9452
9736
|
return target2.explicit ? { next: nextFor(`screen-relay status --url ${quote(target2.url)}`), label: "Check the remote session" } : { next: nextFor("screen-relay up -d"), label: "Start a session" };
|
|
9453
9737
|
}
|
|
9454
9738
|
function open(target2) {
|
|
9455
|
-
return createClient({ url: target2.url, token: target2.token,
|
|
9739
|
+
return createClient({ url: target2.url, token: target2.token, certificate: target2.certificate, connect: target2.connect, timeout: target2.timeout * 1e3, signal: target2.signal });
|
|
9456
9740
|
}
|
|
9457
9741
|
async function withClient(args, action, target2 = resolveTarget(args)) {
|
|
9458
9742
|
try {
|
|
@@ -9576,15 +9860,15 @@ async function cmdRemoteStatus(args) {
|
|
|
9576
9860
|
// src/cli/host/doctor.ts
|
|
9577
9861
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
9578
9862
|
import { accessSync as accessSync3, constants as constants3, mkdirSync as mkdirSync2, mkdtempSync as mkdtempSync2, readFileSync as readFileSync7, readdirSync as readdirSync3, rmSync as rmSync3, statSync as statSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
9579
|
-
import { homedir as homedir4 } from "node:os";
|
|
9580
|
-
import { join as
|
|
9863
|
+
import { homedir as homedir4, release, userInfo } from "node:os";
|
|
9864
|
+
import { join as join7 } from "node:path";
|
|
9581
9865
|
import { tmpdir } from "node:os";
|
|
9582
9866
|
import { createServer } from "node:net";
|
|
9583
9867
|
import { deflateSync } from "node:zlib";
|
|
9584
9868
|
|
|
9585
9869
|
// src/cli/host/packages.ts
|
|
9586
|
-
import { existsSync as
|
|
9587
|
-
import { dirname as
|
|
9870
|
+
import { existsSync as existsSync3, readFileSync as readFileSync6 } from "node:fs";
|
|
9871
|
+
import { dirname as dirname4, join as join6, resolve as resolve3 } from "node:path";
|
|
9588
9872
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
9589
9873
|
var families = /* @__PURE__ */ new Map([
|
|
9590
9874
|
["debian", "apt"],
|
|
@@ -9595,12 +9879,12 @@ var families = /* @__PURE__ */ new Map([
|
|
|
9595
9879
|
]);
|
|
9596
9880
|
var columns = { apt: 2, dnf: 3, pacman: 4, apk: 5 };
|
|
9597
9881
|
var unsupported = ["rhel", "rocky", "almalinux", "centos"];
|
|
9598
|
-
var runtimeDirectory =
|
|
9882
|
+
var runtimeDirectory = dirname4(fileURLToPath2(import.meta.url));
|
|
9599
9883
|
var table;
|
|
9600
9884
|
function rows() {
|
|
9601
9885
|
if (table) return table;
|
|
9602
|
-
const candidates = [
|
|
9603
|
-
const path2 = candidates.find((candidate) =>
|
|
9886
|
+
const candidates = [join6(runtimeDirectory, "packages.tsv"), resolve3(runtimeDirectory, "../../packages.tsv"), resolve3(runtimeDirectory, "../../../packages.tsv")];
|
|
9887
|
+
const path2 = candidates.find((candidate) => existsSync3(candidate));
|
|
9604
9888
|
if (path2 === void 0) throw new Error(`packages.tsv not found beside ${runtimeDirectory}`);
|
|
9605
9889
|
table = readFileSync6(path2, "utf8").split("\n").filter((line) => line !== "" && !line.startsWith("#")).map((line) => line.split(" "));
|
|
9606
9890
|
return table;
|
|
@@ -9707,8 +9991,8 @@ function iconTool() {
|
|
|
9707
9991
|
return Object.keys(ICON_TOOLS).find((program) => which(program));
|
|
9708
9992
|
}
|
|
9709
9993
|
function iconProbe(tool, suffix, data) {
|
|
9710
|
-
const directory = mkdtempSync2(
|
|
9711
|
-
const image =
|
|
9994
|
+
const directory = mkdtempSync2(join7(tmpdir(), "relay-icon-"));
|
|
9995
|
+
const image = join7(directory, `probe${suffix}`);
|
|
9712
9996
|
try {
|
|
9713
9997
|
writeFileSync4(image, data);
|
|
9714
9998
|
const command = clearedCommand([tool, ...ICON_TOOLS[tool](image)]);
|
|
@@ -9727,7 +10011,8 @@ async function cmdDoctor(args) {
|
|
|
9727
10011
|
checks.push(checkProgram(name, ok, detail2, fix, level));
|
|
9728
10012
|
return ok;
|
|
9729
10013
|
};
|
|
9730
|
-
const
|
|
10014
|
+
const windows = process.platform === "win32";
|
|
10015
|
+
const linux = process.platform === "darwin" || windows ? false : check("platform", isLinux(), process.platform, "Run doctor on the Linux host; this machine can use client commands with --url.");
|
|
9731
10016
|
if (process.platform === "darwin") {
|
|
9732
10017
|
const versionResult = run(["sw_vers", "-productVersion"]);
|
|
9733
10018
|
const version2 = versionResult.status === 0 ? versionResult.stdout.trim() : "";
|
|
@@ -9735,7 +10020,21 @@ async function cmdDoctor(args) {
|
|
|
9735
10020
|
const supported = Boolean(parts && (Number(parts[1]) > 12 || Number(parts[1]) === 12 && Number(parts[2]) >= 3));
|
|
9736
10021
|
check("platform", supported, version2 ? `macOS ${version2}` : "macOS version unavailable", "Use macOS 12.3 or later.");
|
|
9737
10022
|
}
|
|
9738
|
-
if (
|
|
10023
|
+
if (windows) {
|
|
10024
|
+
const version2 = release();
|
|
10025
|
+
check("platform", true, "Windows");
|
|
10026
|
+
check("windows version", Number(version2.split(".")[0]) >= 10, `Windows ${version2}`, "Use Windows 10 or later.");
|
|
10027
|
+
const installation2 = msys2Installation();
|
|
10028
|
+
check(
|
|
10029
|
+
"msys2",
|
|
10030
|
+
installation2.state === "trusted",
|
|
10031
|
+
installation2.state === "untrusted" ? installation2.reason : MSYS2_ROOT,
|
|
10032
|
+
installation2.state === "untrusted" ? msys2Fix(installation2) : "Run `screen-relay install`."
|
|
10033
|
+
);
|
|
10034
|
+
const session = windowsSessionId();
|
|
10035
|
+
check("desktop session", session !== null && session !== 0, session === null ? "session unknown" : `session ${session}`, "Run screen-relay in a terminal on the signed-in user's desktop.");
|
|
10036
|
+
}
|
|
10037
|
+
if (linux || process.platform === "darwin" || windows) {
|
|
9739
10038
|
const root = typeof process.getuid === "function" && process.getuid() === 0;
|
|
9740
10039
|
const sudo = root ? "" : "sudo ";
|
|
9741
10040
|
let family;
|
|
@@ -9762,7 +10061,7 @@ async function cmdDoctor(args) {
|
|
|
9762
10061
|
backend = requestedBackend2 === "x11" || requestedBackend2 === "wayland" ? requestedBackend2 : "x11";
|
|
9763
10062
|
}
|
|
9764
10063
|
const x11 = backend === "x11";
|
|
9765
|
-
check("user", true, root ? "root" : `uid ${process.getuid?.() ?? -1}`);
|
|
10064
|
+
check("user", true, windows ? userInfo().username : root ? "root" : `uid ${process.getuid?.() ?? -1}`);
|
|
9766
10065
|
check("node", Number(process.versions.node.split(".")[0]) >= 22, process.versions.node, "Install Node 22 or newer.");
|
|
9767
10066
|
if (linux) check("setpriv", Boolean(which("setpriv")), which("setpriv") ?? "not found", packageHint(["setpriv"]));
|
|
9768
10067
|
let homeWritable = true;
|
|
@@ -9772,7 +10071,7 @@ async function cmdDoctor(args) {
|
|
|
9772
10071
|
homeWritable = false;
|
|
9773
10072
|
}
|
|
9774
10073
|
check("home", homeWritable, homedir4(), "export HOME=/path/to/a/writable/dir");
|
|
9775
|
-
const state =
|
|
10074
|
+
const state = join7(stateDir("default"), "..");
|
|
9776
10075
|
let writable = true;
|
|
9777
10076
|
try {
|
|
9778
10077
|
mkdirSync2(state, { recursive: true });
|
|
@@ -9782,15 +10081,16 @@ async function cmdDoctor(args) {
|
|
|
9782
10081
|
}
|
|
9783
10082
|
check("state dir", writable, state, "export XDG_STATE_HOME=/path/to/a/writable/dir");
|
|
9784
10083
|
const engine = findEngine();
|
|
9785
|
-
const
|
|
9786
|
-
|
|
10084
|
+
const blocked = windows && engine && msys2Installation().state === "untrusted";
|
|
10085
|
+
const engineRuns = blocked ? check("engine", false, `${engine} cannot load its MSYS2 libraries until MSYS2 is trusted`, "Fix the msys2 check first.") : check("engine", Boolean(engine && run([engine, "--help"], { env: engineEnvironment(), cwd: engineWorkingDirectory(engine) }).status === 0), engine ?? "relay-engine not found", installCommand(backend));
|
|
10086
|
+
if (process.platform === "darwin") {
|
|
9787
10087
|
if (engineRuns && backendResolved && engine) {
|
|
9788
10088
|
const result = run([engine, "--backend", "macos", "--check"], { timeout: 2e4 });
|
|
9789
10089
|
check("permissions", result.status === 0, result.status === 0 ? "Screen Recording and Accessibility granted" : "backend initialization failed", result.stderr?.trim() || result.error?.message || "Run `relay-engine --backend macos --check` for details.");
|
|
9790
10090
|
} else {
|
|
9791
10091
|
check("permissions", false, "not checked", "Fix the engine and backend checks first.", "warn");
|
|
9792
10092
|
}
|
|
9793
|
-
} else {
|
|
10093
|
+
} else if (linux) {
|
|
9794
10094
|
const x264 = findLibrary("x264");
|
|
9795
10095
|
const rpmFusionCommand = `${sudo}dnf -y install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm`;
|
|
9796
10096
|
const x264Hint = family === "apt" ? installCommand2(family, ["$(apt-cache search --names-only '^libx264-[0-9]+$' | cut -d' ' -f1)"], sudo) : family === "dnf" ? `Enable RPM Fusion Free with ${rpmFusionCommand}, then install with ${packageHint(["x264-dev"])}` : packageHint(["x264-dev"]);
|
|
@@ -9824,8 +10124,8 @@ async function cmdDoctor(args) {
|
|
|
9824
10124
|
check("port", free, `127.0.0.1:${DEFAULT_PORT} ${free ? "free" : "in use"}`, `screen-relay up --port ${DEFAULT_PORT + 1}`, "warn");
|
|
9825
10125
|
if (linux) {
|
|
9826
10126
|
if (x11 && which("Xvfb") && which("xauth") && which("xdpyinfo")) {
|
|
9827
|
-
const scratch = mkdtempSync2(
|
|
9828
|
-
const auth =
|
|
10127
|
+
const scratch = mkdtempSync2(join7(tmpdir(), "relay-doctor-"));
|
|
10128
|
+
const auth = join7(scratch, "auth");
|
|
9829
10129
|
const children = [];
|
|
9830
10130
|
writeFileSync4(auth, "");
|
|
9831
10131
|
try {
|
|
@@ -9909,15 +10209,15 @@ async function cmdDoctor(args) {
|
|
|
9909
10209
|
|
|
9910
10210
|
// src/cli/host/session_commands.ts
|
|
9911
10211
|
import { spawn as spawn4 } from "node:child_process";
|
|
9912
|
-
import { chmodSync, closeSync as closeSync3, existsSync as
|
|
10212
|
+
import { chmodSync, closeSync as closeSync3, existsSync as existsSync6, mkdirSync as mkdirSync4, openSync as openSync3, readFileSync as readFileSync9, readSync as readSync2, rmSync as rmSync5, statSync as statSync4, writeFileSync as writeFileSync5 } from "node:fs";
|
|
9913
10213
|
import { homedir as homedir5 } from "node:os";
|
|
9914
|
-
import { join as
|
|
10214
|
+
import { basename, join as join9 } from "node:path";
|
|
9915
10215
|
import { setTimeout as delay3 } from "node:timers/promises";
|
|
9916
10216
|
|
|
9917
10217
|
// src/cli/host/setup.ts
|
|
9918
10218
|
import { spawn as spawn3 } from "node:child_process";
|
|
9919
|
-
import { cpSync, existsSync as
|
|
9920
|
-
import { dirname as
|
|
10219
|
+
import { cpSync, existsSync as existsSync5, mkdirSync as mkdirSync3, mkdtempSync as mkdtempSync3, readFileSync as readFileSync8, renameSync as renameSync2, rmSync as rmSync4 } from "node:fs";
|
|
10220
|
+
import { dirname as dirname5, join as join8, resolve as resolve4 } from "node:path";
|
|
9921
10221
|
import { setTimeout as delay2 } from "node:timers/promises";
|
|
9922
10222
|
|
|
9923
10223
|
// node_modules/@clack/core/dist/index.mjs
|
|
@@ -10914,21 +11214,37 @@ var i = `${styleText("gray", S_BAR)} `;
|
|
|
10914
11214
|
// src/cli/host/setup.ts
|
|
10915
11215
|
var SOURCE = resolve4(LAUNCHER_DIR, "..", "..");
|
|
10916
11216
|
var BREW_PACKAGES = ["pkgconf", "x264", "libwebsockets"];
|
|
11217
|
+
var MSYS2_PACKAGES = ["make", "diffutils", "mingw-w64-ucrt-x86_64-gcc", "mingw-w64-ucrt-x86_64-pkgconf", "mingw-w64-ucrt-x86_64-libwebsockets", "mingw-w64-ucrt-x86_64-x264"];
|
|
11218
|
+
var WINGET_MSYS2 = ["install", "--id", "MSYS2.MSYS2", "-e", "--silent", "--accept-package-agreements", "--accept-source-agreements"];
|
|
10917
11219
|
var OPTIONAL_APT = ["glycin-loaders", "gdk-pixbuf-bin"];
|
|
11220
|
+
function msysEnv() {
|
|
11221
|
+
return { ...process.env, MSYSTEM: "UCRT64", CHERE_INVOKING: "1" };
|
|
11222
|
+
}
|
|
11223
|
+
function msysCommand(command) {
|
|
11224
|
+
return `export PATH=${MSYS2_PATH}; ${command}`;
|
|
11225
|
+
}
|
|
11226
|
+
function shellPath(path2) {
|
|
11227
|
+
return process.platform === "win32" ? path2.replaceAll("\\", "/") : path2;
|
|
11228
|
+
}
|
|
10918
11229
|
function buildable(backends) {
|
|
10919
|
-
|
|
11230
|
+
if (!existsSync5(join8(SOURCE, "Makefile"))) return false;
|
|
11231
|
+
if (process.platform !== "win32") return run(["make", "-s", "-C", SOURCE, `BACKENDS=${backends.join(" ")}`, "deps"]).status === 0;
|
|
11232
|
+
const installation2 = msys2Installation();
|
|
11233
|
+
if (installation2.state !== "trusted") return false;
|
|
11234
|
+
return run([installation2.shell, "-lc", msysCommand(`make -s -C ${quote(shellPath(SOURCE))} BACKENDS=${quote(backends.join(" "))} deps`)], { env: msysEnv() }).status === 0;
|
|
10920
11235
|
}
|
|
10921
11236
|
function planSetup(request2) {
|
|
10922
11237
|
const compiled = compiledBackends();
|
|
10923
11238
|
const build = request2.backends.some((backend) => !compiled.includes(backend));
|
|
10924
11239
|
const backends = BACKENDS.filter((backend) => compiled.includes(backend) || request2.backends.includes(backend));
|
|
10925
11240
|
const programs = request2.backends.flatMap((backend) => sessionNeeds(backend, request2).missing).filter((program) => provides(program === "swaymsg" ? "sway" : program));
|
|
10926
|
-
const
|
|
11241
|
+
const untrusted = process.platform === "win32" && msys2Installation().state === "untrusted";
|
|
11242
|
+
const packages = programs.length > 0 || untrusted || build && !buildable(backends);
|
|
10927
11243
|
const xfce = request2.backends.includes("x11") && sessionNeeds("x11", request2).desktop === "xfce";
|
|
10928
11244
|
const groups = ["core", ...backends, ...xfce ? ["xfce"] : []];
|
|
10929
11245
|
return { state: packages ? "needs-packages" : build ? "needs-build" : "ready", backends, build, groups };
|
|
10930
11246
|
}
|
|
10931
|
-
async function step(title, done, command, args, required = true) {
|
|
11247
|
+
async function step(title, done, command, args, required = true, argv) {
|
|
10932
11248
|
const style = theme(args);
|
|
10933
11249
|
const started = Date.now();
|
|
10934
11250
|
const quiet = Boolean(args.json);
|
|
@@ -10936,8 +11252,10 @@ async function step(title, done, command, args, required = true) {
|
|
|
10936
11252
|
${style.muted(` ${command}`)}
|
|
10937
11253
|
`);
|
|
10938
11254
|
let output = "";
|
|
11255
|
+
const msys = process.platform === "win32" && !argv;
|
|
11256
|
+
const [program, ...programArgs] = argv ?? (msys ? [msys2Shell(), "-lc", msysCommand(command)] : ["sh", "-c", command]);
|
|
10939
11257
|
const code = await new Promise((resolveExit, reject) => {
|
|
10940
|
-
const child = spawn3(
|
|
11258
|
+
const child = spawn3(program, programArgs, { stdio: quiet ? ["ignore", "pipe", "pipe"] : ["inherit", 2, 2], env: msys ? msysEnv() : process.env, signal: args.signal });
|
|
10941
11259
|
for (const stream of [child.stdout, child.stderr]) stream?.on("data", (chunk) => {
|
|
10942
11260
|
output = (output + chunk.toString()).slice(-16e3);
|
|
10943
11261
|
});
|
|
@@ -10975,6 +11293,30 @@ function packageWork(groups, args) {
|
|
|
10975
11293
|
}
|
|
10976
11294
|
return { manager: "brew", packages: BREW_PACKAGES, run: () => step("Installing Homebrew packages", "Installed Homebrew packages", `brew install ${BREW_PACKAGES.join(" ")}`, args) };
|
|
10977
11295
|
}
|
|
11296
|
+
if (process.platform === "win32") {
|
|
11297
|
+
const installation2 = msys2Installation();
|
|
11298
|
+
return {
|
|
11299
|
+
manager: "MSYS2 pacman",
|
|
11300
|
+
packages: installation2.state === "trusted" ? MSYS2_PACKAGES : ["MSYS2", ...MSYS2_PACKAGES],
|
|
11301
|
+
run: async () => {
|
|
11302
|
+
if (installation2.state === "untrusted") throw msys2Failure(installation2);
|
|
11303
|
+
if (installation2.state === "missing") {
|
|
11304
|
+
const winget = wingetPath();
|
|
11305
|
+
if (!winget || run([winget, "--version"]).status !== 0) {
|
|
11306
|
+
throw new Failure("missing_dependency", "MSYS2 is not installed, and winget is not available to install it", "Install MSYS2 from https://www.msys2.org, then run screen-relay install again.");
|
|
11307
|
+
}
|
|
11308
|
+
await step("Installing MSYS2", "Installed MSYS2", `winget ${WINGET_MSYS2.join(" ")}`, args, true, [winget, ...WINGET_MSYS2]);
|
|
11309
|
+
forgetMsys2Installation();
|
|
11310
|
+
if (msys2Installation().state === "untrusted" && !args.json) process.stderr.write("Removing the rights C:\\msys64 inherits from C:\\\n");
|
|
11311
|
+
repairMsys2();
|
|
11312
|
+
const installed = msys2Installation();
|
|
11313
|
+
if (installed.state !== "trusted") throw msys2Failure(installed);
|
|
11314
|
+
}
|
|
11315
|
+
const keyring = "{ [ -d /etc/pacman.d/gnupg ] || { pacman-key --init && pacman-key --populate msys2 && gpgconf --kill all; }; }";
|
|
11316
|
+
await step("Installing MSYS2 packages", "Installed MSYS2 packages", `${keyring} && pacman -Sy --noconfirm --needed ${MSYS2_PACKAGES.join(" ")}`, args);
|
|
11317
|
+
}
|
|
11318
|
+
};
|
|
11319
|
+
}
|
|
10978
11320
|
let osRelease = "";
|
|
10979
11321
|
try {
|
|
10980
11322
|
osRelease = readFileSync8("/etc/os-release", "utf8");
|
|
@@ -10997,7 +11339,7 @@ function packageWork(groups, args) {
|
|
|
10997
11339
|
await step("Updating package lists", "Updated package lists", `${elevate}apt-get update`, args, false);
|
|
10998
11340
|
if (/^ID(_LIKE)?=.*ubuntu/m.test(osRelease) && !available(x264)) {
|
|
10999
11341
|
const sources = "/etc/apt/sources.list.d/ubuntu.sources";
|
|
11000
|
-
if (!
|
|
11342
|
+
if (!existsSync5(sources)) throw new Failure("missing_dependency", `${x264} is not available`, "Enable the Ubuntu universe component, then run `screen-relay install` again.");
|
|
11001
11343
|
await step(
|
|
11002
11344
|
"Enabling the Ubuntu universe component",
|
|
11003
11345
|
"Enabled the Ubuntu universe component",
|
|
@@ -11024,18 +11366,18 @@ function packageWork(groups, args) {
|
|
|
11024
11366
|
return { manager: { apt: "apt-get", dnf: "dnf", pacman: "pacman", apk: "apk" }[family], packages, run: install };
|
|
11025
11367
|
}
|
|
11026
11368
|
async function buildEngine(backends, args) {
|
|
11027
|
-
if (!
|
|
11369
|
+
if (!existsSync5(join8(SOURCE, "src", "engine"))) {
|
|
11028
11370
|
throw new Failure("missing_dependency", "The engine source is missing from this install", "Reinstall it with `npm install -g screen-relay`.");
|
|
11029
11371
|
}
|
|
11030
11372
|
const target2 = engineDirectory();
|
|
11031
|
-
mkdirSync3(
|
|
11032
|
-
const scratch = mkdtempSync3(
|
|
11373
|
+
mkdirSync3(dirname5(target2), { recursive: true });
|
|
11374
|
+
const scratch = mkdtempSync3(join8(dirname5(target2), "build-"));
|
|
11033
11375
|
try {
|
|
11034
|
-
mkdirSync3(
|
|
11035
|
-
cpSync(
|
|
11036
|
-
cpSync(
|
|
11037
|
-
await step(`Building the engine (${backends.join(", ")})`, "Built the engine", `make -C ${quote(scratch)} BACKENDS=${quote(backends.join(" "))} relay-engine`, args);
|
|
11038
|
-
for (const name of ["src", "build", "Makefile"]) rmSync4(
|
|
11376
|
+
mkdirSync3(join8(scratch, "src"));
|
|
11377
|
+
cpSync(join8(SOURCE, "Makefile"), join8(scratch, "Makefile"));
|
|
11378
|
+
cpSync(join8(SOURCE, "src", "engine"), join8(scratch, "src", "engine"), { recursive: true });
|
|
11379
|
+
await step(`Building the engine (${backends.join(", ")})`, "Built the engine", `make -C ${quote(shellPath(scratch))} BACKENDS=${quote(backends.join(" "))} relay-engine`, args);
|
|
11380
|
+
for (const name of ["src", "build", "Makefile"]) rmSync4(join8(scratch, name), { recursive: true, force: true });
|
|
11039
11381
|
rmSync4(target2, { recursive: true, force: true });
|
|
11040
11382
|
renameSync2(scratch, target2);
|
|
11041
11383
|
} finally {
|
|
@@ -11043,9 +11385,9 @@ async function buildEngine(backends, args) {
|
|
|
11043
11385
|
}
|
|
11044
11386
|
}
|
|
11045
11387
|
async function withSetupLock(args, work) {
|
|
11046
|
-
const directory =
|
|
11388
|
+
const directory = dirname5(dirname5(engineDirectory()));
|
|
11047
11389
|
mkdirSync3(directory, { recursive: true });
|
|
11048
|
-
const file =
|
|
11390
|
+
const file = join8(directory, "setup.lock");
|
|
11049
11391
|
let announced = false;
|
|
11050
11392
|
while (!claimLock(file)) {
|
|
11051
11393
|
if (!lockOwnerAlive(file)) {
|
|
@@ -11065,9 +11407,9 @@ async function withSetupLock(args, work) {
|
|
|
11065
11407
|
async function setUp(request2, args) {
|
|
11066
11408
|
if (planSetup(request2).state === "ready") return false;
|
|
11067
11409
|
return withSetupLock(args, async () => {
|
|
11068
|
-
const
|
|
11069
|
-
if (
|
|
11070
|
-
await applySetup(request2,
|
|
11410
|
+
const plan2 = planSetup(request2);
|
|
11411
|
+
if (plan2.state === "ready") return false;
|
|
11412
|
+
await applySetup(request2, plan2, args);
|
|
11071
11413
|
return true;
|
|
11072
11414
|
});
|
|
11073
11415
|
}
|
|
@@ -11076,14 +11418,14 @@ async function answer(prompt) {
|
|
|
11076
11418
|
if (isCancel(value)) throw new Failure("canceled", "Setup canceled.");
|
|
11077
11419
|
return value;
|
|
11078
11420
|
}
|
|
11079
|
-
async function applySetup(request2,
|
|
11421
|
+
async function applySetup(request2, plan2, args) {
|
|
11080
11422
|
const names = request2.backends.join(" and ");
|
|
11081
|
-
if (
|
|
11423
|
+
if (plan2.state === "needs-packages") {
|
|
11082
11424
|
if (!args.yes && !interactive(args)) {
|
|
11083
|
-
const flag = process.platform === "darwin" ? "" : ` --backend ${request2.backends.length > 1 ? "all" : request2.backends[0]}`;
|
|
11425
|
+
const flag = process.platform === "darwin" || process.platform === "win32" ? "" : ` --backend ${request2.backends.length > 1 ? "all" : request2.backends[0]}`;
|
|
11084
11426
|
throw new Failure("missing_input", `Setting up the ${names} backend installs system packages`, `Run \`screen-relay install${flag} --yes\` to allow it.`);
|
|
11085
11427
|
}
|
|
11086
|
-
const work = packageWork(
|
|
11428
|
+
const work = packageWork(plan2.groups, args);
|
|
11087
11429
|
if (!args.yes) {
|
|
11088
11430
|
process.stderr.write(`Setting up the ${names} backend installs ${count(work.packages.length, "package")} with ${work.manager}, then builds the engine:
|
|
11089
11431
|
${work.packages.join(" ")}
|
|
@@ -11092,7 +11434,7 @@ async function applySetup(request2, plan, args) {
|
|
|
11092
11434
|
}
|
|
11093
11435
|
await work.run();
|
|
11094
11436
|
}
|
|
11095
|
-
if (
|
|
11437
|
+
if (plan2.build) await buildEngine(plan2.backends, args);
|
|
11096
11438
|
if (planSetup(request2).state !== "ready") {
|
|
11097
11439
|
throw new Failure("missing_dependency", `This machine is still missing what the ${names} backend needs`, "Run `screen-relay doctor` to see what is missing.");
|
|
11098
11440
|
}
|
|
@@ -11138,7 +11480,7 @@ async function cmdInstall(args) {
|
|
|
11138
11480
|
requireHost();
|
|
11139
11481
|
const [settings2, , present] = loadConfig(typeof args.config === "string" && args.config ? args.config : void 0);
|
|
11140
11482
|
const chosen = args.backend ?? settings2.backend;
|
|
11141
|
-
if (chosen === "all" && !isLinux()) throw new Failure("invalid_input", "--backend all is only supported on Linux", "Use --backend macos on macOS.");
|
|
11483
|
+
if (chosen === "all" && !isLinux()) throw new Failure("invalid_input", "--backend all is only supported on Linux", process.platform === "win32" ? "Use --backend windows on Windows." : "Use --backend macos on macOS.");
|
|
11142
11484
|
const backends = chosen === "all" ? ["x11", "wayland"] : [requestedBackend(chosen) ?? "x11"];
|
|
11143
11485
|
const request2 = { backends, desktop: args.desktop ?? (present.has("desktop") ? settings2.desktop : void 0) };
|
|
11144
11486
|
const label = await setUp(request2, args) ? "Installed" : "Unchanged";
|
|
@@ -11386,11 +11728,12 @@ async function reapSession(directory, session, signal) {
|
|
|
11386
11728
|
}
|
|
11387
11729
|
async function cmdUp(args) {
|
|
11388
11730
|
requireHost();
|
|
11389
|
-
|
|
11390
|
-
|
|
11731
|
+
const attachedHost = process.platform === "darwin" ? "macOS" : process.platform === "win32" ? "Windows" : void 0;
|
|
11732
|
+
if (attachedHost && args.display !== void 0) {
|
|
11733
|
+
throw new Failure("invalid_input", `--display is not supported on ${attachedHost}`, `Remove --display; screen-relay attaches to the current display on ${attachedHost}.`);
|
|
11391
11734
|
}
|
|
11392
11735
|
const [settings2, , present] = loadConfig(typeof args.config === "string" && args.config ? args.config : void 0);
|
|
11393
|
-
const warnings = (args.display ||
|
|
11736
|
+
const warnings = (args.display || attachedHost) && present.has("display.resolution") ? [{ reason: "display_resolution_ignored", message: attachedHost ? `display.resolution is ignored on ${attachedHost}; the existing display size is used` : "display.resolution is ignored with --display; the existing display size is used" }] : [];
|
|
11394
11737
|
for (const warning of warnings) printWarning(warning.message, args);
|
|
11395
11738
|
applyTo(args, settings2, present);
|
|
11396
11739
|
const port = Number(args.port ?? 8080);
|
|
@@ -11469,20 +11812,22 @@ async function cmdUp(args) {
|
|
|
11469
11812
|
async function detach(args, directory, timeout2, warnings, chosen) {
|
|
11470
11813
|
const probe = await lock(args.name, directory);
|
|
11471
11814
|
await probe.close();
|
|
11472
|
-
const logPath =
|
|
11815
|
+
const logPath = join9(directory, "supervisor.log");
|
|
11473
11816
|
const log = openSync3(logPath, "w", 384);
|
|
11474
11817
|
const child = spawn4(process.execPath, [process.argv[1] ?? "", ...process.argv.slice(2), ...chosen], {
|
|
11475
11818
|
cwd: process.cwd(),
|
|
11476
11819
|
env: { ...process.env, SCREEN_RELAY_READY_FD: "3" },
|
|
11477
11820
|
detached: true,
|
|
11821
|
+
windowsHide: true,
|
|
11478
11822
|
stdio: ["ignore", log, log, "pipe"]
|
|
11479
11823
|
});
|
|
11480
11824
|
const signal = args.signal;
|
|
11481
|
-
const
|
|
11482
|
-
child.kill("SIGTERM");
|
|
11825
|
+
const stopChild = () => {
|
|
11826
|
+
if (process.platform !== "win32") child.kill("SIGTERM");
|
|
11827
|
+
else if (child.pid !== void 0) killTree(child.pid);
|
|
11483
11828
|
};
|
|
11484
|
-
signal?.addEventListener("abort",
|
|
11485
|
-
if (signal?.aborted)
|
|
11829
|
+
signal?.addEventListener("abort", stopChild, { once: true });
|
|
11830
|
+
if (signal?.aborted) stopChild();
|
|
11486
11831
|
closeSync3(log);
|
|
11487
11832
|
const stream = child.stdio[3];
|
|
11488
11833
|
let data = "";
|
|
@@ -11504,11 +11849,11 @@ async function detach(args, directory, timeout2, warnings, chosen) {
|
|
|
11504
11849
|
resolve6(data);
|
|
11505
11850
|
});
|
|
11506
11851
|
});
|
|
11507
|
-
signal?.removeEventListener("abort",
|
|
11852
|
+
signal?.removeEventListener("abort", stopChild);
|
|
11508
11853
|
if (signal?.aborted) throw new Failure("canceled", "Session startup canceled.");
|
|
11509
11854
|
if (!result) {
|
|
11510
11855
|
if (child.exitCode === null) {
|
|
11511
|
-
|
|
11856
|
+
stopChild();
|
|
11512
11857
|
throw new Failure("timeout", "Background supervisor did not report readiness in time", `See ${logPath}.`, { component: "supervisor", log: tail(logPath), logs: directory });
|
|
11513
11858
|
}
|
|
11514
11859
|
throw new Failure("component_failed", "Background supervisor exited before it was ready", `See ${logPath}.`, { component: "supervisor", log: tail(logPath), logs: directory });
|
|
@@ -11531,14 +11876,18 @@ async function cmdDown(args) {
|
|
|
11531
11876
|
const supervisor = session?.supervisor;
|
|
11532
11877
|
const running = alive(supervisor);
|
|
11533
11878
|
if (running) {
|
|
11534
|
-
process.
|
|
11879
|
+
if (process.platform === "win32") killTree(supervisor.pid);
|
|
11880
|
+
else process.kill(supervisor.pid, "SIGTERM");
|
|
11535
11881
|
const deadline = Date.now() + 2e4;
|
|
11536
11882
|
while (alive(supervisor) && Date.now() < deadline) await delay3(100, void 0, { signal: args.signal });
|
|
11537
11883
|
args.signal?.throwIfAborted();
|
|
11538
|
-
if (alive(supervisor)) {
|
|
11884
|
+
if (alive(supervisor) && process.platform !== "win32") {
|
|
11539
11885
|
process.kill(supervisor.pid, "SIGKILL");
|
|
11540
11886
|
while (alive(supervisor)) await delay3(50, void 0, { signal: args.signal });
|
|
11541
11887
|
}
|
|
11888
|
+
if (alive(supervisor) && process.platform === "win32") {
|
|
11889
|
+
throw new Failure("timeout", `Session "${args.name}" did not stop`, "Run `" + sessionCommand("down", args.name) + "` again from a terminal with the same rights as the one that started the session.");
|
|
11890
|
+
}
|
|
11542
11891
|
}
|
|
11543
11892
|
if (session) {
|
|
11544
11893
|
let held;
|
|
@@ -11585,7 +11934,7 @@ async function cmdStatus(args) {
|
|
|
11585
11934
|
session.capabilities = await createClient({
|
|
11586
11935
|
url: session.localUrl,
|
|
11587
11936
|
token: token ?? void 0,
|
|
11588
|
-
|
|
11937
|
+
certificate: session.tlsCert ?? void 0,
|
|
11589
11938
|
connect: connectHost(session.bind) ?? void 0,
|
|
11590
11939
|
timeout: timeout2 * 1e3,
|
|
11591
11940
|
signal: args.signal
|
|
@@ -11602,30 +11951,65 @@ async function cmdStatus(args) {
|
|
|
11602
11951
|
async function cmdLogs(args) {
|
|
11603
11952
|
const directory = stateDir(args.name);
|
|
11604
11953
|
const components = args.component ? [String(args.component)] : COMPONENTS;
|
|
11605
|
-
const files = components.map((component) =>
|
|
11954
|
+
const files = components.map((component) => join9(directory, `${component}.log`)).filter(existsSync6);
|
|
11606
11955
|
if (!files.length) throw new Failure("not_running", `No logs for "${args.name}"`, "Start a session with `screen-relay up`.");
|
|
11607
11956
|
if (args.json) {
|
|
11608
11957
|
if (args.follow) throw new Failure("invalid_input", "--follow cannot be combined with --json", "Run `screen-relay logs --help`.");
|
|
11609
|
-
emit(args, { logs: Object.fromEntries(files.map((file) => [
|
|
11958
|
+
emit(args, { logs: Object.fromEntries(files.map((file) => [basename(file, ".log"), tail(file, 200)])) }, "");
|
|
11610
11959
|
return 0;
|
|
11611
11960
|
}
|
|
11961
|
+
if (process.platform === "win32") return printWindowsLogs(files, args);
|
|
11612
11962
|
const child = spawn4("tail", ["-n", "200", ...args.follow ? ["-F"] : [], ...files], { stdio: "inherit", signal: args.signal });
|
|
11613
11963
|
return await new Promise((resolve6) => {
|
|
11614
11964
|
child.once("error", () => resolve6(1));
|
|
11615
11965
|
child.once("exit", (code) => resolve6(code ?? 1));
|
|
11616
11966
|
});
|
|
11617
11967
|
}
|
|
11968
|
+
async function printWindowsLogs(files, args) {
|
|
11969
|
+
const offsets = /* @__PURE__ */ new Map();
|
|
11970
|
+
files.forEach((file, index) => {
|
|
11971
|
+
if (files.length > 1) process.stdout.write(`${index ? "\n" : ""}==> ${file} <==
|
|
11972
|
+
`);
|
|
11973
|
+
const text = tail(file, 201).replace(/\r?\n$/, "");
|
|
11974
|
+
if (text) process.stdout.write(`${text.split(/\r?\n/).slice(-200).join("\n")}
|
|
11975
|
+
`);
|
|
11976
|
+
offsets.set(file, statSync4(file).size);
|
|
11977
|
+
});
|
|
11978
|
+
if (!args.follow) return 0;
|
|
11979
|
+
for (; ; ) {
|
|
11980
|
+
await delay3(200, void 0, { signal: args.signal });
|
|
11981
|
+
for (const file of files) {
|
|
11982
|
+
const size2 = statSync4(file).size;
|
|
11983
|
+
const previous = offsets.get(file) ?? 0;
|
|
11984
|
+
const from = size2 < previous ? 0 : previous;
|
|
11985
|
+
if (size2 > from) {
|
|
11986
|
+
const descriptor = openSync3(file, "r");
|
|
11987
|
+
try {
|
|
11988
|
+
const buffer = Buffer.alloc(size2 - from);
|
|
11989
|
+
readSync2(descriptor, buffer, 0, buffer.length, from);
|
|
11990
|
+
process.stdout.write(buffer);
|
|
11991
|
+
} finally {
|
|
11992
|
+
closeSync3(descriptor);
|
|
11993
|
+
}
|
|
11994
|
+
}
|
|
11995
|
+
offsets.set(file, size2);
|
|
11996
|
+
}
|
|
11997
|
+
}
|
|
11998
|
+
}
|
|
11618
11999
|
async function cmdRun(args) {
|
|
11619
12000
|
requireHost();
|
|
12001
|
+
if (args.restart && process.platform === "win32") throw new Failure("invalid_input", "--restart is not supported on Windows", "Remove --restart and run the app again.");
|
|
11620
12002
|
const rest = args.args === void 0 ? [] : Array.isArray(args.args) ? args.args : [args.args];
|
|
11621
12003
|
const command = [args.app, ...rest].filter((value) => value !== void 0).map(String);
|
|
11622
12004
|
if (!command.length) throw new Failure("missing_command", "Name the app to start", "Run `screen-relay run --help`.");
|
|
11623
|
-
|
|
12005
|
+
const found = which(command[0]);
|
|
12006
|
+
if (!found) throw new Failure("spawn_failed", `${command[0]} was not found`, "Install it or check the name, then run the command again.");
|
|
12007
|
+
const spawned = process.platform === "win32" ? [found, ...command.slice(1)] : command;
|
|
11624
12008
|
const session = readSession(args.name);
|
|
11625
12009
|
if (!session || session.state !== "ready" || !alive(session.supervisor)) throw new Failure("not_found", `No running session named "${args.name}"`, "Start one with `screen-relay up -d`.");
|
|
11626
12010
|
const directory = stateDir(args.name);
|
|
11627
|
-
const env = session.ownsDisplay === false ? { ...process.env, ...session.backend
|
|
11628
|
-
if (session.backend
|
|
12011
|
+
const env = session.ownsDisplay === false ? { ...process.env, ...attaches(session.backend) ? session.environment ?? {} : {}, SCREEN_RELAY_SESSION: directory } : { ...desktopEnv(directory), ...session.environment ?? {} };
|
|
12012
|
+
if (attaches(session.backend)) {
|
|
11629
12013
|
delete env.DISPLAY;
|
|
11630
12014
|
delete env.WAYLAND_DISPLAY;
|
|
11631
12015
|
delete env.XAUTHORITY;
|
|
@@ -11636,7 +12020,7 @@ async function cmdRun(args) {
|
|
|
11636
12020
|
if (session.waylandDisplay) env.WAYLAND_DISPLAY = session.waylandDisplay;
|
|
11637
12021
|
if (session.xauthority) env.XAUTHORITY = session.xauthority;
|
|
11638
12022
|
}
|
|
11639
|
-
const path2 =
|
|
12023
|
+
const path2 = join9(directory, "apps.log");
|
|
11640
12024
|
const log = openSync3(path2, "a", 384);
|
|
11641
12025
|
let pid;
|
|
11642
12026
|
try {
|
|
@@ -11646,7 +12030,7 @@ async function cmdRun(args) {
|
|
|
11646
12030
|
if (started.exited) throw new Failure("component_failed", `${command[0]} exited with code ${started.exited}`, "Read `screen-relay logs apps`.", { component: "apps", log: tail(path2) });
|
|
11647
12031
|
pid = started.pid;
|
|
11648
12032
|
} else {
|
|
11649
|
-
const child = spawnCleared(
|
|
12033
|
+
const child = spawnCleared(spawned, { cwd: homedir5(), env, stdio: ["ignore", log, log], detached: true, signal: args.signal });
|
|
11650
12034
|
await new Promise((resolve6, reject) => {
|
|
11651
12035
|
child.once("spawn", () => resolve6());
|
|
11652
12036
|
child.once("error", reject);
|
|
@@ -11668,7 +12052,7 @@ async function cmdRun(args) {
|
|
|
11668
12052
|
emit(
|
|
11669
12053
|
args,
|
|
11670
12054
|
{ app: { pid, command }, outcome: "started" },
|
|
11671
|
-
formatStarted(command[0], pid, session.backend === "macos" ? "macOS" : session.display, path2, args) + "\n" + nextStep("Read app output", sessionCommand("logs apps", args.name), args),
|
|
12055
|
+
formatStarted(command[0], pid, session.backend === "macos" ? "macOS" : session.backend === "windows" ? "Windows" : session.display, path2, args) + "\n" + nextStep("Read app output", sessionCommand("logs apps", args.name), args),
|
|
11672
12056
|
{ identifier: String(pid) }
|
|
11673
12057
|
);
|
|
11674
12058
|
return 0;
|
|
@@ -11676,17 +12060,17 @@ async function cmdRun(args) {
|
|
|
11676
12060
|
|
|
11677
12061
|
// src/cli/skills.ts
|
|
11678
12062
|
var import_yaml2 = __toESM(require_dist2(), 1);
|
|
11679
|
-
import { readdirSync as readdirSync4, readFileSync as readFileSync10, statSync as
|
|
11680
|
-
import { dirname as
|
|
12063
|
+
import { readdirSync as readdirSync4, readFileSync as readFileSync10, statSync as statSync5 } from "node:fs";
|
|
12064
|
+
import { dirname as dirname6, join as join10, resolve as resolve5 } from "node:path";
|
|
11681
12065
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
11682
|
-
var runtimeDirectory2 =
|
|
11683
|
-
var skillsDirectory = [
|
|
12066
|
+
var runtimeDirectory2 = dirname6(fileURLToPath3(import.meta.url));
|
|
12067
|
+
var skillsDirectory = [join10(runtimeDirectory2, "skills"), resolve5(runtimeDirectory2, "../../skills")].find((path2) => {
|
|
11684
12068
|
try {
|
|
11685
|
-
return
|
|
12069
|
+
return statSync5(path2).isDirectory();
|
|
11686
12070
|
} catch {
|
|
11687
12071
|
return false;
|
|
11688
12072
|
}
|
|
11689
|
-
}) ??
|
|
12073
|
+
}) ?? join10(runtimeDirectory2, "skills");
|
|
11690
12074
|
function discover() {
|
|
11691
12075
|
let entries;
|
|
11692
12076
|
try {
|
|
@@ -11695,10 +12079,10 @@ function discover() {
|
|
|
11695
12079
|
return [];
|
|
11696
12080
|
}
|
|
11697
12081
|
return entries.flatMap((entry) => {
|
|
11698
|
-
const location2 =
|
|
11699
|
-
const file =
|
|
12082
|
+
const location2 = join10(skillsDirectory, entry);
|
|
12083
|
+
const file = join10(location2, "SKILL.md");
|
|
11700
12084
|
try {
|
|
11701
|
-
if (!
|
|
12085
|
+
if (!statSync5(location2).isDirectory()) return [];
|
|
11702
12086
|
const content = readFileSync10(file, "utf8");
|
|
11703
12087
|
const frontmatter = content.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/)?.[1];
|
|
11704
12088
|
if (!frontmatter) return [];
|
|
@@ -11719,10 +12103,10 @@ function missing(name) {
|
|
|
11719
12103
|
function get(name, options = {}) {
|
|
11720
12104
|
const skill = discover().find((candidate) => candidate.name === name);
|
|
11721
12105
|
if (!skill) throw missing(name);
|
|
11722
|
-
let content = readFileSync10(
|
|
12106
|
+
let content = readFileSync10(join10(skill.directory, "SKILL.md"), "utf8");
|
|
11723
12107
|
if (options.full) {
|
|
11724
12108
|
for (const subdirectory of ["references", "templates"]) {
|
|
11725
|
-
const directory =
|
|
12109
|
+
const directory = join10(skill.directory, subdirectory);
|
|
11726
12110
|
let entries;
|
|
11727
12111
|
try {
|
|
11728
12112
|
entries = readdirSync4(directory).sort();
|
|
@@ -11730,8 +12114,8 @@ function get(name, options = {}) {
|
|
|
11730
12114
|
continue;
|
|
11731
12115
|
}
|
|
11732
12116
|
for (const entry of entries) {
|
|
11733
|
-
const path2 =
|
|
11734
|
-
if (!
|
|
12117
|
+
const path2 = join10(directory, entry);
|
|
12118
|
+
if (!statSync5(path2).isFile()) continue;
|
|
11735
12119
|
content += `
|
|
11736
12120
|
|
|
11737
12121
|
## ${subdirectory}/${entry}
|
|
@@ -11802,10 +12186,10 @@ var commands = {
|
|
|
11802
12186
|
{ name: "detach", short: "d", type: "boolean", summary: "Run in the background", default: false },
|
|
11803
12187
|
configOption,
|
|
11804
12188
|
{ name: "port", type: "number", valueHint: "<PORT>", summary: "Listen on this port", environment: "SCREEN_RELAY_PORT", default: 8080, deferredDefault: true, validate: (value) => Number.isInteger(value) && Number(value) >= 1 && Number(value) <= 65535 },
|
|
11805
|
-
{ name: "desktop", type: "string", valueHint: "<COMMAND>", summary: "Start xfce, none, or a desktop command; defaults to xfce on x11, foot on wayland, or none when attaching. On macOS, the desktop is always none", environment: "SCREEN_RELAY_DESKTOP" },
|
|
12189
|
+
{ name: "desktop", type: "string", valueHint: "<COMMAND>", summary: "Start xfce, none, or a desktop command; defaults to xfce on x11, foot on wayland, or none when attaching. On macOS and Windows, the desktop is always none", environment: "SCREEN_RELAY_DESKTOP" },
|
|
11806
12190
|
{ name: "display", type: "string", valueHint: "<DISPLAY>", summary: "Attach to an existing X display (:0) or Wayland socket (wayland-1) on Linux" },
|
|
11807
|
-
{ name: "backend", type: "string", valueHint: "<BACKEND>", summary: "On Linux, defaults to x11 when the engine has it, else wayland; a --display without a colon selects wayland. On macOS, defaults to macos", environment: "SCREEN_RELAY_BACKEND", acceptedValues: BACKENDS },
|
|
11808
|
-
{ name: "output", type: "string", valueHint: "<NAME>", summary: "Capture a Wayland output by name or a
|
|
12191
|
+
{ name: "backend", type: "string", valueHint: "<BACKEND>", summary: "On Linux, defaults to x11 when the engine has it, else wayland; a --display without a colon selects wayland. On macOS, defaults to macos; on Windows, defaults to windows", environment: "SCREEN_RELAY_BACKEND", acceptedValues: BACKENDS },
|
|
12192
|
+
{ name: "output", type: "string", valueHint: "<NAME>", summary: "Capture a Wayland output by name, a macOS display by CGDirectDisplayID, or a Windows display by device name" },
|
|
11809
12193
|
{ name: "public", type: "string", valueHint: "<URL>", summary: "Advertise this HTTPS origin", environment: "SCREEN_RELAY_PUBLIC", validate: (value) => /^https:\/\/[^/?#@\\\s]+$/.test(String(value)) },
|
|
11810
12194
|
{ name: "tls-cert", type: "string", valueHint: "<FILE>", summary: "Serve TLS with this certificate", environment: "SCREEN_RELAY_TLS_CERT" },
|
|
11811
12195
|
{ name: "tls-key", type: "string", valueHint: "<FILE>", summary: "Read the TLS private key", environment: "SCREEN_RELAY_TLS_KEY" },
|
|
@@ -11819,7 +12203,7 @@ var commands = {
|
|
|
11819
12203
|
{ description: "Attach to the running Wayland compositor", command: 'screen-relay up -d --display "$WAYLAND_DISPLAY"' },
|
|
11820
12204
|
{ description: "Attach to the current display on macOS", command: "screen-relay up -d --backend macos" }
|
|
11821
12205
|
],
|
|
11822
|
-
notes: ["Without --detach, Ctrl+C stops the session.", "On Linux, --display uses the existing display size and defaults to no desktop. On macOS, screen-relay always attaches to the existing display.", "Flags override config values. SCREEN_RELAY_CONFIG selects the config file.", "Config-only settings and their variables: display.resolution (SCREEN_RELAY_RESOLUTION), stream.fps (SCREEN_RELAY_FPS), stream.bitrate.* (SCREEN_RELAY_BITRATE_MIN, SCREEN_RELAY_BITRATE_START, SCREEN_RELAY_BITRATE_MAX), keyboard.layout (SCREEN_RELAY_KEYBOARD_LAYOUT).", "On a machine that is not set up yet, up installs the system packages and builds the engine first. At a terminal it asks before installing; anywhere else it needs --yes."],
|
|
12206
|
+
notes: ["Without --detach, Ctrl+C stops the session.", "On Linux, --display uses the existing display size and defaults to no desktop. On macOS and Windows, screen-relay always attaches to the existing display.", "Flags override config values. SCREEN_RELAY_CONFIG selects the config file.", "Config-only settings and their variables: display.resolution (SCREEN_RELAY_RESOLUTION), stream.fps (SCREEN_RELAY_FPS), stream.bitrate.* (SCREEN_RELAY_BITRATE_MIN, SCREEN_RELAY_BITRATE_START, SCREEN_RELAY_BITRATE_MAX), keyboard.layout (SCREEN_RELAY_KEYBOARD_LAYOUT).", "On a machine that is not set up yet, up installs the system packages and builds the engine first. At a terminal it asks before installing; anywhere else it needs --yes."],
|
|
11823
12207
|
resultSchema: { session: "object", outcome: "started" },
|
|
11824
12208
|
validate: (args) => args.display === "" ? new Failure("invalid_input", "--display is empty", "Set WAYLAND_DISPLAY or DISPLAY, or drop --display to start a new desktop.") : void 0,
|
|
11825
12209
|
run: cmdUp
|
|
@@ -11848,7 +12232,7 @@ var commands = {
|
|
|
11848
12232
|
runsOn: "vm",
|
|
11849
12233
|
arguments: [],
|
|
11850
12234
|
options: [
|
|
11851
|
-
{ name: "backend", type: "string", valueHint: "<BACKEND>", summary: "Set up x11, wayland, or all on Linux; defaults to x11. On macOS, the backend is always macos", environment: "SCREEN_RELAY_BACKEND", acceptedValues: [...BACKENDS, "all"] },
|
|
12235
|
+
{ name: "backend", type: "string", valueHint: "<BACKEND>", summary: "Set up x11, wayland, or all on Linux; defaults to x11. On macOS, the backend is always macos; on Windows, it is always windows", environment: "SCREEN_RELAY_BACKEND", acceptedValues: [...BACKENDS, "all"] },
|
|
11852
12236
|
{ name: "desktop", type: "string", valueHint: "<COMMAND>", summary: "Install the XFCE packages only for xfce, the x11 default; none or another command skips them", environment: "SCREEN_RELAY_DESKTOP" },
|
|
11853
12237
|
configOption,
|
|
11854
12238
|
yes
|
|
@@ -11861,7 +12245,7 @@ var commands = {
|
|
|
11861
12245
|
resultSchema: { install: { backends: "array", engine: "string" }, outcome: ["installed", "unchanged"] },
|
|
11862
12246
|
run: cmdInstall
|
|
11863
12247
|
},
|
|
11864
|
-
doctor: { summary: "Check this machine and show fixes", group: "Machine", runsOn: "vm", arguments: [], options: [configOption], examples: example("Check host dependencies", "screen-relay doctor"), notes: ["On Linux, checks the x11 backend unless SCREEN_RELAY_BACKEND or the config backend key says otherwise; run SCREEN_RELAY_BACKEND=wayland screen-relay doctor for Wayland. On macOS, checks the macos backend."], resultSchema: { checks: "array", summary: "object" }, run: cmdDoctor },
|
|
12248
|
+
doctor: { summary: "Check this machine and show fixes", group: "Machine", runsOn: "vm", arguments: [], options: [configOption], examples: example("Check host dependencies", "screen-relay doctor"), notes: ["On Linux, checks the x11 backend unless SCREEN_RELAY_BACKEND or the config backend key says otherwise; run SCREEN_RELAY_BACKEND=wayland screen-relay doctor for Wayland. On macOS, checks the macos backend. On Windows, checks the windows backend, MSYS2 and the desktop session."], resultSchema: { checks: "array", summary: "object" }, run: cmdDoctor },
|
|
11865
12249
|
screenshot: { summary: "Save a PNG of the screen", group: "Control", runsOn: "client", arguments: [{ name: "file", type: "string", valueHint: "file", summary: "Destination path, or - for PNG stdout", default: "screen.png" }], options: client, examples: example("Save the current screen", "screen-relay screenshot screen.png"), notes: ["Use - to write PNG bytes to stdout. This cannot be combined with --json."], resultSchema: { screenshot: { path: "string", width: "number", height: "number", bytes: "number" }, outcome: "saved" }, validate: (args) => args.file === "-" && args.json ? "PNG stdout cannot be combined with --json" : void 0, run: cmdScreenshot },
|
|
11866
12250
|
click: { summary: "Click at screen coordinates", group: "Control", runsOn: "client", arguments: coordinates, options: [...client, { name: "button", type: "string", valueHint: "<BUTTON>", summary: "Select the mouse button", default: "left", acceptedValues: ["left", "middle", "right"] }], examples: example("Click the center", "screen-relay click 0.5 0.5"), notes: coordinateNotes, resultSchema: inputResult, run: cmdClick },
|
|
11867
12251
|
move: { summary: "Move the pointer to screen coordinates", group: "Control", runsOn: "client", arguments: coordinates, options: client, examples: example("Move to the center", "screen-relay move 0.5 0.5"), notes: coordinateNotes, resultSchema: inputResult, run: cmdMove },
|
|
@@ -11898,7 +12282,7 @@ var commands = {
|
|
|
11898
12282
|
};
|
|
11899
12283
|
|
|
11900
12284
|
// src/cli/help.ts
|
|
11901
|
-
var docs = "https://relay.
|
|
12285
|
+
var docs = "https://screen-relay.dev/docs/cli";
|
|
11902
12286
|
var summary = "Start a streamed desktop and control it";
|
|
11903
12287
|
var width = 80;
|
|
11904
12288
|
var labelLimit = 24;
|
|
@@ -12013,12 +12397,12 @@ function humanUsage(name, style) {
|
|
|
12013
12397
|
return `${head}${command.separator ? ` ${command.separator}` : ""}${tail2 ? ` ${tail2}` : ""} [options]`;
|
|
12014
12398
|
}
|
|
12015
12399
|
var sections = [
|
|
12016
|
-
{ runsOn: "vm", label: "Host commands (run on the Linux or
|
|
12400
|
+
{ runsOn: "vm", label: "Host commands (run on the Linux, macOS, or Windows machine that shows the desktop):" },
|
|
12017
12401
|
{ runsOn: "client", label: "Client commands (run on the host, or anywhere with --url and a token):" },
|
|
12018
12402
|
{ runsOn: "anywhere", label: "Other commands:" }
|
|
12019
12403
|
];
|
|
12020
12404
|
var location = {
|
|
12021
|
-
vm: "Run it on the Linux or
|
|
12405
|
+
vm: "Run it on the Linux, macOS, or Windows machine that shows the desktop.",
|
|
12022
12406
|
client: "Runs on the host, or on another machine with --url and a token file.",
|
|
12023
12407
|
anywhere: "Runs on any machine. It does not reach an engine."
|
|
12024
12408
|
};
|