@x-tech-laboratories/x-app 0.121.0 → 0.123.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 +22 -12
- package/dist/agent/programs.d.ts +4 -0
- package/dist/agent/programs.js +24 -4
- package/dist/agent/ssh_config.d.ts +12 -0
- package/dist/agent/ssh_config.js +72 -0
- package/dist/app/daemon.d.ts +1 -0
- package/dist/app/daemon.js +21 -8
- package/dist/app/define.d.ts +16 -0
- package/dist/app/desktop.d.ts +1 -0
- package/dist/app/desktop.js +7 -4
- package/dist/app/host_tables.d.ts +1 -0
- package/dist/app/host_tables.js +16 -2
- package/dist/app/protocol.d.ts +4 -0
- package/dist/app/protocol.js +2 -0
- package/dist/app/server.d.ts +14 -3
- package/dist/app/server.js +88 -20
- package/dist/app/services.d.ts +13 -2
- package/dist/app/web/app_page.d.ts +1 -1
- package/dist/app/web/app_page.js +42 -14
- package/dist/app/web/hosts.d.ts +1 -1
- package/dist/app/web/hosts.js +2 -2
- package/dist/app/web/portal.d.ts +1 -0
- package/dist/app/web/portal.js +12 -1
- package/dist/app/web/settings_page.d.ts +9 -1
- package/dist/app/web/settings_page.js +31 -3
- package/dist/config/electron_builder.d.ts +1 -0
- package/dist/config/electron_builder.js +1 -0
- package/dist/phone_notices.d.ts +7 -0
- package/dist/server/sqlite_backups.d.ts +2 -2
- package/dist/server/sqlite_backups.js +2 -2
- package/dist/server/viewer_scope.d.ts +3 -0
- package/dist/server/viewer_scope.js +14 -0
- package/dist/web/react/shell.js +1 -1
- package/dist/web/theme.d.ts +8 -0
- package/dist/web/theme.js +23 -0
- package/package.json +1 -1
|
@@ -8,11 +8,13 @@ import { TrustedCertificates } from "../../web/react/certificates.js";
|
|
|
8
8
|
import { ConnectionSettings } from "../../web/react/connections.js";
|
|
9
9
|
import { LocalMcpSettings } from "../../web/react/local_mcp_settings.js";
|
|
10
10
|
import { Switch } from "../../web/react/controls.js";
|
|
11
|
+
import { users_settings } from "../../web/react/accounts.js";
|
|
11
12
|
import { PageHeading, SettingRow, SettingsPage } from "../../web/react/layout.js";
|
|
12
13
|
import { Loaded } from "../../web/react/states.js";
|
|
13
14
|
import { RemoteAccessSettings } from "../../web/react/remote_access_settings.js";
|
|
14
15
|
import { PeerListeningSettings, SyncSettings } from "../../web/react/sync_settings.js";
|
|
15
|
-
import {
|
|
16
|
+
import { read_picked, save_text } from "../../web/files.js";
|
|
17
|
+
import { attempt, attempt_value, toast } from "../../web/react/toasts.js";
|
|
16
18
|
import { calls, data_watch, page, use_settings } from "./page.js";
|
|
17
19
|
// ── Sections ─────────────────────────────────────────────────────────────────
|
|
18
20
|
// A phone's backups go in a folder picked once in its storage, where file managers and sync apps reach them.
|
|
@@ -56,6 +58,23 @@ function NoticeSwitches({ app, switches }) {
|
|
|
56
58
|
attempt(switches.set(key, on));
|
|
57
59
|
} }) }, key))) }));
|
|
58
60
|
}
|
|
61
|
+
// Every setting but this device's own, as a file to take to another device or install, and read back.
|
|
62
|
+
function SettingsFile({ app_id }) {
|
|
63
|
+
const settings_calls = calls();
|
|
64
|
+
const export_file = async () => {
|
|
65
|
+
const file = await attempt_value(() => settings_calls.export_settings());
|
|
66
|
+
if (file)
|
|
67
|
+
save_text(`${app_id}-settings-${new Date().toISOString().slice(0, 10)}.json`, JSON.stringify(file, null, 2));
|
|
68
|
+
};
|
|
69
|
+
const import_file = async (text) => {
|
|
70
|
+
if (text === null)
|
|
71
|
+
return;
|
|
72
|
+
const result = await attempt_value(() => settings_calls.import_settings(text));
|
|
73
|
+
if (result)
|
|
74
|
+
toast(result.changed === 1 ? "1 setting set." : `${result.changed} settings set.`, { tone: "good" });
|
|
75
|
+
};
|
|
76
|
+
return (_jsx(SettingRow, { label: "Settings file", hint: "Every setting but this device's own, such as its notifications; keys for other services stay out.", children: _jsxs("div", { className: "button-list", children: [_jsx("button", { type: "button", onClick: () => void export_file(), children: "Export" }), _jsxs("label", { className: "button", children: ["Import", _jsx("input", { type: "file", accept: ".json,application/json", className: "visually-hidden", "aria-label": "Import settings", onChange: (event) => void read_picked(event).then(import_file) })] })] }) }));
|
|
77
|
+
}
|
|
59
78
|
// A desktop window on a server's daemon, or a phone that keeps no data, works on the host's data, as a browser does.
|
|
60
79
|
function storage_category(pages, is_admin) {
|
|
61
80
|
const { app } = pages;
|
|
@@ -81,6 +100,7 @@ function storage_category(pages, is_admin) {
|
|
|
81
100
|
}
|
|
82
101
|
if (desktop && !on_server)
|
|
83
102
|
sections.push({ id: "storage", heading: "Storage", hint: `Where this computer keeps its ${data_name}.`, content: _jsx(DataFolder, { desktop: desktop }) });
|
|
103
|
+
sections.push({ id: "settings-file", heading: "Import and export", hint: `Take ${name}'s settings to another device, or bring them back.`, content: _jsx(SettingsFile, { app_id: app.id }) });
|
|
84
104
|
if (backups && (!on_server || is_admin)) {
|
|
85
105
|
const hint = backup_folder ? `This device's ${data_name}, kept in a folder of the phone's storage.` : on_server ? `The server's ${data_name}, kept in its data folder.` : `This device's ${data_name}, kept beside its database.`;
|
|
86
106
|
// This computer's backups folder opens in the file manager.
|
|
@@ -90,8 +110,15 @@ function storage_category(pages, is_admin) {
|
|
|
90
110
|
}
|
|
91
111
|
return sections.length === 0 ? [] : [{ heading: host === "web" ? "Server" : "This device", sections }];
|
|
92
112
|
}
|
|
93
|
-
// ──
|
|
94
|
-
|
|
113
|
+
// ── Users ────────────────────────────────────────────────────────────────────
|
|
114
|
+
// The server's users and every token, for its admin in a browser; nobody else sees the category.
|
|
115
|
+
function users_category(pages, viewer) {
|
|
116
|
+
if (viewer === null)
|
|
117
|
+
return [];
|
|
118
|
+
const sections = users_settings({ client: viewer.client, me: viewer.me, ...(pages.role_text ? { role_text: pages.role_text } : {}) });
|
|
119
|
+
return sections.length > 0 ? [{ heading: "Users", sections }] : [];
|
|
120
|
+
}
|
|
121
|
+
export function SettingsView({ pages, is_admin = true, viewer = null }) {
|
|
95
122
|
const settings = use_settings();
|
|
96
123
|
const set_setting = async (key, value) => void (await calls().set_setting(key, value));
|
|
97
124
|
return (_jsxs(_Fragment, { children: [_jsx(PageHeading, { title: "Settings" }), _jsx(Loaded, { resource: settings, children: (values) => {
|
|
@@ -104,6 +131,7 @@ export function SettingsView({ pages, is_admin = true }) {
|
|
|
104
131
|
.map((each) => ({ heading: each.label, sections: each.settings?.(props) ?? [] }))
|
|
105
132
|
.filter((category) => category.sections.length > 0),
|
|
106
133
|
...storage_category(pages, is_admin && page().admin !== false),
|
|
134
|
+
...users_category(pages, viewer),
|
|
107
135
|
] }));
|
|
108
136
|
} })] }));
|
|
109
137
|
}
|
|
@@ -6,5 +6,6 @@ export interface ElectronBuilderOptions {
|
|
|
6
6
|
categories?: readonly string[];
|
|
7
7
|
link_scheme?: string;
|
|
8
8
|
copyright?: string;
|
|
9
|
+
flatpak_permissions?: readonly string[];
|
|
9
10
|
}
|
|
10
11
|
export declare function electron_builder_config(options: ElectronBuilderOptions): Record<string, unknown>;
|
|
@@ -37,6 +37,7 @@ export function electron_builder_config(options) {
|
|
|
37
37
|
`--filesystem=xdg-config/${options.id}:create`,
|
|
38
38
|
// The login entry that starts the app in the background.
|
|
39
39
|
"--filesystem=xdg-config/autostart:create",
|
|
40
|
+
...(options.flatpak_permissions ?? []),
|
|
40
41
|
],
|
|
41
42
|
},
|
|
42
43
|
};
|
package/dist/phone_notices.d.ts
CHANGED
|
@@ -33,6 +33,13 @@ export interface LocalNotificationsLike {
|
|
|
33
33
|
extra?: unknown;
|
|
34
34
|
};
|
|
35
35
|
}) => void): Promise<unknown>;
|
|
36
|
+
removeDeliveredNotifications?(options: {
|
|
37
|
+
notifications: {
|
|
38
|
+
id: number;
|
|
39
|
+
title: string;
|
|
40
|
+
body: string;
|
|
41
|
+
}[];
|
|
42
|
+
}): Promise<void>;
|
|
36
43
|
}
|
|
37
44
|
export interface PhoneNotice {
|
|
38
45
|
key: string;
|
|
@@ -5,8 +5,8 @@ export interface SqliteBackupOptions {
|
|
|
5
5
|
naming: BackupNaming;
|
|
6
6
|
database: () => SqlDatabase;
|
|
7
7
|
database_path: () => string;
|
|
8
|
-
close?: () => void
|
|
9
|
-
open?: () => void
|
|
8
|
+
close?: () => void | Promise<void>;
|
|
9
|
+
open?: () => void | Promise<void>;
|
|
10
10
|
after_restore?: (database: SqlDatabase) => void;
|
|
11
11
|
after_staging?: () => void;
|
|
12
12
|
}
|
|
@@ -33,14 +33,14 @@ export function sqlite_backups(options) {
|
|
|
33
33
|
options.after_staging?.();
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
|
-
close();
|
|
36
|
+
await close();
|
|
37
37
|
try {
|
|
38
38
|
rmSync(`${target}-wal`, { force: true });
|
|
39
39
|
rmSync(`${target}-shm`, { force: true });
|
|
40
40
|
copyFileSync(source, target);
|
|
41
41
|
}
|
|
42
42
|
finally {
|
|
43
|
-
open();
|
|
43
|
+
await open();
|
|
44
44
|
}
|
|
45
45
|
options.after_restore?.(options.database());
|
|
46
46
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Who a request a host answers came from, kept across the call's awaits, so work a route hands off, such as an app's
|
|
2
|
+
// host table call, can name who asked in its audit log or refuse what they may not do.
|
|
3
|
+
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
4
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
|
+
// ── Scope ────────────────────────────────────────────────────────────────────
|
|
6
|
+
const storage = new AsyncLocalStorage();
|
|
7
|
+
// Runs the work with the viewer given as the one asking.
|
|
8
|
+
export function with_viewer(viewer, work) {
|
|
9
|
+
return storage.run(viewer ?? null, work);
|
|
10
|
+
}
|
|
11
|
+
// The viewer of the request in hand, or null outside one or when nobody signed in, as on a daemon's own socket.
|
|
12
|
+
export function current_viewer() {
|
|
13
|
+
return storage.getStore() ?? null;
|
|
14
|
+
}
|
package/dist/web/react/shell.js
CHANGED
|
@@ -248,7 +248,7 @@ export function Shell({ brand, brand_icon, brand_logo, sections = [], views, act
|
|
|
248
248
|
window.scrollTo(0, 0);
|
|
249
249
|
main.current?.scrollTo?.(0, 0);
|
|
250
250
|
}, [view_key]);
|
|
251
|
-
return (_jsxs(_Fragment, { children: [_jsx("a", { className: "skip", href: "#main", children: labels.skip_to_content }), _jsxs("header", { className: "topbar", children: [_jsx("button", { ref: menu_button, className: "icon menu-button", "aria-label": labels.open_menu, "aria-expanded": menu_open, "aria-controls": "sidebar", onClick: () => set_menu_open(!menu_open), children: "\u2630" }), !(brand_in_sidebar && !logged_out) && _jsx("a", { href: brand_href, className: "brand", children: _jsx(BrandMark, { brand: brand, icon: brand_icon, logo: brand_logo }) }), !logged_out && tools, pane_open && !narrow && !logged_out && pane_head] }), _jsxs("div", { className: "layout", style: width === undefined ? undefined : { "--sidebar-width": `${width}px` }, children: [_jsxs(Sidebar, { ref: sidebar, id: "sidebar", className: "sidebar", "aria-label": views ? undefined : labels.main_navigation, children: [brand_in_sidebar && _jsx("a", { href: brand_href, className: "sidebar-brand", children: _jsx(BrandMark, { brand: brand, icon: brand_icon, logo: brand_logo }) }), views || has_content || folding ? (_jsxs("div", { className: "sidebar-content", children: [views && (_jsx("nav", { className: "sidebar-nav", "aria-label": labels.main_navigation, children: views.map((view) => (_jsx(RowLink, { href: view.href, current: view.id === active, icon: view.icon && _jsx(Icon, { icon: view.icon }), label: view.label }, view.id))) })), folding && _jsx(SectionTree, { sections: sections, active: active, active_item: active_item, pref_key: sections_pref, label: labels.main_navigation }), sidebar_content] })) : (_jsx("div", { className: "sidebar-links", children: sections.map((section) => (_jsx("a", { href: section.href, "data-section": section.id, className: section.id === active ? "active" : undefined, "aria-current": section.id === active ? "page" : undefined, children: section.label }, section.id))) })), _jsxs("div", { className: "sidebar-foot", children: [sidebar_foot, _jsx(ThemeRow, { choice: theme, labels: labels }), user_name !== undefined && (_jsxs("div", { className: "sidebar-account", children: [user_href
|
|
251
|
+
return (_jsxs(_Fragment, { children: [_jsx("a", { className: "skip", href: "#main", children: labels.skip_to_content }), _jsxs("header", { className: "topbar", children: [_jsx("button", { ref: menu_button, className: "icon menu-button", "aria-label": labels.open_menu, "aria-expanded": menu_open, "aria-controls": "sidebar", onClick: () => set_menu_open(!menu_open), children: "\u2630" }), !(brand_in_sidebar && !logged_out) && _jsx("a", { href: brand_href, className: "brand", children: _jsx(BrandMark, { brand: brand, icon: brand_icon, logo: brand_logo }) }), !logged_out && tools, pane_open && !narrow && !logged_out && pane_head] }), _jsxs("div", { className: "layout", style: width === undefined ? undefined : { "--sidebar-width": `${width}px` }, children: [_jsxs(Sidebar, { ref: sidebar, id: "sidebar", className: "sidebar", "aria-label": views ? undefined : labels.main_navigation, children: [brand_in_sidebar && _jsx("a", { href: brand_href, className: "sidebar-brand", children: _jsx(BrandMark, { brand: brand, icon: brand_icon, logo: brand_logo }) }), views || has_content || folding ? (_jsxs("div", { className: "sidebar-content", children: [views && (_jsx("nav", { className: "sidebar-nav", "aria-label": labels.main_navigation, children: views.map((view) => (_jsx(RowLink, { href: view.href, current: view.id === active, icon: view.icon && _jsx(Icon, { icon: view.icon }), label: view.label }, view.id))) })), folding && _jsx(SectionTree, { sections: sections, active: active, active_item: active_item, pref_key: sections_pref, label: labels.main_navigation }), sidebar_content] })) : (_jsx("div", { className: "sidebar-links", children: sections.map((section) => (_jsx("a", { href: section.href, "data-section": section.id, className: section.id === active ? "active" : undefined, "aria-current": section.id === active ? "page" : undefined, children: section.label }, section.id))) })), _jsxs("div", { className: "sidebar-foot", children: [sidebar_foot, !theme.pinned && _jsx(ThemeRow, { choice: theme, labels: labels }), user_name !== undefined && (_jsxs("div", { className: "sidebar-account", children: [user_href
|
|
252
252
|
? _jsx(RowLink, { href: user_href, current: location.hash === user_href, icon: _jsx(PersonIcon, {}), label: user_name })
|
|
253
253
|
: _jsx("span", { className: "tree-row", children: _jsxs("span", { className: "tree-label", children: [_jsx(PersonIcon, {}), _jsx("span", { className: "user-name", children: user_name })] }) }), on_logout && _jsx("button", { className: "tree-row", onClick: on_logout, children: labels.sign_out })] })), settings && _jsx(RowLink, { href: settings.href, current: settings.active ?? active === "settings", icon: _jsx(CogIcon, {}), label: labels.settings, on_open: settings.on_open })] }), sidebar_width && width !== undefined && (_jsx(ResizeHandle, { side: "left", size: width, min: sidebar_width.min, max: sidebar_width.max, default_size: sidebar_width.default_width, on_resize: (next) => change_width(next, false), on_resize_end: (next) => change_width(next, true), label: labels.resize_sidebar, class_name: "sidebar-resize" }))] }), _jsx("div", { className: "scrim", hidden: !menu_open, onClick: () => set_menu_open(false) }), side_pane ? (_jsxs("main", { ref: main, id: "main", className: [main_class, "with-side-pane"].filter(Boolean).join(" "), tabIndex: -1,
|
|
254
254
|
// Closed, the pane's column takes no room, so main's children keep their place and their state.
|
package/dist/web/theme.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export interface ThemeChoice {
|
|
|
4
4
|
set(theme: Theme): void;
|
|
5
5
|
on_change(listener: (theme: Theme) => void): () => void;
|
|
6
6
|
apply(theme?: Theme): void;
|
|
7
|
+
readonly pinned?: boolean;
|
|
7
8
|
}
|
|
8
9
|
export interface ThemeStorage {
|
|
9
10
|
read(): Theme | undefined;
|
|
@@ -13,3 +14,10 @@ export declare function local_theme_storage(storage_key: string): ThemeStorage;
|
|
|
13
14
|
export declare function theme_choice(where: string | ThemeStorage): ThemeChoice;
|
|
14
15
|
export declare function next_theme(theme: Theme): Theme;
|
|
15
16
|
export declare function follow_host_theme(): boolean;
|
|
17
|
+
export interface ServerTheme {
|
|
18
|
+
scheme: Theme | null;
|
|
19
|
+
colors: Record<string, string>;
|
|
20
|
+
}
|
|
21
|
+
export declare function read_server_theme(value: unknown): ServerTheme;
|
|
22
|
+
export declare function pinned_theme_choice(theme: Theme): ThemeChoice;
|
|
23
|
+
export declare function apply_theme_colors(colors: Readonly<Record<string, string>>, root?: HTMLElement): void;
|
package/dist/web/theme.js
CHANGED
|
@@ -56,3 +56,26 @@ export function follow_host_theme() {
|
|
|
56
56
|
document.documentElement.classList.toggle("follows-host-theme", is_hosted);
|
|
57
57
|
return is_hosted;
|
|
58
58
|
}
|
|
59
|
+
const token_name = /^[a-z][a-z0-9-]*$/;
|
|
60
|
+
// The config's theme block as a server theme, leaving out what is not a scheme, a token name or a colour.
|
|
61
|
+
export function read_server_theme(value) {
|
|
62
|
+
const block = typeof value === "object" && value !== null ? value : {};
|
|
63
|
+
const scheme = block.scheme === "light" || block.scheme === "dark" || block.scheme === "system" ? block.scheme : null;
|
|
64
|
+
const colors = {};
|
|
65
|
+
if (typeof block.colors === "object" && block.colors !== null) {
|
|
66
|
+
for (const [name, color] of Object.entries(block.colors)) {
|
|
67
|
+
if (token_name.test(name) && typeof color === "string" && /^[#a-zA-Z0-9(),.%\s-]+$/.test(color))
|
|
68
|
+
colors[name] = color.trim();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return { scheme, colors };
|
|
72
|
+
}
|
|
73
|
+
// The scheme the server pins, which a pick does not change, so the page shows that scheme alone and no theme switch.
|
|
74
|
+
export function pinned_theme_choice(theme) {
|
|
75
|
+
return { ...theme_choice({ read: () => (theme === "system" ? undefined : theme), write: () => undefined }), pinned: true };
|
|
76
|
+
}
|
|
77
|
+
// Sets the server's colours on the page's root, where they win over both schemes' tokens.
|
|
78
|
+
export function apply_theme_colors(colors, root = document.documentElement) {
|
|
79
|
+
for (const [name, color] of Object.entries(colors))
|
|
80
|
+
root.style.setProperty(`--${name}`, color);
|
|
81
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x-tech-laboratories/x-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.123.0",
|
|
4
4
|
"description": "Code the X-apps share: agents and their long runs, passwords and sign-in, the Fastify server pieces, durations, and the web page's helpers and widgets",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"repository": {
|