@bom0792/herdgate 0.9.7 → 0.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app-mod/herdgate/main.js +10 -1
- package/bin/herdgate.mjs +51 -14
- package/package.json +1 -1
- package/src/web/app.js +28 -1
- package/src/web/herdgate-host.zip +0 -0
- package/src/web/index.html +6 -0
- package/src/web/sw.js +1 -1
package/app-mod/herdgate/main.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
import { View, div } from "gpui-kit";
|
|
22
22
|
import { v_flex, h_flex, InputState, Input } from "gpui-base";
|
|
23
|
-
import { exec, appHome, readTextFile, notify, theme, props } from "herdr";
|
|
23
|
+
import { exec, appHome, readTextFile, notify, theme, props, shared, setShared } from "herdr";
|
|
24
24
|
|
|
25
25
|
const BASE = `${appHome()}/herdgate`;
|
|
26
26
|
const SETTINGS = `${BASE}/settings.json`;
|
|
@@ -71,6 +71,15 @@ async function readJson(path) {
|
|
|
71
71
|
export default class Herdgate extends View {
|
|
72
72
|
init(_props, cx) {
|
|
73
73
|
this.h = cx.focus_handle();
|
|
74
|
+
// The shipped tabs mod renders its panel buttons from shared("workspace.panels")
|
|
75
|
+
// (the welcome may have fixed it to ["files","changes"] — the layout clone's new
|
|
76
|
+
// default never applies then). Self-heal: join the list once, keeping whatever
|
|
77
|
+
// the person chose.
|
|
78
|
+
{
|
|
79
|
+
const panels = shared("workspace.panels");
|
|
80
|
+
const list = Array.isArray(panels) ? panels : ["files", "changes"];
|
|
81
|
+
if (!list.includes("herdgate")) setShared("workspace.panels", [...list, "herdgate"]);
|
|
82
|
+
}
|
|
74
83
|
this.settings = { cloud: "", root: "", name: "" };
|
|
75
84
|
this.paired = false;
|
|
76
85
|
this.cloud = "";
|
package/bin/herdgate.mjs
CHANGED
|
@@ -102,32 +102,55 @@ function do_(args) {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
function integrate(home) {
|
|
105
|
-
const probe = spawnSync("herdr-app", ["status"], { encoding: "utf8" });
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
//
|
|
105
|
+
const probe = spawnSync("herdr-app", ["status"], { encoding: "utf8" });
|
|
106
|
+
const live = probe.status === 0;
|
|
107
|
+
// 1. clone the tabs mod and add our button. Live: the app's own command (it also
|
|
108
|
+
// registers the clone). Offline: shipped mods are plain files — copy them; a
|
|
109
|
+
// closed app reads the folder at start.
|
|
110
110
|
let tabs = join(home, "mods", "tabs-herdgate", "main.js");
|
|
111
111
|
if (!existsSync(tabs)) {
|
|
112
|
-
|
|
113
|
-
if (
|
|
112
|
+
let ok = false;
|
|
113
|
+
if (live) ok = do_(["mod.clone", JSON.stringify({ name: "tabs", as: "tabs-herdgate" })]).ok;
|
|
114
|
+
if (!ok) cpSync(join(home, "mods", "tabs"), join(home, "mods", "tabs-herdgate"), { recursive: true });
|
|
115
|
+
if (!existsSync(tabs)) return console.log("herdgate: could not clone the tabs mod — panel stays reachable via pane.split");
|
|
114
116
|
}
|
|
115
117
|
let src = readFileSync(tabs, "utf8");
|
|
116
118
|
const anchor = `.when(enabled.includes("changes"), el => el.child(panelButton("changes", "Changes", "mods/changes/changes.svg")))`;
|
|
117
119
|
const btn = `.when(enabled.includes("herdgate"), el => el.child(panelButton("herdgate", "herdgate", "mods/herdgate/herdgate.svg")))`;
|
|
120
|
+
let changed = false;
|
|
118
121
|
if (src.includes(anchor) && !src.includes(btn)) {
|
|
119
122
|
src = src.replace(anchor, `${anchor}\n ${btn}`);
|
|
120
|
-
|
|
121
|
-
writeFileSync(tabs, src);
|
|
123
|
+
changed = true;
|
|
122
124
|
} else if (!src.includes(btn)) {
|
|
123
125
|
console.log("herdgate: tabs mod anchors not found (Herdr version drift?) — button not added, pane.split still works");
|
|
124
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);
|
|
139
|
+
src = src.replace(
|
|
140
|
+
`import { spaces, panes, run, openOverlay, theme, window, shared, layout, settings } from "herdr";`,
|
|
141
|
+
`import { spaces, panes, run, openOverlay, theme, window, shared, setShared, layout, settings } from "herdr";`,
|
|
142
|
+
);
|
|
143
|
+
changed = true;
|
|
144
|
+
}
|
|
145
|
+
if (changed) writeFileSync(tabs, src);
|
|
125
146
|
|
|
126
147
|
// 2. clone the main layout, seat herdgate in panel-body, point the tab bar at the clone.
|
|
127
148
|
const layoutPath = join(home, "layouts", "herdgate-main.json");
|
|
128
149
|
if (!existsSync(layoutPath)) {
|
|
129
|
-
|
|
130
|
-
if (
|
|
150
|
+
let ok = false;
|
|
151
|
+
if (live) ok = do_(["layout.clone", JSON.stringify({ name: "main", as: "herdgate-main" })]).ok;
|
|
152
|
+
if (!ok) cpSync(join(home, "layouts", "main.json"), layoutPath);
|
|
153
|
+
if (!existsSync(layoutPath)) return console.log("herdgate: could not create the herdgate-main layout");
|
|
131
154
|
}
|
|
132
155
|
const tree = JSON.parse(readFileSync(layoutPath, "utf8"));
|
|
133
156
|
const find = (n, id) => {
|
|
@@ -144,9 +167,23 @@ function integrate(home) {
|
|
|
144
167
|
}
|
|
145
168
|
const tabsBlock = find(tree, "tabs");
|
|
146
169
|
if (tabsBlock?.content?.mod === "tabs") tabsBlock.content.mod = "tabs-herdgate";
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
170
|
+
if (live) {
|
|
171
|
+
const set = do_(["layout.set", JSON.stringify({ layout: tree })]);
|
|
172
|
+
if (!set.ok) return console.log(`herdgate: layout.set failed (${set.out.slice(0, 120)})`);
|
|
173
|
+
do_(["layout.switch", JSON.stringify({ name: "herdgate-main" })]);
|
|
174
|
+
} else {
|
|
175
|
+
// App closed: the files are ours to write. Switch the layout and join the panel
|
|
176
|
+
// list directly (the tab-bar clone re-checks at load, this just makes it immediate).
|
|
177
|
+
writeFileSync(layoutPath, JSON.stringify(tree, null, 1) + "\n");
|
|
178
|
+
const sharedPath = join(home, "shared.json");
|
|
179
|
+
let sh = {};
|
|
180
|
+
try { sh = JSON.parse(readFileSync(sharedPath, "utf8")); } catch { /* none yet */ }
|
|
181
|
+
sh.layout = "herdgate-main";
|
|
182
|
+
const panels = Array.isArray(sh["workspace.panels"]) ? sh["workspace.panels"] : ["files", "changes"];
|
|
183
|
+
if (!panels.includes("herdgate")) panels.push("herdgate");
|
|
184
|
+
sh["workspace.panels"] = panels;
|
|
185
|
+
writeFileSync(sharedPath, JSON.stringify(sh, null, 2) + "\n");
|
|
186
|
+
}
|
|
150
187
|
console.log("herdgate: panel button added to the tab bar (layout herdgate-main) — press it any time;");
|
|
151
188
|
console.log(" the shipped layout `main` stays untouched (layout.switch main goes back).");
|
|
152
189
|
}
|
package/package.json
CHANGED
package/src/web/app.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// - the token lives in localStorage on this device and is never sent anywhere but the
|
|
12
12
|
// cloud's own WS endpoint.
|
|
13
13
|
|
|
14
|
-
const BUILD = "v0.9.
|
|
14
|
+
const BUILD = "v0.9.8";
|
|
15
15
|
|
|
16
16
|
const $ = (id) => document.getElementById(id);
|
|
17
17
|
const TOKEN_KEY = "herdgate.token";
|
|
@@ -742,6 +742,33 @@ $("signin-form").addEventListener("submit", (event) => {
|
|
|
742
742
|
connect();
|
|
743
743
|
});
|
|
744
744
|
|
|
745
|
+
// Approve a new machine: the owner types the code its herdgate panel shows.
|
|
746
|
+
$("addmachine").addEventListener("submit", async (event) => {
|
|
747
|
+
event.preventDefault();
|
|
748
|
+
const code = $("addmachine-code").value.trim();
|
|
749
|
+
const noteEl = $("addmachine-note");
|
|
750
|
+
noteEl.hidden = false;
|
|
751
|
+
noteEl.className = "muted small";
|
|
752
|
+
noteEl.textContent = "approving…";
|
|
753
|
+
try {
|
|
754
|
+
const r = await fetch(`${cloudBase()}/v1/agent/approve`, {
|
|
755
|
+
method: "POST",
|
|
756
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${state.token}` },
|
|
757
|
+
body: JSON.stringify({ code }),
|
|
758
|
+
});
|
|
759
|
+
if (!r.ok) throw new Error((await r.json().catch(() => ({}))).error ?? `HTTP ${r.status}`);
|
|
760
|
+
$("addmachine-code").value = "";
|
|
761
|
+
noteEl.textContent = "approved — the machine appears when its publisher connects";
|
|
762
|
+
// A fresh hello lists the new room (rooms come from hello).
|
|
763
|
+
state.closedByUs = true;
|
|
764
|
+
state.ws?.close();
|
|
765
|
+
connect();
|
|
766
|
+
} catch (e) {
|
|
767
|
+
noteEl.className = "error small";
|
|
768
|
+
noteEl.textContent = String(e.message ?? e);
|
|
769
|
+
}
|
|
770
|
+
});
|
|
771
|
+
|
|
745
772
|
$("menu").addEventListener("click", () => {
|
|
746
773
|
$("cloud").value = state.cloud;
|
|
747
774
|
$("settings").showModal();
|
|
Binary file
|
package/src/web/index.html
CHANGED
|
@@ -39,6 +39,12 @@
|
|
|
39
39
|
<p id="rooms-empty" class="muted" hidden>
|
|
40
40
|
No machine is paired yet. Pair one from Herdr — its plugin or app panel prints a code.
|
|
41
41
|
</p>
|
|
42
|
+
<form id="addmachine" autocomplete="off">
|
|
43
|
+
<label for="addmachine-code">Add a machine — enter the code its herdgate panel shows</label>
|
|
44
|
+
<input id="addmachine-code" type="text" inputmode="text" autocomplete="off" placeholder="pairing code" required />
|
|
45
|
+
<button type="submit">Approve</button>
|
|
46
|
+
</form>
|
|
47
|
+
<p id="addmachine-note" class="muted small" hidden></p>
|
|
42
48
|
<p id="build" class="muted small"></p>
|
|
43
49
|
</section>
|
|
44
50
|
|
package/src/web/sw.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
// Bump VERSION when a shell file changes; old caches are dropped on activate.
|
|
5
5
|
|
|
6
|
-
const VERSION = "herdgate-
|
|
6
|
+
const VERSION = "herdgate-v9";
|
|
7
7
|
const SHELL = ["/", "/app.css", "/e2e.js", "/app.js", "/app.webmanifest", "/icons/icon.svg"];
|
|
8
8
|
|
|
9
9
|
self.addEventListener("install", (event) => {
|