@x-tech-laboratories/x-app 0.115.0 → 0.116.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 +17 -10
- package/dist/app/define.d.ts +3 -0
- package/dist/app/define.js +6 -1
- package/dist/app/desktop.d.ts +7 -2
- package/dist/app/desktop.js +11 -0
- package/dist/app/protocol.d.ts +8 -1
- package/dist/app/protocol.js +1 -1
- package/dist/app/web/app_page.d.ts +5 -0
- package/dist/app/web/app_page.js +45 -4
- package/dist/app/web/settings_page.d.ts +3 -2
- package/dist/app/web/settings_page.js +13 -1
- package/dist/app_android.d.ts +2 -0
- package/dist/app_android.js +36 -2
- package/dist/app_android_key.d.ts +10 -0
- package/dist/app_android_key.js +53 -0
- package/dist/app_new.js +35 -9
- package/dist/config/electron_builder.d.ts +10 -0
- package/dist/config/electron_builder.js +43 -0
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -9,15 +9,15 @@ an app moves over by changing the package name in its imports and its `x-libs-*`
|
|
|
9
9
|
|
|
10
10
|
| Import | What it holds |
|
|
11
11
|
| ---------------------------------------- | ----------------------------------------------------------------------------- |
|
|
12
|
-
| `app/define` | The base app: `define_app` puts an X-app's name, ports, files, its own settings and its `define_feature` features (tables, migrations, calls, `api_spec`, settings, histories) together into one store every device keeps (`open_store` calling each feature's `on_open`, `needs_upgrade`, `bind_methods(database, on_change, caller)` running each call as its `caller`, calling each feature's `after_write`, recording versions and announcing writes, `is_read_only`), `page_only` (the specs' `page_only` calls and the writes of `user_only` settings, refused with `page_only_refusal`), its sync engine, its backups' names and schedule, and its bridges named after the app; `AppMethodsOf<typeof app>` types the app's calls. `history_days` sets how far an app's history reaches back until the user chooses (365 unless set); what opening changed is recorded as this device's version, and old versions are pruned on opening and after a write once a day. `settings_knows(key)` lets an import take keys without a spec of their own, such as `diet.target_protein`; `upgrade_layout: { needed, run }` brings a database an older version laid out its own way, such as a versions table keyed another way, in line before any migration, backed up first; `adopt_backup_schedule(database, saved)` moves a schedule an older version kept elsewhere into the setting once. `tools`, a feature of the app's own, is what MCP offers in place of the page's calls, such as tools that take names rather than ids, each run as the `program` caller (`app.mcp`). Sync's and history's triggers come off while migrations run, so a step may drop a column they name. |
|
|
12
|
+
| `app/define` | The base app: `define_app` puts an X-app's name, ports, files, its own settings and its `define_feature` features (tables, migrations, calls, `api_spec`, settings, histories) together into one store every device keeps (`open_store` calling each feature's `on_open`, `needs_upgrade`, `bind_methods(database, on_change, caller)` running each call as its `caller`, calling each feature's `after_write`, recording versions and announcing writes, `is_read_only`), `page_only` (the specs' `page_only` calls and the writes of `user_only` settings, refused with `page_only_refusal`), its sync engine, its backups' names and schedule, and its bridges named after the app; `AppMethodsOf<typeof app>` types the app's calls. `history_days` sets how far an app's history reaches back until the user chooses (365 unless set); what opening changed is recorded as this device's version, and old versions are pruned on opening and after a write once a day. `settings_knows(key)` lets an import take keys without a spec of their own, such as `diet.target_protein`; `upgrade_layout: { needed, run }` brings a database an older version laid out its own way, such as a versions table keyed another way, in line before any migration, backed up first; `adopt_backup_schedule(database, saved)` moves a schedule an older version kept elsewhere into the setting once. `tools`, a feature of the app's own, is what MCP offers in place of the page's calls, such as tools that take names rather than ids, each run as the `program` caller (`app.mcp`). Sync's and history's triggers come off while migrations run, so a step may drop a column they name. `synced_theme` keeps the light, dark or system theme as a synced setting, `theme`, so every device shows the one picked last. |
|
|
13
13
|
| `app/server`, `app/daemon` | `run_server(app, { web_folder })`: the web server from `<PREFIX>_CONFIG` with accounts in `accounts.db` (moved there once from the data's own file, tokens starting with the app's `token_prefix`), the calls, OpenAPI, MCP, the server's backups and its sync peer, a token or MCP client refused the app's `page_only` calls and the `user_only_backup_calls` (restore, remove, schedule) and its calls run as the `program` caller; `run_daemon(app)`: the desktop daemon from `<PREFIX>_DB` with sync, letting devices connect, backups, certificates and the desktop settings; Both take the app's `services` (see `app/services`), `run_daemon(app, env, { services })`. A `backup-schedule.json` an older version kept beside the database moves into this device's setting on opening. Both tell every page when another program, such as an older build, writes the database file (`watch_outside_changes`, on SQLite's `data_version`). `build_server`, `start_daemon`, `open_app_database` (with `on_restore` hooks) and `register_app_calls` for tests and apps that add their own. |
|
|
14
14
|
| `app/services` | An app's own work beside its calls, run by both hosts: `StartServices` gets a `HostContext` (`kind`, `database()`, `profile`, `device_name`, the server's raw `config`, `plugins_folder`, `declared_file` from `<PREFIX>_DECLARED_FILE` or `/etc/<id>/declared.json`, `announce`, `emit(event, data)` for the page's `on_event`, `side_database(name)` for a never-backed-up file such as `<base>-index.db`, `back_up`) and returns `HostServices` (`before_restore`, `after_restore`, `stop`), stopped before sync and the database. |
|
|
15
15
|
| `app/links` | `app_link(scheme, route)` and `route_of_link(scheme, link)`: an app's links such as `x-notes://note/<id>` and the page route they open. |
|
|
16
|
-
| `app/desktop`, `app/preload` | `run_desktop(app, electron, { main_dir })`: Electron's main process as a portal onto this computer's daemon or a server, with the window (`default_size` fixed or from the screen's free area, the daemon told while one is in front for its services' `window_in_front`), the tray (`show_tray_icon`, the app's own `tray` rows above Show, Quit and Quit completely, a write a row makes reaching every window at once, closing the last window leaving the app in it, `--hidden` starting there), the app's `link_scheme` links opening the window on their page (`route_of_link` to map them its own way; the page follows the `open` event), the login entry, a second launch and `--daemon`; the app's own `desktop_settings` switches sit in Settings → Desktop app beside the base's; `run_preload(app, electron)` puts every bridge on the page. The page's `desktop` calls also give the computer's idle seconds (`get_idle_seconds`, from Electron's `powerMonitor`) and `save_text_file`, which asks where through the Save dialog, starting in Downloads (`save_dialog_options`); opening the window replaces a daemon another build left running, and a Flatpak keeps its profile in `~/.config/<id>` as the other builds do. Electron is handed in, so neither imports it. An app with `local_mcp: { default_port }` serves its calls as MCP on 127.0.0.1 from the desktop daemon (`electron/mcp`, page-only calls left out, calls run as `program`), turned on under Settings → MCP server. |
|
|
16
|
+
| `app/desktop`, `app/preload` | `run_desktop(app, electron, { main_dir })`: Electron's main process as a portal onto this computer's daemon or a server, with the window (`default_size` fixed or from the screen's free area, the daemon told while one is in front for its services' `window_in_front`), the tray (`show_tray_icon`, the app's own `tray` rows above Show, Quit and Quit completely, a write a row makes reaching every window at once, closing the last window leaving the app in it, `--hidden` starting there), the app's `link_scheme` links opening the window on their page (`route_of_link` to map them its own way; the page follows the `open` event), the login entry, a second launch and `--daemon`; the app's own `desktop_settings` switches sit in Settings → Desktop app beside the base's; `run_preload(app, electron)` puts every bridge on the page. The page's `desktop` calls also give the computer's idle seconds (`get_idle_seconds`, from Electron's `powerMonitor`) `set_window_theme`, which the page calls so the window's own parts follow its theme, `get_data_paths` and `show_data_path`, which show this computer's database and backups folder in the file manager from Settings, and `save_text_file`, which asks where through the Save dialog, starting in Downloads (`save_dialog_options`); opening the window replaces a daemon another build left running, and a Flatpak keeps its profile in `~/.config/<id>` as the other builds do. Electron is handed in, so neither imports it. An app with `local_mcp: { default_port }` serves its calls as MCP on 127.0.0.1 from the desktop daemon (`electron/mcp`, page-only calls left out, calls run as `program`), turned on under Settings → MCP server. |
|
|
17
17
|
| `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`. |
|
|
18
18
|
| `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`. |
|
|
19
|
-
| `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, Your account, Settings (the app's general sections, each page's own, Connections, Desktop app, Sync and Backups) 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), 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. |
|
|
20
|
-
| `config/vite`, `config/electron_vite`, `config/vitest`, `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. |
|
|
19
|
+
| `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 and Backups) 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), 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. |
|
|
20
|
+
| `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. |
|
|
21
21
|
| `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`. |
|
|
22
22
|
| `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. |
|
|
23
23
|
| `durations` | `parse_duration` for settings such as `"2h30m"`, `format_duration` in months down to seconds and "less than a second" below one, `format_age`, and `format_clock` for a playing time such as `"3:07"`, with `{ hours: "always" }` writing `"0:03:07"` so a column of times lines up and `empty` for no time. |
|
|
@@ -54,7 +54,8 @@ an app moves over by changing the package name in its imports and its `x-libs-*`
|
|
|
54
54
|
| `drizzle`, `drizzle_migrations` | Typed SQLite on Drizzle ORM 1.0.0-rc.5, chosen over Kysely and hand-written SQL because it types rows from one schema in TypeScript, writes the migration SQL from it with drizzle-kit and runs synchronously: `open_drizzle` over any `SqlDatabase`, and `drizzle_of`, which the stores call, making it once per connection, so the same queries run on node:sqlite and in a phone's page, `synced_tables` reading the sync list from the schema's primary keys, `migrate_drizzle` per owner, the schema builders and query operators so an app never imports Drizzle, with `AnySQLiteColumn` for a table whose rows point at its own, and `x-app-bundle-migrations <folder>`, which turns drizzle-kit's migration folders into an `index.ts` a server running .ts files can import. |
|
|
55
55
|
| `sync_engine`, `sync_peer`, `sync_protocol`, `sync_seal`, `server/sync_peer_routes`, `sync_peer_discovery`, `sync_peer_listening` | SQLite kept alike on every device with no server: `create_sync_engine` stamps each value of the tables it is given through triggers, so the app's own writes need no change, and the newest write of each value wins, each key of a table's `map_columns` (JSON objects such as ids from many sources) counting as a value of its own so two devices adding different keys keep both. Every copy is a peer: `create_sync_peer` pairs with another device through a one-time code (`create_pairing_code`, `pair_device`), the two copies merging with nothing asked, then sends each paired device its changes within seconds, takes theirs in the same round trip, holds a waiting call open to hear of theirs at once, and passes on what it took from the others, so devices that never reach each other still end up alike; the group's list of devices travels too, so a new device is introduced to the rest and a removed one (`remove_device`) is refused by all. Each call is sealed with both devices' keys on tweetnacl's box (`sync_seal`), chosen over TLS with pinned certificates because it runs alike on Node and in a phone's page; calls still travel over https only. After a restore (`forget_history`) each peer is made to match the restored copy once, keeping a copy of its own first. `register_sync_peer_routes` answers other devices at `sync/peer` under a daemon's prefix, `listen_for_peers` opens a desktop daemon's own port for them, `discover_peers` finds paired devices on the local network by mDNS, on bonjour-service, and `keep_listening_for_peers` (`sync_peer_listening`) is a desktop daemon's "Let other devices connect" setting, kept in a file beside the database, which answers over https with a self-signed certificate made once (`peer_certificate`, on selfsigned, chosen because it makes one with Node's own crypto) and whose `PeerListeningMethods`, its fingerprint included, the page shows with `PeerListeningSettings`; `SyncSettings` given `certificates` asks to review and trust that certificate when pairing fails over it, and pairs again. |
|
|
56
56
|
| `sync_files`, `node_file_store`, `electron/file_protocol` | Files that sync beside the rows that name them, such as covers or photos, so a large picture never travels with every change: each is named by the sha256 of its bytes (`hash_bytes`, `put_file`, `is_file_name`) and kept in a `SyncFileStore`, a folder on Node (`folder_file_store`, written through a rename) or IndexedDB on a phone (`indexed_db_files`); given `files: { store, referenced }`, the sync peer sends each paired device the named files it lacks and fetches those this device lacks after each exchange, a few at a time, trying a file neither has yet again next round, and keeps the ones it is sent, refusing bytes that do not match their name; `register_file_scheme` and `serve_files` show them in a desktop page as `<scheme>://<name>`. |
|
|
57
|
-
| `app_android` | `x-app-android [app folder]`: the app's Capacitor project in `android/`, made from Capacitor's template when it is missing, given X-App's `config/android/release.gradle` (the version CI hands each build, and signing when the release key is in the environment), its launcher icons from `x-app-icons`, then `cap sync android`. Run after the Android page is built; the app keeps `android/` out of git. |
|
|
57
|
+
| `app_android` | `x-app-android [app folder]`: the app's Capacitor project in `android/`, made from Capacitor's template when it is missing, given X-App's `config/android/release.gradle` and, where it has none of its own, a network rule allowing plain http only to the phone itself (`network_security_config`), for `adb reverse` while testing, (the version CI hands each build, and signing when the release key is in the environment), its launcher icons from `x-app-icons`, then `cap sync android`. Run after the Android page is built; the app keeps `android/` out of git. |
|
|
58
|
+
| `app_android_key` | `x-app-android-key [app folder]`: the app's Android release key, made once with keytool in `~/.local/share/<name>/signing` and never replaced, and stored with gh as the `ANDROID_KEYSTORE_BASE64`, `ANDROID_KEYSTORE_PASSWORD` and `ANDROID_KEY_ALIAS` secrets `app-android` signs with, handed over on stdin so nothing prints it. Run it in the app's Android shell. |
|
|
58
59
|
| `app_icons` | `x-app-icons [app folder]`: every icon an app ships generated from its `resources/icon.svg`, as the Design Guidelines ask: `resources/icon.png` for the desktop, the Android launcher icons at each density with an adaptive icon on white when there is an `android/` project, and `icon.svg`, `icon-192.png` and `icon-512.png` in `src/web/public` when there is one. Drawn with `@resvg/resvg-js`, an optional peer the app installs as a dev dependency. |
|
|
59
60
|
| `change_checks`, `change_checks_git`, `change_checks_cli` | Checks on a change that any repository's CI runs, as `x-app-check` (see [Change checks](#change-checks)): `commits` (Conventional Commits, the `Assisted-by` trailer in the organisation's repositories and nowhere else, no AI mention outside it), `secrets` (keys and tokens in added lines, commit messages and added `.env` files, naming only the kind and place, never the value), `leftovers` (console logging, `debugger`, code commented out, a TODO without an issue), `comments` (a comment longer than one line, but for a file's overview), `coverage` (a floor lowered or code newly left out), `x-libs` (an import of a library X-App wraps) and `dependencies` (each new one named with its licence, failing a licence not allowed, read as SPDX by `spdx-satisfies`); each a pure function on a described `Change` giving `{ gate, outcome, findings }` with file:line, reading only the code around strings and regular expressions; `create_check_registry` for an app's own checks, `x_tech_options` the defaults, and `read_change` reading a change from git, its `base` resolved to a commit; `run_check_command` runs the command for an app with its own checks, defaults and name. |
|
|
60
61
|
| `certificates`, `certificate_protocol`, `electron/certificates` | Servers whose https certificate the device refuses, such as a home server's self-signed one: `check_certificate` reads the certificate and what is wrong with it (self-signed, unknown authority, wrong name, expired, not yet valid), `create_certificate_trust` keeps the ones the user trusts in a JSON file, each for its own host and exact fingerprint, re-checked before it is saved, and its `methods` are the page's calls; `trust_in_session` makes Chromium accept them in a session, the window's from the next start, and `trusting_fetch` sends the main process's requests, such as the sync client's, through a Chromium session made fresh each time the list changes, so a new choice holds at once; `use_in_node` also hands them to Node's own https, which then accepts a self-signed server whose name matches. |
|
|
@@ -243,14 +244,20 @@ The rest of an app's files are short calls into X-App too:
|
|
|
243
244
|
copy in, and `link_scheme`, such as `"codex"`, makes the desktop entry open its links; `desktop_path`, such as
|
|
244
245
|
`pkgs: [ pkgs.libnotify ]`, puts programs the desktop app runs on its PATH, and `state_name` keeps an older service's
|
|
245
246
|
data folder `/var/lib/<state_name>`; the desktop wrapper sets
|
|
246
|
-
`<PREFIX>_LAUNCHER` so the login entry runs the installed command.
|
|
247
|
+
`<PREFIX>_LAUNCHER` so the login entry runs the installed command. `android_emulator_shell nixpkgs system app` adds an
|
|
248
|
+
Android 36 emulator to the Android shell, with `<name>-emulator` to start it and `<name>-emulator-install` to build
|
|
249
|
+
and open the app on it, never on a connected phone.
|
|
247
250
|
- **Android**: `npm run build:android` builds the phone's page and runs `x-app-android`, which makes or updates the
|
|
248
251
|
Capacitor project in `android/`, so the app keeps only `capacitor.config.json` and leaves `android/` out of git.
|
|
252
|
+
`x-app-android-key` makes the release key once and stores it as the repository's secrets.
|
|
249
253
|
- **CI**: the app's `ci` job runs `x-tech-laboratories/X-App/.github/actions/app-ci@main`, its `nix` job
|
|
250
|
-
`app-nix@main` with the targets to build,
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
+
`app-nix@main` with the targets to build, and its Dependabot workflow `app-dependabot-auto-merge@main`. Every push to
|
|
255
|
+
`main` is a release: an Android app's `android` job runs `app-android@main` with `release: push` and the release key's
|
|
256
|
+
secrets, a desktop app's `linux` job runs `app-linux@main` for the AppImage and Flatpak bundle from
|
|
257
|
+
`config/electron-builder.mjs`, and a `release` job after them runs `app-release@main`, which publishes them as the
|
|
258
|
+
latest GitHub release `v<version>.<run>`, so Obtainium sees each one as newer. A published APK must be signed: without
|
|
259
|
+
the key the `android` job fails, and nothing is released. They are composite actions, so the jobs keep the names `ci`
|
|
260
|
+
and `nix` the ruleset requires.
|
|
254
261
|
|
|
255
262
|
`npx x-app-new X-Notes` writes all of it for a new app.
|
|
256
263
|
|
package/dist/app/define.d.ts
CHANGED
|
@@ -67,11 +67,13 @@ export interface AppOptions<Features extends readonly Feature[]> {
|
|
|
67
67
|
local_mcp?: {
|
|
68
68
|
default_port: number;
|
|
69
69
|
};
|
|
70
|
+
synced_theme?: boolean;
|
|
70
71
|
}
|
|
71
72
|
export declare const base_setting_defaults: {
|
|
72
73
|
history_days: number;
|
|
73
74
|
};
|
|
74
75
|
export declare const backup_schedule_key = "backup_schedule";
|
|
76
|
+
export declare const theme_key = "theme";
|
|
75
77
|
export declare function is_backup_schedule(value: unknown): value is BackupSchedule;
|
|
76
78
|
export interface Restorable extends Backups {
|
|
77
79
|
restore: (name: string) => Promise<void>;
|
|
@@ -127,6 +129,7 @@ export declare function define_app<const Features extends readonly Feature[]>(op
|
|
|
127
129
|
local_mcp?: {
|
|
128
130
|
default_port: number;
|
|
129
131
|
};
|
|
132
|
+
synced_theme?: boolean;
|
|
130
133
|
features: readonly Feature<Record<string, StoreMethod>>[];
|
|
131
134
|
settings_store: SettingsStore;
|
|
132
135
|
setting_defaults: Readonly<import("../settings.ts").Settings>;
|
package/dist/app/define.js
CHANGED
|
@@ -30,6 +30,8 @@ export const base_setting_defaults = {
|
|
|
30
30
|
history_days: 365,
|
|
31
31
|
};
|
|
32
32
|
export const backup_schedule_key = "backup_schedule";
|
|
33
|
+
// The synced setting an app with synced_theme keeps its theme in.
|
|
34
|
+
export const theme_key = "theme";
|
|
33
35
|
const base_settings = {
|
|
34
36
|
...settings_of(base_setting_defaults),
|
|
35
37
|
// How this device backs up is its own, never synced.
|
|
@@ -41,7 +43,10 @@ export function is_backup_schedule(value) {
|
|
|
41
43
|
}
|
|
42
44
|
export function define_app(options) {
|
|
43
45
|
// ── Settings ─────────────────────────────────────────────────────────
|
|
44
|
-
const own_base_settings =
|
|
46
|
+
const own_base_settings = {
|
|
47
|
+
...(options.history_days === undefined ? base_settings : { ...base_settings, history_days: { ...base_settings.history_days, default: options.history_days } }),
|
|
48
|
+
...(options.synced_theme ? { [theme_key]: { default: "system" } } : {}),
|
|
49
|
+
};
|
|
45
50
|
const settings_store = create_settings_store([own_base_settings, options.settings ?? {}, ...options.features.map((feature) => feature.settings ?? {})], {
|
|
46
51
|
app: { id: options.id, name: options.name },
|
|
47
52
|
...(options.settings_descriptions ? { descriptions: options.settings_descriptions } : {}),
|
package/dist/app/desktop.d.ts
CHANGED
|
@@ -38,7 +38,9 @@ export interface ElectronLike {
|
|
|
38
38
|
getSystemIdleTime(): number;
|
|
39
39
|
};
|
|
40
40
|
ipcMain: IpcMainLike;
|
|
41
|
-
nativeTheme: NativeThemeLike
|
|
41
|
+
nativeTheme: NativeThemeLike & {
|
|
42
|
+
themeSource?: "system" | "light" | "dark";
|
|
43
|
+
};
|
|
42
44
|
screen: ScreenLike & {
|
|
43
45
|
getPrimaryDisplay(): {
|
|
44
46
|
workAreaSize: {
|
|
@@ -47,7 +49,10 @@ export interface ElectronLike {
|
|
|
47
49
|
};
|
|
48
50
|
};
|
|
49
51
|
};
|
|
50
|
-
shell: ShellLike
|
|
52
|
+
shell: ShellLike & {
|
|
53
|
+
showItemInFolder?(path: string): void;
|
|
54
|
+
openPath?(path: string): Promise<string>;
|
|
55
|
+
};
|
|
51
56
|
Tray?: new (image: never) => TrayLike;
|
|
52
57
|
Menu?: TrayElectronLike<unknown>["Menu"];
|
|
53
58
|
nativeImage?: {
|
package/dist/app/desktop.js
CHANGED
|
@@ -228,6 +228,17 @@ export function run_desktop(app, electron, options) {
|
|
|
228
228
|
quit_completely,
|
|
229
229
|
get_idle_seconds: () => electron.powerMonitor?.getSystemIdleTime() ?? 0,
|
|
230
230
|
save_text_file,
|
|
231
|
+
set_window_theme: (theme) => {
|
|
232
|
+
if (theme === "system" || theme === "light" || theme === "dark")
|
|
233
|
+
electron.nativeTheme.themeSource = theme;
|
|
234
|
+
},
|
|
235
|
+
get_data_paths: () => ({ database: database_path, backups: join(profile, "backups") }),
|
|
236
|
+
show_data_path: async (which) => {
|
|
237
|
+
if (which === "database")
|
|
238
|
+
electron.shell.showItemInFolder?.(database_path);
|
|
239
|
+
else
|
|
240
|
+
await electron.shell.openPath?.(join(profile, "backups"));
|
|
241
|
+
},
|
|
231
242
|
};
|
|
232
243
|
bridges.desktop.handle(ipcMain, desktop, handle_options);
|
|
233
244
|
}
|
package/dist/app/protocol.d.ts
CHANGED
|
@@ -23,8 +23,15 @@ export interface DesktopMethods {
|
|
|
23
23
|
quit_completely: () => void;
|
|
24
24
|
get_idle_seconds: () => number;
|
|
25
25
|
save_text_file: (file_name: string, text: string) => boolean;
|
|
26
|
+
set_window_theme: (theme: "system" | "light" | "dark") => void;
|
|
27
|
+
get_data_paths: () => DataPaths;
|
|
28
|
+
show_data_path: (which: keyof DataPaths) => void;
|
|
26
29
|
}
|
|
27
|
-
export
|
|
30
|
+
export interface DataPaths {
|
|
31
|
+
database: string;
|
|
32
|
+
backups: string;
|
|
33
|
+
}
|
|
34
|
+
export declare const desktop_method_names: readonly ["get_desktop_settings", "set_desktop_setting", "quit_completely", "get_idle_seconds", "save_text_file", "set_window_theme", "get_data_paths", "show_data_path"];
|
|
28
35
|
export interface DaemonMethods {
|
|
29
36
|
get_desktop_settings: () => DesktopSettings;
|
|
30
37
|
set_desktop_setting: (key: keyof DesktopSettings, value: boolean) => void;
|
package/dist/app/protocol.js
CHANGED
|
@@ -11,4 +11,4 @@ export function read_desktop_settings(saved, specs = {}) {
|
|
|
11
11
|
const defaults = { ...desktop_setting_defaults, ...Object.fromEntries(Object.entries(specs).map(([key, spec]) => [key, spec.default])) };
|
|
12
12
|
return Object.fromEntries(Object.entries(defaults).map(([key, fallback]) => [key, typeof settings[key] === "boolean" ? settings[key] : fallback]));
|
|
13
13
|
}
|
|
14
|
-
export const desktop_method_names = ["get_desktop_settings", "set_desktop_setting", "quit_completely", "get_idle_seconds", "save_text_file"];
|
|
14
|
+
export const desktop_method_names = ["get_desktop_settings", "set_desktop_setting", "quit_completely", "get_idle_seconds", "save_text_file", "set_window_theme", "get_data_paths", "show_data_path"];
|
|
@@ -3,6 +3,11 @@ 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 { AppPage, AppPages, AppSubpage, PageSettingsProps } from "./settings_page.tsx";
|
|
6
|
+
export declare const default_sidebar_width: {
|
|
7
|
+
default_width: number;
|
|
8
|
+
min: number;
|
|
9
|
+
max: number;
|
|
10
|
+
};
|
|
6
11
|
export declare function AppView({ pages }: {
|
|
7
12
|
pages: AppPages;
|
|
8
13
|
}): import("react").JSX.Element;
|
package/dist/app/web/app_page.js
CHANGED
|
@@ -4,7 +4,7 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
|
|
|
4
4
|
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
5
5
|
import "@x-tech-laboratories/halon/halon-tokens.css";
|
|
6
6
|
import "@x-tech-laboratories/halon/halon.css";
|
|
7
|
-
import { Fragment, useEffect } from "react";
|
|
7
|
+
import { Fragment, useEffect, useMemo, useRef } from "react";
|
|
8
8
|
import { createRoot } from "react-dom/client";
|
|
9
9
|
import { create_accounts_client } from "../../web/accounts.js";
|
|
10
10
|
import { AccountView, UsersView } from "../../web/react/accounts.js";
|
|
@@ -13,9 +13,9 @@ import { PageHeading } from "../../web/react/layout.js";
|
|
|
13
13
|
import { Shell, use_route } from "../../web/react/shell.js";
|
|
14
14
|
import { SignInForm, use_account } from "../../web/react/sign_in.js";
|
|
15
15
|
import { SyncButton } from "../../web/react/sync_settings.js";
|
|
16
|
-
import { theme_choice } from "../../web/theme.js";
|
|
16
|
+
import { local_theme_storage, theme_choice } from "../../web/theme.js";
|
|
17
17
|
import { desktop_api, is_android, is_desktop, web_api } from "./hosts.js";
|
|
18
|
-
import { data_watch, page, set_page_api } from "./page.js";
|
|
18
|
+
import { calls, data_watch, page, set_page_api, use_settings } from "./page.js";
|
|
19
19
|
import { SettingsView } from "./settings_page.js";
|
|
20
20
|
// ── Pages ────────────────────────────────────────────────────────────────────
|
|
21
21
|
// Relative, so a server behind a proxy under a folder keeps it.
|
|
@@ -32,6 +32,46 @@ function SidebarFoot() {
|
|
|
32
32
|
const { device } = page();
|
|
33
33
|
return device ? _jsx(SyncButton, { device: device, subscribe: (listener) => data_watch.subscribe(listener), on_open_settings: () => (window.location.hash = "/settings") }) : null;
|
|
34
34
|
}
|
|
35
|
+
// The sidebar's first width and the range it is dragged within, remembered on this device unless the app holds it.
|
|
36
|
+
export const default_sidebar_width = { default_width: 248, min: 180, max: 480 };
|
|
37
|
+
function is_theme(value) {
|
|
38
|
+
return value === "system" || value === "light" || value === "dark";
|
|
39
|
+
}
|
|
40
|
+
// The theme kept in this browser, or for an app with synced_theme in its synced setting, which a change on another
|
|
41
|
+
// device applies here too; this browser's copy shows it before the settings arrive.
|
|
42
|
+
function use_theme(app) {
|
|
43
|
+
const settings = use_settings();
|
|
44
|
+
const synced = app.synced_theme === true;
|
|
45
|
+
const stored = synced ? settings.data?.theme : undefined;
|
|
46
|
+
const latest = useRef(undefined);
|
|
47
|
+
latest.current = stored;
|
|
48
|
+
const theme = useMemo(() => {
|
|
49
|
+
const local = local_theme_storage(`${app.id}-theme`);
|
|
50
|
+
if (!synced)
|
|
51
|
+
return theme_choice(local);
|
|
52
|
+
return theme_choice({
|
|
53
|
+
read: () => (is_theme(latest.current) ? latest.current : local.read()),
|
|
54
|
+
write: (chosen) => {
|
|
55
|
+
latest.current = chosen;
|
|
56
|
+
local.write(chosen);
|
|
57
|
+
void calls().set_setting("theme", chosen).catch(() => undefined);
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}, [app.id, synced]);
|
|
61
|
+
// The desktop window's own parts, such as menus, follow the page's theme.
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
const tell = (chosen) => void page().desktop?.set_window_theme(chosen).catch(() => undefined);
|
|
64
|
+
tell(theme.get());
|
|
65
|
+
return theme.on_change(tell);
|
|
66
|
+
}, [theme]);
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (!is_theme(stored))
|
|
69
|
+
return;
|
|
70
|
+
local_theme_storage(`${app.id}-theme`).write(stored);
|
|
71
|
+
theme.apply(stored);
|
|
72
|
+
}, [stored, theme]);
|
|
73
|
+
return theme;
|
|
74
|
+
}
|
|
35
75
|
function Pages({ pages, account }) {
|
|
36
76
|
const { app } = pages;
|
|
37
77
|
const route = use_route();
|
|
@@ -44,6 +84,7 @@ function Pages({ pages, account }) {
|
|
|
44
84
|
const label = shown ? (subpage ? `${subpage.label} · ${shown.label}` : shown.label) : is_account ? "Your account" : "Settings";
|
|
45
85
|
const view_key = route.parts.join("/");
|
|
46
86
|
const chrome = pages.use_chrome?.(route.parts) ?? {};
|
|
87
|
+
const theme = use_theme(app);
|
|
47
88
|
useEffect(() => {
|
|
48
89
|
document.title = `${label} · ${app.name}`;
|
|
49
90
|
}, [label, app.name]);
|
|
@@ -63,7 +104,7 @@ function Pages({ pages, account }) {
|
|
|
63
104
|
const framed = _jsx(Fragment, { children: view }, view_key);
|
|
64
105
|
if (chrome.bare)
|
|
65
106
|
return _jsx(_Fragment, { children: chrome.around ? chrome.around(framed) : framed });
|
|
66
|
-
return (_jsx(Shell, { brand: app.name, brand_icon: pages.brand_icon ?? "icon.svg", ...(with_icons ? { views } : { sections }), active: shown?.active_as ?? section, active_item: subpage?.id ?? null, sections_pref: `${app.id}-sidebar-collapsed`, ...(chrome.sidebar ? { sidebar: chrome.sidebar } : {}), ...(chrome.tools ? { tools: chrome.tools } : {}), ...(chrome.side_pane ? { side_pane: chrome.side_pane } : {}), ...(chrome.contained ? { contained: true } : {}), ...(chrome.main_class ? { main_class: chrome.main_class } : {}), theme:
|
|
107
|
+
return (_jsx(Shell, { brand: app.name, brand_icon: pages.brand_icon ?? "icon.svg", ...(with_icons ? { views } : { sections }), active: shown?.active_as ?? section, active_item: subpage?.id ?? null, sections_pref: `${app.id}-sidebar-collapsed`, ...(chrome.sidebar ? { sidebar: chrome.sidebar } : {}), ...(chrome.tools ? { tools: chrome.tools } : {}), ...(chrome.side_pane ? { side_pane: chrome.side_pane } : {}), ...(chrome.contained ? { contained: true } : {}), ...(chrome.main_class ? { main_class: chrome.main_class } : {}), theme: theme, sidebar_width: chrome.sidebar_width ?? { ...default_sidebar_width, storage_key: `${app.id}-sidebar-width` }, view_key: view_key, user: account ? account.me.name : undefined, user_href: account ? "#/account" : undefined, on_logout: account ? () => void account.sign_out() : undefined, sidebar_foot: _jsx(SidebarFoot, {}), settings: { href: "#/settings" }, children: chrome.around ? chrome.around(framed) : framed }));
|
|
67
108
|
}
|
|
68
109
|
// ── App ──────────────────────────────────────────────────────────────────────
|
|
69
110
|
// A browser reaches the server's data, so it signs in; the desktop and phone apps keep their own and sign in only to sync.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IconGlyph } from "../../web/react/icons.tsx";
|
|
2
2
|
import { type SettingsCategory, type SettingsSection } from "../../web/react/layout.tsx";
|
|
3
|
-
import type { ShellSidePane } from "../../web/react/shell.tsx";
|
|
3
|
+
import type { ShellSidePane, SidebarWidth } from "../../web/react/shell.tsx";
|
|
4
4
|
import type { App } from "../define.ts";
|
|
5
5
|
import type { StartPhoneServices } from "./android.ts";
|
|
6
6
|
export interface PageSettingsProps {
|
|
@@ -30,9 +30,10 @@ export interface AppChrome {
|
|
|
30
30
|
main_class?: string;
|
|
31
31
|
around?: (view: React.ReactNode) => React.ReactNode;
|
|
32
32
|
bare?: boolean;
|
|
33
|
+
sidebar_width?: SidebarWidth;
|
|
33
34
|
}
|
|
34
35
|
export interface AppPages {
|
|
35
|
-
app: Pick<App, "id" | "name" | "data_name" | "server_example" | "bridges"> & Partial<Pick<App, "desktop_settings">>;
|
|
36
|
+
app: Pick<App, "id" | "name" | "data_name" | "server_example" | "bridges"> & Partial<Pick<App, "desktop_settings" | "synced_theme">>;
|
|
36
37
|
pages: readonly AppPage[];
|
|
37
38
|
general_settings?: (props: PageSettingsProps) => SettingsSection[];
|
|
38
39
|
settings_categories?: (props: PageSettingsProps) => SettingsCategory[];
|
|
@@ -35,6 +35,14 @@ function Desktop({ app_name, own }) {
|
|
|
35
35
|
};
|
|
36
36
|
return (_jsxs(_Fragment, { children: [_jsx(SettingRow, { label: "Show the tray icon", hint: `Keeps ${app_name} in the tray, where closing the window leaves it.`, as_label: true, children: _jsx(Switch, { label: "Show the tray icon", checked: settings.show_tray_icon, on_change: (on) => change("show_tray_icon", on) }) }), _jsx(SettingRow, { label: "Keep running in the background", hint: "Sync and backups carry on with the window closed. Turned off, they stop shortly after the last window closes.", as_label: true, children: _jsx(Switch, { label: "Keep running in the background", checked: settings.keep_running_in_background, on_change: (on) => change("keep_running_in_background", on) }) }), _jsx(SettingRow, { label: "Start at login", hint: `Starts ${app_name} in the background when you log in, without opening its window.`, as_label: true, children: _jsx(Switch, { label: "Start at login", checked: settings.start_at_login, disabled: !settings.keep_running_in_background, on_change: (on) => change("start_at_login", on) }) }), Object.entries(own).map(([key, spec]) => (_jsx(SettingRow, { label: spec.label, ...(spec.hint ? { hint: spec.hint } : {}), as_label: true, children: _jsx(Switch, { label: spec.label, checked: settings[key] ?? spec.default, on_change: (on) => change(key, on) }) }, key))), _jsx(SettingRow, { label: "Quit completely", hint: `Closes the window and stops ${app_name} in the background too, until you open it again.`, children: _jsx("button", { type: "button", onClick: () => attempt(desktop.quit_completely()), children: "Quit completely" }) })] }));
|
|
37
37
|
}
|
|
38
|
+
// Where this computer keeps the data, with a button that shows it in the file manager.
|
|
39
|
+
function DataFolder({ desktop }) {
|
|
40
|
+
const [paths, set_paths] = useState(null);
|
|
41
|
+
useEffect(() => void desktop.get_data_paths().then(set_paths, () => undefined), [desktop]);
|
|
42
|
+
if (!paths)
|
|
43
|
+
return null;
|
|
44
|
+
return (_jsx(SettingRow, { label: "Database", hint: _jsx("span", { className: "path", children: paths.database }), children: _jsx("button", { type: "button", onClick: () => attempt(desktop.show_data_path("database")), children: "Show in folder" }) }));
|
|
45
|
+
}
|
|
38
46
|
// A desktop window on a server's daemon works on the server's data, as a browser does.
|
|
39
47
|
function storage_category(app, is_admin) {
|
|
40
48
|
const { backups, backup_folder, certificates, connections, desktop, device, host, local_mcp, peer_listening } = page();
|
|
@@ -52,9 +60,13 @@ function storage_category(app, is_admin) {
|
|
|
52
60
|
const hint = on_server ? `Keep the server's ${data_name} alike with the devices paired with it.` : `Keep this device's ${data_name} alike with your other devices and your ${name} server.`;
|
|
53
61
|
sections.push({ id: "sync", heading: "Sync", hint, content: _jsx(SyncSettings, { device: device, subscribe: (listener) => data_watch.subscribe(listener), data_name: data_name, extra: peer_listening && _jsx(PeerListeningSettings, { listening: peer_listening }) }) });
|
|
54
62
|
}
|
|
63
|
+
if (desktop && !on_server)
|
|
64
|
+
sections.push({ id: "storage", heading: "Storage", hint: `Where this computer keeps its ${data_name}.`, content: _jsx(DataFolder, { desktop: desktop }) });
|
|
55
65
|
if (backups && (!on_server || is_admin)) {
|
|
56
66
|
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.`;
|
|
57
|
-
|
|
67
|
+
// This computer's backups folder opens in the file manager.
|
|
68
|
+
const show_folder = !on_server && desktop && (_jsx(SettingRow, { label: "Backup folder", children: _jsx("button", { type: "button", onClick: () => attempt(desktop.show_data_path("backups")), children: "Show folder" }) }));
|
|
69
|
+
const content = backup_folder ? _jsx(FolderBackups, { backups: backups, folder: backup_folder, data_name: data_name }) : _jsx(BackupSettings, { device: backups, data_name: data_name, on_restored: () => location.reload(), ...(show_folder ? { folder_row: show_folder } : {}) });
|
|
58
70
|
sections.push({ id: "backups", heading: "Backups", hint, content });
|
|
59
71
|
}
|
|
60
72
|
return sections.length === 0 ? [] : [{ heading: host === "web" ? "Server" : "This device", sections }];
|
package/dist/app_android.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
export declare const release_line = "apply from: \"../../node_modules/@x-tech-laboratories/x-app/config/android/release.gradle\"";
|
|
3
3
|
export declare function apply_release_settings(app_folder: string): boolean;
|
|
4
|
+
export declare const network_security_config = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!-- Servers need https; plain http is allowed only to this phone itself, which a computer reaches through `adb reverse` while testing. -->\n<network-security-config>\n <base-config cleartextTrafficPermitted=\"false\" />\n <domain-config cleartextTrafficPermitted=\"true\">\n <domain includeSubdomains=\"false\">localhost</domain>\n <domain includeSubdomains=\"false\">127.0.0.1</domain>\n </domain-config>\n</network-security-config>\n";
|
|
5
|
+
export declare function apply_network_security(app_folder: string): boolean;
|
|
4
6
|
export type RunCapacitor = (app_folder: string, args: string[]) => void;
|
|
5
7
|
export declare function prepare_android(app_folder: string, run?: RunCapacitor): string[];
|
package/dist/app_android.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
// Android page is built, since Capacitor copies that page in.
|
|
7
7
|
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
8
8
|
import { spawnSync } from "node:child_process";
|
|
9
|
-
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
10
|
-
import { join, resolve } from "node:path";
|
|
9
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { dirname, join, resolve } from "node:path";
|
|
11
11
|
import { write_app_icons } from "./app_icons.js";
|
|
12
12
|
// ── Release settings ─────────────────────────────────────────────────────────
|
|
13
13
|
// The line that applies X-App's release settings, from the app's own node_modules so it follows X-App's version.
|
|
@@ -21,6 +21,38 @@ export function apply_release_settings(app_folder) {
|
|
|
21
21
|
writeFileSync(build_file, `${build.trimEnd()}\n\n// X-App's release settings: the build's version and, when the key is present, its signature.\n${release_line}\n`);
|
|
22
22
|
return true;
|
|
23
23
|
}
|
|
24
|
+
// ── Network security ─────────────────────────────────────────────────────────
|
|
25
|
+
// Servers need https; plain http goes only to the phone itself, which a computer reaches through `adb reverse` while
|
|
26
|
+
// testing. An app with a file of its own keeps it.
|
|
27
|
+
export const network_security_config = `<?xml version="1.0" encoding="utf-8"?>
|
|
28
|
+
<!-- Servers need https; plain http is allowed only to this phone itself, which a computer reaches through \`adb reverse\` while testing. -->
|
|
29
|
+
<network-security-config>
|
|
30
|
+
<base-config cleartextTrafficPermitted="false" />
|
|
31
|
+
<domain-config cleartextTrafficPermitted="true">
|
|
32
|
+
<domain includeSubdomains="false">localhost</domain>
|
|
33
|
+
<domain includeSubdomains="false">127.0.0.1</domain>
|
|
34
|
+
</domain-config>
|
|
35
|
+
</network-security-config>
|
|
36
|
+
`;
|
|
37
|
+
const security_attribute = 'android:networkSecurityConfig="@xml/network_security_config"';
|
|
38
|
+
// Writes the rule where the app has none and points the manifest's application at it, and says whether it changed either.
|
|
39
|
+
export function apply_network_security(app_folder) {
|
|
40
|
+
const main = join(app_folder, "android", "app", "src", "main");
|
|
41
|
+
const config_file = join(main, "res", "xml", "network_security_config.xml");
|
|
42
|
+
let changed = false;
|
|
43
|
+
if (!existsSync(config_file)) {
|
|
44
|
+
mkdirSync(dirname(config_file), { recursive: true });
|
|
45
|
+
writeFileSync(config_file, network_security_config);
|
|
46
|
+
changed = true;
|
|
47
|
+
}
|
|
48
|
+
const manifest_file = join(main, "AndroidManifest.xml");
|
|
49
|
+
const manifest = readFileSync(manifest_file, "utf8");
|
|
50
|
+
if (!manifest.includes("android:networkSecurityConfig=")) {
|
|
51
|
+
writeFileSync(manifest_file, manifest.replace(/<application\b/, `<application\n ${security_attribute}`));
|
|
52
|
+
changed = true;
|
|
53
|
+
}
|
|
54
|
+
return changed;
|
|
55
|
+
}
|
|
24
56
|
const run_capacitor = (app_folder, args) => {
|
|
25
57
|
const result = spawnSync("npx", ["cap", ...args], { cwd: app_folder, stdio: "inherit" });
|
|
26
58
|
if (result.status !== 0)
|
|
@@ -37,6 +69,8 @@ export function prepare_android(app_folder, run = run_capacitor) {
|
|
|
37
69
|
}
|
|
38
70
|
if (apply_release_settings(app_folder))
|
|
39
71
|
done.push("Applied X-App's release settings");
|
|
72
|
+
if (apply_network_security(app_folder))
|
|
73
|
+
done.push("Allowed plain http only to the phone itself");
|
|
40
74
|
done.push(`Drew ${write_app_icons(app_folder).length} icons`);
|
|
41
75
|
run(app_folder, ["sync", "android"]);
|
|
42
76
|
done.push("Synced the page and plugins into the Android project");
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
export type RunProgram = (program: string, args: string[], input?: Buffer | string) => void;
|
|
3
|
+
export interface KeyPlan {
|
|
4
|
+
folder: string;
|
|
5
|
+
keystore: string;
|
|
6
|
+
password_file: string;
|
|
7
|
+
alias: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function key_plan(app_folder: string, folder?: string, home?: string): KeyPlan;
|
|
10
|
+
export declare function make_release_key(plan: KeyPlan, run?: RunProgram): void;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The `x-app-android-key [app folder]` command: an app's Android release key, made once and stored as the repository's
|
|
3
|
+
// secrets that X-App's `app-android` action signs with, without ever printing it. The key lives in
|
|
4
|
+
// ~/.local/share/<app>/signing, named after the app's package, and is never replaced, since Android installs an update
|
|
5
|
+
// only when it carries the same key. Run it inside the app's Android shell, which has keytool, with gh signed in.
|
|
6
|
+
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
7
|
+
import { spawnSync } from "node:child_process";
|
|
8
|
+
import { randomBytes } from "node:crypto";
|
|
9
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { homedir } from "node:os";
|
|
11
|
+
import { join, resolve } from "node:path";
|
|
12
|
+
const run_program = (program, args, input) => {
|
|
13
|
+
const result = spawnSync(program, args, { input, stdio: [input === undefined ? "inherit" : "pipe", "inherit", "inherit"] });
|
|
14
|
+
if (result.error)
|
|
15
|
+
throw new Error(`${program} could not run: ${result.error.message}`);
|
|
16
|
+
if (result.status !== 0)
|
|
17
|
+
throw new Error(`${program} ${args[0] ?? ""} failed`);
|
|
18
|
+
};
|
|
19
|
+
// Where the app's key goes: its package's name in the user's data folder, unless a folder is given.
|
|
20
|
+
export function key_plan(app_folder, folder, home = homedir()) {
|
|
21
|
+
const { name } = JSON.parse(readFileSync(join(app_folder, "package.json"), "utf8"));
|
|
22
|
+
const signing = folder ?? join(home, ".local", "share", name, "signing");
|
|
23
|
+
return { folder: signing, keystore: join(signing, `${name}-release.p12`), password_file: join(signing, "keystore-password.txt"), alias: name };
|
|
24
|
+
}
|
|
25
|
+
// Makes the key with one random password for the keystore and the key, then sets the three secrets with gh; refuses a
|
|
26
|
+
// key already there, which is the app's for good.
|
|
27
|
+
export function make_release_key(plan, run = run_program) {
|
|
28
|
+
if (existsSync(plan.keystore))
|
|
29
|
+
throw new Error(`${plan.keystore} already exists; it is the app's permanent key, so it is never replaced`);
|
|
30
|
+
mkdirSync(plan.folder, { recursive: true, mode: 0o700 });
|
|
31
|
+
writeFileSync(plan.password_file, randomBytes(32).toString("base64"), { mode: 0o600 });
|
|
32
|
+
run("keytool", [
|
|
33
|
+
"-genkeypair", "-keystore", plan.keystore, "-storetype", "PKCS12", "-alias", plan.alias,
|
|
34
|
+
"-keyalg", "RSA", "-keysize", "4096", "-validity", "36500",
|
|
35
|
+
"-dname", "CN=X-Tech Laboratories, O=X-Tech Laboratories",
|
|
36
|
+
"-storepass:file", plan.password_file, "-keypass:file", plan.password_file,
|
|
37
|
+
]);
|
|
38
|
+
run("gh", ["secret", "set", "ANDROID_KEYSTORE_BASE64"], readFileSync(plan.keystore).toString("base64"));
|
|
39
|
+
run("gh", ["secret", "set", "ANDROID_KEYSTORE_PASSWORD"], readFileSync(plan.password_file));
|
|
40
|
+
run("gh", ["secret", "set", "ANDROID_KEY_ALIAS"], plan.alias);
|
|
41
|
+
}
|
|
42
|
+
if (import.meta.main) {
|
|
43
|
+
try {
|
|
44
|
+
const plan = key_plan(resolve(process.argv[2] ?? "."), process.argv[3]);
|
|
45
|
+
make_release_key(plan);
|
|
46
|
+
console.info(`Saved the key in ${plan.folder} and uploaded it to GitHub.`);
|
|
47
|
+
console.info("Back up both files in that folder; losing them means no later build can install over this app.");
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
}
|
package/dist/app_new.js
CHANGED
|
@@ -74,7 +74,7 @@ function package_json(names, options) {
|
|
|
74
74
|
"@types/react-dom",
|
|
75
75
|
"@vitejs/plugin-react",
|
|
76
76
|
"@vitest/coverage-v8",
|
|
77
|
-
...(options.desktop ? ["electron", "electron-vite"] : []),
|
|
77
|
+
...(options.desktop ? ["electron", "electron-builder", "electron-vite"] : []),
|
|
78
78
|
"jsdom",
|
|
79
79
|
"oxlint",
|
|
80
80
|
"typescript",
|
|
@@ -338,6 +338,12 @@ import { defineConfig } from "electron-vite";
|
|
|
338
338
|
import { desktop_vite_config } from "@x-tech-laboratories/x-app/config/electron_vite";
|
|
339
339
|
|
|
340
340
|
export default defineConfig(desktop_vite_config());
|
|
341
|
+
`,
|
|
342
|
+
"config/electron-builder.mjs": `// The desktop app's AppImage and Flatpak bundle, from X-App's preset.
|
|
343
|
+
|
|
344
|
+
import { electron_builder_config } from "@x-tech-laboratories/x-app/config/electron_builder";
|
|
345
|
+
|
|
346
|
+
export default electron_builder_config({ id: "${names.slug}", name: "${names.name}", app_id: "${names.app_id}", comment: "${names.name}" });
|
|
341
347
|
`,
|
|
342
348
|
}
|
|
343
349
|
: {}),
|
|
@@ -394,7 +400,7 @@ function nix_files(names, options) {
|
|
|
394
400
|
in
|
|
395
401
|
{
|
|
396
402
|
packages.default = x-app.lib.package pkgs app;${options.desktop ? "\n packages.desktop = x-app.lib.desktop_package pkgs app;" : ""}
|
|
397
|
-
devShells.default = x-app.lib.shell pkgs app;${options.android ? "\n devShells.android = x-app.lib.android_shell nixpkgs system;" : ""}
|
|
403
|
+
devShells.default = x-app.lib.shell pkgs app;${options.android ? "\n devShells.android = x-app.lib.android_shell nixpkgs system;\n devShells.android-emulator = x-app.lib.android_emulator_shell nixpkgs system app;" : ""}
|
|
398
404
|
}
|
|
399
405
|
) // {
|
|
400
406
|
nixosModules.default = x-app.lib.module self app;
|
|
@@ -412,29 +418,49 @@ in
|
|
|
412
418
|
`,
|
|
413
419
|
};
|
|
414
420
|
}
|
|
415
|
-
// Every push to main builds the Android package once the tests pass, signed
|
|
416
|
-
// and a version tag publishes it as a release.
|
|
421
|
+
// Every push to main builds the Android package once the tests pass, signed with the key x-app-android-key made.
|
|
417
422
|
const android_job = `
|
|
418
423
|
android:
|
|
419
424
|
needs: ci
|
|
420
|
-
if: github.event_name
|
|
425
|
+
if: github.event_name == 'push'
|
|
421
426
|
runs-on: ubuntu-latest
|
|
422
|
-
permissions:
|
|
423
|
-
contents: write
|
|
424
427
|
steps:
|
|
425
428
|
- uses: x-tech-laboratories/X-App/.github/actions/app-android@main
|
|
426
429
|
with:
|
|
430
|
+
release: push
|
|
427
431
|
keystore-base64: \${{ secrets.ANDROID_KEYSTORE_BASE64 }}
|
|
428
432
|
keystore-password: \${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
|
|
429
433
|
key-alias: \${{ secrets.ANDROID_KEY_ALIAS }}
|
|
430
434
|
`;
|
|
435
|
+
// Every push to main builds the desktop app's AppImage and Flatpak bundle once the tests pass.
|
|
436
|
+
const linux_job = `
|
|
437
|
+
linux:
|
|
438
|
+
needs: ci
|
|
439
|
+
if: github.event_name == 'push'
|
|
440
|
+
runs-on: ubuntu-latest
|
|
441
|
+
steps:
|
|
442
|
+
- uses: x-tech-laboratories/X-App/.github/actions/app-linux@main
|
|
443
|
+
`;
|
|
444
|
+
// Each push to main is published as the latest release, v<version>.<run>, with every package the jobs above built.
|
|
445
|
+
function release_job(options) {
|
|
446
|
+
const needs = [...(options.android ? ["android"] : []), ...(options.desktop ? ["linux"] : [])];
|
|
447
|
+
return `
|
|
448
|
+
release:
|
|
449
|
+
needs: [${needs.join(", ")}]
|
|
450
|
+
runs-on: ubuntu-latest
|
|
451
|
+
permissions:
|
|
452
|
+
contents: write
|
|
453
|
+
steps:
|
|
454
|
+
- uses: x-tech-laboratories/X-App/.github/actions/app-release@main
|
|
455
|
+
`;
|
|
456
|
+
}
|
|
431
457
|
function github_files(options) {
|
|
432
458
|
return {
|
|
433
459
|
".github/workflows/ci.yml": `name: CI
|
|
434
460
|
|
|
435
461
|
on:
|
|
436
462
|
push:
|
|
437
|
-
branches: [main]
|
|
463
|
+
branches: [main]
|
|
438
464
|
pull_request:
|
|
439
465
|
branches: [main]
|
|
440
466
|
workflow_dispatch:
|
|
@@ -452,7 +478,7 @@ jobs:
|
|
|
452
478
|
- uses: x-tech-laboratories/X-App/.github/actions/app-nix@main
|
|
453
479
|
with:
|
|
454
480
|
targets: ./nix#default${options.desktop ? " ./nix#desktop" : ""}
|
|
455
|
-
${options.android ? android_job : ""}`,
|
|
481
|
+
${options.android ? android_job : ""}${options.desktop ? linux_job : ""}${options.android || options.desktop ? release_job(options) : ""}`,
|
|
456
482
|
".github/workflows/dependabot-auto-merge.yml": `name: Dependabot auto-merge
|
|
457
483
|
|
|
458
484
|
on: pull_request
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface ElectronBuilderOptions {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
app_id: string;
|
|
5
|
+
comment: string;
|
|
6
|
+
categories?: readonly string[];
|
|
7
|
+
link_scheme?: string;
|
|
8
|
+
copyright?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function electron_builder_config(options: ElectronBuilderOptions): Record<string, unknown>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// The base app's electron-builder config: a desktop app's AppImage and Flatpak bundle for Linux outside Nix, built from
|
|
2
|
+
// electron-vite's out/ and the app's resources/. The Flatpak keeps its data in ~/.config/<id>, as the other builds do,
|
|
3
|
+
// so moving between them keeps the data, and may write the login entry that starts the app in the background.
|
|
4
|
+
// ── Config ───────────────────────────────────────────────────────────────────
|
|
5
|
+
export function electron_builder_config(options) {
|
|
6
|
+
const categories = options.categories ?? ["Utility"];
|
|
7
|
+
return {
|
|
8
|
+
appId: options.app_id,
|
|
9
|
+
productName: options.name,
|
|
10
|
+
executableName: options.id,
|
|
11
|
+
copyright: options.copyright ?? "X-Tech Laboratories",
|
|
12
|
+
directories: { output: "dist" },
|
|
13
|
+
files: ["out/main/**", "out/preload/**", "out/renderer/**", "resources/**", "package.json"],
|
|
14
|
+
...(options.link_scheme ? { protocols: [{ name: `${options.name} link`, schemes: [options.link_scheme] }] } : {}),
|
|
15
|
+
linux: {
|
|
16
|
+
target: ["AppImage", "flatpak"],
|
|
17
|
+
category: categories[0],
|
|
18
|
+
icon: "resources/icon.png",
|
|
19
|
+
synopsis: options.comment,
|
|
20
|
+
desktop: { entry: { Name: options.name, Comment: options.comment, Categories: `${categories.join(";")};` } },
|
|
21
|
+
},
|
|
22
|
+
appImage: { artifactName: `${options.id}-\${arch}.AppImage` },
|
|
23
|
+
flatpak: {
|
|
24
|
+
artifactName: `${options.id}-\${arch}.flatpak`,
|
|
25
|
+
runtimeVersion: "25.08",
|
|
26
|
+
baseVersion: "25.08",
|
|
27
|
+
finishArgs: [
|
|
28
|
+
"--share=ipc",
|
|
29
|
+
"--share=network",
|
|
30
|
+
"--socket=x11",
|
|
31
|
+
"--socket=wayland",
|
|
32
|
+
"--device=dri",
|
|
33
|
+
"--talk-name=org.freedesktop.Notifications",
|
|
34
|
+
// VSCode's terminal exports this, which makes Electron run as bare node.
|
|
35
|
+
"--unset-env=ELECTRON_RUN_AS_NODE",
|
|
36
|
+
// The same data folder the other builds use, so switching between them keeps the data.
|
|
37
|
+
`--filesystem=xdg-config/${options.id}:create`,
|
|
38
|
+
// The login entry that starts the app in the background.
|
|
39
|
+
"--filesystem=xdg-config/autostart:create",
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x-tech-laboratories/x-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.116.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": {
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"bin": {
|
|
21
21
|
"x-app-android": "dist/app_android.js",
|
|
22
|
+
"x-app-android-key": "dist/app_android_key.js",
|
|
22
23
|
"x-app-bundle-migrations": "dist/drizzle_migrations.js",
|
|
23
24
|
"x-app-check": "dist/change_checks_cli.js",
|
|
24
25
|
"x-app-icons": "dist/app_icons.js",
|
|
@@ -57,6 +58,7 @@
|
|
|
57
58
|
"@sqlite.org/sqlite-wasm": "3.53.4-build2",
|
|
58
59
|
"@vitejs/plugin-react": "^6.2.1",
|
|
59
60
|
"@x-tech-laboratories/halon": "^0.31.0 || ^0.32.0 || ^0.33.0 || ^0.34.0 || ^0.35.0",
|
|
61
|
+
"electron-builder": "^26.18.0",
|
|
60
62
|
"electron-vite": "^6.0.0",
|
|
61
63
|
"fastify": "^5.12.7",
|
|
62
64
|
"mermaid": "^11.0.0",
|
|
@@ -127,6 +129,9 @@
|
|
|
127
129
|
"@x-tech-laboratories/halon": {
|
|
128
130
|
"optional": true
|
|
129
131
|
},
|
|
132
|
+
"electron-builder": {
|
|
133
|
+
"optional": true
|
|
134
|
+
},
|
|
130
135
|
"electron-vite": {
|
|
131
136
|
"optional": true
|
|
132
137
|
},
|