mindwire 0.1.28 → 0.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-5WYSGXFN.js → chunk-RN7ERVJ2.js} +39 -12
- package/dist/chunk-RN7ERVJ2.js.map +1 -0
- package/dist/cli.js +87 -89
- package/dist/cli.js.map +1 -1
- package/dist/computer/connection-flow.d.ts +16 -3
- package/dist/computer/controller-handoff.d.ts +6 -0
- package/dist/computer/lifecycle.d.ts +4 -0
- package/dist/computer/relay-health.d.ts +11 -0
- package/dist/computer.d.ts +17 -1
- package/dist/{controller-5ZTNIHUV.js → controller-DIJKMWWU.js} +156 -11
- package/dist/controller-DIJKMWWU.js.map +1 -0
- package/dist/controller-handoff-4GXF4ATR.js +71 -0
- package/dist/controller-handoff-4GXF4ATR.js.map +1 -0
- package/dist/index.cjs +20 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +20 -12
- package/dist/index.js.map +1 -1
- package/dist/version.d.ts +1 -0
- package/package.json +7 -3
- package/dist/chunk-5WYSGXFN.js.map +0 -1
- package/dist/controller-5ZTNIHUV.js.map +0 -1
|
@@ -34,11 +34,19 @@ var ComputerApi = class {
|
|
|
34
34
|
pairing(id) {
|
|
35
35
|
return this.client.http.request("GET", `/computer/pairings/${encodeURIComponent(id)}`);
|
|
36
36
|
}
|
|
37
|
+
/** pairingVersion >= 2. Releases an unused QR when a saved phone reconnects.
|
|
38
|
+
* Returns false if a phone already submitted a request, which must be handled. */
|
|
39
|
+
closeUnusedPairing(id) {
|
|
40
|
+
return this.client.http.request("DELETE", `/computer/pairings/${encodeURIComponent(id)}`);
|
|
41
|
+
}
|
|
37
42
|
completePairing(id, requestId) {
|
|
38
43
|
return this.client.http.request("POST", `/computer/pairings/${encodeURIComponent(id)}/complete`, { body: { requestId } });
|
|
39
44
|
}
|
|
40
|
-
decide(id, requestId, approve) {
|
|
41
|
-
|
|
45
|
+
async decide(id, requestId, approve, options = {}) {
|
|
46
|
+
if (options.replaceDeviceIds?.length && ((await this.info()).pairingVersion ?? 0) < 2) {
|
|
47
|
+
throw new Error("Update the Mindwire service before replacing saved phone approvals.");
|
|
48
|
+
}
|
|
49
|
+
return this.client.http.request("POST", `/computer/pairings/${encodeURIComponent(id)}/decision`, { body: { requestId, approve, ...options } });
|
|
42
50
|
}
|
|
43
51
|
devices() {
|
|
44
52
|
return this.client.http.request("GET", "/computer/devices");
|
|
@@ -71,7 +79,16 @@ function computerPairingURI(invitation) {
|
|
|
71
79
|
}
|
|
72
80
|
|
|
73
81
|
// src/version.ts
|
|
74
|
-
var SDK_VERSION = "0.1.
|
|
82
|
+
var SDK_VERSION = "0.1.30" ;
|
|
83
|
+
function versionAtLeast(actual, desired) {
|
|
84
|
+
if (actual === desired) return true;
|
|
85
|
+
if (!actual || !/^\d+\.\d+\.\d+$/.test(actual) || !/^\d+\.\d+\.\d+$/.test(desired)) return false;
|
|
86
|
+
const a = actual.split(".").map(Number), b = desired.split(".").map(Number);
|
|
87
|
+
for (let i = 0; i < 3; i++) {
|
|
88
|
+
if (a[i] !== b[i]) return a[i] > b[i];
|
|
89
|
+
}
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
75
92
|
|
|
76
93
|
// src/daemon-binary.ts
|
|
77
94
|
function supported(platform, arch) {
|
|
@@ -1876,6 +1893,7 @@ async function acquireProcessLock(file, options = {}) {
|
|
|
1876
1893
|
}
|
|
1877
1894
|
|
|
1878
1895
|
// src/computer/lifecycle.ts
|
|
1896
|
+
var CONTROLLER_PROTOCOL = 2;
|
|
1879
1897
|
var defaultStateDirectory = () => path.join(homedir(), ".mindwire", "computer");
|
|
1880
1898
|
var defaultComputerConfig = () => ({ directory: homedir(), bind: "0.0.0.0", sshPort: 8791, websocketPort: 8792, relay: { kind: "cloudflare" } });
|
|
1881
1899
|
async function readJSON(file) {
|
|
@@ -1930,6 +1948,9 @@ async function ensureComputer(directory, cliPath, patch = {}, onProgress, option
|
|
|
1930
1948
|
const configPath = path.join(directory, "computer-config.json");
|
|
1931
1949
|
const previous = await readJSON(configPath);
|
|
1932
1950
|
const config = { ...defaultComputerConfig(), ...previous, ...patch };
|
|
1951
|
+
const requestedAt = resume ? Date.now() : 0;
|
|
1952
|
+
if (resume) await writeJSON(path.join(directory, "computer-check.json"), { requestedAt });
|
|
1953
|
+
const compatible = (controller) => (controller?.protocol ?? 0) >= CONTROLLER_PROTOCOL && versionAtLeast(controller?.cliVersion, SDK_VERSION);
|
|
1933
1954
|
let launchedPID;
|
|
1934
1955
|
let launchFailure;
|
|
1935
1956
|
const waitUntilReady = async () => {
|
|
@@ -1943,7 +1964,7 @@ async function ensureComputer(directory, cliPath, patch = {}, onProgress, option
|
|
|
1943
1964
|
continue;
|
|
1944
1965
|
}
|
|
1945
1966
|
if (controller?.error && !controller.recovering) throw new Error(controller.error);
|
|
1946
|
-
if (controller?.ready && await processStateAlive(controller)) return computerClient(directory);
|
|
1967
|
+
if (controller?.ready && compatible(controller) && (controller.checkedAt ?? 0) >= requestedAt && await processStateAlive(controller)) return computerClient(directory);
|
|
1947
1968
|
if (controller?.phase && controller.phase !== phase) {
|
|
1948
1969
|
phase = controller.phase;
|
|
1949
1970
|
onProgress?.(phase);
|
|
@@ -1957,14 +1978,14 @@ async function ensureComputer(directory, cliPath, patch = {}, onProgress, option
|
|
|
1957
1978
|
throw new Error("Mindwire is running with different connection settings. Run mindwire stop when idle, then retry with the new settings.");
|
|
1958
1979
|
}
|
|
1959
1980
|
const controller = await readJSON(path.join(directory, "computer-controller.json"));
|
|
1960
|
-
if (await processStateAlive(controller)) return waitUntilReady();
|
|
1981
|
+
if (compatible(controller) && await processStateAlive(controller)) return waitUntilReady();
|
|
1961
1982
|
}
|
|
1962
1983
|
const lockPath = path.join(directory, "launch.lock");
|
|
1963
1984
|
const lock = await acquireProcessLock(lockPath, {
|
|
1964
1985
|
signal: options.signal,
|
|
1965
1986
|
onWait: async () => {
|
|
1966
1987
|
const controller = await readJSON(path.join(directory, "computer-controller.json"));
|
|
1967
|
-
if (await processStateAlive(controller)) {
|
|
1988
|
+
if (compatible(controller) && await processStateAlive(controller)) {
|
|
1968
1989
|
const saved = await readJSON(configPath);
|
|
1969
1990
|
if (Object.keys(patch).some((key) => JSON.stringify(patch[key]) !== JSON.stringify(saved?.[key]))) {
|
|
1970
1991
|
throw new Error("Another start used different connection settings. Stop Mindwire when idle before changing them.");
|
|
@@ -1988,9 +2009,15 @@ async function ensureComputer(directory, cliPath, patch = {}, onProgress, option
|
|
|
1988
2009
|
throw new Error("Another start used different connection settings. Stop Mindwire when idle before changing them.");
|
|
1989
2010
|
}
|
|
1990
2011
|
const controller2 = await readJSON(path.join(directory, "computer-controller.json"));
|
|
1991
|
-
if (await processStateAlive(controller2)) return waitUntilReady();
|
|
2012
|
+
if (compatible(controller2) && await processStateAlive(controller2)) return waitUntilReady();
|
|
2013
|
+
}
|
|
2014
|
+
let controller = await readJSON(path.join(directory, "computer-controller.json"));
|
|
2015
|
+
if (existing && controller && !compatible(controller) && await processStateAlive(controller)) {
|
|
2016
|
+
onProgress?.("Refreshing the background connection service\u2026");
|
|
2017
|
+
const { handoffController } = await import('./controller-handoff-4GXF4ATR.js');
|
|
2018
|
+
await handoffController(directory, controller, config, await existing.computer.info());
|
|
2019
|
+
controller = void 0;
|
|
1992
2020
|
}
|
|
1993
|
-
const controller = await readJSON(path.join(directory, "computer-controller.json"));
|
|
1994
2021
|
if (await processStateAlive(controller)) {
|
|
1995
2022
|
if (controller?.error && !controller.recovering) throw new Error(controller.error);
|
|
1996
2023
|
} else {
|
|
@@ -2021,7 +2048,7 @@ async function ensureComputer(directory, cliPath, patch = {}, onProgress, option
|
|
|
2021
2048
|
}
|
|
2022
2049
|
}
|
|
2023
2050
|
async function superviseComputer(directory) {
|
|
2024
|
-
const controller = await import('./controller-
|
|
2051
|
+
const controller = await import('./controller-DIJKMWWU.js');
|
|
2025
2052
|
await controller.superviseComputer(directory);
|
|
2026
2053
|
}
|
|
2027
2054
|
async function stopComputer(directory, force = false) {
|
|
@@ -2045,6 +2072,6 @@ async function stopComputer(directory, force = false) {
|
|
|
2045
2072
|
throw new Error("Mindwire is still stopping. Check computer.log.");
|
|
2046
2073
|
}
|
|
2047
2074
|
|
|
2048
|
-
export { SDK_VERSION, acquireProcessLock, adoptProcess, computerClient, computerPairingQRData, computerPairingURI, currentProcessIdentity, defaultStateDirectory, directRoutes, ensureComputer, ensureDaemonBinary, ownChild, processIdentity, processStateAlive, readJSON, stopComputer, superviseComputer, writeJSON };
|
|
2049
|
-
//# sourceMappingURL=chunk-
|
|
2050
|
-
//# sourceMappingURL=chunk-
|
|
2075
|
+
export { CONTROLLER_PROTOCOL, SDK_VERSION, acquireProcessLock, adoptProcess, computerClient, computerPairingQRData, computerPairingURI, currentProcessIdentity, defaultStateDirectory, directRoutes, ensureComputer, ensureDaemonBinary, ownChild, processIdentity, processStateAlive, readJSON, stopComputer, superviseComputer, writeJSON };
|
|
2076
|
+
//# sourceMappingURL=chunk-RN7ERVJ2.js.map
|
|
2077
|
+
//# sourceMappingURL=chunk-RN7ERVJ2.js.map
|