Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.
Rust chatgptclaudeclidesktopdesktop-appelectron-alternativegeminilinuxmacosnativefierno-electronrusttauriweb-to-desktopwebsite-to-appwebviewwindowsyoutube
feat: add a page-colored transparent title bar for runtime apps
Tw936bc1de1d27d1
diff --git a/AGENTS.md b/AGENTS.mdindex 3efea904..24f3a3b9 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -108,6 +108,7 @@ Oracles per row live under `tests/unit/` (for example `event-link-guard.test.js`- 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`.+- `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.- Native build gates use a fresh output directory, require exit code zero and the CLI JSON's exact output path, and verify macOS executable architectures from `CFBundleExecutable`. Compare existing artifact paths with `realpath`, since macOS `/var` and `/private/var` can identify the same file; retain a negative test for genuinely different files. Old bundles, empty directories, or timeout artifacts never prove a successful build.diff --git a/src-tauri/build.rs b/src-tauri/build.rsindex 366c3b62..daca2933 100644--- a/src-tauri/build.rs+++ b/src-tauri/build.rs@@ -13,6 +13,7 @@ fn main() {"update_theme_mode","set_zoom","webview_navigate",+ "set_title_bar_color",]),)).expect("Failed to build Pake permissions")diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.jsonindex 685fcda9..85dd9a77 100644--- a/src-tauri/capabilities/default.json+++ b/src-tauri/capabilities/default.json@@ -14,6 +14,7 @@"allow-update-theme-mode","allow-set-zoom","allow-webview-navigate",+ "allow-set-title-bar-color","shell:allow-open","core:window:allow-theme","core:window:allow-start-dragging",diff --git a/src-tauri/src/app/config.rs b/src-tauri/src/app/config.rsindex 3577321a..3f271ccb 100644--- a/src-tauri/src/app/config.rs+++ b/src-tauri/src/app/config.rs@@ -8,6 +8,10 @@ use tauri::Url;pub struct WindowConfig {pub url: String,pub hide_title_bar: bool,+ /// macOS only, set by the runtime builder rather than a CLI flag: a native+ /// transparent title bar above the page, painted with the page's top color.+ #[serde(default)]+ pub transparent_title_bar: bool,#[serde(default)]pub hide_window_decorations: bool,pub fullscreen: bool,@@ -57,6 +61,14 @@ impl WindowConfig {}}+impl WindowConfig {+ /// The overlay title bar (`hide_title_bar`) keeps precedence, so existing+ /// configs behave exactly as before.+ pub fn title_bar_follows_page(&self) -> bool {+ self.transparent_title_bar && !self.hide_title_bar+ }+}+#[derive(Clone, Debug, Serialize, Deserialize)]pub struct PlatformSpecific<T> {pub macos: T,@@ -204,6 +216,27 @@ mod tests {assert!(!legacy.password_autosave_enabled());}+ #[test]+ fn transparent_title_bar_is_opt_in_and_yields_to_the_overlay() {+ let mut window = config_for("https://example.com").windows.remove(0);+ let mut legacy = serde_json::to_value(&window).unwrap();+ legacy+ .as_object_mut()+ .unwrap()+ .remove("transparent_title_bar");+ let legacy: WindowConfig = serde_json::from_value(legacy).unwrap();+ assert!(!legacy.transparent_title_bar);+ assert!(!legacy.title_bar_follows_page());++ for transparent in [false, true] {+ for hidden in [false, true] {+ window.transparent_title_bar = transparent;+ window.hide_title_bar = hidden;+ assert_eq!(window.title_bar_follows_page(), transparent && !hidden);+ }+ }+ }+fn resolve(config: &PakeConfig) -> Resolved {let manifest: BTreeMap<String, Manifest> = serde_json::from_str(include_str!(concat!(env!("OUT_DIR"),diff --git a/src-tauri/src/app/invoke.rs b/src-tauri/src/app/invoke.rsindex 6d9e46e2..ae784f8c 100644--- a/src-tauri/src/app/invoke.rs+++ b/src-tauri/src/app/invoke.rs@@ -468,6 +468,31 @@ pub async fn update_theme_mode(app: AppHandle, mode: String) {}}+/// Paints the window behind a transparent macOS title bar with the color at+/// the top of the page. Remote pages can call this, so it takes only bounded+/// RGB channels and changes nothing but the calling window's background.+#[command]+pub fn set_title_bar_color(+ window: WebviewWindow,+ red: u8,+ green: u8,+ blue: u8,+) -> Result<(), String> {+ #[cfg(target_os = "macos")]+ {+ window+ .as_ref()+ .window()+ .set_background_color(Some(tauri::window::Color(red, green, blue, 255)))+ .map_err(|e| format!("Failed to set the title bar color: {}", e))+ }+ #[cfg(not(target_os = "macos"))]+ {+ let _ = (window, red, green, blue);+ Ok(())+ }+}+// Apply native WebView zoom (WKWebView pageZoom / WebView2 ZoomFactor / WebKitGTK// zoom level) instead of CSS hacks. CSS `transform: scale` and `html.style.zoom`// break complex SPAs like ChatGPT (fixed positioning shifts, unrepainted layers);diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rsindex 0bb72162..02720a26 100644--- a/src-tauri/src/app/window.rs+++ b/src-tauri/src/app/window.rs@@ -607,13 +607,20 @@ fn build_window(window_builder = window_builder.initialization_script(include_str!("../inject/event.js")).initialization_script(include_str!("../inject/style.js"))- .initialization_script(include_str!("../inject/theme_refresh.js"))- .initialization_script(- config- .runtime_custom_js- .as_deref()- .unwrap_or(include_str!("../inject/custom.js")),- );+ .initialization_script(include_str!("../inject/theme_refresh.js"));++ #[cfg(target_os = "macos")]+ if window_config.title_bar_follows_page() {+ window_builder =+ window_builder.initialization_script(include_str!("../inject/title_bar.js"));+ }++ window_builder = window_builder.initialization_script(+ config+ .runtime_custom_js+ .as_deref()+ .unwrap_or(include_str!("../inject/custom.js")),+ );#[cfg(target_os = "windows")]let mut windows_browser_args = String::from("--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection --disable-blink-features=AutomationControlled");@@ -669,10 +676,17 @@ fn build_window({let title_bar_style = if window_config.hide_title_bar {TitleBarStyle::Overlay+ } else if window_config.title_bar_follows_page() {+ // The page starts below the bar, so the traffic lights never cover+ // it; title_bar.js paints the bar with the page's top color.+ TitleBarStyle::Transparent} else {TitleBarStyle::Visible};window_builder = window_builder.title_bar_style(title_bar_style);+ if window_config.title_bar_follows_page() {+ window_builder = window_builder.hidden_title(true);+ }window_builder = window_builder.theme(theme);// Tauri disables automatic tabbing unless an identifier is provided.diff --git a/src-tauri/src/inject/title_bar.js b/src-tauri/src/inject/title_bar.jsnew file mode 100644index 00000000..67ddf468--- /dev/null+++ b/src-tauri/src/inject/title_bar.js@@ -0,0 +1,103 @@+// Injected only on macOS windows with a transparent title bar. The page starts+// below the bar, so this paints the bar with the color along the page's top+// edge and it reads as part of the page rather than a separate strip.+(function () {+ const SAMPLE_POINTS = [0.25, 0.5, 0.75];+ const MIN_ALPHA = 128;+ let probe = null;+ let lastSent = "";+ let pending = 0;+ let warned = false;++ // A 1x1 canvas resolves any CSS color the engine supports (rgb, oklch,+ // color(), named) into sRGB bytes, so modern color syntax is not missed.+ function toRgb(value) {+ if (!value || value === "transparent") return null;+ if (!probe) {+ const canvas = document.createElement("canvas");+ canvas.width = 1;+ canvas.height = 1;+ probe = canvas.getContext("2d", { willReadFrequently: true });+ if (!probe) return null;+ }+ probe.clearRect(0, 0, 1, 1);+ probe.fillStyle = "rgba(0, 0, 0, 0)";+ probe.fillStyle = value;+ probe.fillRect(0, 0, 1, 1);+ const [red, green, blue, alpha] = probe.getImageData(0, 0, 1, 1).data;+ return alpha >= MIN_ALPHA ? { red, green, blue } : null;+ }++ function backgroundAt(x) {+ let element = document.elementFromPoint(x, 0);+ while (element) {+ const color = toRgb(window.getComputedStyle(element).backgroundColor);+ if (color) return color;+ element = element.parentElement;+ }+ return null;+ }++ // The most common of three samples along the top edge, so a sidebar or a+ // logo under one sample point does not decide the whole bar.+ function pageTopColor() {+ const width = window.innerWidth;+ if (!width) return null;+ const samples = SAMPLE_POINTS.map((share) =>+ backgroundAt(Math.floor(width * share)),+ );+ const keys = samples.map((color) =>+ color ? `${color.red},${color.green},${color.blue}` : "",+ );+ const majority = keys.findIndex(+ (key, index) => key && keys.indexOf(key, index + 1) !== -1,+ );+ return samples[majority === -1 ? 1 : majority];+ }++ function update() {+ pending = 0;+ const color = pageTopColor();+ if (!color) return;+ const key = `${color.red},${color.green},${color.blue}`;+ if (key === lastSent) return;+ const invoke = window.__TAURI__?.core?.invoke;+ if (!invoke) return;+ lastSent = key;+ // Pages outside the configured origin have no IPC grant; warn once and+ // keep the last color rather than retrying every interval.+ invoke("set_title_bar_color", color).catch((error) => {+ if (warned) return;+ warned = true;+ console.warn("[Pake] Failed to color the title bar:", error);+ });+ }++ function schedule() {+ if (!pending) pending = setTimeout(update, 150);+ }++ function start() {+ update();+ const observer = new MutationObserver(schedule);+ const attributes = {+ attributes: true,+ attributeFilter: ["class", "style", "data-theme"],+ };+ observer.observe(document.documentElement, attributes);+ if (document.body) observer.observe(document.body, attributes);+ window.addEventListener("load", schedule);+ window.addEventListener("resize", schedule);+ window+ .matchMedia?.("(prefers-color-scheme: dark)")+ ?.addEventListener?.("change", schedule);+ // Single-page apps repaint their header without touching html or body.+ setInterval(schedule, 1500);+ }++ if (document.readyState === "loading") {+ document.addEventListener("DOMContentLoaded", start, { once: true });+ } else {+ start();+ }+})();diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rsindex 0e9d2a38..7dbdcdb0 100644--- a/src-tauri/src/lib.rs+++ b/src-tauri/src/lib.rs@@ -30,8 +30,8 @@ const GDK_BACKEND: &str = "GDK_BACKEND";use app::{invoke::{clear_dock_badge, close_notification, download_file, increment_dock_badge,- send_notification, set_dock_badge, set_dock_badge_label, set_zoom, update_theme_mode,- webview_navigate,+ send_notification, set_dock_badge, set_dock_badge_label, set_title_bar_color, set_zoom,+ update_theme_mode, webview_navigate,},setup::{set_global_shortcut, set_system_tray},window::{@@ -409,6 +409,7 @@ pub fn run_app() {update_theme_mode,set_zoom,webview_navigate,+ set_title_bar_color,]).setup(move |app| {// Grant remote IPC only to the immutable, packaged entry origins,diff --git a/tests/unit/title-bar-color.test.js b/tests/unit/title-bar-color.test.jsnew file mode 100644index 00000000..7d46b8e1--- /dev/null+++ b/tests/unit/title-bar-color.test.js@@ -0,0 +1,141 @@+import fs from "fs";+import path from "path";+import { runInNewContext } from "node:vm";+import { describe, expect, it } from "vitest";++const source = fs.readFileSync(+ path.join(process.cwd(), "src-tauri/src/inject/title_bar.js"),+ "utf-8",+);++// Colors are written as "r,g,b,a" so the fake canvas can resolve them without+// a real CSS parser; anything else behaves like an unsupported value.+function parse(value) {+ const parts = String(value).split(",").map(Number);+ return parts.length === 4 && parts.every((n) => Number.isFinite(n))+ ? parts+ : null;+}++function element(background, parentElement = null) {+ return { background, parentElement };+}++function loadTitleBar({ columns, width = 1000 }) {+ const calls = [];+ let current = columns;+ let timer = null;+ let observed = null;+ const context = {+ console,+ setTimeout: (callback) => {+ timer = callback;+ return 1;+ },+ setInterval: () => 0,+ MutationObserver: class {+ constructor(callback) {+ observed = callback;+ }+ observe() {}+ },+ document: {+ readyState: "complete",+ documentElement: {},+ body: {},+ addEventListener() {},+ createElement() {+ let fill = [0, 0, 0, 0];+ return {+ getContext: () => ({+ clearRect() {},+ fillRect() {},+ set fillStyle(value) {+ const parsed = parse(value);+ if (parsed) fill = parsed;+ },+ getImageData: () => ({ data: fill }),+ }),+ };+ },+ elementFromPoint(x) {+ const column = Math.min(2, Math.floor((x / width) * 3));+ return current[column];+ },+ },+ window: {+ innerWidth: width,+ addEventListener() {},+ getComputedStyle: (node) => ({ backgroundColor: node.background }),+ __TAURI__: {+ core: {+ invoke(command, args) {+ calls.push({ command, args });+ return Promise.resolve();+ },+ },+ },+ },+ };+ context.window.document = context.document;+ runInNewContext(source, context);+ return {+ calls,+ // A page mutation followed by the debounce timer firing.+ repaint(next) {+ current = next;+ observed();+ const run = timer;+ timer = null;+ run?.();+ },+ };+}++describe("macOS transparent title bar color", () => {+ it("sends the color most of the top edge shares", () => {+ const white = element("255,255,255,255");+ const logo = element("240,240,240,255");+ const { calls } = loadTitleBar({ columns: [white, logo, white] });+ expect(calls).toEqual([+ {+ command: "set_title_bar_color",+ args: { red: 255, green: 255, blue: 255 },+ },+ ]);+ });++ it("walks up past transparent layers to the painted ancestor", () => {+ const page = element("20,20,24,255");+ const overlay = element("0,0,0,0", page);+ const { calls } = loadTitleBar({ columns: [overlay, overlay, overlay] });+ expect(calls[0].args).toEqual({ red: 20, green: 20, blue: 24 });+ });++ it("uses the center sample when all three differ", () => {+ const { calls } = loadTitleBar({+ columns: [+ element("10,10,10,255"),+ element("200,100,50,255"),+ element("90,90,90,255"),+ ],+ });+ expect(calls[0].args).toEqual({ red: 200, green: 100, blue: 50 });+ });++ it("sends again only when the top color changes", () => {+ const white = element("255,255,255,255");+ const { calls, repaint } = loadTitleBar({ columns: [white, white, white] });+ repaint([white, white, white]);+ expect(calls).toHaveLength(1);+ const dark = element("30,30,30,255");+ repaint([dark, dark, dark]);+ expect(calls.map((call) => call.args.red)).toEqual([255, 30]);+ });++ it("leaves the native color alone when nothing on top is painted", () => {+ const clear = element("0,0,0,0");+ const { calls } = loadTitleBar({ columns: [clear, clear, null] });+ expect(calls).toEqual([]);+ });+});