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.

feat(cli): add --navigation-buttons option for macOS title bar

Tw9349137ba4f07d
diff --git a/bin/defaults.ts b/bin/defaults.ts
index c73d37eb..17b66c8b 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,
+ navigationButtons: false,
hideWindowDecorations: false,
alwaysOnTop: false,
appVersion: '1.0.0',
diff --git a/bin/helpers/cli-program.ts b/bin/helpers/cli-program.ts
index 5fb6687c..ed199da5 100644
--- a/bin/helpers/cli-program.ts
+++ b/bin/helpers/cli-program.ts
@@ -50,6 +50,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(
+ '--navigation-buttons',
+ 'For Mac, show Back and Forward buttons in the title bar',
+ DEFAULT.navigationButtons,
+ )
.option(
'--hide-window-decorations',
'Hide native window decorations on Windows and Linux',
diff --git a/bin/helpers/merge.ts b/bin/helpers/merge.ts
index b7b9dd5c..9df50008 100644
--- a/bin/helpers/merge.ts
+++ b/bin/helpers/merge.ts
@@ -44,6 +44,8 @@ export function buildWindowConfigOverrides(
const platformHideOnClose = options.hideOnClose ?? platform === 'darwin';
const platformHideTitleBar =
platform === 'darwin' ? options.hideTitleBar : false;
+ const platformNavigationButtons =
+ platform === 'darwin' ? Boolean(options.navigationButtons) : false;
const platformHideWindowDecorations =
platform !== 'darwin' ? options.hideWindowDecorations : false;
return {
@@ -53,6 +55,7 @@ export function buildWindowConfigOverrides(
maximize: options.maximize,
resizable: options.resizable ?? true,
hide_title_bar: platformHideTitleBar,
+ navigation_buttons: platformNavigationButtons,
hide_window_decorations: platformHideWindowDecorations,
activation_shortcut: options.activationShortcut,
always_on_top: options.alwaysOnTop,
@@ -623,6 +626,11 @@ export async function mergeConfig(
'✼ --hide-title-bar is only supported on macOS and will be ignored on this platform.',
);
}
+ if (options.navigationButtons && platform !== 'darwin') {
+ logger.warn(
+ '✼ --navigation-buttons 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.',
diff --git a/bin/types.ts b/bin/types.ts
index f95ac86c..2d8bc36f 100644
--- a/bin/types.ts
+++ b/bin/types.ts
@@ -32,6 +32,9 @@ export interface PakeCliOptions {
// Enable immersive header, default false. macOS only.
hideTitleBar: boolean;
+ // Show Back and Forward buttons in the title bar, default false. macOS only.
+ navigationButtons: boolean;
+
// Hide native window decorations, default false. Windows and Linux only.
hideWindowDecorations: boolean;
@@ -185,6 +188,7 @@ export interface PlatformSpecific<T> {
export interface WindowConfig {
url: string;
hide_title_bar: boolean;
+ navigation_buttons: boolean;
hide_window_decorations: boolean;
fullscreen: boolean;
maximize: boolean;
diff --git a/dist/cli.js b/dist/cli.js
index 0c4f5068..256be233 100644
--- a/dist/cli.js
+++ b/dist/cli.js
@@ -1327,6 +1327,7 @@ async function applyDarwinIconComposerPackage(options) {
function buildWindowConfigOverrides(options, platform = asSupportedPlatform(process.platform)) {
const platformHideOnClose = options.hideOnClose ?? platform === 'darwin';
const platformHideTitleBar = platform === 'darwin' ? options.hideTitleBar : false;
+ const platformNavigationButtons = platform === 'darwin' ? Boolean(options.navigationButtons) : false;
const platformHideWindowDecorations = platform !== 'darwin' ? options.hideWindowDecorations : false;
return {
width: options.width,
@@ -1335,6 +1336,7 @@ function buildWindowConfigOverrides(options, platform = asSupportedPlatform(proc
maximize: options.maximize,
resizable: options.resizable ?? true,
hide_title_bar: platformHideTitleBar,
+ navigation_buttons: platformNavigationButtons,
hide_window_decorations: platformHideWindowDecorations,
activation_shortcut: options.activationShortcut,
always_on_top: options.alwaysOnTop,
@@ -1733,6 +1735,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.navigationButtons && platform !== 'darwin') {
+ logger.warn('✼ --navigation-buttons 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.');
}
@@ -3924,6 +3929,7 @@ const DEFAULT_PAKE_OPTIONS = {
maximize: false,
resizable: true,
hideTitleBar: false,
+ navigationButtons: false,
hideWindowDecorations: false,
alwaysOnTop: false,
appVersion: '1.0.0',
@@ -4002,6 +4008,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('--navigation-buttons', 'For Mac, show Back and Forward buttons in the title bar', DEFAULT_PAKE_OPTIONS.navigationButtons)
.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) => {
diff --git a/docs/cli-usage.md b/docs/cli-usage.md
index 77187457..1e6a0e3d 100644
--- a/docs/cli-usage.md
+++ b/docs/cli-usage.md
@@ -90,6 +90,7 @@ The table lists the common options, `pake --help` shows every option, and each o
| `--width` | Window width (default: 1200px) | `--width 1400` |
| `--height` | Window height (default: 780px) | `--height 900` |
| `--hide-title-bar` | Immersive header (macOS only) | `--hide-title-bar` |
+| `--navigation-buttons` | Show Back and Forward buttons in title bar (macOS) | `--navigation-buttons` |
| `--hide-window-decorations` | Hide native window decorations (Windows/Linux only) | `--hide-window-decorations` |
| `--debug` | Enable development tools | `--debug` |
| `--config` | Load options from a JSON config file | `--config app.json` |
diff --git a/docs/cli-usage_CN.md b/docs/cli-usage_CN.md
index 820e7a85..29de3974 100644
--- a/docs/cli-usage_CN.md
+++ b/docs/cli-usage_CN.md
@@ -90,6 +90,7 @@ pake ./dist --name MyTool
| `--width` | 窗口宽度(默认:1200px) | `--width 1400` |
| `--height` | 窗口高度(默认:780px) | `--height 900` |
| `--hide-title-bar` | 隐藏标题栏(仅 macOS) | `--hide-title-bar` |
+| `--navigation-buttons` | 在标题栏显示前进/后退按钮(仅 macOS) | `--navigation-buttons` |
| `--hide-window-decorations` | 隐藏原生窗口装饰(仅 Windows/Linux) | `--hide-window-decorations` |
| `--debug` | 启用开发者工具 | `--debug` |
| `--config` | 从 JSON 配置文件读取选项 | `--config app.json` |
diff --git a/schema/pake.schema.json b/schema/pake.schema.json
index 31284233..97d29f7e 100644
--- a/schema/pake.schema.json
+++ b/schema/pake.schema.json
@@ -58,6 +58,11 @@
"description": "macOS only: hide title bar (immersive header).",
"default": false
},
+ "navigationButtons": {
+ "type": "boolean",
+ "description": "macOS only: show Back and Forward buttons in the title bar.",
+ "default": false
+ },
"hideWindowDecorations": {
"type": "boolean",
"description": "Windows/Linux only: hide native window decorations.",
diff --git a/tests/unit/__snapshots__/merge-window-options.test.ts.snap b/tests/unit/__snapshots__/merge-window-options.test.ts.snap
index 879b598c..ee7c3695 100644
--- a/tests/unit/__snapshots__/merge-window-options.test.ts.snap
+++ b/tests/unit/__snapshots__/merge-window-options.test.ts.snap
@@ -20,6 +20,7 @@ exports[`buildWindowConfigOverrides > matches the default snapshot on Linux 1`]
"maximize": false,
"min_height": 0,
"min_width": 0,
+ "navigation_buttons": false,
"new_window": false,
"password_autosave": false,
"resizable": true,
@@ -51,6 +52,7 @@ exports[`buildWindowConfigOverrides > matches the default snapshot on Windows 1`
"maximize": false,
"min_height": 0,
"min_width": 0,
+ "navigation_buttons": false,
"new_window": false,
"password_autosave": false,
"resizable": true,
@@ -82,6 +84,7 @@ exports[`buildWindowConfigOverrides > matches the default snapshot on macOS 1`]
"maximize": false,
"min_height": 0,
"min_width": 0,
+ "navigation_buttons": false,
"new_window": false,
"password_autosave": false,
"resizable": true,
diff --git a/tests/unit/merge-window-options.test.ts b/tests/unit/merge-window-options.test.ts
index c7331b23..e3200446 100644
--- a/tests/unit/merge-window-options.test.ts
+++ b/tests/unit/merge-window-options.test.ts
@@ -101,6 +101,27 @@ describe('buildWindowConfigOverrides', () => {
).toBe(false);
});
+ it('only forwards navigationButtons on macOS', () => {
+ expect(
+ buildWindowConfigOverrides(
+ { ...makeOptions(), navigationButtons: true },
+ 'darwin',
+ ).navigation_buttons,
+ ).toBe(true);
+ expect(
+ buildWindowConfigOverrides(
+ { ...makeOptions(), navigationButtons: true },
+ 'linux',
+ ).navigation_buttons,
+ ).toBe(false);
+ expect(
+ buildWindowConfigOverrides(
+ { ...makeOptions(), navigationButtons: true },
+ 'win32',
+ ).navigation_buttons,
+ ).toBe(false);
+ });
+
it('only forwards hideWindowDecorations on Windows and Linux', () => {
expect(
buildWindowConfigOverrides(