@firstpick/pi-package-webui 0.6.0 → 0.6.1
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 +2 -2
- package/bin/pi-webui.mjs +161 -9
- package/package.json +1 -1
- package/public/app.js +494 -33
- package/public/index.html +20 -2
- package/public/styles.css +316 -2
- package/tests/mobile-static.test.mjs +4 -2
- package/tests/theme-scheme-mode.test.mjs +132 -0
package/public/app.js
CHANGED
|
@@ -5,6 +5,7 @@ const elements = {
|
|
|
5
5
|
webuiDevBadge: $("#webuiDevBadge"),
|
|
6
6
|
tabBar: $("#tabBar"),
|
|
7
7
|
terminalTabsToggleButton: $("#terminalTabsToggleButton"),
|
|
8
|
+
splitTabButton: $("#splitTabButton"),
|
|
8
9
|
newTabMenu: $("#newTabMenu"),
|
|
9
10
|
newTabButton: $("#newTabButton"),
|
|
10
11
|
newTabMenuPanel: $("#newTabMenuPanel"),
|
|
@@ -12,6 +13,11 @@ const elements = {
|
|
|
12
13
|
newTabChooseDirectoryButton: $("#newTabChooseDirectoryButton"),
|
|
13
14
|
newTabWorktreeButton: $("#newTabWorktreeButton"),
|
|
14
15
|
closeAllTabsButton: $("#closeAllTabsButton"),
|
|
16
|
+
terminalSplitShell: $("#terminalSplitShell"),
|
|
17
|
+
terminalSplitFrame: $("#terminalSplitFrame"),
|
|
18
|
+
terminalSplitTitle: $("#terminalSplitTitle"),
|
|
19
|
+
terminalSplitMeta: $("#terminalSplitMeta"),
|
|
20
|
+
terminalSplitCloseButton: $("#terminalSplitCloseButton"),
|
|
15
21
|
commandPaletteButton: $("#commandPaletteButton"),
|
|
16
22
|
workspaceDashboardToggleButton: $("#workspaceDashboardToggleButton"),
|
|
17
23
|
workspaceDashboard: $("#workspaceDashboard"),
|
|
@@ -143,6 +149,7 @@ const elements = {
|
|
|
143
149
|
themeSearchInput: $("#themeSearchInput"),
|
|
144
150
|
themeSearchResults: $("#themeSearchResults"),
|
|
145
151
|
themeSelect: $("#themeSelect"),
|
|
152
|
+
themeSchemeToggle: $("#themeSchemeToggle"),
|
|
146
153
|
backgroundInput: $("#backgroundInput"),
|
|
147
154
|
backgroundChooseButton: $("#backgroundChooseButton"),
|
|
148
155
|
backgroundClearButton: $("#backgroundClearButton"),
|
|
@@ -320,6 +327,7 @@ let openTerminalTabGroupKey = null;
|
|
|
320
327
|
let terminalCustomGroups = new Map();
|
|
321
328
|
let terminalCustomGroupSerial = 1;
|
|
322
329
|
let terminalTabDragId = null;
|
|
330
|
+
let splitTabId = null;
|
|
323
331
|
let newTabMenuOpen = false;
|
|
324
332
|
let nativeCommandMenuOpen = false;
|
|
325
333
|
let appRunnerMenuOpen = false;
|
|
@@ -527,6 +535,17 @@ const LONG_INPUT_ATTACHMENT_MIME_TYPE = "text/plain";
|
|
|
527
535
|
const INLINE_IMAGE_MIME_TYPES = new Set(["image/png", "image/jpeg", "image/webp", "image/gif"]);
|
|
528
536
|
const BACKGROUND_IMAGE_MIME_TYPES = new Set(["image/png", "image/jpeg", "image/webp", "image/gif"]);
|
|
529
537
|
const DEFAULT_THEME_NAME = "catppuccin-mocha";
|
|
538
|
+
// Theme scheme mode (Light / Dark / Auto). The picker chooses the theme for the
|
|
539
|
+
// active scheme; "auto" follows the OS prefers-color-scheme and swaps between the
|
|
540
|
+
// remembered light and dark picks. Existing users keep their theme (see migration
|
|
541
|
+
// in initializeThemes), so auto is strictly opt-in.
|
|
542
|
+
const THEME_MODE_STORAGE_KEY = "pi-webui-theme-mode";
|
|
543
|
+
const THEME_LIGHT_STORAGE_KEY = "pi-webui-theme-light";
|
|
544
|
+
const THEME_DARK_STORAGE_KEY = "pi-webui-theme-dark";
|
|
545
|
+
const THEME_LIGHT_DEFAULT = "catppuccin-latte";
|
|
546
|
+
const THEME_DARK_DEFAULT = "catppuccin-mocha";
|
|
547
|
+
const THEME_SCHEME_MODES = new Set(["light", "dark", "auto"]);
|
|
548
|
+
let themeSchemeMode = "light"; // "light" | "dark" | "auto"; finalized in initializeThemes
|
|
530
549
|
const TERMINAL_TABS_LAYOUTS = new Set(["top", "left"]);
|
|
531
550
|
const TERMINAL_TABS_LAYOUT_LABELS = { top: "Top bar", left: "Left sidebar" };
|
|
532
551
|
const BUSY_PROMPT_BEHAVIOR_VALUES = new Set(["followUp", "steer"]);
|
|
@@ -573,6 +592,10 @@ const AGENT_DONE_NOTIFICATION_TAG_PREFIX = "pi-webui-agent-done";
|
|
|
573
592
|
const BLOCKED_TAB_NOTIFICATION_ICON = "/icon-192.png";
|
|
574
593
|
const mobileViewMedia = window.matchMedia?.(MOBILE_VIEW_QUERY) || null;
|
|
575
594
|
const sidePanelOverlayMedia = window.matchMedia?.(SIDE_PANEL_OVERLAY_QUERY) || mobileViewMedia;
|
|
595
|
+
const colorSchemeMedia = window.matchMedia?.("(prefers-color-scheme: dark)") || null;
|
|
596
|
+
const initialUrlParams = new URLSearchParams(window.location.search);
|
|
597
|
+
const embeddedSplitMode = initialUrlParams.get("embed") === "split";
|
|
598
|
+
document.body.classList.toggle("embedded-split", embeddedSplitMode);
|
|
576
599
|
const statusEntries = new Map();
|
|
577
600
|
const widgets = new Map();
|
|
578
601
|
const widgetsByTab = new Map();
|
|
@@ -758,6 +781,9 @@ const SETTINGS_AUTOCOMPLETE_OPTIONS = ["3", "5", "7", "10", "15", "20"];
|
|
|
758
781
|
const optionalFeatureInstallInProgress = new Set();
|
|
759
782
|
const optionalFeaturePackageStatuses = new Map();
|
|
760
783
|
const optionalFeatureInstallMessages = new Map();
|
|
784
|
+
const optionalFeatureInstallStates = new Map();
|
|
785
|
+
const optionalFeatureInstallProgressTimers = new Map();
|
|
786
|
+
let optionalFeaturePackageStatusError = "";
|
|
761
787
|
const gitFooterPayloadRefreshInFlightByTab = new Set();
|
|
762
788
|
const gitFooterSyncPushInFlightByTab = new Set();
|
|
763
789
|
const gitFooterPiCalibrationInFlightByTab = new Set();
|
|
@@ -2422,10 +2448,12 @@ function bindSidePanelOverlayViewChanges() {
|
|
|
2422
2448
|
const syncForViewport = (event) => {
|
|
2423
2449
|
if (event.matches) {
|
|
2424
2450
|
setSidePanelCollapsed(true, { persist: false });
|
|
2451
|
+
updateTerminalSplitUi();
|
|
2425
2452
|
return;
|
|
2426
2453
|
}
|
|
2427
2454
|
const stored = readStoredSidePanelCollapsed();
|
|
2428
2455
|
setSidePanelCollapsed(stored ?? false, { persist: false });
|
|
2456
|
+
updateTerminalSplitUi();
|
|
2429
2457
|
};
|
|
2430
2458
|
if (typeof sidePanelOverlayMedia.addEventListener === "function") sidePanelOverlayMedia.addEventListener("change", syncForViewport);
|
|
2431
2459
|
else sidePanelOverlayMedia.addListener?.(syncForViewport);
|
|
@@ -3081,15 +3109,15 @@ function renderUpdateNotification(status = latestUpdateStatus, { force = false }
|
|
|
3081
3109
|
if (elements.updateNotificationMessage) {
|
|
3082
3110
|
let message = "Updates are available. Direct Web UI updates are only enabled from localhost on the host machine.";
|
|
3083
3111
|
if (canRunUpdate) {
|
|
3084
|
-
if (hasPiUpdate && hasPackageUpdate) message = "Run pi update for Pi only, or
|
|
3085
|
-
else if (hasPackageUpdate) message = "
|
|
3112
|
+
if (hasPiUpdate && hasPackageUpdate) message = "Run pi update for Pi only, or update all to include Web UI, Optional Features, configured Pi packages, and detected Pi package roots, then restart this Web UI server automatically.";
|
|
3113
|
+
else if (hasPackageUpdate) message = "Update all to refresh Web UI/package entries, Optional Features, configured Pi packages, and detected Pi package roots, then restart this Web UI server automatically.";
|
|
3086
3114
|
else message = "Run pi update for Pi only, then restart this Web UI server automatically.";
|
|
3087
3115
|
}
|
|
3088
3116
|
elements.updateNotificationMessage.textContent = message;
|
|
3089
3117
|
}
|
|
3090
3118
|
const details = [
|
|
3091
3119
|
items.join(" · "),
|
|
3092
|
-
latestUpdateStatus.webuiDev && latestUpdateStatus.webui?.updateAvailable ? "The current Web UI is a dev checkout;
|
|
3120
|
+
latestUpdateStatus.webuiDev && latestUpdateStatus.webui?.updateAvailable ? "The current Web UI is a dev checkout; update all also refreshes detected Web UI/Optional Feature Pi package dependencies when possible." : "",
|
|
3093
3121
|
latestUpdateStatus.packages?.note || "",
|
|
3094
3122
|
].filter(Boolean).join(" ");
|
|
3095
3123
|
if (elements.updateNotificationDetail) elements.updateNotificationDetail.textContent = details;
|
|
@@ -3138,8 +3166,9 @@ function piUpdateConfirmationText({ all = false } = {}) {
|
|
|
3138
3166
|
const workingWarning = hasWorkingTab() ? "\n\nOne or more Pi tabs look busy or blocked. Finish or abort in-flight work before updating if you need to preserve it." : "";
|
|
3139
3167
|
const versionText = items.length ? `\n\nDetected update: ${items.join(" · ")}.` : "";
|
|
3140
3168
|
const command = all ? "pi update --all" : "pi update";
|
|
3141
|
-
const scope = all ? "Pi and
|
|
3142
|
-
|
|
3169
|
+
const scope = all ? "Pi, configured packages, Optional Features, and detected Pi package roots" : "Pi only";
|
|
3170
|
+
const extra = all ? " It will also run npm/bun package updates for detected Web UI, Optional Feature, agent, project, and global Pi package roots." : "";
|
|
3171
|
+
return `Run ${scope} now?${versionText}\n\nThis will run \"${command}\" on the Web UI host.${extra} After it finishes, Pi Web UI will restart itself. Browser clients will briefly disconnect, and managed Pi tabs/RPC processes will be restarted from saved session state when possible.${workingWarning}`;
|
|
3143
3172
|
}
|
|
3144
3173
|
|
|
3145
3174
|
async function runPiUpdateAndRestart({ all = false } = {}) {
|
|
@@ -4012,6 +4041,42 @@ function storeThemeName(name) {
|
|
|
4012
4041
|
}
|
|
4013
4042
|
}
|
|
4014
4043
|
|
|
4044
|
+
function storedThemeMode() {
|
|
4045
|
+
try {
|
|
4046
|
+
const raw = localStorage.getItem(THEME_MODE_STORAGE_KEY);
|
|
4047
|
+
return THEME_SCHEME_MODES.has(raw) ? raw : null;
|
|
4048
|
+
} catch {
|
|
4049
|
+
return null;
|
|
4050
|
+
}
|
|
4051
|
+
}
|
|
4052
|
+
|
|
4053
|
+
function storeThemeMode(mode) {
|
|
4054
|
+
try {
|
|
4055
|
+
localStorage.setItem(THEME_MODE_STORAGE_KEY, mode);
|
|
4056
|
+
} catch {
|
|
4057
|
+
// Ignore storage failures; the mode still applies for this page load.
|
|
4058
|
+
}
|
|
4059
|
+
}
|
|
4060
|
+
|
|
4061
|
+
function storedSchemeTheme(scheme) {
|
|
4062
|
+
const key = scheme === "dark" ? THEME_DARK_STORAGE_KEY : THEME_LIGHT_STORAGE_KEY;
|
|
4063
|
+
const fallback = scheme === "dark" ? THEME_DARK_DEFAULT : THEME_LIGHT_DEFAULT;
|
|
4064
|
+
try {
|
|
4065
|
+
return localStorage.getItem(key) || fallback;
|
|
4066
|
+
} catch {
|
|
4067
|
+
return fallback;
|
|
4068
|
+
}
|
|
4069
|
+
}
|
|
4070
|
+
|
|
4071
|
+
function storeSchemeTheme(scheme, name) {
|
|
4072
|
+
const key = scheme === "dark" ? THEME_DARK_STORAGE_KEY : THEME_LIGHT_STORAGE_KEY;
|
|
4073
|
+
try {
|
|
4074
|
+
localStorage.setItem(key, name);
|
|
4075
|
+
} catch {
|
|
4076
|
+
// Ignore storage failures.
|
|
4077
|
+
}
|
|
4078
|
+
}
|
|
4079
|
+
|
|
4015
4080
|
function loadDisabledOptionalFeatures() {
|
|
4016
4081
|
try {
|
|
4017
4082
|
const parsed = JSON.parse(localStorage.getItem(OPTIONAL_FEATURES_STORAGE_KEY) || "[]");
|
|
@@ -4184,8 +4249,7 @@ function renderConversationModeControls() {
|
|
|
4184
4249
|
const tooltip = commandName
|
|
4185
4250
|
? `${active ? "End" : "Start"} Natural Conversation Mode for this Pi tab via /${commandName}. Safety is owned by @firstpick/pi-package-natural-conversation.`
|
|
4186
4251
|
: conversationModeUnavailableText();
|
|
4187
|
-
elements.optionsConversationModeButton
|
|
4188
|
-
elements.optionsConversationModeButton.setAttribute("data-tooltip", tooltip);
|
|
4252
|
+
applyStyledTooltip(elements.optionsConversationModeButton, tooltip, { ariaLabel: false, align: "end" });
|
|
4189
4253
|
elements.optionsConversationModeButton.setAttribute("aria-pressed", active ? "true" : "false");
|
|
4190
4254
|
}
|
|
4191
4255
|
|
|
@@ -4862,7 +4926,7 @@ function rgbaColor(rgb, alpha) {
|
|
|
4862
4926
|
}
|
|
4863
4927
|
|
|
4864
4928
|
function relativeLuminance(color) {
|
|
4865
|
-
const rgb =
|
|
4929
|
+
const rgb = cssColorToRgb(color);
|
|
4866
4930
|
if (!rgb) return 0;
|
|
4867
4931
|
const channel = (value) => {
|
|
4868
4932
|
const normalized = value / 255;
|
|
@@ -4972,10 +5036,103 @@ function applyTheme(theme, { persist = false, announce = false } = {}) {
|
|
|
4972
5036
|
document.querySelector('meta[name="theme-color"]')?.setAttribute("content", pageBg);
|
|
4973
5037
|
currentThemeName = theme.name;
|
|
4974
5038
|
if (elements.themeSelect && elements.themeSelect.value !== theme.name) elements.themeSelect.value = theme.name;
|
|
4975
|
-
if (persist)
|
|
5039
|
+
if (persist) {
|
|
5040
|
+
storeSchemeTheme(isLight ? "light" : "dark", theme.name);
|
|
5041
|
+
storeThemeName(theme.name);
|
|
5042
|
+
}
|
|
4976
5043
|
if (announce) addEvent(`theme changed to ${theme.label || displayThemeName(theme.name) || theme.name}`);
|
|
4977
5044
|
}
|
|
4978
5045
|
|
|
5046
|
+
function osPrefersDark() {
|
|
5047
|
+
return !!(colorSchemeMedia && colorSchemeMedia.matches);
|
|
5048
|
+
}
|
|
5049
|
+
|
|
5050
|
+
function effectiveScheme() {
|
|
5051
|
+
if (themeSchemeMode === "auto") return osPrefersDark() ? "dark" : "light";
|
|
5052
|
+
return themeSchemeMode === "dark" ? "dark" : "light";
|
|
5053
|
+
}
|
|
5054
|
+
|
|
5055
|
+
function themeIsLight(theme) {
|
|
5056
|
+
if (!theme) return false;
|
|
5057
|
+
return relativeLuminance(themeExportColor(theme, "pageBg", "#11111b")) > 0.62;
|
|
5058
|
+
}
|
|
5059
|
+
|
|
5060
|
+
function effectiveThemeName() {
|
|
5061
|
+
const scheme = effectiveScheme();
|
|
5062
|
+
const name = storedSchemeTheme(scheme);
|
|
5063
|
+
if (availableThemes.some((theme) => theme.name === name)) return name;
|
|
5064
|
+
const fallback = scheme === "dark" ? THEME_DARK_DEFAULT : THEME_LIGHT_DEFAULT;
|
|
5065
|
+
if (availableThemes.some((theme) => theme.name === fallback)) return fallback;
|
|
5066
|
+
return availableThemes[0]?.name || fallback;
|
|
5067
|
+
}
|
|
5068
|
+
|
|
5069
|
+
function renderThemeSchemeToggle() {
|
|
5070
|
+
const group = elements.themeSchemeToggle;
|
|
5071
|
+
if (!group) return;
|
|
5072
|
+
for (const button of group.querySelectorAll("[data-scheme-mode]")) {
|
|
5073
|
+
const active = button.dataset.schemeMode === themeSchemeMode;
|
|
5074
|
+
button.classList.toggle("active", active);
|
|
5075
|
+
button.setAttribute("aria-pressed", String(active));
|
|
5076
|
+
}
|
|
5077
|
+
}
|
|
5078
|
+
|
|
5079
|
+
// Apply the theme for the current scheme (mode + OS). Never persists: the scheme
|
|
5080
|
+
// slots and the legacy key only record explicit user picks, so one degraded theme
|
|
5081
|
+
// bundle load cannot clobber stored choices.
|
|
5082
|
+
async function applySchemeTheme(options = {}) {
|
|
5083
|
+
await setThemeByName(effectiveThemeName(), { ...options, persist: false });
|
|
5084
|
+
}
|
|
5085
|
+
|
|
5086
|
+
// A theme picked from the selector/search is assigned to its own light/dark slot.
|
|
5087
|
+
// Persistence happens inside applyTheme, only after the theme was validated and applied.
|
|
5088
|
+
async function chooseTheme(name, options = {}) {
|
|
5089
|
+
await setThemeByName(name, { ...options, persist: true });
|
|
5090
|
+
}
|
|
5091
|
+
|
|
5092
|
+
function handleOsSchemeChange() {
|
|
5093
|
+
if (themeSchemeMode !== "auto") return;
|
|
5094
|
+
applySchemeTheme({ announce: true }).catch((error) => addEvent(error.message || String(error), "error"));
|
|
5095
|
+
}
|
|
5096
|
+
|
|
5097
|
+
function updateColorSchemeListener() {
|
|
5098
|
+
if (!colorSchemeMedia) return;
|
|
5099
|
+
if (typeof colorSchemeMedia.addEventListener === "function") {
|
|
5100
|
+
colorSchemeMedia.removeEventListener("change", handleOsSchemeChange);
|
|
5101
|
+
if (themeSchemeMode === "auto") colorSchemeMedia.addEventListener("change", handleOsSchemeChange);
|
|
5102
|
+
} else {
|
|
5103
|
+
colorSchemeMedia.removeListener?.(handleOsSchemeChange);
|
|
5104
|
+
if (themeSchemeMode === "auto") colorSchemeMedia.addListener?.(handleOsSchemeChange);
|
|
5105
|
+
}
|
|
5106
|
+
}
|
|
5107
|
+
|
|
5108
|
+
async function setThemeSchemeMode(mode, { announce = false } = {}) {
|
|
5109
|
+
if (!THEME_SCHEME_MODES.has(mode)) return;
|
|
5110
|
+
if (themeSchemeMode === mode) {
|
|
5111
|
+
renderThemeSchemeToggle();
|
|
5112
|
+
return;
|
|
5113
|
+
}
|
|
5114
|
+
themeSchemeMode = mode;
|
|
5115
|
+
storeThemeMode(mode);
|
|
5116
|
+
updateColorSchemeListener();
|
|
5117
|
+
renderThemeSchemeToggle();
|
|
5118
|
+
await applySchemeTheme({ announce });
|
|
5119
|
+
}
|
|
5120
|
+
|
|
5121
|
+
// First run with the scheme switch: migrate a pre-existing single theme into the slot
|
|
5122
|
+
// matching its own light/dark scheme and default the mode to that scheme, so existing
|
|
5123
|
+
// users see no change and auto stays opt-in.
|
|
5124
|
+
function seedThemeSchemeFromStoredTheme() {
|
|
5125
|
+
const stored = storedThemeName();
|
|
5126
|
+
const storedTheme = availableThemes.find((theme) => theme.name === stored);
|
|
5127
|
+
// Degraded load (empty bundle or stored theme missing): fall back for this page
|
|
5128
|
+
// load only, without persisting, so the migration retries once the bundle is healthy.
|
|
5129
|
+
if (!storedTheme) return "dark";
|
|
5130
|
+
const scheme = themeIsLight(storedTheme) ? "light" : "dark";
|
|
5131
|
+
storeSchemeTheme(scheme, stored);
|
|
5132
|
+
storeThemeMode(scheme);
|
|
5133
|
+
return scheme;
|
|
5134
|
+
}
|
|
5135
|
+
|
|
4979
5136
|
function themeDisplayLabel(theme) {
|
|
4980
5137
|
return theme?.label || displayThemeName(theme?.name) || theme?.name || "";
|
|
4981
5138
|
}
|
|
@@ -5000,10 +5157,13 @@ function renderThemeSearchResults(themes = []) {
|
|
|
5000
5157
|
button.setAttribute("role", "option");
|
|
5001
5158
|
button.setAttribute("aria-selected", String(selected));
|
|
5002
5159
|
button.title = themeSearchText(theme);
|
|
5003
|
-
|
|
5160
|
+
const title = make("span", "theme-search-result-title");
|
|
5161
|
+
title.append(make("span", "model-search-result-main", themeDisplayLabel(theme)));
|
|
5162
|
+
title.append(make("span", `theme-search-result-scheme ${themeIsLight(theme) ? "light" : "dark"}`, themeIsLight(theme) ? "Light" : "Dark"));
|
|
5163
|
+
button.append(title);
|
|
5004
5164
|
button.addEventListener("click", () => {
|
|
5005
5165
|
if (elements.themeSelect) elements.themeSelect.value = theme.name;
|
|
5006
|
-
|
|
5166
|
+
chooseTheme(theme.name, { announce: true }).catch((error) => addEvent(error.message || String(error), "error"));
|
|
5007
5167
|
});
|
|
5008
5168
|
elements.themeSearchResults.append(button);
|
|
5009
5169
|
}
|
|
@@ -5105,11 +5265,11 @@ async function initializeThemes() {
|
|
|
5105
5265
|
availableThemes = Array.isArray(response.data?.themes) ? response.data.themes : [];
|
|
5106
5266
|
optionalFeatureAvailability.themeBundle = availableThemes.length > 0;
|
|
5107
5267
|
renderOptionalFeatureControls();
|
|
5108
|
-
|
|
5109
|
-
currentThemeName = availableThemes.some((theme) => theme.name === stored) ? stored : DEFAULT_THEME_NAME;
|
|
5268
|
+
themeSchemeMode = storedThemeMode() ?? seedThemeSchemeFromStoredTheme();
|
|
5110
5269
|
renderThemeSelect();
|
|
5111
|
-
|
|
5112
|
-
|
|
5270
|
+
renderThemeSchemeToggle();
|
|
5271
|
+
updateColorSchemeListener();
|
|
5272
|
+
await applySchemeTheme({ includeLegacy: true });
|
|
5113
5273
|
if (!availableThemes.length) addEvent("theme bundle unavailable; using built-in default theme", "warn");
|
|
5114
5274
|
}
|
|
5115
5275
|
|
|
@@ -5404,6 +5564,7 @@ function trackAutoRetryStateFromEvent(event) {
|
|
|
5404
5564
|
}
|
|
5405
5565
|
|
|
5406
5566
|
function rememberActiveTab() {
|
|
5567
|
+
if (embeddedSplitMode) return;
|
|
5407
5568
|
try {
|
|
5408
5569
|
if (activeTabId) localStorage.setItem(TAB_STORAGE_KEY, activeTabId);
|
|
5409
5570
|
} catch {
|
|
@@ -5957,6 +6118,7 @@ function setNewTabMenuOpen(open) {
|
|
|
5957
6118
|
|
|
5958
6119
|
function initializeTerminalHeaderTooltips() {
|
|
5959
6120
|
applyStyledTooltip(elements.newTabButton, "Start a separate isolated Pi terminal", { ariaLabel: "Start a separate isolated Pi terminal" });
|
|
6121
|
+
applyStyledTooltip(elements.splitTabButton, "Split the active terminal to the right", { ariaLabel: "Split the active terminal to the right" });
|
|
5960
6122
|
applyStyledTooltip(elements.closeAllTabsButton, "Close all terminal tabs", { ariaLabel: "Close all terminal tabs" });
|
|
5961
6123
|
}
|
|
5962
6124
|
|
|
@@ -6020,6 +6182,7 @@ function renderTabs() {
|
|
|
6020
6182
|
elements.tabBar.append(elements.newTabMenu);
|
|
6021
6183
|
elements.closeAllTabsButton.disabled = tabs.length === 0;
|
|
6022
6184
|
updateTerminalTabGroupOpenState();
|
|
6185
|
+
reconcileTerminalSplitState();
|
|
6023
6186
|
setMobileTabsExpanded(mobileTabsExpanded);
|
|
6024
6187
|
updateDocumentTitle();
|
|
6025
6188
|
renderWorkspaceDashboard();
|
|
@@ -6054,6 +6217,7 @@ async function switchTab(tabId) {
|
|
|
6054
6217
|
footerThinkingPickerOpen = false;
|
|
6055
6218
|
footerBranchPickerOpen = false;
|
|
6056
6219
|
footerBranchPickerRequestSerial += 1;
|
|
6220
|
+
if (tabId === splitTabId) closeTerminalSplitView();
|
|
6057
6221
|
saveActiveDraft();
|
|
6058
6222
|
cacheMessagesForTab(activeTabId);
|
|
6059
6223
|
cacheWidgetsForTab(activeTabId);
|
|
@@ -6072,6 +6236,95 @@ function currentDirectoryForNewTab() {
|
|
|
6072
6236
|
return latestWorkspace?.cwd || activeTab()?.cwd || "";
|
|
6073
6237
|
}
|
|
6074
6238
|
|
|
6239
|
+
function terminalSplitTab() {
|
|
6240
|
+
return splitTabId ? tabs.find((tab) => tab.id === splitTabId) || null : null;
|
|
6241
|
+
}
|
|
6242
|
+
|
|
6243
|
+
function terminalSplitFrameUrl(tabId) {
|
|
6244
|
+
const url = new URL("/", window.location.href);
|
|
6245
|
+
url.searchParams.set("embed", "split");
|
|
6246
|
+
url.searchParams.set("tab", tabId);
|
|
6247
|
+
return `${url.pathname}${url.search}`;
|
|
6248
|
+
}
|
|
6249
|
+
|
|
6250
|
+
function updateTerminalSplitUi() {
|
|
6251
|
+
const tab = terminalSplitTab();
|
|
6252
|
+
const canShowSplit = !!tab && !embeddedSplitMode && !isSidePanelOverlayView();
|
|
6253
|
+
document.body.classList.toggle("terminal-split-open", canShowSplit);
|
|
6254
|
+
if (elements.terminalSplitShell) elements.terminalSplitShell.hidden = !canShowSplit;
|
|
6255
|
+
if (elements.splitTabButton) {
|
|
6256
|
+
elements.splitTabButton.disabled = embeddedSplitMode || isSidePanelOverlayView() || !activeTab();
|
|
6257
|
+
elements.splitTabButton.setAttribute("aria-pressed", canShowSplit ? "true" : "false");
|
|
6258
|
+
elements.splitTabButton.dataset.splitState = canShowSplit ? "unsplit" : "split";
|
|
6259
|
+
const label = canShowSplit ? `Close split view for ${tab.title}` : "Split the active terminal to the right";
|
|
6260
|
+
applyStyledTooltip(elements.splitTabButton, label, { ariaLabel: label });
|
|
6261
|
+
}
|
|
6262
|
+
if (!canShowSplit) return;
|
|
6263
|
+
if (elements.terminalSplitTitle) elements.terminalSplitTitle.textContent = tab.title || "Split terminal";
|
|
6264
|
+
if (elements.terminalSplitMeta) elements.terminalSplitMeta.textContent = [tab.running ? `pid ${tab.pid || "starting"}` : "stopped", normalizeDisplayPath(tab.cwd || "")].filter(Boolean).join(" · ");
|
|
6265
|
+
if (elements.terminalSplitFrame && elements.terminalSplitFrame.dataset.tabId !== tab.id) {
|
|
6266
|
+
elements.terminalSplitFrame.dataset.tabId = tab.id;
|
|
6267
|
+
elements.terminalSplitFrame.src = terminalSplitFrameUrl(tab.id);
|
|
6268
|
+
}
|
|
6269
|
+
}
|
|
6270
|
+
|
|
6271
|
+
function closeTerminalSplitView() {
|
|
6272
|
+
splitTabId = null;
|
|
6273
|
+
if (elements.terminalSplitFrame) {
|
|
6274
|
+
elements.terminalSplitFrame.removeAttribute("src");
|
|
6275
|
+
delete elements.terminalSplitFrame.dataset.tabId;
|
|
6276
|
+
}
|
|
6277
|
+
updateTerminalSplitUi();
|
|
6278
|
+
}
|
|
6279
|
+
|
|
6280
|
+
function setTerminalSplitTab(tabId) {
|
|
6281
|
+
splitTabId = tabId || null;
|
|
6282
|
+
updateTerminalSplitUi();
|
|
6283
|
+
}
|
|
6284
|
+
|
|
6285
|
+
function reconcileTerminalSplitState() {
|
|
6286
|
+
if (embeddedSplitMode) return;
|
|
6287
|
+
if (splitTabId && !tabs.some((tab) => tab.id === splitTabId)) {
|
|
6288
|
+
closeTerminalSplitView();
|
|
6289
|
+
return;
|
|
6290
|
+
}
|
|
6291
|
+
updateTerminalSplitUi();
|
|
6292
|
+
}
|
|
6293
|
+
|
|
6294
|
+
async function splitActiveTerminalTab({ triggerButton = elements.splitTabButton } = {}) {
|
|
6295
|
+
if (embeddedSplitMode) return;
|
|
6296
|
+
if (splitTabId) {
|
|
6297
|
+
closeTerminalSplitView();
|
|
6298
|
+
return;
|
|
6299
|
+
}
|
|
6300
|
+
const sourceTab = activeTab();
|
|
6301
|
+
let resolvedCwd = latestWorkspace?.cwd || sourceTab?.cwd || currentDirectoryForNewTab();
|
|
6302
|
+
setMobileTabsExpanded(false);
|
|
6303
|
+
setNewTabMenuOpen(false);
|
|
6304
|
+
if (!resolvedCwd) {
|
|
6305
|
+
resolvedCwd = await pickCwd(sourceTab || { id: "split-terminal", title: "split terminal" }, "", { title: "Choose CWD for split terminal" });
|
|
6306
|
+
if (!resolvedCwd) return;
|
|
6307
|
+
}
|
|
6308
|
+
const disabledButtons = new Set([elements.splitTabButton, triggerButton].filter(Boolean));
|
|
6309
|
+
for (const button of disabledButtons) button.disabled = true;
|
|
6310
|
+
try {
|
|
6311
|
+
const response = await api("/api/tabs", { method: "POST", body: { cwd: resolvedCwd }, scoped: false });
|
|
6312
|
+
tabs = response.data?.tabs || tabs;
|
|
6313
|
+
syncTabMetadata(tabs);
|
|
6314
|
+
const tab = response.data?.tab;
|
|
6315
|
+
if (tab?.id) {
|
|
6316
|
+
setTerminalSplitTab(tab.id);
|
|
6317
|
+
renderTabs();
|
|
6318
|
+
addEvent(`split ${sourceTab?.title || "terminal"} into independent ${tab.title}`, "info");
|
|
6319
|
+
}
|
|
6320
|
+
} catch (error) {
|
|
6321
|
+
addEvent(error.message, "error");
|
|
6322
|
+
} finally {
|
|
6323
|
+
for (const button of disabledButtons) button.disabled = false;
|
|
6324
|
+
updateTerminalSplitUi();
|
|
6325
|
+
}
|
|
6326
|
+
}
|
|
6327
|
+
|
|
6075
6328
|
async function createTerminalTab(cwd = currentDirectoryForNewTab(), { triggerButton = elements.newTabButton, customGroupId = null } = {}) {
|
|
6076
6329
|
setMobileTabsExpanded(false);
|
|
6077
6330
|
setNewTabMenuOpen(false);
|
|
@@ -17880,9 +18133,88 @@ function optionalFeaturePackageVersionLabel(status) {
|
|
|
17880
18133
|
return status.declaredSpec ? `${status.installedVersion} (expects ${status.declaredSpec})` : status.installedVersion;
|
|
17881
18134
|
}
|
|
17882
18135
|
|
|
18136
|
+
function optionalFeatureInstallState(featureId) {
|
|
18137
|
+
return optionalFeatureInstallStates.get(featureId) || null;
|
|
18138
|
+
}
|
|
18139
|
+
|
|
18140
|
+
function optionalFeatureInstallIsActive(state) {
|
|
18141
|
+
return state && !["done", "failed"].includes(state.phase);
|
|
18142
|
+
}
|
|
18143
|
+
|
|
18144
|
+
function optionalFeatureInstallElapsed(state) {
|
|
18145
|
+
if (!state?.startedAt) return "";
|
|
18146
|
+
return formatDuration((state.endedAt || Date.now()) - state.startedAt);
|
|
18147
|
+
}
|
|
18148
|
+
|
|
18149
|
+
function optionalFeatureInstallPhaseLabel(state) {
|
|
18150
|
+
const actionLabel = state?.actionLabel || "Install";
|
|
18151
|
+
switch (state?.phase) {
|
|
18152
|
+
case "preparing": return `${actionLabel} starting`;
|
|
18153
|
+
case "installing": return `${actionLabel} running`;
|
|
18154
|
+
case "refreshing": return "Checking install";
|
|
18155
|
+
case "done": return `${actionLabel} done`;
|
|
18156
|
+
case "failed": return `${actionLabel} failed`;
|
|
18157
|
+
default: return actionLabel;
|
|
18158
|
+
}
|
|
18159
|
+
}
|
|
18160
|
+
|
|
18161
|
+
function optionalFeatureInstallDetail(state, fallback = "") {
|
|
18162
|
+
const detail = String(state?.detail || fallback || "").trim();
|
|
18163
|
+
const elapsed = optionalFeatureInstallElapsed(state);
|
|
18164
|
+
return [detail, elapsed ? `${state?.endedAt ? "finished after" : "elapsed"} ${elapsed}` : ""].filter(Boolean).join(" · ");
|
|
18165
|
+
}
|
|
18166
|
+
|
|
18167
|
+
function setOptionalFeatureInstallState(featureId, patch = {}) {
|
|
18168
|
+
const previous = optionalFeatureInstallState(featureId) || {};
|
|
18169
|
+
optionalFeatureInstallStates.set(featureId, { ...previous, ...patch });
|
|
18170
|
+
renderOptionalFeaturePanel();
|
|
18171
|
+
}
|
|
18172
|
+
|
|
18173
|
+
function clearOptionalFeatureInstallProgressTimer(featureId) {
|
|
18174
|
+
const timer = optionalFeatureInstallProgressTimers.get(featureId);
|
|
18175
|
+
if (timer) clearInterval(timer);
|
|
18176
|
+
optionalFeatureInstallProgressTimers.delete(featureId);
|
|
18177
|
+
}
|
|
18178
|
+
|
|
18179
|
+
function startOptionalFeatureInstallProgressTimer(featureId) {
|
|
18180
|
+
clearOptionalFeatureInstallProgressTimer(featureId);
|
|
18181
|
+
optionalFeatureInstallProgressTimers.set(featureId, setInterval(() => {
|
|
18182
|
+
if (!optionalFeatureInstallInProgress.has(featureId)) {
|
|
18183
|
+
clearOptionalFeatureInstallProgressTimer(featureId);
|
|
18184
|
+
return;
|
|
18185
|
+
}
|
|
18186
|
+
renderOptionalFeaturePanel();
|
|
18187
|
+
}, 1000));
|
|
18188
|
+
}
|
|
18189
|
+
|
|
18190
|
+
function optionalFeatureInstallFailureFromError(error) {
|
|
18191
|
+
const details = error?.data?.optionalFeatureInstall || {};
|
|
18192
|
+
const message = details.message || error?.message || String(error);
|
|
18193
|
+
const hint = details.hint || (error?.backendOffline
|
|
18194
|
+
? "The Web UI server connection failed. Check that pi-webui is still running, then retry."
|
|
18195
|
+
: "Run the shown npm command manually from the Web UI host to inspect the full package-manager output.");
|
|
18196
|
+
return { ...details, message, hint, statusCode: error?.statusCode };
|
|
18197
|
+
}
|
|
18198
|
+
|
|
18199
|
+
async function copyOptionalFeatureInstallCommand(featureId) {
|
|
18200
|
+
const state = optionalFeatureInstallState(featureId);
|
|
18201
|
+
const command = String(state?.command || "").trim();
|
|
18202
|
+
if (!command) {
|
|
18203
|
+
addEvent("optional feature install command is not available yet", "warn");
|
|
18204
|
+
return;
|
|
18205
|
+
}
|
|
18206
|
+
try {
|
|
18207
|
+
await copyText(command);
|
|
18208
|
+
addEvent("copied optional feature install command", "info");
|
|
18209
|
+
} catch (error) {
|
|
18210
|
+
addEvent(`optional feature install command copy failed: ${error.message || String(error)}`, "warn");
|
|
18211
|
+
}
|
|
18212
|
+
}
|
|
18213
|
+
|
|
17883
18214
|
async function refreshOptionalFeaturePackageStatuses({ announce = false } = {}) {
|
|
17884
18215
|
try {
|
|
17885
18216
|
const response = await api("/api/optional-features", { scoped: false });
|
|
18217
|
+
optionalFeaturePackageStatusError = "";
|
|
17886
18218
|
optionalFeaturePackageStatuses.clear();
|
|
17887
18219
|
for (const status of response.data?.features || []) {
|
|
17888
18220
|
if (status?.featureId) optionalFeaturePackageStatuses.set(status.featureId, status);
|
|
@@ -17890,7 +18222,9 @@ async function refreshOptionalFeaturePackageStatuses({ announce = false } = {})
|
|
|
17890
18222
|
renderOptionalFeatureControls();
|
|
17891
18223
|
return true;
|
|
17892
18224
|
} catch (error) {
|
|
17893
|
-
|
|
18225
|
+
optionalFeaturePackageStatusError = error.message || String(error);
|
|
18226
|
+
renderOptionalFeatureControls();
|
|
18227
|
+
if (announce) addEvent(`optional feature package status check failed: ${optionalFeaturePackageStatusError}`, "warn");
|
|
17894
18228
|
return false;
|
|
17895
18229
|
}
|
|
17896
18230
|
}
|
|
@@ -17940,13 +18274,33 @@ function optionalFeatureStatus(featureId) {
|
|
|
17940
18274
|
const disabled = isOptionalFeatureDisabled(featureId);
|
|
17941
18275
|
const packageStatus = optionalFeaturePackageStatus(featureId);
|
|
17942
18276
|
const installMessage = optionalFeatureInstallMessages.get(featureId);
|
|
18277
|
+
const installState = optionalFeatureInstallState(featureId);
|
|
18278
|
+
const installActive = optionalFeatureInstallInProgress.has(featureId) || optionalFeatureInstallIsActive(installState);
|
|
17943
18279
|
const versionLabel = optionalFeaturePackageVersionLabel(packageStatus);
|
|
17944
18280
|
const versionSuffix = versionLabel ? ` · package ${versionLabel}` : "";
|
|
17945
|
-
if (
|
|
18281
|
+
if (installActive) {
|
|
18282
|
+
return {
|
|
18283
|
+
label: optionalFeatureInstallPhaseLabel(installState),
|
|
18284
|
+
className: "updating",
|
|
18285
|
+
detail: optionalFeatureInstallDetail(installState, installMessage || "npm install is running; waiting for package-manager output"),
|
|
18286
|
+
hint: "The package manager may be quiet for a while; elapsed time updates here until npm exits.",
|
|
18287
|
+
command: installState?.command || "",
|
|
18288
|
+
};
|
|
18289
|
+
}
|
|
18290
|
+
if (installState?.phase === "failed") {
|
|
18291
|
+
return {
|
|
18292
|
+
label: optionalFeatureInstallPhaseLabel(installState),
|
|
18293
|
+
className: "failed",
|
|
18294
|
+
detail: optionalFeatureInstallDetail(installState, installState.detail || installMessage || "npm install failed"),
|
|
18295
|
+
hint: installState.hint || "Copy the npm command and run it manually from the Web UI host for full diagnostics.",
|
|
18296
|
+
command: installState.command || "",
|
|
18297
|
+
};
|
|
18298
|
+
}
|
|
18299
|
+
const doneDetail = installState?.phase === "done" ? optionalFeatureInstallDetail(installState, installMessage) : "";
|
|
17946
18300
|
if (packageStatus?.updateAvailable) return { label: "Update available", className: "updating", detail: packageStatus.updateReason || `Installed package is older than the Web UI expects${versionSuffix}` };
|
|
17947
|
-
if (detected && !disabled) return { label: "Enabled", className: "enabled", detail: `Detected and enabled in Web UI${versionSuffix}
|
|
18301
|
+
if (detected && !disabled) return { label: "Enabled", className: "enabled", detail: doneDetail || `Detected and enabled in Web UI${versionSuffix}`, command: installState?.command || "" };
|
|
17948
18302
|
if (detected && disabled) return { label: "Disabled", className: "disabled", detail: `Detected, but disabled in Web UI${versionSuffix}` };
|
|
17949
|
-
if (packageStatus?.installed) return { label: "Installed", className: "installed", detail: `Package is installed but not loaded in the active Pi tab${versionSuffix}
|
|
18303
|
+
if (packageStatus?.installed) return { label: "Installed", className: "installed", detail: doneDetail || `Package is installed but not loaded in the active Pi tab${versionSuffix}`, command: installState?.command || "" };
|
|
17950
18304
|
return { label: "Install needed", className: "missing", detail: installMessage || "Package is not installed or not visible from the Web UI package root" };
|
|
17951
18305
|
}
|
|
17952
18306
|
|
|
@@ -17955,12 +18309,14 @@ function optionalFeatureTooltip(feature, status) {
|
|
|
17955
18309
|
feature.label,
|
|
17956
18310
|
`Status: ${status.label}`,
|
|
17957
18311
|
status.detail,
|
|
18312
|
+
status.hint,
|
|
18313
|
+
status.command ? `Command: ${status.command}` : "",
|
|
17958
18314
|
"",
|
|
17959
18315
|
feature.description,
|
|
17960
18316
|
"",
|
|
17961
18317
|
`Check: ${feature.capabilityLabel}`,
|
|
17962
18318
|
`Package: ${feature.packageName}`,
|
|
17963
|
-
].join("\n");
|
|
18319
|
+
].filter((line) => line !== undefined && line !== null).join("\n");
|
|
17964
18320
|
}
|
|
17965
18321
|
|
|
17966
18322
|
function optionalFeatureWidgetFeatureId(key) {
|
|
@@ -17982,10 +18338,26 @@ function renderOptionalFeaturePanel() {
|
|
|
17982
18338
|
elements.optionalFeaturesBox.replaceChildren();
|
|
17983
18339
|
elements.optionalFeaturesBox.classList.remove("muted");
|
|
17984
18340
|
|
|
18341
|
+
if (optionalFeaturePackageStatusError) {
|
|
18342
|
+
const notice = make("div", "optional-feature-panel-notice error");
|
|
18343
|
+
const copy = make("div", "optional-feature-panel-notice-copy");
|
|
18344
|
+
copy.append(
|
|
18345
|
+
make("strong", undefined, "Package status check failed"),
|
|
18346
|
+
make("span", undefined, optionalFeaturePackageStatusError),
|
|
18347
|
+
);
|
|
18348
|
+
const retry = make("button", "optional-feature-action setup", "Retry");
|
|
18349
|
+
retry.type = "button";
|
|
18350
|
+
retry.addEventListener("click", () => refreshOptionalFeaturePackageStatuses({ announce: true }));
|
|
18351
|
+
notice.append(copy, retry);
|
|
18352
|
+
elements.optionalFeaturesBox.append(notice);
|
|
18353
|
+
}
|
|
18354
|
+
|
|
17985
18355
|
for (const feature of OPTIONAL_FEATURES) {
|
|
17986
18356
|
const detected = isOptionalFeatureDetected(feature.id);
|
|
17987
18357
|
const enabled = isOptionalFeatureEnabled(feature.id);
|
|
17988
|
-
const
|
|
18358
|
+
const installState = optionalFeatureInstallState(feature.id);
|
|
18359
|
+
const installing = optionalFeatureInstallInProgress.has(feature.id) || optionalFeatureInstallIsActive(installState);
|
|
18360
|
+
const failed = installState?.phase === "failed";
|
|
17989
18361
|
const packageStatus = optionalFeaturePackageStatus(feature.id);
|
|
17990
18362
|
const status = optionalFeatureStatus(feature.id);
|
|
17991
18363
|
const row = make("div", `optional-feature-row ${status.className}`);
|
|
@@ -17998,13 +18370,37 @@ function renderOptionalFeaturePanel() {
|
|
|
17998
18370
|
const title = make("div", "optional-feature-title");
|
|
17999
18371
|
title.append(make("strong", undefined, feature.label), make("span", `optional-feature-pill ${status.className}`, status.label));
|
|
18000
18372
|
main.append(title);
|
|
18373
|
+
if (status.detail) {
|
|
18374
|
+
const detail = make("div", `optional-feature-detail ${status.className === "failed" ? "error" : ""}`.trim(), status.detail);
|
|
18375
|
+
detail.setAttribute("aria-live", installing ? "polite" : "off");
|
|
18376
|
+
main.append(detail);
|
|
18377
|
+
}
|
|
18378
|
+
if (installing) {
|
|
18379
|
+
const progress = make("div", "optional-feature-progress");
|
|
18380
|
+
progress.setAttribute("aria-hidden", "true");
|
|
18381
|
+
progress.append(make("span"));
|
|
18382
|
+
main.append(progress);
|
|
18383
|
+
}
|
|
18384
|
+
if (status.hint) main.append(make("div", "optional-feature-hint", status.hint));
|
|
18385
|
+
if (status.command) {
|
|
18386
|
+
const command = make("div", "optional-feature-command");
|
|
18387
|
+
command.append(make("code", undefined, status.command));
|
|
18388
|
+
main.append(command);
|
|
18389
|
+
}
|
|
18390
|
+
if (failed && installState?.outputTail) main.append(make("pre", "optional-feature-error-output", installState.outputTail));
|
|
18001
18391
|
|
|
18002
18392
|
const actions = make("div", "optional-feature-actions");
|
|
18003
18393
|
const action = make("button", "optional-feature-action");
|
|
18004
18394
|
action.type = "button";
|
|
18005
18395
|
action.disabled = installing;
|
|
18006
18396
|
if (installing) {
|
|
18007
|
-
action.textContent = "Installing…";
|
|
18397
|
+
action.textContent = installState?.actionLabel === "Update" ? "Updating…" : "Installing…";
|
|
18398
|
+
action.setAttribute("aria-busy", "true");
|
|
18399
|
+
} else if (failed) {
|
|
18400
|
+
const retryAsUpdate = installState?.actionLabel === "Update" || packageStatus?.updateAvailable;
|
|
18401
|
+
action.textContent = "Retry…";
|
|
18402
|
+
action.classList.add(retryAsUpdate ? "update" : "install");
|
|
18403
|
+
action.addEventListener("click", () => installOptionalFeature(feature.id, { update: retryAsUpdate }));
|
|
18008
18404
|
} else if (packageStatus?.updateAvailable) {
|
|
18009
18405
|
action.textContent = "Update…";
|
|
18010
18406
|
action.classList.add("update");
|
|
@@ -18021,6 +18417,12 @@ function renderOptionalFeaturePanel() {
|
|
|
18021
18417
|
action.addEventListener("click", () => installOptionalFeature(feature.id));
|
|
18022
18418
|
}
|
|
18023
18419
|
actions.append(action);
|
|
18420
|
+
if (status.command) {
|
|
18421
|
+
const copyCommand = make("button", "optional-feature-action copy-command", "Copy cmd");
|
|
18422
|
+
copyCommand.type = "button";
|
|
18423
|
+
copyCommand.addEventListener("click", () => copyOptionalFeatureInstallCommand(feature.id));
|
|
18424
|
+
actions.append(copyCommand);
|
|
18425
|
+
}
|
|
18024
18426
|
|
|
18025
18427
|
row.append(main, actions);
|
|
18026
18428
|
elements.optionalFeaturesBox.append(row);
|
|
@@ -18130,27 +18532,67 @@ async function installOptionalFeature(featureId, { update = false } = {}) {
|
|
|
18130
18532
|
"",
|
|
18131
18533
|
`This will run npm install for ${feature.packageName} in the Web UI package install root.`,
|
|
18132
18534
|
"It can download code from npm and modify the local Pi/Web UI npm installation.",
|
|
18133
|
-
"Progress and failures will be shown in the optional-features row and activity log.",
|
|
18535
|
+
"Progress, elapsed time, the npm command, and actionable failures will be shown in the optional-features row and activity log.",
|
|
18134
18536
|
"If this feature is already installed but disabled in Pi settings, cancel and enable it there instead.",
|
|
18135
18537
|
"",
|
|
18136
18538
|
"Continue?",
|
|
18137
18539
|
].join("\n");
|
|
18138
18540
|
if (!confirm(warning)) return;
|
|
18139
18541
|
|
|
18542
|
+
const startedAt = Date.now();
|
|
18140
18543
|
optionalFeatureInstallInProgress.add(featureId);
|
|
18141
|
-
optionalFeatureInstallMessages.set(featureId, `${actionLabel}
|
|
18142
|
-
|
|
18544
|
+
optionalFeatureInstallMessages.set(featureId, `${actionLabel} preparing; resolving Web UI package install root…`);
|
|
18545
|
+
setOptionalFeatureInstallState(featureId, {
|
|
18546
|
+
phase: "preparing",
|
|
18547
|
+
actionLabel,
|
|
18548
|
+
startedAt,
|
|
18549
|
+
endedAt: 0,
|
|
18550
|
+
detail: "Resolving safe Web UI package install root…",
|
|
18551
|
+
hint: "The package manager has not started yet.",
|
|
18552
|
+
command: "",
|
|
18553
|
+
outputTail: "",
|
|
18554
|
+
});
|
|
18555
|
+
startOptionalFeatureInstallProgressTimer(featureId);
|
|
18143
18556
|
addEvent(`${update ? "updating" : "installing"} optional feature ${feature.label} (${feature.packageName})…`, "warn");
|
|
18557
|
+
setTimeout(() => {
|
|
18558
|
+
const state = optionalFeatureInstallState(featureId);
|
|
18559
|
+
if (optionalFeatureInstallInProgress.has(featureId) && state?.startedAt === startedAt && state.phase === "preparing") {
|
|
18560
|
+
optionalFeatureInstallMessages.set(featureId, `${actionLabel} running via npm; waiting for package-manager output…`);
|
|
18561
|
+
setOptionalFeatureInstallState(featureId, {
|
|
18562
|
+
phase: "installing",
|
|
18563
|
+
detail: "npm install is running; waiting for package-manager output…",
|
|
18564
|
+
hint: "npm can be quiet while resolving packages. Keep this page open; elapsed time updates here.",
|
|
18565
|
+
});
|
|
18566
|
+
}
|
|
18567
|
+
}, 1200);
|
|
18568
|
+
|
|
18144
18569
|
try {
|
|
18145
18570
|
const response = await api("/api/optional-feature-install", { method: "POST", body: { featureId }, scoped: false });
|
|
18571
|
+
const command = response.data?.command || "";
|
|
18146
18572
|
disabledOptionalFeatures.delete(featureId);
|
|
18147
18573
|
storeDisabledOptionalFeatures();
|
|
18148
|
-
|
|
18149
|
-
|
|
18574
|
+
optionalFeatureInstallMessages.set(featureId, response.data?.message || `${actionLabel} finished`);
|
|
18575
|
+
setOptionalFeatureInstallState(featureId, {
|
|
18576
|
+
phase: "refreshing",
|
|
18577
|
+
actionLabel,
|
|
18578
|
+
startedAt,
|
|
18579
|
+
detail: "npm finished; checking package status and refreshed Web UI capabilities…",
|
|
18580
|
+
hint: "If the package is installed but not detected, reload the active Pi tab.",
|
|
18581
|
+
command,
|
|
18582
|
+
outputTail: "",
|
|
18583
|
+
});
|
|
18150
18584
|
addEvent(response.data?.message || `${update ? "updated" : "installed"} ${feature.packageName}`, "info");
|
|
18151
18585
|
const output = [response.data?.stderr, response.data?.stdout].filter(Boolean).join("\n").trim();
|
|
18152
18586
|
if (output) addEvent(`npm output for ${feature.packageName}:\n${output.slice(-4000)}`, "info");
|
|
18153
18587
|
await refreshOptionalFeaturePackageStatuses({ announce: true });
|
|
18588
|
+
setOptionalFeatureInstallState(featureId, {
|
|
18589
|
+
phase: "done",
|
|
18590
|
+
actionLabel,
|
|
18591
|
+
endedAt: Date.now(),
|
|
18592
|
+
detail: response.data?.message || `${actionLabel} finished. Reload the active Pi tab to load newly installed resources.`,
|
|
18593
|
+
hint: "Use Reload if this row still says Installed instead of Enabled.",
|
|
18594
|
+
command,
|
|
18595
|
+
});
|
|
18154
18596
|
if (confirm(`${feature.label} ${actionLabel.toLowerCase()} finished. Reload the active Pi tab now to enable newly loaded resources?`)) {
|
|
18155
18597
|
sendPrompt("prompt", "/reload");
|
|
18156
18598
|
} else {
|
|
@@ -18159,10 +18601,22 @@ async function installOptionalFeature(featureId, { update = false } = {}) {
|
|
|
18159
18601
|
if (isCurrentTabContext(tabContext)) renderOptionalFeatureControls();
|
|
18160
18602
|
}
|
|
18161
18603
|
} catch (error) {
|
|
18162
|
-
|
|
18163
|
-
|
|
18604
|
+
const failure = optionalFeatureInstallFailureFromError(error);
|
|
18605
|
+
optionalFeatureInstallMessages.set(featureId, `${actionLabel} failed: ${failure.message}`);
|
|
18606
|
+
setOptionalFeatureInstallState(featureId, {
|
|
18607
|
+
phase: "failed",
|
|
18608
|
+
actionLabel,
|
|
18609
|
+
endedAt: Date.now(),
|
|
18610
|
+
detail: failure.message,
|
|
18611
|
+
hint: failure.hint,
|
|
18612
|
+
command: failure.command || optionalFeatureInstallState(featureId)?.command || "",
|
|
18613
|
+
outputTail: failure.outputTail || "",
|
|
18614
|
+
errorKind: failure.kind || "unknown",
|
|
18615
|
+
});
|
|
18616
|
+
addEvent(`${actionLabel.toLowerCase()} optional feature ${feature.label} failed: ${failure.message}${failure.hint ? `\nHint: ${failure.hint}` : ""}`, "error");
|
|
18164
18617
|
} finally {
|
|
18165
18618
|
optionalFeatureInstallInProgress.delete(featureId);
|
|
18619
|
+
clearOptionalFeatureInstallProgressTimer(featureId);
|
|
18166
18620
|
renderOptionalFeatureControls();
|
|
18167
18621
|
}
|
|
18168
18622
|
}
|
|
@@ -18378,7 +18832,7 @@ function openNativeThemeSelector() {
|
|
|
18378
18832
|
activeId: currentThemeName,
|
|
18379
18833
|
onSelect: async (item) => {
|
|
18380
18834
|
try {
|
|
18381
|
-
await
|
|
18835
|
+
await chooseTheme(item.theme.name, { announce: true });
|
|
18382
18836
|
addTransientMessage({ role: "native", title: "/theme", content: `Theme set to ${item.label}.`, level: "info" });
|
|
18383
18837
|
closeNativeCommandDialog();
|
|
18384
18838
|
} catch (error) {
|
|
@@ -20772,7 +21226,7 @@ function updateServerActionButton() {
|
|
|
20772
21226
|
button.classList.toggle("danger", action === "stop");
|
|
20773
21227
|
if (action === "restart") setServerActionStatus("Ready to restart the Web UI server.", "info");
|
|
20774
21228
|
else if (action === "update") setServerActionStatus("Ready to run pi update for Pi only, then restart the Web UI server.", "info");
|
|
20775
|
-
else if (action === "update-all") setServerActionStatus("Ready to run pi update --all
|
|
21229
|
+
else if (action === "update-all") setServerActionStatus("Ready to run pi update --all plus detected Web UI/Optional Feature Pi package root updates, then restart the Web UI server.", "info");
|
|
20776
21230
|
else if (action === "stop") setServerActionStatus("Ready to stop the Web UI server.", "info");
|
|
20777
21231
|
else setServerActionStatus();
|
|
20778
21232
|
}
|
|
@@ -21849,6 +22303,8 @@ elements.newTabMenu?.addEventListener("focusout", () => {
|
|
|
21849
22303
|
elements.newTabCurrentDirectoryButton?.addEventListener("click", () => createTerminalTab(currentDirectoryForNewTab(), { triggerButton: elements.newTabCurrentDirectoryButton }));
|
|
21850
22304
|
elements.newTabChooseDirectoryButton?.addEventListener("click", () => createTerminalTabFromChosenDirectory({ triggerButton: elements.newTabChooseDirectoryButton }));
|
|
21851
22305
|
elements.newTabWorktreeButton?.addEventListener("click", () => openBranchWorktreePicker());
|
|
22306
|
+
elements.splitTabButton?.addEventListener("click", () => splitActiveTerminalTab());
|
|
22307
|
+
elements.terminalSplitCloseButton?.addEventListener("click", () => closeTerminalSplitView());
|
|
21852
22308
|
elements.closeAllTabsButton.addEventListener("click", () => closeAllTerminalTabs());
|
|
21853
22309
|
elements.commandPaletteButton?.addEventListener("click", () => openCommandPalette());
|
|
21854
22310
|
elements.workspaceDashboardToggleButton?.addEventListener("click", () => setWorkspaceDashboardCollapsed(!workspaceDashboardCollapsed));
|
|
@@ -22394,7 +22850,7 @@ elements.themeSearchInput?.addEventListener("keydown", (event) => {
|
|
|
22394
22850
|
if (event.key === "Enter") {
|
|
22395
22851
|
event.preventDefault();
|
|
22396
22852
|
const [theme] = populateThemeSelect(availableThemes, elements.themeSearchInput.value);
|
|
22397
|
-
if (theme)
|
|
22853
|
+
if (theme) chooseTheme(theme.name, { announce: true }).catch((error) => addEvent(error.message || String(error), "error"));
|
|
22398
22854
|
} else if (event.key === "Escape") {
|
|
22399
22855
|
elements.themeSearchInput.value = "";
|
|
22400
22856
|
populateThemeSelect(availableThemes, "");
|
|
@@ -22402,7 +22858,12 @@ elements.themeSearchInput?.addEventListener("keydown", (event) => {
|
|
|
22402
22858
|
}
|
|
22403
22859
|
});
|
|
22404
22860
|
elements.themeSelect.addEventListener("change", () => {
|
|
22405
|
-
|
|
22861
|
+
chooseTheme(elements.themeSelect.value, { announce: true }).catch((error) => addEvent(error.message || String(error), "error"));
|
|
22862
|
+
});
|
|
22863
|
+
elements.themeSchemeToggle?.querySelectorAll("[data-scheme-mode]").forEach((button) => {
|
|
22864
|
+
button.addEventListener("click", () => {
|
|
22865
|
+
setThemeSchemeMode(button.dataset.schemeMode, { announce: true }).catch((error) => addEvent(error.message || String(error), "error"));
|
|
22866
|
+
});
|
|
22406
22867
|
});
|
|
22407
22868
|
if (elements.backgroundChooseButton && elements.backgroundInput) {
|
|
22408
22869
|
elements.backgroundChooseButton.addEventListener("click", () => elements.backgroundInput.click());
|