@bom0792/herdgate 0.9.12 → 0.9.14
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/app-mod/herdgate/main.js +18 -12
- package/bin/herdgate.mjs +38 -20
- package/package.json +1 -1
- package/src/web/herdgate-host.zip +0 -0
package/app-mod/herdgate/main.js
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
|
|
22
22
|
import { View, div } from "gpui-kit";
|
|
23
23
|
import { v_flex, h_flex, InputState, Input } from "gpui-base";
|
|
24
|
-
import { exec, appHome, readTextFile, notify, theme, props,
|
|
24
|
+
import { exec, appHome, readTextFile, notify, theme, props, window } from "herdr";
|
|
25
25
|
|
|
26
26
|
const BASE = `${appHome()}/herdgate`;
|
|
27
27
|
const SETTINGS = `${BASE}/settings.json`;
|
|
@@ -84,22 +84,15 @@ export default class Herdgate extends View {
|
|
|
84
84
|
this.busy = { pair: false, publish: false, approve: false, save: false };
|
|
85
85
|
this.notified = false;
|
|
86
86
|
|
|
87
|
+
this.isWindows = false;
|
|
88
|
+
try { this.isWindows = window()?.platform === "windows"; } catch { /* window() unavailable this early */ }
|
|
89
|
+
|
|
87
90
|
this.cloudInput = InputState.new({ placeholder: "https://herd.example.com" });
|
|
88
91
|
this.rootInput = InputState.new({ placeholder: "set by `npx @bom0792/herdgate setup-host`" });
|
|
89
92
|
this.nameInput = InputState.new({ placeholder: "this-machine" });
|
|
90
93
|
this.tokenInput = InputState.new({ placeholder: "account token — only for approving other machines" });
|
|
91
94
|
this.codeInput = InputState.new({ placeholder: "the code its panel shows" });
|
|
92
95
|
|
|
93
|
-
// The shipped tabs mod renders its panel buttons from shared("workspace.panels")
|
|
94
|
-
// (the welcome may have fixed it to ["files","changes"] — the layout clone's new
|
|
95
|
-
// default never applies then). Self-heal: join the list once, keeping whatever
|
|
96
|
-
// the person chose.
|
|
97
|
-
{
|
|
98
|
-
const panels = shared("workspace.panels");
|
|
99
|
-
const list = Array.isArray(panels) ? panels : ["files", "changes"];
|
|
100
|
-
if (!list.includes("herdgate")) setShared("workspace.panels", [...list, "herdgate"]);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
96
|
cx.spawn(async (cx) => {
|
|
104
97
|
await this.load();
|
|
105
98
|
cx.notify();
|
|
@@ -280,6 +273,12 @@ export default class Herdgate extends View {
|
|
|
280
273
|
}
|
|
281
274
|
|
|
282
275
|
startPublisher(cx) {
|
|
276
|
+
if (this.isWindows) {
|
|
277
|
+
this.phase = "error";
|
|
278
|
+
this.message = "publishing this machine needs Linux/macOS for now (Windows host is coming) — pairing and approving below still work";
|
|
279
|
+
cx.notify();
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
283
282
|
if (!this.paired) {
|
|
284
283
|
this.phase = "error";
|
|
285
284
|
this.message = "pair this machine first";
|
|
@@ -324,6 +323,12 @@ export default class Herdgate extends View {
|
|
|
324
323
|
}
|
|
325
324
|
|
|
326
325
|
stopPublisher(cx) {
|
|
326
|
+
if (this.isWindows) {
|
|
327
|
+
this.phase = "error";
|
|
328
|
+
this.message = "no publisher can be running here (Windows host is coming)";
|
|
329
|
+
cx.notify();
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
327
332
|
this.busy.publish = true;
|
|
328
333
|
cx.spawn(async (cx) => {
|
|
329
334
|
if (this.publisher.pid) await sh('kill "$1" 2>/dev/null; true', [String(this.publisher.pid)]);
|
|
@@ -406,6 +411,7 @@ export default class Herdgate extends View {
|
|
|
406
411
|
),
|
|
407
412
|
)
|
|
408
413
|
.child(section("THIS MACHINE"))
|
|
414
|
+
.when(this.isWindows, (el) => el.child(div().text_size(10).text_color(t.dim).child("this machine can pair and approve others; publishing it needs Linux/macOS for now")))
|
|
409
415
|
.child(this.pairingBlock(t, cx))
|
|
410
416
|
.child(section("ADD ANOTHER MACHINE"))
|
|
411
417
|
.child(this.approveBlock(t, cx))
|
|
@@ -450,7 +456,7 @@ export default class Herdgate extends View {
|
|
|
450
456
|
return v_flex()
|
|
451
457
|
.id("hg-approve")
|
|
452
458
|
.gap(5)
|
|
453
|
-
.child(div().text_size(10.5).text_color(t.dim).child("
|
|
459
|
+
.child(div().text_size(10.5).text_color(t.dim).child("want another machine in the herd? on IT: npx @bom0792/herdgate setup-host → its herdgate panel → Pair — it shows a code. type that code here:"))
|
|
454
460
|
.child(
|
|
455
461
|
h_flex()
|
|
456
462
|
.gap(6)
|
package/bin/herdgate.mjs
CHANGED
|
@@ -101,6 +101,20 @@ function do_(args) {
|
|
|
101
101
|
return { ok: r.status === 0, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
/** A clone the app rejects (version drift, a broken older patch) must never stay:
|
|
105
|
+
* verify, and on failure rebuild from the shipped mod and re-patch once. */
|
|
106
|
+
function verifyTabs(home, live) {
|
|
107
|
+
const dir = join(home, "mods", "tabs-herdgate");
|
|
108
|
+
const main = join(dir, "main.js");
|
|
109
|
+
if (!existsSync(main)) return false;
|
|
110
|
+
if (live) {
|
|
111
|
+
const r = spawnSync("herdr-app", ["check", dir], { encoding: "utf8" });
|
|
112
|
+
return r.status === 0 && !/failed|error/i.test(`${r.stdout}${r.stderr}`);
|
|
113
|
+
}
|
|
114
|
+
const r = spawnSync(process.execPath, ["--check", main], { encoding: "utf8" });
|
|
115
|
+
return r.status === 0;
|
|
116
|
+
}
|
|
117
|
+
|
|
104
118
|
function integrate(home) {
|
|
105
119
|
const probe = spawnSync("herdr-app", ["status"], { encoding: "utf8" });
|
|
106
120
|
const live = probe.status === 0;
|
|
@@ -108,6 +122,10 @@ function integrate(home) {
|
|
|
108
122
|
// registers the clone). Offline: shipped mods are plain files — copy them; a
|
|
109
123
|
// closed app reads the folder at start.
|
|
110
124
|
let tabs = join(home, "mods", "tabs-herdgate", "main.js");
|
|
125
|
+
if (existsSync(tabs) && !verifyTabs(home, live)) {
|
|
126
|
+
console.log("herdgate: the existing tabs-herdgate does not load — rebuilding it from the shipped tabs mod");
|
|
127
|
+
cpSync(join(home, "mods", "tabs"), join(home, "mods", "tabs-herdgate"), { recursive: true });
|
|
128
|
+
}
|
|
111
129
|
if (!existsSync(tabs)) {
|
|
112
130
|
let ok = false;
|
|
113
131
|
if (live) ok = do_(["mod.clone", JSON.stringify({ name: "tabs", as: "tabs-herdgate" })]).ok;
|
|
@@ -119,30 +137,30 @@ function integrate(home) {
|
|
|
119
137
|
const btn = `.when(enabled.includes("herdgate"), el => el.child(panelButton("herdgate", "herdgate", "mods/herdgate/herdgate.svg")))`;
|
|
120
138
|
let changed = false;
|
|
121
139
|
if (src.includes(anchor) && !src.includes(btn)) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
console.log("herdgate: tabs mod anchors not found (Herdr version drift?) — button not added, pane.split still works");
|
|
126
|
-
}
|
|
127
|
-
// Independent of the button: the tab bar always loads, so IT self-heals the panel
|
|
128
|
-
// list — if the welcome fixed workspace.panels without us, join it (converges in
|
|
129
|
-
// one re-render). Machines patched by older installers lack this; re-running adds it.
|
|
130
|
-
if (!src.includes("setShared(\"workspace.panels\")")) {
|
|
131
|
-
const heal = `const __panels = shared("workspace.panels");
|
|
132
|
-
if (!Array.isArray(__panels) || !__panels.includes("herdgate"))
|
|
133
|
-
setShared("workspace.panels", [...(Array.isArray(__panels) ? __panels : ["files", "changes"]), "herdgate"]);
|
|
134
|
-
const enabled = shared("workspace.panels") ?? ["files", "changes"];`;
|
|
135
|
-
// 0.9.7-patched clones carry the herdgate variant of the enabled default.
|
|
136
|
-
const before = src;
|
|
137
|
-
src = src.replace(`const enabled = shared("workspace.panels") ?? ["files", "changes"];`, heal);
|
|
138
|
-
if (src === before) src = src.replace(`const enabled = shared("workspace.panels") ?? ["files", "changes", "herdgate"];`, heal);
|
|
140
|
+
// Unconditional .child — no shared("workspace.panels") gate, no new imports:
|
|
141
|
+
// the button exists on every Herdr version (older apps may lack setShared).
|
|
142
|
+
src = src.replace(anchor, `${anchor}\n .child(panelButton("herdgate", "herdgate", "mods/herdgate/herdgate.svg"))`);
|
|
139
143
|
src = src.replace(
|
|
140
|
-
`
|
|
141
|
-
`
|
|
144
|
+
`const enabled = shared("workspace.panels") ?? ["files", "changes"];`,
|
|
145
|
+
`const enabled = shared("workspace.panels") ?? ["files", "changes", "herdgate"];`,
|
|
142
146
|
);
|
|
143
147
|
changed = true;
|
|
148
|
+
} else if (!src.includes(btn) && !src.includes('panelButton("herdgate"')) {
|
|
149
|
+
console.log("herdgate: tabs mod anchors not found (Herdr version drift?) — button not added, pane.split still works");
|
|
150
|
+
}
|
|
151
|
+
if (changed) writeFileSync(tabs, src);
|
|
152
|
+
if (changed && !verifyTabs(home, live)) {
|
|
153
|
+
console.log("herdgate: the patched tabs clone does not load — retrying from a fresh copy");
|
|
154
|
+
cpSync(join(home, "mods", "tabs"), join(home, "mods", "tabs-herdgate"), { recursive: true });
|
|
155
|
+
const fresh = readFileSync(tabs, "utf8");
|
|
156
|
+
if (fresh.includes(anchor)) {
|
|
157
|
+
writeFileSync(tabs, fresh.replace(anchor, `${anchor}\n .child(panelButton("herdgate", "herdgate", "mods/herdgate/herdgate.svg"))`));
|
|
158
|
+
}
|
|
159
|
+
if (!verifyTabs(home, live)) {
|
|
160
|
+
console.log("herdgate: still no — restoring the shipped tabs mod untouched (button not added; pane.split still works)");
|
|
161
|
+
cpSync(join(home, "mods", "tabs"), join(home, "mods", "tabs-herdgate"), { recursive: true });
|
|
162
|
+
}
|
|
144
163
|
}
|
|
145
|
-
if (changed) writeFileSync(tabs, src);
|
|
146
164
|
|
|
147
165
|
// 2. clone the main layout, seat herdgate in panel-body, point the tab bar at the clone.
|
|
148
166
|
const layoutPath = join(home, "layouts", "herdgate-main.json");
|
package/package.json
CHANGED
|
Binary file
|