Skip to content

armgit / Pake

Public Imported from GitHub
0

Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.

refactor: keep a single runtime app flag

youxi798e9cd4fedcc04
diff --git a/AGENTS.md b/AGENTS.md
index ea180974..ed6b4bb2 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -108,7 +108,7 @@ Oracles per row live under `tests/unit/` (for example `event-link-guard.test.js`
- CLI options are user-facing and must stay synchronized across `bin/helpers/cli-program.ts`, `bin/types.ts`, `bin/defaults.ts`, `bin/helpers/merge.ts`, generated `dist/cli.js`, `schema/pake.schema.json`, and `docs/cli-usage*.md`. Schema-to-CLI sync is enforced by `tests/unit/config-file.test.ts`; the rest is manual discipline.
- The `--json` machine contract is public API for agents: stdout carries exactly one JSON result (nothing else may write to stdout in machine mode), and the exit codes (0/2/3/4/1) plus error codes (`INVALID_INPUT`, `ENV_MISSING`, `BUILD_FAILED`, `UNEXPECTED`, plus `NETWORK` which is reserved and currently unused, since network failures report under the phase code) must stay stable. `logger.warn` feeds the JSON `warnings` array, so warn is for real warnings only, not status lines. Owners: `bin/utils/output.ts`, `bin/cli.ts`, `bin/utils/shell.ts`.
- Packaging CLI builds use a private temporary workspace for configs, injected code, icons, entitlements, and local content. The installed package is the template, not a writable staging area. Complete installed Tauri dependencies are reused without reinstalling; incomplete dependencies are installed only in the private workspace. Owners: `bin/utils/build-workspace.ts`, `bin/utils/dir.ts`, and `bin/helpers/merge.ts`. `restoreLocalTree()` at CLI startup remains only to recover a `dist_bak` left by the published 3.15.7 implementation. The repository's `bin/dev.ts` intentionally retains source-based Tauri development/watch behavior.
-- The `runtime-template` Cargo feature builds a prebuilt runtime that a separate builder customizes without a compiler: at launch it reads `pake-runtime/{pake.json, app.json, custom.js?, tray.png?}` from `Contents/Resources` on macOS or next to the executable elsewhere, and applies app.json's `identifier` and `productName` to the Tauri context before build. The CLI never enables the feature, so CLI-built apps keep their compiled configuration even if such a folder appears. A present but invalid override exits with a `[Pake]` message instead of falling back to the template's identity. A runtime app keys its WebView profile folder under the config dir (`%APPDATA%\<identifier>\EBWebView` on Windows) by identifier instead of product name (`data_dir_name`), so a rename keeps logins and a generated name cannot share another program's folder; CLI apps keep the product-name folder. On Windows a runtime app also sets the process AppUserModelID to its identifier before any window exists, so shortcuts carrying that ID group with the running window and toasts are attributed to it. Logic and tests live in `src-tauri/src/util.rs` (`apply_runtime_override`, `data_dir_name`, `app_user_model_id`); keep `cargo clippy` and `cargo test --lib` green both with and without `--features runtime-template`.
+- The `runtime-template` Cargo feature builds a prebuilt runtime that a separate builder customizes without a compiler: at launch it reads `pake-runtime/{pake.json, app.json, custom.js?, tray.png?}` from `Contents/Resources` on macOS or next to the executable elsewhere, and applies app.json's `identifier` and `productName` to the Tauri context before build. The CLI never enables the feature, so CLI-built apps keep their compiled configuration even if such a folder appears. A present but invalid override exits with a `[Pake]` message instead of falling back to the template's identity. A runtime app keys its WebView profile folder under the config dir (`%APPDATA%\<identifier>\EBWebView` on Windows) by identifier instead of product name (`data_dir_name`), so a rename keeps logins and a generated name cannot share another program's folder; CLI apps keep the product-name folder. On Windows a runtime app also sets the process AppUserModelID to its identifier before any window exists, so shortcuts carrying that ID group with the running window and toasts are attributed to it. Logic and tests live in `src-tauri/src/util.rs` (`apply_runtime_override`, `data_dir_name`, `set_app_user_model_id`); `PakeConfig::runtime_app` is the single runtime-app flag, and `run_app` copies the overridden identity from the returned Tauri config into the context; keep `cargo clippy` and `cargo test --lib` green both with and without `--features runtime-template`.
- `transparent_title_bar` is a runtime-only macOS window field (no CLI flag; the paid apps set it): Tauri's `Transparent` title bar keeps the page below the bar, and `src-tauri/src/inject/title_bar.js` paints the window background with the page's top-edge color through `set_title_bar_color`. `hide_title_bar` keeps precedence and its overlay behavior. The color is the majority of three top-edge samples, resolved through a canvas so `oklch()`/`color()` values work; do not skip sampling for `document.hidden`, or windows revealed after load stay uncolored. Cover it with `tests/unit/title-bar-color.test.js`; when checking a real bundle, window captures carry the display profile, so convert the sRGB page color before comparing pixels.
- Linux multi-format builds compile once with `--no-bundle`, then use `tauri bundle` for each format with the same config, features, target, and debug profile. Keep per-format failure isolation and AppImage `NO_STRIP` retries on bundling only. Single-format builds retain the combined build path.
- Build preparation uses private workspaces before acquiring the shared compilation cache lock. Cancellation while waiting must clean only that workspace and leave the active owner's lock intact.
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 51e45a4f..6da43cbd 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -289,18 +289,22 @@ pub fn run_app() {
apply_linux_webkit_runtime_flags();
}
- let (pake_config, tauri_config, runtime_app) = get_pake_config();
+ let (pake_config, tauri_config) = get_pake_config();
+ // A runtime app sets the shell's AppUserModelID to its identifier so
+ // shortcuts and toasts group with its windows; CLI apps keep the default.
#[cfg(windows)]
- if let Some(id) = util::app_user_model_id(runtime_app.as_ref()) {
- util::set_app_user_model_id(id);
+ if pake_config.runtime_app {
+ util::set_app_user_model_id(&tauri_config.identifier);
}
let mut context = tauri::generate_context!();
// Paths, app data and the macOS menu derive from the context, so a runtime
// app must not share the template's identity.
- if let Some(app) = runtime_app {
- context.config_mut().identifier = app.identifier;
- context.config_mut().product_name = Some(app.product_name.clone());
- context.package_info_mut().name = app.product_name;
+ if pake_config.runtime_app {
+ context.config_mut().identifier = tauri_config.identifier.clone();
+ if let Some(name) = &tauri_config.product_name {
+ context.config_mut().product_name = Some(name.clone());
+ context.package_info_mut().name = name.clone();
+ }
}
let tauri_app = tauri::Builder::default();
diff --git a/src-tauri/src/util.rs b/src-tauri/src/util.rs
index 4191a63b..858c0ecf 100644
--- a/src-tauri/src/util.rs
+++ b/src-tauri/src/util.rs
@@ -4,7 +4,7 @@ use std::env;
use std::path::{Path, PathBuf};
use tauri::{AppHandle, Config, Manager, WebviewWindow};
-pub fn get_pake_config() -> (PakeConfig, Config, Option<RuntimeApp>) {
+pub fn get_pake_config() -> (PakeConfig, Config) {
#[cfg(feature = "cli-build")]
let pake_config: PakeConfig = serde_json::from_str(include_str!("../.pake/pake.json"))
.expect("Failed to parse pake config");
@@ -41,11 +41,11 @@ pub fn get_pake_config() -> (PakeConfig, Config, Option<RuntimeApp>) {
const RUNTIME_DIR: &str = "pake-runtime";
/// App identity supplied next to a runtime `pake.json`.
-#[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize)]
+#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
-pub struct RuntimeApp {
- pub identifier: String,
- pub product_name: String,
+struct RuntimeApp {
+ identifier: String,
+ product_name: String,
}
/// macOS keeps overrides in `Contents/Resources/pake-runtime`; other platforms
@@ -74,13 +74,13 @@ fn apply_runtime_override(
mut pake_config: PakeConfig,
mut tauri_config: Config,
runtime_dir: Option<&Path>,
-) -> Result<(PakeConfig, Config, Option<RuntimeApp>), String> {
+) -> Result<(PakeConfig, Config), String> {
let Some(dir) = runtime_dir else {
- return Ok((pake_config, tauri_config, None));
+ return Ok((pake_config, tauri_config));
};
let pake_path = dir.join("pake.json");
let Some(pake_json) = read_optional(&pake_path)? else {
- return Ok((pake_config, tauri_config, None));
+ return Ok((pake_config, tauri_config));
};
let app_path = dir.join("app.json");
let app_json =
@@ -118,9 +118,9 @@ fn apply_runtime_override(
.into_owned();
}
pake_config.runtime_app = true;
- tauri_config.identifier = app.identifier.clone();
- tauri_config.product_name = Some(app.product_name.clone());
- Ok((pake_config, tauri_config, Some(app)))
+ tauri_config.identifier = app.identifier;
+ tauri_config.product_name = Some(app.product_name);
+ Ok((pake_config, tauri_config))
}
/// Same rule as the CLI's --identifier check, capped at the 128 characters an
@@ -150,15 +150,6 @@ pub fn data_dir_name(pake_config: &PakeConfig, tauri_config: &Config) -> String
}
}
-/// The Windows AppUserModelID a runtime app sets before creating windows, so
-/// a shortcut carrying the identifier groups with the running window and
-/// toasts (sent under the identifier) are attributed to it. CLI apps keep the
-/// shell's default.
-#[cfg_attr(not(windows), allow(dead_code))]
-pub fn app_user_model_id(runtime_app: Option<&RuntimeApp>) -> Option<&str> {
- runtime_app.map(|app| app.identifier.as_str())
-}
-
/// Must run before any window exists; the shell reads the ID at window creation.
#[cfg(windows)]
pub fn set_app_user_model_id(id: &str) {
@@ -669,20 +660,20 @@ mod tests {
let (pake, tauri) = compiled_configs();
let expected = snapshot(&pake, &tauri);
- let (pake, tauri, app) = apply_runtime_override(pake, tauri, None).unwrap();
- assert!(app.is_none());
+ let (pake, tauri) = apply_runtime_override(pake, tauri, None).unwrap();
+ assert!(!pake.runtime_app);
assert_eq!(snapshot(&pake, &tauri), expected);
// A directory without pake.json is not a runtime app, even with app.json.
let dir = runtime_dir(&[("app.json", RUNTIME_APP), ("custom.js", "x")]);
- let (pake, tauri, app) = apply_runtime_override(pake, tauri, Some(&dir)).unwrap();
- assert!(app.is_none());
+ let (pake, tauri) = apply_runtime_override(pake, tauri, Some(&dir)).unwrap();
+ assert!(!pake.runtime_app);
assert!(pake.runtime_custom_js.is_none());
assert_eq!(snapshot(&pake, &tauri), expected);
let missing = dir.join("missing");
- let (pake, tauri, app) = apply_runtime_override(pake, tauri, Some(&missing)).unwrap();
- assert!(app.is_none());
+ let (pake, tauri) = apply_runtime_override(pake, tauri, Some(&missing)).unwrap();
+ assert!(!pake.runtime_app);
assert_eq!(snapshot(&pake, &tauri), expected);
fs::remove_dir_all(dir.parent().unwrap()).unwrap();
}
@@ -705,14 +696,8 @@ mod tests {
]);
let (pake, tauri) = compiled_configs();
- let (pake, tauri, app) = apply_runtime_override(pake, tauri, Some(&dir)).unwrap();
- assert_eq!(
- app,
- Some(RuntimeApp {
- identifier: "com.pake.a1b2c3".into(),
- product_name: "Runtime Probe".into(),
- })
- );
+ let (pake, tauri) = apply_runtime_override(pake, tauri, Some(&dir)).unwrap();
+ assert!(pake.runtime_app);
assert_eq!(tauri.identifier, "com.pake.a1b2c3");
assert_eq!(tauri.product_name.as_deref(), Some("Runtime Probe"));
assert_eq!(pake.windows[0].url, "https://example.com/app");
@@ -731,7 +716,7 @@ mod tests {
fs::write(dir.join("pake.json"), runtime.to_string()).unwrap();
fs::remove_file(dir.join("custom.js")).unwrap();
let (pake, tauri) = compiled_configs();
- let (pake, _, _) = apply_runtime_override(pake, tauri, Some(&dir)).unwrap();
+ let (pake, _) = apply_runtime_override(pake, tauri, Some(&dir)).unwrap();
assert_eq!(PathBuf::from(&pake.system_tray_path), absolute);
assert!(pake.runtime_custom_js.is_none());
fs::remove_dir_all(dir.parent().unwrap()).unwrap();
@@ -784,7 +769,7 @@ mod tests {
fn data_dir_follows_product_name_for_cli_and_identifier_for_runtime() {
let (pake, tauri) = compiled_configs();
let cli_name = tauri.product_name.clone().unwrap();
- let (pake, tauri, _) = apply_runtime_override(pake, tauri, None).unwrap();
+ let (pake, tauri) = apply_runtime_override(pake, tauri, None).unwrap();
assert_eq!(data_dir_name(&pake, &tauri), cli_name);
let mut nameless = tauri.clone();
@@ -795,7 +780,7 @@ mod tests {
("pake.json", include_str!("../pake.json")),
("app.json", RUNTIME_APP),
]);
- let (pake, tauri, _) = apply_runtime_override(pake, tauri, Some(&dir)).unwrap();
+ let (pake, tauri) = apply_runtime_override(pake, tauri, Some(&dir)).unwrap();
assert_eq!(data_dir_name(&pake, &tauri), "com.pake.a1b2c3");
fs::remove_dir_all(dir.parent().unwrap()).unwrap();
}
@@ -818,14 +803,4 @@ mod tests {
assert!(!is_valid_identifier(id), "{id}");
}
}
-
- #[test]
- fn app_user_model_id_is_set_only_for_runtime_apps() {
- assert_eq!(app_user_model_id(None), None);
- let app = RuntimeApp {
- identifier: "com.pake.a1b2c3".into(),
- product_name: "Runtime Probe".into(),
- };
- assert_eq!(app_user_model_id(Some(&app)), Some("com.pake.a1b2c3"));
- }
}