@x-tech-laboratories/x-app 0.131.0 → 0.132.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 CHANGED
@@ -25,6 +25,7 @@ depends on the agent package alone.
25
25
  | `app/window_size` | `fit_window_size(work_area)`: a first window of most of the screen's free area, between 960×640 and 1800×1200 and never past the screen; hand it to `run_desktop` as `default_size`. |
26
26
  | `app/seed` | A development database of an app's example data, made by its own calls: `seed_app_database(app, { file, reset, seed })` opens a fresh file with the app's schema and hands `seed` the app's calls, refusing a file already there without `reset` (which takes its `-wal` and `-shm` too) and the desktop app's real database in `~/.config/<id>` (`real_database_path`) whatever path leads there; `run_seed(app, seed)` is the seed script's whole command line, `<file> [--reset]`, read by `seed_target`. |
27
27
  | `app/web/app_page`, `app/web/page` | `render_app({ app, pages, general_settings })`: the page on the web, the desktop or Android in the `Shell`, with sign-in in a browser, the theme kept in this browser or, for an app with `synced_theme`, in its synced setting, the sidebar's dragged width remembered on this device (`default_sidebar_width`) unless the chrome's `sidebar_width` holds it, Your account, Settings (the app's general sections, each page's own, Connections, Desktop app, Sync, Backups and Import and export, the settings as a file) and `SyncButton`; `page_hooks<Methods>()` gives the app's typed `calls`, `use_data` and `use_settings`. The phone's host (`app/web/android`) loads only on Android. The page API's `on_event(name, listener)` hears the named events the app's services `emit`, on the web and the desktop. A page may have an `icon` (the sidebar then shows icon rows), a `use_badge` hook ("Inbox · 3"), `in_sidebar: false` with `active_as` for a page reached only by its route; `default_page` names the page an empty route opens, and the `use_chrome(parts)` hook gives the `sidebar` content under the rows, header `tools`, a `side_pane`, a `contained` window where only the page scrolls with a `main_class` for its box, `around`, which wraps the page, such as in the app's own context or with dialogs over any page, and `bare` for the page alone with no sidebar or header, such as a strip embedded in another program. `settings_categories(props)` adds the app's own Settings categories after General, for settings no one page owns. A page's `children` fold open under its row in the sidebar (`#/diet/foods`, the title "Foods · Diet", the first shown when none is named, a single child leaving the page one row); its `use_items` hook gives rows worked out as the page runs, such as each paired device, folding open under it onto `#/devices/<id>` with the title "Pixel · Devices", and its `title(parts)` names the window for its route, such as "Job 12"; and `phone_services` loads the app's own work on the phone only there, such as reminders handed to Android, told of every write, every change from another device and each return to the app; an older version's backup schedule in the page's storage moves into the setting. In a browser, Settings ends with Users and Tokens (`users_settings`) for an admin of the server, with the app's `role_text`; an app's own `use_chrome` sidebar, such as a tree, sits under the pages' rows. |
28
+ | `app/web/page_dashboards` | A page's own dashboards: a page declares `dashboard: { data_sources, ready_cards, initial, place }` and the base app draws `Dashboards` on its main route, above its view or in its place, each person's kept per page under the account preference `dashboards`, which every app's server allows and cleans with `clean_page_dashboards`, or on the device where no one signs in; the tabs' menu adds, renames, duplicates, resets and deletes them. |
28
29
  | `config/vite`, `config/electron_vite`, `config/vitest`, `config/electron_builder`, `config/tsconfig/*.json` | An X-app's configs as presets: `web_vite_config({ port })` and `android_vite_config()` for the page, `desktop_vite_config()` for electron-vite's window, daemon, preload and page, `vitest_config()` for tests in `tests/` in UTC with coverage of `src/` to the terminal, merged with the app's own floor so `autoUpdate` still raises it, and `base`, `node`, `web` and `tests` tsconfigs to extend. The page presets stand in for Capacitor where the app has none installed (`config/capacitor`'s `capacitor_stand_in`), so a web and desktop app needs no phone packages, and the dev server proxies `/api/`, leaving the page's own `api.ts` to Vite. `electron_builder_config({ id, name, app_id, comment, categories, link_scheme })` is the desktop app's AppImage and Flatpak bundle for electron-builder, the Flatpak keeping its data in `~/.config/<id>` as the other builds do, and reaching what else `flatpak_permissions` names, such as `--system-talk-name=org.bluez`. |
29
30
  | `app_new` | The `x-app-new <X-Name>` command: a new X-app's files written once, laid out as the Application Standard asks, on the base app, the presets, X-App's Nix lib and its CI actions, with an example notes feature; `--port`, `--folder`, `--no-desktop` and `--no-android`. |
30
31
  | `idle_watch` | `step_idle_watch`: time away from the computer while something runs, such as a timer: each look at the idle seconds (the desktop's `get_idle_seconds`) moves the watch on, and once someone comes back it hands back the stretch away (`AwaySpan`) when it passed the threshold, a long gap between looks, as when the computer slept, counting as time away from the last look; `fresh_idle_watch` to start. |
@@ -12,7 +12,7 @@ import { define_bridge } from "../electron/bridge.js";
12
12
  import { define_events } from "../electron/events.js";
13
13
  import { local_mcp_method_names } from "../local_mcp_protocol.js";
14
14
  import { create_settings_store, read_setting, settings_of, write_setting } from "../settings.js";
15
- import { migrate } from "../sql.js";
15
+ import { in_transaction, migrate } from "../sql.js";
16
16
  import { create_sync_engine } from "../sync_engine.js";
17
17
  import { backup_method_names } from "../backups.js";
18
18
  import { peer_listening_method_names, sync_device_method_names } from "../sync_protocol.js";
@@ -113,15 +113,20 @@ export function define_app(options) {
113
113
  if (options.upgrade_layout?.needed(database))
114
114
  options.upgrade_layout.run(database);
115
115
  // Sync's and history's triggers name columns, so they come off while a step reshapes a table; install puts them back.
116
- sync_engine.drop_triggers(database);
117
- for (const history of histories)
118
- history.drop_triggers?.(database);
116
+ // Each group is one transaction: a commit per trigger made opening take seconds where every commit waits on the disk.
117
+ in_transaction(database, () => {
118
+ sync_engine.drop_triggers(database);
119
+ for (const history of histories)
120
+ history.drop_triggers?.(database);
121
+ });
119
122
  // Each feature keeps its own schema version, so features grow apart without renumbering each other's steps.
120
123
  for (const feature of features)
121
124
  migrate(database, feature.migrations, { owner: feature.id });
122
- for (const history of histories)
123
- history.install(database);
124
- sync_engine.install(database);
125
+ in_transaction(database, () => {
126
+ for (const history of histories)
127
+ history.install(database);
128
+ sync_engine.install(database);
129
+ });
125
130
  for (const feature of features)
126
131
  feature.on_open?.(database);
127
132
  // What opening changed, such as rows an upgrade moved, is kept as a change made on this device.
@@ -2,6 +2,7 @@
2
2
  // OpenAPI and MCP, the server's backups and its own sync peer, all on one database. run_server starts it from the
3
3
  // app's config, as `npm start` and the NixOS module run it.
4
4
  // ── Imports ──────────────────────────────────────────────────────────────────
5
+ import { clean_page_dashboards } from "../dashboard.js";
5
6
  import { existsSync, mkdirSync, readFileSync, rmSync } from "node:fs";
6
7
  import { hostname } from "node:os";
7
8
  import { dirname, join, resolve } from "node:path";
@@ -264,7 +265,8 @@ export async function build_server(app, options) {
264
265
  // A token is refused the calls only the user at the page may make; a read-only one may make the calls that only read.
265
266
  call_of: calls_under("/api/call"),
266
267
  is_read_only: app.is_read_only,
267
- prefs: app.account_prefs ?? null,
268
+ // Every page's dashboards are kept for each person beside the app's own preferences.
269
+ prefs: { ...app.account_prefs, keys: { dashboards: clean_page_dashboards, ...app.account_prefs?.keys } },
268
270
  page_only: app.page_only,
269
271
  });
270
272
  const { changes, database } = options;
@@ -3,6 +3,7 @@ import "@x-tech-laboratories/halon/halon.css";
3
3
  import type { App } from "../define.ts";
4
4
  import { type AppPages } from "./settings_page.tsx";
5
5
  export type { AppChrome, AppPage, AppPages, AppSubpage, PageSettingsProps } from "./settings_page.tsx";
6
+ export type { PageDashboard } from "./page_dashboards.tsx";
6
7
  export declare const default_sidebar_width: {
7
8
  default_width: number;
8
9
  min: number;
@@ -18,6 +18,7 @@ import { apply_theme_colors, local_theme_storage, pinned_theme_choice, read_serv
18
18
  import { phone_outside_fetch } from "../outside_fetch.js";
19
19
  import { desktop_api, is_android, is_desktop, web_api } from "./hosts.js";
20
20
  import { calls, data_watch, page, set_page_api, set_page_reach, use_data, use_settings } from "./page.js";
21
+ import { PageDashboardsView } from "./page_dashboards.js";
21
22
  import { SettingsView } from "./settings_page.js";
22
23
  // ── Pages ────────────────────────────────────────────────────────────────────
23
24
  // Relative, so a server behind a proxy under a folder keeps it.
@@ -99,6 +100,15 @@ function use_default_page(pages) {
99
100
  return null;
100
101
  return pages.pages.some((each) => each.id === chosen.data) ? String(chosen.data) : fallback;
101
102
  }
103
+ // A page's view with its dashboards above it, or in its place, on its main route.
104
+ function with_dashboards(shown, rest, app_id, client) {
105
+ if (!shown.dashboard || rest.length > 0)
106
+ return shown.view(rest);
107
+ const dashboards = _jsx(PageDashboardsView, { app_id: app_id, page_id: shown.id, dashboard: shown.dashboard, client: client });
108
+ if (shown.dashboard.place === "only")
109
+ return _jsx("div", { className: "page", children: dashboards });
110
+ return _jsxs(_Fragment, { children: [_jsx("div", { className: "page", children: dashboards }), shown.view(rest)] });
111
+ }
102
112
  function Pages({ pages, account }) {
103
113
  const default_page = use_default_page(pages);
104
114
  const route = use_route();
@@ -142,7 +152,8 @@ function RoutedPages({ pages, account, default_page }) {
142
152
  return { id: each.id, label: row_label(index), href: `#/${each.id}`, ...(under.length ? { children: under.map((child) => ({ id: child.id, label: child.label, href: `#/${each.id}/${child.id}` })) } : {}) };
143
153
  });
144
154
  const views = listed.map((each, index) => ({ id: each.id, label: row_label(index), href: `#/${each.id}`, ...(each.icon ? { icon: each.icon } : {}) }));
145
- const view = shown ? shown.view(rest) : is_account ? _jsx(AccountPage, { account: account }) : _jsx(SettingsView, { pages: pages, is_admin: account === null || is_admin(account.me), viewer: account ? { client: accounts, me: account.me } : null });
155
+ const own_view = shown ? with_dashboards(shown, rest, app.id, account ? accounts : null) : null;
156
+ const view = shown ? own_view : is_account ? _jsx(AccountPage, { account: account }) : _jsx(SettingsView, { pages: pages, is_admin: account === null || is_admin(account.me), viewer: account ? { client: accounts, me: account.me } : null });
146
157
  const framed = _jsx(Fragment, { children: view }, view_key);
147
158
  if (chrome.bare)
148
159
  return _jsx(_Fragment, { children: chrome.around ? chrome.around(framed) : framed });
@@ -0,0 +1,20 @@
1
+ import { type Dashboard } from "../../dashboard.ts";
2
+ import type { AccountPrefsClient } from "../../web/react/account_prefs.ts";
3
+ import { type DataSource, type ReadyCardKind } from "../../web/react/dashboard.tsx";
4
+ export interface PageDashboard {
5
+ data_sources: DataSource[];
6
+ ready_cards?: ReadyCardKind[];
7
+ initial?: () => Dashboard;
8
+ place?: "above" | "only";
9
+ refresh_in_milliseconds?: number;
10
+ }
11
+ export declare const page_dashboards_pref = "dashboards";
12
+ interface PageDashboardsProps {
13
+ app_id: string;
14
+ page_id: string;
15
+ dashboard: PageDashboard;
16
+ client: AccountPrefsClient | null;
17
+ width?: number;
18
+ }
19
+ export declare function PageDashboardsView(props: PageDashboardsProps): import("react").JSX.Element;
20
+ export {};
@@ -0,0 +1,45 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // A page's own dashboards, as the base app draws them above the page: the app declares the data its cards may chart,
3
+ // its ready-made cards and the dashboard each person starts with, and every person arranges their own, kept with their
4
+ // account or, with no one signed in, on this device. The tabs' menu adds, renames, duplicates, resets and deletes them.
5
+ // ── Imports ──────────────────────────────────────────────────────────────────
6
+ import { clean_page_dashboards } from "../../dashboard.js";
7
+ import { use_account_pref } from "../../web/react/account_prefs.js";
8
+ import { Dashboards } from "../../web/react/dashboard.js";
9
+ import { use_pref } from "../../web/react/prefs.js";
10
+ import { Failure, Skeleton } from "../../web/react/states.js";
11
+ import { toast } from "../../web/react/toasts.js";
12
+ import { data_watch } from "./page.js";
13
+ // The account preference every page's dashboards are kept under, which the base app's server allows.
14
+ export const page_dashboards_pref = "dashboards";
15
+ // ── Keeping ──────────────────────────────────────────────────────────────────
16
+ const no_dashboards = {};
17
+ const is_page_dashboards = (value) => typeof value === "object" && value !== null && JSON.stringify(clean_page_dashboards(value)) === JSON.stringify(value);
18
+ function use_kept_on_account(client) {
19
+ const [value, set, state] = use_account_pref(client, page_dashboards_pref, no_dashboards, is_page_dashboards, {
20
+ on_save_error: (message) => toast(message, { tone: "bad" }),
21
+ });
22
+ return [value, set, state.status, state.error];
23
+ }
24
+ function use_kept_here(app_id) {
25
+ const [value, set] = use_pref(`${app_id}.dashboards`, no_dashboards, is_page_dashboards);
26
+ return [value, set, "loaded", null];
27
+ }
28
+ export function PageDashboardsView(props) {
29
+ return props.client ? _jsx(OnAccount, { ...props, client: props.client }) : _jsx(Here, { ...props });
30
+ }
31
+ function OnAccount(props) {
32
+ return _jsx(Shown, { ...props, kept: use_kept_on_account(props.client) });
33
+ }
34
+ function Here(props) {
35
+ return _jsx(Shown, { ...props, kept: use_kept_here(props.app_id) });
36
+ }
37
+ function Shown({ app_id, page_id, dashboard, kept, width }) {
38
+ const [all, set_all, status, error] = kept;
39
+ const [active, set_active] = use_pref(`${app_id}.dashboard.${page_id}`, "");
40
+ if (status === "loading")
41
+ return _jsx(Skeleton, { lines: 6 });
42
+ if (status === "failed")
43
+ return _jsx(Failure, { error: error, retry: () => window.location.reload() });
44
+ return (_jsx(Dashboards, { dashboards: all[page_id] ?? [], on_change: (next) => set_all({ ...all, [page_id]: next }), active: active || null, on_select: set_active, data_sources: dashboard.data_sources, ready_cards: dashboard.ready_cards ?? [], refresh: { watch: data_watch, refresh_in_milliseconds: dashboard.refresh_in_milliseconds ?? 60_000 }, ...(dashboard.initial ? { new_dashboard: dashboard.initial } : {}), ...(width !== undefined ? { width } : {}) }));
45
+ }
@@ -1,3 +1,4 @@
1
+ import type { PageDashboard } from "./page_dashboards.tsx";
1
2
  import type { IconGlyph } from "../../web/react/icons.tsx";
2
3
  import type { AccountsClient, Me } from "../../web/accounts.ts";
3
4
  import { type AccessEditor } from "../../web/react/accounts.tsx";
@@ -23,6 +24,7 @@ export interface AppPage {
23
24
  children?: readonly AppSubpage[];
24
25
  use_items?: () => readonly AppSubpage[] | null;
25
26
  title?: (parts: string[]) => string | null;
27
+ dashboard?: PageDashboard;
26
28
  }
27
29
  export interface AppSubpage {
28
30
  id: string;
@@ -1,7 +1,4 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- // The base app's Settings: the app's own general sections, each page's own settings, the desktop app's daemons and
3
- // its own settings, sync on a device, and backups of a device or the server.
4
- // ── Imports ──────────────────────────────────────────────────────────────────
5
2
  import { useEffect, useState } from "react";
6
3
  import { BackupSettings } from "../../web/react/backup_settings.js";
7
4
  import { TrustedCertificates } from "../../web/react/certificates.js";
@@ -120,3 +120,9 @@ export declare const dashboard_limits: {
120
120
  filter_leaves: number;
121
121
  };
122
122
  export declare function clean_dashboards(value: unknown): Dashboard[];
123
+ export type PageDashboards = Record<string, Dashboard[]>;
124
+ export declare const page_dashboard_limits: {
125
+ pages: number;
126
+ id: number;
127
+ };
128
+ export declare function clean_page_dashboards(value: unknown): PageDashboards;
package/dist/dashboard.js CHANGED
@@ -429,3 +429,16 @@ export function clean_dashboards(value) {
429
429
  });
430
430
  return unique_by_id(dashboards);
431
431
  }
432
+ export const page_dashboard_limits = { pages: 100, id: 100 };
433
+ // Saved dashboards of every page as well-formed ones: a page id that is not plain text is left out, and each page's dashboards are cleaned as `clean_dashboards` cleans them.
434
+ export function clean_page_dashboards(value) {
435
+ if (typeof value !== "object" || value === null || Array.isArray(value))
436
+ return {};
437
+ const cleaned = {};
438
+ for (const [page, dashboards] of Object.entries(value).slice(0, page_dashboard_limits.pages)) {
439
+ if (page === "" || page.length > page_dashboard_limits.id)
440
+ continue;
441
+ cleaned[page] = clean_dashboards(dashboards);
442
+ }
443
+ return cleaned;
444
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x-tech-laboratories/x-app",
3
- "version": "0.131.0",
3
+ "version": "0.132.1",
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": {