Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions herdr-insights/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ npm run install:local --prefix herdr-insights

The installer checks `mods/insights` before copying it to the app home, which
defaults to `$HERDR_APP_HOME` or `~/.config/herdr-app`. First install creates and
selects a personal layout whose **Insights** button sits beside the native tabs.
Reinstall updates owned files without rewriting layouts. Shipped tabs, keys, and
selects a personal layout whose **Insights** button sits beside the tab bar
(Herdr's `tabs` or a personal clone of it): after it on macOS, before it on
Windows and Linux so the bar's own window buttons stay last.
Reinstall updates owned files without rewriting layouts. To move a button placed
by an older version: uninstall, select the layout you want the button in (install
wraps whichever layout is selected), and install again. Shipped tabs, keys, and
usage data are preserved.

Success requires one `herdr-app check passed` message **and exit code 0**.
Expand Down
10 changes: 6 additions & 4 deletions herdr-insights/RECIPE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ of 1180px. Use Herdr theme colors, 1px borders, 8px card corners, 6px control
corners, no decorative shadows, and 4/8/12/16/24px spacing. Page padding is 12px
below 620px, 16px below 900px, and 24px otherwise. Support light and dark themes.

The `insights` mod's toolbar mode draws the **Insights** button after the native
The `insights` mod's toolbar mode draws the **Insights** button beside the native
tabs. Match Herdr's panel controls: 26px height, 8px horizontal padding, 5px
icon/text gap, 6px corners, 12px type, 14px theme-tinted chart icon, chrome
background, muted text, and native hover colors. Its root matches the tab bar's
Expand Down Expand Up @@ -96,9 +96,11 @@ parents; choose a numeric suffix if either the destination layout or its state
already exists. Never overwrite another layout's state, including leftover state
from uninstall. Do not edit or remove Herdr-managed click state. In the personal clone only, turn the existing `tabs`
block into a nonresizable row, keeping its ID, height, paint, and window-drag
attributes. Its first child is a weight-1 block with the original `content`
(including its props); its second is a 104px block whose content is
`{mod: "insights", props: {mode: "toolbar"}}`.
attributes. Its children are a weight-1 block with the original `content`
(including its props; any mod, so a personal clone of `tabs` works) and a 104px
block whose content is `{mod: "insights", props: {mode: "toolbar"}}`. Put the
button last on macOS and first elsewhere, where the tab bar ends with its own
minimize/maximize/close and those must stay last.
Do not copy or modify the shipped `tabs` mod. Refuse unsupported/ambiguous layouts.
Record the personal layout's name, source, and hash in `toolbar-install.json`.
Reinstall must not rewrite this layout or switch the user's selected layout.
Expand Down
16 changes: 11 additions & 5 deletions herdr-insights/scripts/toolbar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ async function command(appHome, args) {
return result.stdout;
}

/** Preserve the original tabs mod and its updates; compose one native button beside it. */
export function withInsightsToolbar(layout) {
/**
* Preserve the tab bar's mod (Herdr's `tabs` or a personal clone) and its
* updates; compose one native button beside it.
*/
export function withInsightsToolbar(layout, platform = process.platform) {
const copy = structuredClone(layout);
const nodes = [];
function walk(node) {
Expand All @@ -67,9 +70,9 @@ export function withInsightsToolbar(layout) {
if (nodes.some((node) => node.id === BUTTON_ID || node.id === "insights-original-tabs")) {
throw new Error("This layout already contains Insights toolbar blocks.");
}
const matches = nodes.filter((node) => node.id === "tabs" && node.type === "block" && node.content?.mod === "tabs");
const matches = nodes.filter((node) => node.id === "tabs" && node.type === "block" && typeof node.content?.mod === "string");
if (matches.length !== 1) {
throw new Error('Expected one native "tabs" block. This layout cannot be integrated safely.');
throw new Error('Expected one "tabs" block showing a mod. This layout cannot be integrated safely.');
}
const tabs = matches[0];
const content = tabs.content;
Expand All @@ -80,6 +83,9 @@ export function withInsightsToolbar(layout) {
{ id: "insights-original-tabs", type: "block", size: { weight: 1 }, content },
{ id: BUTTON_ID, type: "block", size: { px: 104 }, content: { mod: "insights", props: { mode: "toolbar" } } },
];
// Off macOS the tab bar ends with its own minimize/maximize/close, which must
// stay last. On macOS a leading button would sit under the traffic lights.
if (platform !== "darwin") tabs.children.reverse();
return copy;
}

Expand Down Expand Up @@ -139,7 +145,7 @@ export async function applyToolbar(plan) {
try { await command(appHome, ["do", "layout.switch", JSON.stringify({ name: source })]); } catch { /* retain original failure */ }
throw error;
}
console.log(`Added Insights beside Files/Changes in personal layout ${layout}; Herdr's tabs mod is unchanged.`);
console.log(`Added Insights to the tab bar row in personal layout ${layout}; the tab bar's mod is unchanged.`);
}

export async function prepareToolbarRemoval(appHome) {
Expand Down
15 changes: 14 additions & 1 deletion tests/herdr-insights/toolbar-layout.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test("layout composition keeps the original tabs code and points the toolbar at
const tabs = { id: "tabs", type: "block", size: { px: 42 }, window_drag: true, content: { mod: "tabs", props: { custom: true } } };
const original = { id: "root", type: "column", theme: "ink", children: [tabs, { id: "main", type: "block", content: { tab: "active" } }] };
const snapshot = structuredClone(original);
const integrated = withInsightsToolbar(original);
const integrated = withInsightsToolbar(original, "darwin");
assert.deepEqual(original, snapshot, "input must not be mutated");
assert.equal(integrated.theme, "ink");
assert.deepEqual(integrated.children[1], original.children[1]);
Expand All @@ -35,4 +35,17 @@ test("layout composition keeps the original tabs code and points the toolbar at
assert.throws(() => withInsightsToolbar(integrated), /already contains/);
assert.throws(() => withInsightsToolbar({ id: "root", type: "row", children: [] }), /cannot be integrated safely/);
assert.throws(() => withInsightsToolbar({ id: "root", type: "row", children: [tabs, tabs] }), /cannot be integrated safely/);
const notMod = { id: "tabs", type: "block", content: { tab: "active" } };
assert.throws(() => withInsightsToolbar({ id: "root", type: "row", children: [notMod] }), /cannot be integrated safely/);
});

test("off macOS the button leads, so a cloned tab bar's own window buttons stay last", () => {
const content = { mod: "tabs-graph" };
for (const platform of ["win32", "linux"]) {
const layout = { id: "root", type: "column", children: [{ id: "tabs", type: "block", content }] };
const [button, bar] = withInsightsToolbar(layout, platform).children[0].children;
assert.equal(button.id, "insights-toolbar-button", platform);
assert.deepEqual(button.content, SINGLE_TOOLBAR_CONTENT);
assert.deepEqual(bar, { id: "insights-original-tabs", type: "block", size: { weight: 1 }, content });
}
});