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 hide-window-decorations for Windows and Linux
Vinicius Martinsa3ebfa6edd3e
diff --git a/.agents/skills/use-pake/SKILL.md b/.agents/skills/use-pake/SKILL.mdindex 9a77e521..dc32a032 100644--- a/.agents/skills/use-pake/SKILL.md+++ b/.agents/skills/use-pake/SKILL.md@@ -93,12 +93,13 @@ After build, confirm:### Window Behavior-| Option | Default | Description |-| ------------------ | ------- | -------------------- |-| `--fullscreen` | false | Start fullscreen |-| `--maximize` | false | Start maximized |-| `--always-on-top` | false | Pin window on top |-| `--hide-title-bar` | false | Hide macOS title bar |+| Option | Default | Description |+| --------------------------- | ------- | ----------------------------------------------- |+| `--fullscreen` | false | Start fullscreen |+| `--maximize` | false | Start maximized |+| `--always-on-top` | false | Pin window on top |+| `--hide-title-bar` | false | Hide macOS title bar |+| `--hide-window-decorations` | false | Hide native window decorations on Windows/Linux |### Advanceddiff --git a/README.md b/README.mdindex 1b214ea6..edf921a9 100644--- a/README.md+++ b/README.md@@ -153,8 +153,9 @@| <kbd>⌘</kbd> + <kbd>⇧</kbd> + <kbd>H</kbd> | <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>H</kbd> | Go to Home Page || <kbd>⌘</kbd> + <kbd>⌥</kbd> + <kbd>I</kbd> | <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>I</kbd> | Toggle Developer Tools (Debug Only) || <kbd>⌘</kbd> + <kbd>⇧</kbd> + <kbd>⌫</kbd> | <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Del</kbd> | Clear Cache & Restart |+| <kbd>⌃</kbd> + <kbd>⌘</kbd> + <kbd>F</kbd> | <kbd>F11</kbd> | Toggle native window fullscreen |-In addition, double-click the title bar to switch to full-screen mode. For Mac users, you can also use the gesture to go to the previous or next page and drag the title bar to move the window. The new menu also offers options for navigation, zoom, and window controls.+In addition, double-click the title bar to switch to full-screen mode. On Windows and Linux, use `--hide-window-decorations` for a frameless window with a top drag region. For Mac users, you can also use the gesture to go to the previous or next page and drag the title bar to move the window. The new menu also offers options for navigation, zoom, and window controls.</details>diff --git a/README_CN.md b/README_CN.mdindex ec97872b..68c7ce78 100644--- a/README_CN.md+++ b/README_CN.md@@ -154,8 +154,9 @@| <kbd>⌘</kbd> + <kbd>⇧</kbd> + <kbd>H</kbd> | <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>H</kbd> | 回到首页 || <kbd>⌘</kbd> + <kbd>⌥</kbd> + <kbd>I</kbd> | <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>I</kbd> | 开启调试 (仅开发版) || <kbd>⌘</kbd> + <kbd>⇧</kbd> + <kbd>⌫</kbd> | <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Del</kbd> | 清除缓存并重启 |+| <kbd>⌃</kbd> + <kbd>⌘</kbd> + <kbd>F</kbd> | <kbd>F11</kbd> | 切换原生全屏 |-此外还支持双击头部全屏切换,拖拽头部移动窗口,Mac 用户支持手势返回和前进,新菜单也提供了导航、缩放和窗口控制等选项。+此外还支持双击头部全屏切换。Windows 和 Linux 可使用 `--hide-window-decorations` 创建带顶部拖拽区域的无边框窗口。Mac 用户支持手势返回和前进,新菜单也提供了导航、缩放和窗口控制等选项。</details>diff --git a/bin/defaults.ts b/bin/defaults.tsindex 3629d60a..7ae2ca34 100644--- a/bin/defaults.ts+++ b/bin/defaults.ts@@ -9,6 +9,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {maximize: false,resizable: true,hideTitleBar: false,+ hideWindowDecorations: false,alwaysOnTop: false,appVersion: '1.0.0',darkMode: false,diff --git a/bin/helpers/cli-program.ts b/bin/helpers/cli-program.tsindex f6ae7f89..5b05dca1 100644--- a/bin/helpers/cli-program.ts+++ b/bin/helpers/cli-program.ts@@ -46,6 +46,11 @@ ${green('|_| \\__,_|_|\\_\\___| can turn any webpage into a desktop app with).option('--fullscreen', 'Start in full screen', DEFAULT.fullscreen).option('--hide-title-bar', 'For Mac, hide title bar', DEFAULT.hideTitleBar)+ .option(+ '--hide-window-decorations',+ 'Hide native window decorations on Windows and Linux',+ DEFAULT.hideWindowDecorations,+ ).option('--multi-arch', 'For Mac, both Intel and M1', DEFAULT.multiArch).option('--inject <files>',diff --git a/bin/helpers/merge.ts b/bin/helpers/merge.tsindex 4f392cee..ff2e602b 100644--- a/bin/helpers/merge.ts+++ b/bin/helpers/merge.ts@@ -33,6 +33,8 @@ export function buildWindowConfigOverrides(const platformHideOnClose = options.hideOnClose ?? platform === 'darwin';const platformHideTitleBar =platform === 'darwin' ? options.hideTitleBar : false;+ const platformHideWindowDecorations =+ platform !== 'darwin' ? options.hideWindowDecorations : false;return {width: options.width,height: options.height,@@ -40,6 +42,7 @@ export function buildWindowConfigOverrides(maximize: options.maximize,resizable: options.resizable ?? true,hide_title_bar: platformHideTitleBar,+ hide_window_decorations: platformHideWindowDecorations,activation_shortcut: options.activationShortcut,always_on_top: options.alwaysOnTop,dark_mode: options.darkMode,@@ -476,6 +479,11 @@ export async function mergeConfig('✼ --hide-title-bar is only supported on macOS and will be ignored on this platform.',);}+ if (options.hideWindowDecorations && platform === 'darwin') {+ logger.warn(+ '✼ --hide-window-decorations is only supported on Windows and Linux and will be ignored on this platform.',+ );+ }const tauriConfWindowOptions = buildWindowConfigOverrides(options, platform);Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions });diff --git a/bin/types.ts b/bin/types.tsindex ed7399f9..7e67b460 100644--- a/bin/types.ts+++ b/bin/types.ts@@ -29,9 +29,12 @@ export interface PakeCliOptions {// Start window maximized, default falsemaximize: boolean;- // Enable immersive header, default false.+ // Enable immersive header, default false. macOS only.hideTitleBar: boolean;+ // Hide native window decorations, default false. Windows and Linux only.+ hideWindowDecorations: boolean;+// Enable windows always on top, default falsealwaysOnTop: boolean;@@ -159,6 +162,7 @@ export interface PlatformSpecific<T> {export interface WindowConfig {url: string;hide_title_bar: boolean;+ hide_window_decorations: boolean;fullscreen: boolean;maximize: boolean;width: number;diff --git a/dist/cli.js b/dist/cli.jsindex 6f2eb5bd..87337272 100644--- a/dist/cli.js+++ b/dist/cli.js@@ -535,6 +535,7 @@ function resolveLinuxBundleTargets(targets) {function buildWindowConfigOverrides(options, platform = asSupportedPlatform(process.platform)) {const platformHideOnClose = options.hideOnClose ?? platform === 'darwin';const platformHideTitleBar = platform === 'darwin' ? options.hideTitleBar : false;+ const platformHideWindowDecorations = platform !== 'darwin' ? options.hideWindowDecorations : false;return {width: options.width,height: options.height,@@ -542,6 +543,7 @@ function buildWindowConfigOverrides(options, platform = asSupportedPlatform(procmaximize: options.maximize,resizable: options.resizable ?? true,hide_title_bar: platformHideTitleBar,+ hide_window_decorations: platformHideWindowDecorations,activation_shortcut: options.activationShortcut,always_on_top: options.alwaysOnTop,dark_mode: options.darkMode,@@ -827,6 +829,9 @@ async function mergeConfig(url, options, tauriConf) {if (options.hideTitleBar && platform !== 'darwin') {logger.warn('✼ --hide-title-bar is only supported on macOS and will be ignored on this platform.');}+ if (options.hideWindowDecorations && platform === 'darwin') {+ logger.warn('✼ --hide-window-decorations is only supported on Windows and Linux and will be ignored on this platform.');+ }const tauriConfWindowOptions = buildWindowConfigOverrides(options, platform);Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions });tauriConf.productName = name;@@ -2728,6 +2733,7 @@ const DEFAULT_PAKE_OPTIONS = {fullscreen: false,maximize: false,hideTitleBar: false,+ hideWindowDecorations: false,alwaysOnTop: false,appVersion: '1.0.0',darkMode: false,@@ -2829,6 +2835,7 @@ ${green('|_| \\__,_|_|\\_\\___| can turn any webpage into a desktop app with.option('--use-local-file', 'Use local file packaging', DEFAULT_PAKE_OPTIONS.useLocalFile).option('--fullscreen', 'Start in full screen', DEFAULT_PAKE_OPTIONS.fullscreen).option('--hide-title-bar', 'For Mac, hide title bar', DEFAULT_PAKE_OPTIONS.hideTitleBar)+ .option('--hide-window-decorations', 'Hide native window decorations on Windows and Linux', DEFAULT_PAKE_OPTIONS.hideWindowDecorations).option('--multi-arch', 'For Mac, both Intel and M1', DEFAULT_PAKE_OPTIONS.multiArch).option('--inject <files>', 'Inject local CSS/JS files into the page', (val, previous) => {if (!val)diff --git a/docs/advanced-usage.md b/docs/advanced-usage.mdindex d2c9d186..a446bde0 100644--- a/docs/advanced-usage.md+++ b/docs/advanced-usage.md@@ -116,7 +116,7 @@ Configure window properties in `pake.json`:}```-`hide_title_bar` is the `pake.json` key (the CLI exposes it as `--hide-title-bar`). It is only supported on macOS and is ignored on Windows and Linux.+`hide_title_bar` is the `pake.json` key (the CLI exposes it as `--hide-title-bar`). It is only supported on macOS and is ignored on Windows and Linux. Use `hide_window_decorations` (`--hide-window-decorations`) for frameless windows on Windows and Linux.## Static File Packagingdiff --git a/docs/advanced-usage_CN.md b/docs/advanced-usage_CN.mdindex 2b01bfc6..15bc1c3e 100644--- a/docs/advanced-usage_CN.md+++ b/docs/advanced-usage_CN.md@@ -116,7 +116,7 @@ fn handle_scroll(scroll_y: f64, scroll_x: f64) {}```-`hide_title_bar` 是 `pake.json` 中的字段名(CLI 对应参数为 `--hide-title-bar`)。仅支持 macOS,在 Windows 和 Linux 上会被忽略。+`hide_title_bar` 是 `pake.json` 中的字段名(CLI 对应参数为 `--hide-title-bar`)。仅支持 macOS,在 Windows 和 Linux 上会被忽略。Windows 和 Linux 请使用 `hide_window_decorations`(`--hide-window-decorations`)。## 静态文件打包diff --git a/docs/cli-usage.md b/docs/cli-usage.mdindex 210cdb96..d785262c 100644--- a/docs/cli-usage.md+++ b/docs/cli-usage.md@@ -72,16 +72,17 @@ The URL is the link to the web page you want to package or the path to a local HVarious options are available for customization. `pake --help` shows every supported CLI option. This page is the complete reference.-| Option | Description | Example |-| ------------------ | ----------------------------------------------- | ---------------------------------------------- |-| `--name` | Application name | `--name "Weekly"` |-| `--icon` | Custom icon (optional, auto-fetch website icon) | `--icon https://cdn.tw93.fun/pake/weekly.icns` |-| `--width` | Window width (default: 1200px) | `--width 1400` |-| `--height` | Window height (default: 780px) | `--height 900` |-| `--hide-title-bar` | Immersive header (macOS only) | `--hide-title-bar` |-| `--debug` | Enable development tools | `--debug` |-| `--help` | Show all CLI options | `--help` |-| `--version` | Show CLI version | `--version` |+| Option | Description | Example |+| --------------------------- | --------------------------------------------------- | ---------------------------------------------- |+| `--name` | Application name | `--name "Weekly"` |+| `--icon` | Custom icon (optional, auto-fetch website icon) | `--icon https://cdn.tw93.fun/pake/weekly.icns` |+| `--width` | Window width (default: 1200px) | `--width 1400` |+| `--height` | Window height (default: 780px) | `--height 900` |+| `--hide-title-bar` | Immersive header (macOS only) | `--hide-title-bar` |+| `--hide-window-decorations` | Hide native window decorations (Windows/Linux only) | `--hide-window-decorations` |+| `--debug` | Enable development tools | `--debug` |+| `--help` | Show all CLI options | `--help` |+| `--version` | Show CLI version | `--version` |For complete options, see detailed sections below.@@ -174,6 +175,14 @@ Enable or disable immersive header. Default is `false`. Use the following comman--hide-title-bar```+#### [hide-window-decorations]++Hide the native window decorations on Windows and Linux. Default is `false`. This removes the title bar and window controls, then adds a top drag region for moving the window. Use `F11` to toggle native fullscreen. Ignored on macOS.++```shell+--hide-window-decorations+```+#### [fullscreen]Determine whether the application launches in full screen. Default is `false`. Use the following command to enable fulldiff --git a/docs/cli-usage_CN.md b/docs/cli-usage_CN.mdindex c18a343c..e07128d3 100644--- a/docs/cli-usage_CN.md+++ b/docs/cli-usage_CN.md@@ -72,16 +72,17 @@ pake [url] [options]您可以通过传递以下选项来定制打包过程。`pake --help` 展示全部支持的 CLI 选项。本文档是完整参考。-| 选项 | 描述 | 示例 |-| ------------------ | ------------------------------------ | ---------------------------------------------- |-| `--name` | 应用程序名称 | `--name "Weekly"` |-| `--icon` | 自定义图标(可选,自动获取网站图标) | `--icon https://cdn.tw93.fun/pake/weekly.icns` |-| `--width` | 窗口宽度(默认:1200px) | `--width 1400` |-| `--height` | 窗口高度(默认:780px) | `--height 900` |-| `--hide-title-bar` | 沉浸式标题栏(仅macOS) | `--hide-title-bar` |-| `--debug` | 启用开发者工具 | `--debug` |-| `--help` | 显示全部 CLI 选项 | `--help` |-| `--version` | 显示 CLI 版本 | `--version` |+| 选项 | 描述 | 示例 |+| --------------------------- | ------------------------------------ | ---------------------------------------------- |+| `--name` | 应用程序名称 | `--name "Weekly"` |+| `--icon` | 自定义图标(可选,自动获取网站图标) | `--icon https://cdn.tw93.fun/pake/weekly.icns` |+| `--width` | 窗口宽度(默认:1200px) | `--width 1400` |+| `--height` | 窗口高度(默认:780px) | `--height 900` |+| `--hide-title-bar` | 沉浸式标题栏(仅 macOS) | `--hide-title-bar` |+| `--hide-window-decorations` | 隐藏原生窗口装饰(仅 Windows/Linux) | `--hide-window-decorations` |+| `--debug` | 启用开发者工具 | `--debug` |+| `--help` | 显示全部 CLI 选项 | `--help` |+| `--version` | 显示 CLI 版本 | `--version` |完整选项请参见下面的详细说明:@@ -174,6 +175,14 @@ pake https://github.com --name GitHub--hide-title-bar```+#### [hide-window-decorations]++在 Windows 和 Linux 上隐藏原生窗口装饰,默认为 `false`。该选项会移除标题栏和窗口控制按钮,并在顶部提供拖拽区域以移动窗口。可使用 `F11` 切换原生全屏。在 macOS 上会被忽略。++```shell+--hide-window-decorations+```+#### [fullscreen]设置应用程序是否在启动时自动全屏,默认为 `false`。使用以下命令可以设置应用程序启动时自动全屏。diff --git a/src-tauri/pake.json b/src-tauri/pake.jsonindex c797c644..75a4e3c9 100644--- a/src-tauri/pake.json+++ b/src-tauri/pake.json@@ -4,6 +4,7 @@"url": "https://weekly.tw93.fun/en","url_type": "web","hide_title_bar": true,+ "hide_window_decorations": false,"fullscreen": false,"width": 1200,"height": 780,diff --git a/src-tauri/src/app/config.rs b/src-tauri/src/app/config.rsindex 67f63b08..5724f5e6 100644--- a/src-tauri/src/app/config.rs+++ b/src-tauri/src/app/config.rs@@ -4,6 +4,8 @@ use serde::{Deserialize, Serialize};pub struct WindowConfig {pub url: String,pub hide_title_bar: bool,+ #[serde(default)]+ pub hide_window_decorations: bool,pub fullscreen: bool,pub maximize: bool,pub width: f64,diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rsindex eacc6b81..cef79957 100644--- a/src-tauri/src/app/window.rs+++ b/src-tauri/src/app/window.rs@@ -380,6 +380,10 @@ fn build_window({window_builder = window_builder.data_directory(_data_dir).theme(theme);+ if window_config.hide_window_decorations {+ window_builder = window_builder.decorations(false);+ }+if !config.proxy_url.is_empty() {if let Ok(proxy_url) = Url::from_str(&config.proxy_url) {parsed_proxy_url = Some(proxy_url.clone());diff --git a/src-tauri/src/inject/event.js b/src-tauri/src/inject/event.jsindex e9510e92..20ee801d 100644--- a/src-tauri/src/inject/event.js+++ b/src-tauri/src/inject/event.js@@ -60,8 +60,51 @@ function handleShortcut(event) {}}+function toggleNativeFullscreen(appWindow) {+ appWindow+ .isFullscreen()+ .then((fullscreen) => appWindow.setFullscreen(!fullscreen))+ .catch((error) => {+ console.warn("[Pake] Failed to toggle native fullscreen:", error);+ });+}++function handleWindowFullscreenShortcut(event) {+ if (+ !event.isTrusted ||+ event.repeat ||+ event.key !== "F11" ||+ !isNonMacDesktop()+ ) {+ return;+ }++ const appWindow = window.__TAURI__?.window?.getCurrentWindow?.();+ if (!appWindow) {+ return;+ }++ event.preventDefault();+ event.stopImmediatePropagation();+ toggleNativeFullscreen(appWindow);+}++function getDesktopPlatform() {+ return (+ navigator.userAgentData?.platform ||+ navigator.platform ||+ navigator.userAgent+ );+}+function isNonMacDesktop() {- return /windows|linux/i.test(navigator.userAgent);+ return /win|linux/i.test(getDesktopPlatform());+}++function hasImmersiveHeader(config = window["pakeConfig"] || {}) {+ return /mac/i.test(getDesktopPlatform())+ ? config.hide_title_bar === true+ : config.hide_window_decorations === true;}function isEditableElement(element) {@@ -509,7 +552,7 @@ document.addEventListener("DOMContentLoaded", () => {}}- if (!document.getElementById("pake-top-dom")) {+ if (!document.getElementById("pake-top-dom") && hasImmersiveHeader()) {const topDom = document.createElement("div");topDom.id = "pake-top-dom";document.body.appendChild(topDom);@@ -517,24 +560,25 @@ document.addEventListener("DOMContentLoaded", () => {const domEl = document.getElementById("pake-top-dom");- domEl.addEventListener("touchstart", () => {- appWindow.startDragging();- });-- domEl.addEventListener("mousedown", (e) => {- e.preventDefault();- if (e.buttons === 1 && e.detail !== 2) {+ if (domEl) {+ domEl.addEventListener("touchstart", () => {appWindow.startDragging();- }- });+ });- domEl.addEventListener("dblclick", () => {- appWindow.isFullscreen().then((fullscreen) => {- appWindow.setFullscreen(!fullscreen);+ domEl.addEventListener("mousedown", (e) => {+ e.preventDefault();+ if (e.buttons === 1 && e.detail !== 2) {+ appWindow.startDragging();+ }});- });++ domEl.addEventListener("dblclick", () => {+ toggleNativeFullscreen(appWindow);+ });+ }if (window["pakeConfig"]?.disabled_web_shortcuts !== true) {+ document.addEventListener("keydown", handleWindowFullscreenShortcut, true);document.addEventListener("keyup", (event) => {if (/windows|linux/i.test(navigator.userAgent) && event.ctrlKey) {handleShortcut(event);diff --git a/src-tauri/src/inject/style.js b/src-tauri/src/inject/style.jsindex 2f7a51ab..6df8adf1 100644--- a/src-tauri/src/inject/style.js+++ b/src-tauri/src/inject/style.js@@ -497,9 +497,29 @@ window.addEventListener("DOMContentLoaded", (_event) => {}`;const isMac = /Mac/i.test(navigator.userAgent);- if (window["pakeConfig"]?.hide_title_bar && isMac) {+ if (hasImmersiveHeader(window["pakeConfig"])) {const topPaddingStyleElement = document.createElement("style");- topPaddingStyleElement.textContent = topPaddingCSS;+ topPaddingStyleElement.textContent = isMac+ ? topPaddingCSS+ : `+ #pake-top-dom:active {+ cursor: grabbing;+ cursor: -webkit-grabbing;+ }++ #pake-top-dom {+ position: fixed;+ background: transparent;+ top: 0;+ width: 100%;+ height: 20px;+ cursor: grab;+ -webkit-app-region: drag;+ user-select: none;+ -webkit-user-select: none;+ z-index: 99999;+ }+ `;document.head.appendChild(topPaddingStyleElement);}});diff --git a/tests/unit/__snapshots__/merge-window-options.test.ts.snap b/tests/unit/__snapshots__/merge-window-options.test.ts.snapindex 42b11440..0d65e2b7 100644--- a/tests/unit/__snapshots__/merge-window-options.test.ts.snap+++ b/tests/unit/__snapshots__/merge-window-options.test.ts.snap@@ -14,6 +14,7 @@ exports[`buildWindowConfigOverrides > matches the default snapshot on Linux 1`]"height": 780,"hide_on_close": false,"hide_title_bar": false,+ "hide_window_decorations": false,"ignore_certificate_errors": false,"incognito": false,"internal_url_regex": "",@@ -43,6 +44,7 @@ exports[`buildWindowConfigOverrides > matches the default snapshot on Windows 1`"height": 780,"hide_on_close": false,"hide_title_bar": false,+ "hide_window_decorations": false,"ignore_certificate_errors": false,"incognito": false,"internal_url_regex": "",@@ -72,6 +74,7 @@ exports[`buildWindowConfigOverrides > matches the default snapshot on macOS 1`]"height": 780,"hide_on_close": true,"hide_title_bar": false,+ "hide_window_decorations": false,"ignore_certificate_errors": false,"incognito": false,"internal_url_regex": "",diff --git a/tests/unit/event-fullscreen-shortcuts.test.js b/tests/unit/event-fullscreen-shortcuts.test.jsnew file mode 100644index 00000000..64ee551f--- /dev/null+++ b/tests/unit/event-fullscreen-shortcuts.test.js@@ -0,0 +1,299 @@+import fs from "fs";+import path from "path";+import { runInNewContext } from "node:vm";+import { describe, expect, it, vi } from "vitest";++function createElement(tagName = "div") {+ return {+ tagName: tagName.toUpperCase(),+ style: {},+ children: [],+ isContentEditable: false,+ addEventListener: () => {},+ appendChild(child) {+ this.children.push(child);+ return child;+ },+ removeChild(child) {+ this.children = this.children.filter((item) => item !== child);+ },+ set id(value) {+ this._id = value;+ },+ get id() {+ return this._id;+ },+ };+}++function loadEventHelpers({+ userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",+ platform = "Win32",+ disabledWebShortcuts = false,+ initialFullscreen = false,+ hideTitleBar = false,+ hideWindowDecorations = false,+} = {}) {+ const source = fs.readFileSync(+ path.join(process.cwd(), "src-tauri/src/inject/event.js"),+ "utf-8",+ );++ const eventListeners = {};+ const elementsById = new Map();+ const fullscreenCalls = [];+ const body = createElement("body");+ body.appendChild = (child) => {+ body.children.push(child);+ if (child.id) elementsById.set(child.id, child);+ return child;+ };++ const registerListener = (type, handler, options) => {+ eventListeners[type] = eventListeners[type] || [];+ eventListeners[type].push({ handler, options });+ };++ let isFullscreen = initialFullscreen;++ const context = {+ console,+ URL,+ Event: class {},+ Notification: function Notification() {},+ setTimeout,+ clearTimeout,+ scrollTo: () => {},+ navigator: {+ userAgent,+ platform,+ language: "en-US",+ clipboard: {+ readText: () => Promise.resolve(""),+ },+ },+ window: {+ history: {+ back: () => {},+ forward: () => {},+ },+ location: {+ href: "https://example.com/app",+ origin: "https://example.com",+ pathname: "/app",+ reload: () => {},+ },+ localStorage: {+ getItem: () => null,+ setItem: () => {},+ },+ addEventListener: registerListener,+ dispatchEvent: () => {},+ getSelection: () => ({+ toString: () => "",+ removeAllRanges: vi.fn(),+ addRange: vi.fn(),+ }),+ open: () => ({}),+ isAuthLink: () => false,+ isAuthPopup: () => false,+ pakeConfig: {+ disabled_web_shortcuts: disabledWebShortcuts,+ hide_title_bar: hideTitleBar,+ hide_window_decorations: hideWindowDecorations,+ },+ __TAURI__: {+ core: {+ invoke: () => Promise.resolve(),+ },+ window: {+ getCurrentWindow: () => ({+ startDragging: () => {},+ isFullscreen: () => Promise.resolve(isFullscreen),+ setFullscreen: (value) => {+ fullscreenCalls.push(value);+ isFullscreen = value;+ return Promise.resolve();+ },+ }),+ },+ },+ },+ document: {+ addEventListener: registerListener,+ createElement: (tagName) => {+ const element = createElement(tagName);+ if (element.id) elementsById.set(element.id, element);+ return element;+ },+ createRange: () => ({+ selectNodeContents: vi.fn(),+ }),+ getElementById: (id) => elementsById.get(id) || null,+ getElementsByTagName: () => [{ style: {} }],+ body,+ activeElement: body,+ execCommand: () => true,+ },+ };+ context.window.navigator = context.navigator;++ runInNewContext(source, context);+ eventListeners.DOMContentLoaded[0].handler();++ return {+ ...context,+ eventListeners,+ fullscreenCalls,+ get isFullscreen() {+ return isFullscreen;+ },+ };+}++function getFullscreenShortcutHandler(context) {+ return context.eventListeners.keydown.find(+ ({ handler }) => handler.name === "handleWindowFullscreenShortcut",+ ).handler;+}++function createKeyEvent(key, overrides = {}) {+ return {+ key,+ ctrlKey: false,+ metaKey: false,+ altKey: false,+ shiftKey: false,+ isTrusted: true,+ repeat: false,+ preventDefault: vi.fn(),+ stopImmediatePropagation: vi.fn(),+ ...overrides,+ };+}++describe("event fullscreen shortcuts", () => {+ it("toggles native fullscreen on F11 for Windows", async () => {+ const context = loadEventHelpers();+ const handler = getFullscreenShortcutHandler(context);+ const event = createKeyEvent("F11");++ handler(event);++ expect(event.preventDefault).toHaveBeenCalled();+ expect(event.stopImmediatePropagation).toHaveBeenCalled();+ await Promise.resolve();+ await Promise.resolve();+ expect(context.fullscreenCalls).toEqual([true]);+ });++ it("exits native fullscreen on F11 when already fullscreen", async () => {+ const context = loadEventHelpers({ initialFullscreen: true });+ const handler = getFullscreenShortcutHandler(context);+ const event = createKeyEvent("F11");++ handler(event);++ await Promise.resolve();+ expect(context.fullscreenCalls).toEqual([false]);+ });++ it("toggles native fullscreen on F11 for Linux", async () => {+ const context = loadEventHelpers({+ userAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36",+ platform: "Linux x86_64",+ });+ const handler = getFullscreenShortcutHandler(context);+ const event = createKeyEvent("F11");++ handler(event);++ expect(event.preventDefault).toHaveBeenCalled();+ await Promise.resolve();+ await Promise.resolve();+ expect(context.fullscreenCalls).toEqual([true]);+ });++ it("does not register fullscreen shortcuts when web shortcuts are disabled", () => {+ const context = loadEventHelpers({ disabledWebShortcuts: true });++ expect(+ context.eventListeners.keydown?.find(+ ({ handler }) => handler.name === "handleWindowFullscreenShortcut",+ ),+ ).toBeUndefined();+ });++ it("does not handle F11 on macOS", async () => {+ const context = loadEventHelpers({+ userAgent:+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15",+ platform: "MacIntel",+ });+ const handler = getFullscreenShortcutHandler(context);+ const event = createKeyEvent("F11");++ handler(event);++ expect(event.preventDefault).not.toHaveBeenCalled();+ await Promise.resolve();+ expect(context.fullscreenCalls).toEqual([]);+ });++ it("does not claim Alt+Enter from hosted web apps", async () => {+ const context = loadEventHelpers();+ const handler = getFullscreenShortcutHandler(context);+ const event = createKeyEvent("Enter", { altKey: true });++ handler(event);++ expect(event.preventDefault).not.toHaveBeenCalled();+ await Promise.resolve();+ expect(context.fullscreenCalls).toEqual([]);+ });++ it("ignores synthetic and repeated F11 events", async () => {+ const context = loadEventHelpers();+ const handler = getFullscreenShortcutHandler(context);++ handler(createKeyEvent("F11", { isTrusted: false }));+ handler(createKeyEvent("F11", { repeat: true }));++ await Promise.resolve();+ expect(context.fullscreenCalls).toEqual([]);+ });++ it("creates the drag region only for the active platform flag", () => {+ const windowsWithMacFlag = loadEventHelpers({ hideTitleBar: true });+ const windowsWithDecorationsFlag = loadEventHelpers({+ userAgent: "CustomBrowser/1.0",+ platform: "Win32",+ hideWindowDecorations: true,+ });+ const macUserAgent =+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15";+ const macWithDecorationsFlag = loadEventHelpers({+ userAgent: macUserAgent,+ platform: "MacIntel",+ hideWindowDecorations: true,+ });+ const macWithTitleBarFlag = loadEventHelpers({+ userAgent: macUserAgent,+ platform: "MacIntel",+ hideTitleBar: true,+ });++ expect(+ windowsWithMacFlag.document.getElementById("pake-top-dom"),+ ).toBeNull();+ expect(+ windowsWithDecorationsFlag.document.getElementById("pake-top-dom"),+ ).not.toBeNull();+ expect(+ macWithDecorationsFlag.document.getElementById("pake-top-dom"),+ ).toBeNull();+ expect(+ macWithTitleBarFlag.document.getElementById("pake-top-dom"),+ ).not.toBeNull();+ });+});diff --git a/tests/unit/merge-window-options.test.ts b/tests/unit/merge-window-options.test.tsindex 6e453a5a..8f094b21 100644--- a/tests/unit/merge-window-options.test.ts+++ b/tests/unit/merge-window-options.test.ts@@ -79,6 +79,27 @@ describe('buildWindowConfigOverrides', () => {).toBe(false);});+ it('only forwards hideWindowDecorations on Windows and Linux', () => {+ expect(+ buildWindowConfigOverrides(+ { ...makeOptions(), hideWindowDecorations: true },+ 'darwin',+ ).hide_window_decorations,+ ).toBe(false);+ expect(+ buildWindowConfigOverrides(+ { ...makeOptions(), hideWindowDecorations: true },+ 'linux',+ ).hide_window_decorations,+ ).toBe(true);+ expect(+ buildWindowConfigOverrides(+ { ...makeOptions(), hideWindowDecorations: true },+ 'win32',+ ).hide_window_decorations,+ ).toBe(true);+ });+it('only enables start_to_tray when both flag and tray are on', () => {expect(buildWindowConfigOverrides(