kiteline 0.1.0 → 0.3.0
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 +5 -5
- package/dist/auth-CYNu-f_h.mjs +104 -0
- package/dist/{banner-DJdyE8-G.mjs → banner-C1Jj4n4W.mjs} +112 -41
- package/dist/cli.mjs +35 -11
- package/dist/client.BPI7fHX3-CSey2FaL.mjs +1437 -0
- package/dist/control-BEq2N-wP.mjs +101 -0
- package/dist/control-BpOGsRCZ.mjs +1 -0
- package/dist/devices-command-Bubh46v1.mjs +76 -0
- package/dist/{package-D46-e3oS.mjs → package-BoxBh8MJ.mjs} +1 -1
- package/dist/pair-command-DBxw6BfK.mjs +107 -0
- package/dist/{service-1H4ozSPX.mjs → service-C2w4PsA8.mjs} +17 -22
- package/dist/{src-BnClcgTs.mjs → src-CR4MmTcf.mjs} +1375 -1235
- package/dist/web/assets/{MagnifyingGlass.es-DLNPT1gT.js → MagnifyingGlass.es-DH9Sttou.js} +1 -1
- package/dist/web/assets/Plus.es-1uU9mFYr.js +1 -0
- package/dist/web/assets/composer-BcIdpxHM.js +1 -0
- package/dist/web/assets/copy-button-DRCJdYml.js +1 -0
- package/dist/web/assets/format-BHMU9nwj.js +9 -0
- package/dist/web/assets/index-BRaZDA7B.css +1 -0
- package/dist/web/assets/index-TWMUhgcM.js +11 -0
- package/dist/web/assets/lazy/{core-DbyPnbRm.js → core-pRLcnHpb.js} +1 -1
- package/dist/web/assets/new-BbSpVHmG.js +1 -0
- package/dist/web/assets/{prefs-CliZrwNF.js → prefs-q6daUElH.js} +1 -1
- package/dist/web/assets/routes-lV-e8sSj.js +1 -0
- package/dist/web/assets/s._sessionId-t7H-a-HP.js +45 -0
- package/dist/web/assets/settings-CbonbiKb.js +1 -0
- package/dist/web/assets/status-CKsUN4Lx.js +1 -0
- package/dist/web/index.html +3 -3
- package/dist/web/sw.js +1 -1
- package/package.json +1 -1
- package/dist/auth-YhkfTv6K.mjs +0 -60
- package/dist/show-pairing-jhFEXWi7.mjs +0 -30
- package/dist/show-pairing-u0LfkF9W.mjs +0 -1
- package/dist/web/assets/IconBase.es-CfbvcPwJ.js +0 -9
- package/dist/web/assets/composer-B6OuQTWV.js +0 -1
- package/dist/web/assets/copy-button-DrJvfi1A.js +0 -1
- package/dist/web/assets/index-CA73h-Vn.css +0 -1
- package/dist/web/assets/index-Da9GDrpu.js +0 -11
- package/dist/web/assets/new-x01_nUpy.js +0 -1
- package/dist/web/assets/routes-NIOlnkZY.js +0 -1
- package/dist/web/assets/s._sessionId-BtgSN22Q.js +0 -45
- package/dist/web/assets/settings-B7yar__r.js +0 -1
- package/dist/web/assets/status-BFb0ZUqi.js +0 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { M as toArray, O as preventNativeAwait, l as toStandardLazyResponse, m as RECURSIVE_CLIENT_UNWRAP_KEYS, o as toFetchRequest, r as StandardRPCLink, t as CompositeStandardLinkPlugin, x as intercept } from "./client.BPI7fHX3-CSey2FaL.mjs";
|
|
2
|
+
import { a as localAddress, o as readComputerKey, r as kitelineHome, s as readServerInfo } from "./auth-CYNu-f_h.mjs";
|
|
3
|
+
import { f as command, m as readSettings, p as loadOwnEnvFile, r as bold } from "./banner-C1Jj4n4W.mjs";
|
|
4
|
+
// ../../node_modules/.pnpm/@orpc+client@1.16.1_@opentelemetry+api@1.10.0/node_modules/@orpc/client/dist/index.mjs
|
|
5
|
+
function resolveFriendlyClientOptions(options) {
|
|
6
|
+
return {
|
|
7
|
+
...options,
|
|
8
|
+
context: options.context ?? {}
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function createORPCClient(link, options = {}) {
|
|
12
|
+
const path = options.path ?? [];
|
|
13
|
+
const procedureClient = async (...[input, options2 = {}]) => {
|
|
14
|
+
return await link.call(path, input, resolveFriendlyClientOptions(options2));
|
|
15
|
+
};
|
|
16
|
+
const recursive = new Proxy(procedureClient, { get(target, key) {
|
|
17
|
+
if (typeof key !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(key)) return Reflect.get(target, key);
|
|
18
|
+
return createORPCClient(link, {
|
|
19
|
+
...options,
|
|
20
|
+
path: [...path, key]
|
|
21
|
+
});
|
|
22
|
+
} });
|
|
23
|
+
return preventNativeAwait(recursive);
|
|
24
|
+
}
|
|
25
|
+
// ../../node_modules/.pnpm/@orpc+client@1.16.1_@opentelemetry+api@1.10.0/node_modules/@orpc/client/dist/adapters/fetch/index.mjs
|
|
26
|
+
var CompositeLinkFetchPlugin = class extends CompositeStandardLinkPlugin {
|
|
27
|
+
initRuntimeAdapter(options) {
|
|
28
|
+
for (const plugin of this.plugins) plugin.initRuntimeAdapter?.(options);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
var LinkFetchClient = class {
|
|
32
|
+
fetch;
|
|
33
|
+
toFetchRequestOptions;
|
|
34
|
+
adapterInterceptors;
|
|
35
|
+
constructor(options) {
|
|
36
|
+
new CompositeLinkFetchPlugin(options.plugins).initRuntimeAdapter(options);
|
|
37
|
+
this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
38
|
+
this.toFetchRequestOptions = options;
|
|
39
|
+
this.adapterInterceptors = toArray(options.adapterInterceptors);
|
|
40
|
+
}
|
|
41
|
+
async call(standardRequest, options, path, input) {
|
|
42
|
+
const request = toFetchRequest(standardRequest, this.toFetchRequestOptions);
|
|
43
|
+
const fetchResponse = await intercept(this.adapterInterceptors, {
|
|
44
|
+
...options,
|
|
45
|
+
request,
|
|
46
|
+
path,
|
|
47
|
+
input,
|
|
48
|
+
init: { redirect: "manual" }
|
|
49
|
+
}, ({ request: request2, path: path2, input: input2, init, ...options2 }) => this.fetch(request2, init, options2, path2, input2));
|
|
50
|
+
return toStandardLazyResponse(fetchResponse, { signal: request.signal });
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var RPCLink = class extends StandardRPCLink {
|
|
54
|
+
constructor(options) {
|
|
55
|
+
const linkClient = new LinkFetchClient(options);
|
|
56
|
+
super(linkClient, options);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
// src/control.ts
|
|
60
|
+
/** Why a `kiteline` command can't reach the Kiteline that should be running, in words to act on. */
|
|
61
|
+
var Unreachable = class extends Error {};
|
|
62
|
+
async function status(url, key) {
|
|
63
|
+
try {
|
|
64
|
+
const response = await fetch(`${url}/auth/status`, {
|
|
65
|
+
headers: key ? { authorization: `Bearer ${key}` } : {},
|
|
66
|
+
signal: AbortSignal.timeout(2500)
|
|
67
|
+
});
|
|
68
|
+
return response.ok ? await response.json() : null;
|
|
69
|
+
} catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The Kiteline running on this computer, for the `kiteline` commands: found at the address it saved
|
|
75
|
+
* when it started, and let in with the computer's key, which only this user can read.
|
|
76
|
+
*/
|
|
77
|
+
async function connectToKiteline() {
|
|
78
|
+
loadOwnEnvFile();
|
|
79
|
+
const home = kitelineHome(process.env.KITELINE_HOME?.trim() || void 0);
|
|
80
|
+
const info = readServerInfo(home);
|
|
81
|
+
const key = readComputerKey(home);
|
|
82
|
+
if (info && key) {
|
|
83
|
+
const answer = await status(info.local, key);
|
|
84
|
+
if (answer?.authed) return {
|
|
85
|
+
client: createORPCClient(new RPCLink({
|
|
86
|
+
url: `${info.local}/rpc`,
|
|
87
|
+
headers: { authorization: `Bearer ${key}` }
|
|
88
|
+
})),
|
|
89
|
+
info
|
|
90
|
+
};
|
|
91
|
+
if (answer) throw new Unreachable("The Kiteline that's running didn't accept this command. Run it as the same user Kiteline runs as, with the same KITELINE_HOME.");
|
|
92
|
+
}
|
|
93
|
+
let guess = "http://127.0.0.1:4545";
|
|
94
|
+
try {
|
|
95
|
+
const settings = readSettings();
|
|
96
|
+
guess = localAddress(settings.port, settings.host);
|
|
97
|
+
} catch {}
|
|
98
|
+
if (await status(guess)) throw new Unreachable(`The Kiteline that's running is older than this command. Restart it, then try again${process.platform === "linux" ? `; in the background, that's ${bold("systemctl --user restart kiteline")}` : ""}.`);
|
|
99
|
+
throw new Unreachable(`Kiteline isn't running. Start it with ${bold(command("start"))}, or keep it running with ${bold("kiteline service install")}.`);
|
|
100
|
+
}
|
|
101
|
+
export { connectToKiteline as n, Unreachable as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as Unreachable, n as connectToKiteline } from "./control-BEq2N-wP.mjs";
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { f as command, i as dim, r as bold, t as accent, u as spaced } from "./banner-C1Jj4n4W.mjs";
|
|
2
|
+
import { n as connectToKiteline, t as Unreachable } from "./control-BEq2N-wP.mjs";
|
|
3
|
+
import { createInterface } from "node:readline/promises";
|
|
4
|
+
// src/devices-command.ts
|
|
5
|
+
const say = (...lines) => console.log(["", ...lines.map((line) => line ? ` ${line}` : "")].join("\n"));
|
|
6
|
+
function ago(iso) {
|
|
7
|
+
const minutes = Math.round((Date.now() - new Date(iso).getTime()) / 6e4);
|
|
8
|
+
if (minutes < 1) return "just now";
|
|
9
|
+
if (minutes < 60) return `${minutes} min ago`;
|
|
10
|
+
const hours = Math.round(minutes / 60);
|
|
11
|
+
if (hours < 24) return `${hours} hour${hours === 1 ? "" : "s"} ago`;
|
|
12
|
+
const days = Math.round(hours / 24);
|
|
13
|
+
return days < 30 ? `${days} day${days === 1 ? "" : "s"} ago` : new Date(iso).toLocaleDateString();
|
|
14
|
+
}
|
|
15
|
+
const day = (iso) => new Date(iso).toLocaleDateString(void 0, {
|
|
16
|
+
day: "numeric",
|
|
17
|
+
month: "short"
|
|
18
|
+
});
|
|
19
|
+
/** Enough of the id to pick a device by, like a short git hash. */
|
|
20
|
+
const shortId = (id) => id.slice(0, 6);
|
|
21
|
+
function seen(device) {
|
|
22
|
+
if (device.active) return "active now";
|
|
23
|
+
return device.lastSeen ? `seen ${ago(device.lastSeen)}` : "never connected";
|
|
24
|
+
}
|
|
25
|
+
/** A device by its id, the start of its id, or its name. */
|
|
26
|
+
function find(devices, target) {
|
|
27
|
+
const wanted = target.trim().toLowerCase();
|
|
28
|
+
const byId = devices.filter((d) => d.id === target || wanted.length >= 4 && d.id.toLowerCase().startsWith(wanted));
|
|
29
|
+
if (byId.length) return byId;
|
|
30
|
+
const byName = devices.filter((d) => d.name.toLowerCase() === wanted);
|
|
31
|
+
return byName.length ? byName : devices.filter((d) => d.name.toLowerCase().includes(wanted));
|
|
32
|
+
}
|
|
33
|
+
function fail(message) {
|
|
34
|
+
throw new Unreachable(message);
|
|
35
|
+
}
|
|
36
|
+
/** `kiteline devices`: what's paired with this computer, and taking one away. */
|
|
37
|
+
async function devicesCommand(action, target, options) {
|
|
38
|
+
const { client } = await connectToKiteline();
|
|
39
|
+
const { devices, requests } = await client.devices.list();
|
|
40
|
+
if (action === void 0 || action === "list") {
|
|
41
|
+
if (!devices.length) {
|
|
42
|
+
say(`${accent("◆")} No devices are paired with this computer.`, "", `Pair one with ${bold(command("pair"))}.`, "");
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const nameWidth = Math.max(...devices.map((d) => d.name.length));
|
|
46
|
+
const seenWidth = Math.max(...devices.map((d) => seen(d).length));
|
|
47
|
+
say(`${accent("◆")} ${devices.length === 1 ? "One device is" : `${devices.length} devices are`} paired with this computer`, "", ...devices.map((d) => ` ${d.name.padEnd(nameWidth)} ${dim(seen(d).padEnd(seenWidth))} ${dim(`${d.via === "relay" ? "relay " : "direct"} paired ${day(d.pairedAt)}`)} ${dim(shortId(d.id))}`), ...requests.length ? [
|
|
48
|
+
"",
|
|
49
|
+
"Waiting to pair:",
|
|
50
|
+
...requests.map((r) => ` ${r.name} ${dim(`its screen shows ${spaced(r.match)}, asked ${ago(r.requestedAt)}`)}`)
|
|
51
|
+
] : [], "", dim(`Remove one with ${command("devices")} remove <name or id>; ${command("pair")} adds one.`), "");
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (action !== "remove" && action !== "rm") fail(`"${command("devices")} ${action}" isn't a thing. Try ${command("devices")}, or ${command("devices")} remove <name or id>.`);
|
|
55
|
+
if (options.all) {
|
|
56
|
+
if (!devices.length) return say("No devices are paired, so there's nothing to remove.", "");
|
|
57
|
+
if (process.stdin.isTTY && process.stdout.isTTY) {
|
|
58
|
+
const rl = createInterface({
|
|
59
|
+
input: process.stdin,
|
|
60
|
+
output: process.stdout
|
|
61
|
+
});
|
|
62
|
+
if (!(await rl.question(`\n Remove all ${devices.length} devices? Each would have to pair again. ${dim("y or n")} `).finally(() => rl.close())).trim().toLowerCase().startsWith("y")) return say("Nothing was removed.", "");
|
|
63
|
+
}
|
|
64
|
+
for (const device of devices) await client.devices.remove({ id: device.id });
|
|
65
|
+
return say(`${accent("◆")} Removed every device. Pair one again with ${bold(command("pair"))}.`, "");
|
|
66
|
+
}
|
|
67
|
+
if (!target) fail(`Say which device: ${command("devices")} remove <name or id>, or --all for every one.`);
|
|
68
|
+
const matches = find(devices, target);
|
|
69
|
+
if (!matches.length) fail(`No paired device matches "${target}". See them with ${command("devices")}.`);
|
|
70
|
+
if (matches.length > 1) fail(`More than one device matches "${target}": ${matches.map((d) => `${d.name} (${shortId(d.id)})`).join(", ")}. Use its id.`);
|
|
71
|
+
const [device] = matches;
|
|
72
|
+
if (!device) return;
|
|
73
|
+
await client.devices.remove({ id: device.id });
|
|
74
|
+
say(`${accent("◆")} Removed ${bold(device.name)}. It can't reach this computer any more.`, dim(`To use it again, pair it again with ${command("pair")}.`), "");
|
|
75
|
+
}
|
|
76
|
+
export { devicesCommand };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { c as printPairingCode, f as command, i as dim, r as bold, t as accent, u as spaced } from "./banner-C1Jj4n4W.mjs";
|
|
2
|
+
import { n as connectToKiteline } from "./control-BEq2N-wP.mjs";
|
|
3
|
+
import { createInterface } from "node:readline/promises";
|
|
4
|
+
// src/pair-command.ts
|
|
5
|
+
const say = (...lines) => console.log(lines.map((line) => line ? ` ${line}` : "").join("\n"));
|
|
6
|
+
const errorText = (error) => error instanceof Error ? error.message : String(error);
|
|
7
|
+
/**
|
|
8
|
+
* `kiteline pair`: a fresh one-time code from the Kiteline that's running, and then, when a device
|
|
9
|
+
* uses it, the question of whether to let it in. Says whether a device was paired.
|
|
10
|
+
*/
|
|
11
|
+
async function pairCommand() {
|
|
12
|
+
const { client } = await connectToKiteline();
|
|
13
|
+
const code = await client.devices.code();
|
|
14
|
+
printPairingCode(code);
|
|
15
|
+
const interactive = !!process.stdin.isTTY && !!process.stdout.isTTY;
|
|
16
|
+
say(dim(interactive ? "Waiting for a phone to use it. Ctrl C stops." : "Waiting for a phone to use it."), "");
|
|
17
|
+
const watching = new AbortController();
|
|
18
|
+
let rl = null;
|
|
19
|
+
let question = null;
|
|
20
|
+
let mine = null;
|
|
21
|
+
/** Answered here: the request leaving the list is this answer, not someone else's. */
|
|
22
|
+
let answering = false;
|
|
23
|
+
let done = false;
|
|
24
|
+
return new Promise((resolve) => {
|
|
25
|
+
const finish = (paired, ...lines) => {
|
|
26
|
+
if (done) return;
|
|
27
|
+
done = true;
|
|
28
|
+
if (lines.length) say(...lines, "");
|
|
29
|
+
clearTimeout(deadline);
|
|
30
|
+
process.off("SIGINT", onSignal);
|
|
31
|
+
question?.abort();
|
|
32
|
+
rl?.close();
|
|
33
|
+
watching.abort();
|
|
34
|
+
resolve(paired);
|
|
35
|
+
};
|
|
36
|
+
const onSignal = () => {
|
|
37
|
+
console.log();
|
|
38
|
+
if (mine) return finish(false);
|
|
39
|
+
const cancelled = client.devices.cancelCode({ id: code.id }).catch(() => {});
|
|
40
|
+
const patience = new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
41
|
+
Promise.race([cancelled, patience]).then(() => finish(false));
|
|
42
|
+
};
|
|
43
|
+
process.on("SIGINT", onSignal);
|
|
44
|
+
let deadline = setTimeout(() => finish(false, `Nobody used the code in time. Run ${bold(command("pair"))} for a new one.`), code.expiresAt - Date.now() + 1e3);
|
|
45
|
+
const ask = async (request) => {
|
|
46
|
+
say(`${accent("◆")} ${bold(request.name)} wants to pair${request.via === "relay" ? ", through the relay" : ""}.`, ` Allow it only if it's yours and its screen shows ${bold(spaced(request.match))}.`);
|
|
47
|
+
if (!interactive) {
|
|
48
|
+
say(dim(" Allow it on a device that's already paired."), "");
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
rl = createInterface({
|
|
52
|
+
input: process.stdin,
|
|
53
|
+
output: process.stdout
|
|
54
|
+
});
|
|
55
|
+
rl.on("SIGINT", onSignal);
|
|
56
|
+
question = new AbortController();
|
|
57
|
+
for (;;) {
|
|
58
|
+
let answer;
|
|
59
|
+
try {
|
|
60
|
+
answer = (await rl.question(` Allow it? ${dim("y or n")} `, { signal: question.signal })).trim().toLowerCase();
|
|
61
|
+
} catch {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (![
|
|
65
|
+
"y",
|
|
66
|
+
"yes",
|
|
67
|
+
"n",
|
|
68
|
+
"no"
|
|
69
|
+
].includes(answer)) continue;
|
|
70
|
+
const allow = answer.startsWith("y");
|
|
71
|
+
answering = true;
|
|
72
|
+
try {
|
|
73
|
+
await client.devices.decide({
|
|
74
|
+
id: request.id,
|
|
75
|
+
allow
|
|
76
|
+
});
|
|
77
|
+
finish(allow, "", allow ? `${accent("◆")} Paired ${bold(request.name)}. See every device with ${bold(command("devices"))}.` : `Declined ${request.name}. It isn't paired.`);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
finish(false, "", errorText(error));
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
(async () => {
|
|
85
|
+
try {
|
|
86
|
+
const stream = await client.devices.watch(void 0, { signal: watching.signal });
|
|
87
|
+
for await (const snapshot of stream) {
|
|
88
|
+
const request = snapshot.requests.find((r) => r.code === code.id);
|
|
89
|
+
if (request && !mine) {
|
|
90
|
+
mine = request;
|
|
91
|
+
clearTimeout(deadline);
|
|
92
|
+
deadline = setTimeout(() => finish(false, "", `${request.name} waited too long. Run ${bold(command("pair"))} again.`), request.expiresAt - Date.now() + 2e3);
|
|
93
|
+
ask(request);
|
|
94
|
+
} else if (!request && mine && !answering) {
|
|
95
|
+
const asked = mine;
|
|
96
|
+
const paired = snapshot.devices.some((d) => d.name === asked.name && Date.parse(d.pairedAt) >= asked.requestedAt);
|
|
97
|
+
finish(paired, "", paired ? `${accent("◆")} ${bold(asked.name)} was allowed on another device.` : `${asked.name} isn't paired: it was declined, or stopped asking.`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
finish(false, "Kiteline stopped.");
|
|
101
|
+
} catch (error) {
|
|
102
|
+
if (!done) finish(false, `Lost Kiteline: ${errorText(error)}`);
|
|
103
|
+
}
|
|
104
|
+
})();
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
export { pairCommand };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { t as showPairing } from "./show-pairing-jhFEXWi7.mjs";
|
|
4
|
-
import { copyFileSync, existsSync, mkdirSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { a as localAddress, r as kitelineHome } from "./auth-CYNu-f_h.mjs";
|
|
2
|
+
import { d as SettingsError, i as dim, m as readSettings, r as bold, t as accent } from "./banner-C1Jj4n4W.mjs";
|
|
5
3
|
import { homedir, userInfo } from "node:os";
|
|
4
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
6
5
|
import { delimiter, dirname, join } from "node:path";
|
|
7
6
|
import { spawnSync } from "node:child_process";
|
|
8
7
|
// src/service.ts
|
|
@@ -12,11 +11,12 @@ import { spawnSync } from "node:child_process";
|
|
|
12
11
|
*/
|
|
13
12
|
const NAME = process.env.KITELINE_SERVICE_NAME?.trim() || "kiteline";
|
|
14
13
|
const MARK = "# Written by `kiteline service install`. Run it again to change these settings.";
|
|
15
|
-
/** The settings worth keeping in the service, when they're set now. Never
|
|
14
|
+
/** The settings worth keeping in the service, when they're set now. Never a key. */
|
|
16
15
|
const KEPT = [
|
|
17
16
|
"PORT",
|
|
18
17
|
"HOST",
|
|
19
18
|
"KITELINE_PUBLIC_URL",
|
|
19
|
+
"KITELINE_RELAY",
|
|
20
20
|
"KITELINE_HOME",
|
|
21
21
|
"CLAUDE_PATH",
|
|
22
22
|
"KITELINE_ALLOW_BYPASS",
|
|
@@ -88,16 +88,6 @@ TimeoutStopSec=15
|
|
|
88
88
|
WantedBy=default.target
|
|
89
89
|
`;
|
|
90
90
|
}
|
|
91
|
-
/** Where the service would answer, to check it came up (or that something else holds the port). */
|
|
92
|
-
function localAddress(port, host) {
|
|
93
|
-
return `http://${[
|
|
94
|
-
"0.0.0.0",
|
|
95
|
-
"::",
|
|
96
|
-
"127.0.0.1",
|
|
97
|
-
"localhost",
|
|
98
|
-
""
|
|
99
|
-
].includes(host) ? "127.0.0.1" : host.includes(":") ? `[${host}]` : host}:${port}`;
|
|
100
|
-
}
|
|
101
91
|
async function answers(url) {
|
|
102
92
|
return fetch(`${url}/auth/status`, { signal: AbortSignal.timeout(1500) }).then((r) => r.ok).catch(() => false);
|
|
103
93
|
}
|
|
@@ -113,7 +103,6 @@ async function install({ force }) {
|
|
|
113
103
|
if (!(error instanceof SettingsError)) throw error;
|
|
114
104
|
fail(error.message);
|
|
115
105
|
}
|
|
116
|
-
if (process.env.KITELINE_TOKEN?.trim()) say(dim("KITELINE_TOKEN stays out of the service file, where it could be read; the service makes its own."));
|
|
117
106
|
const file = unitFile();
|
|
118
107
|
const existing = existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
119
108
|
if (existing !== null && !existing.includes(MARK) && !force) fail(`There's already a ${NAME} service, set up by hand:`, dim(file), `Run ${bold("kiteline service install --force")} to replace it; the old file is kept beside it as .bak.`);
|
|
@@ -122,8 +111,8 @@ async function install({ force }) {
|
|
|
122
111
|
mkdirSync(dirname(file), { recursive: true });
|
|
123
112
|
if (existing !== null && !existing.includes(MARK)) copyFileSync(file, `${file}.bak`);
|
|
124
113
|
writeFileSync(file, unitText(process.execPath, script));
|
|
125
|
-
const
|
|
126
|
-
const before = existsSync(
|
|
114
|
+
const serverFile = join(kitelineHome(settings.home), "server.json");
|
|
115
|
+
const before = existsSync(serverFile) ? statSync(serverFile).mtimeMs : 0;
|
|
127
116
|
for (const step of [
|
|
128
117
|
["daemon-reload"],
|
|
129
118
|
["enable", NAME],
|
|
@@ -150,11 +139,17 @@ async function install({ force }) {
|
|
|
150
139
|
let up = false;
|
|
151
140
|
for (let i = 0; i < 40 && !up; i++) {
|
|
152
141
|
await sleep(250);
|
|
153
|
-
up = existsSync(
|
|
142
|
+
up = existsSync(serverFile) && statSync(serverFile).mtimeMs > before && await answers(url);
|
|
154
143
|
}
|
|
155
144
|
if (!up) fail("The service is set up, but Kiteline didn't come up. See what it said with:", "", ` ${accent(`journalctl --user -u ${NAME} -n 40`)}`);
|
|
156
|
-
|
|
157
|
-
|
|
145
|
+
say(`${bold("Kiteline runs in the background now.")} It starts with your computer and restarts if it stops.`, "", row("See what it's doing", `journalctl --user -u ${NAME} -f`), row("Pair a phone", "kiteline pair"), row("See paired devices", "kiteline devices"), row("Change its settings", "kiteline service install, with the new options"), row("Stop running it", "kiteline service uninstall"), ...lingerNote ? ["", lingerNote] : []);
|
|
146
|
+
const { connectToKiteline } = await import("./control-BpOGsRCZ.mjs");
|
|
147
|
+
const { client } = await connectToKiteline();
|
|
148
|
+
const { devices } = await client.devices.list();
|
|
149
|
+
if (!devices.length && process.stdin.isTTY && process.stdout.isTTY) {
|
|
150
|
+
const { pairCommand } = await import("./pair-command-DBxw6BfK.mjs");
|
|
151
|
+
await pairCommand();
|
|
152
|
+
}
|
|
158
153
|
}
|
|
159
154
|
function uninstall({ force }) {
|
|
160
155
|
requireSystemd();
|
|
@@ -177,7 +172,7 @@ function status() {
|
|
|
177
172
|
return;
|
|
178
173
|
}
|
|
179
174
|
const state = systemctl("is-active", NAME).stdout.trim();
|
|
180
|
-
say(state === "active" ? `${bold("Kiteline is running in the background.")}` : `${bold(`The ${NAME} service is set up, but it's ${state || "not running"}.`)}`, dim(file), "", row("See what it's doing", `journalctl --user -u ${NAME} -f`), row("
|
|
175
|
+
say(state === "active" ? `${bold("Kiteline is running in the background.")}` : `${bold(`The ${NAME} service is set up, but it's ${state || "not running"}.`)}`, dim(file), "", row("See what it's doing", `journalctl --user -u ${NAME} -f`), row("Pair a phone", "kiteline pair"), row("See paired devices", "kiteline devices"), row("Stop running it", "kiteline service uninstall"));
|
|
181
176
|
}
|
|
182
177
|
async function service(action, options) {
|
|
183
178
|
switch (action) {
|