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
Support force internal navigation parameter
Tw93eb829ca85cb2
diff --git a/bin/cli.ts b/bin/cli.tsindex 2a746255..78bc8570 100644--- a/bin/cli.ts+++ b/bin/cli.ts@@ -174,6 +174,14 @@ program.default(DEFAULT.startToTray).hideHelp(),)+ .addOption(+ new Option(+ '--force-internal-navigation',+ 'Keep every link inside the Pake window instead of opening external handlers',+ )+ .default(DEFAULT.forceInternalNavigation)+ .hideHelp(),+ ).addOption(new Option('--installer-language <string>', 'Installer language').default(DEFAULT.installerLanguage)diff --git a/bin/defaults.ts b/bin/defaults.tsindex a78501b9..fed0e1c6 100644--- a/bin/defaults.ts+++ b/bin/defaults.ts@@ -30,6 +30,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {keepBinary: false,multiInstance: false,startToTray: false,+ forceInternalNavigation: false,};// Just for cli developmentdiff --git a/bin/helpers/merge.ts b/bin/helpers/merge.tsindex 311fd922..dbb36300 100644--- a/bin/helpers/merge.ts+++ b/bin/helpers/merge.ts@@ -73,6 +73,7 @@ export async function mergeConfig(enableDragDrop,multiInstance,startToTray,+ forceInternalNavigation,} = options;const { platform } = process;@@ -96,6 +97,7 @@ export async function mergeConfig(enable_wasm: wasm,enable_drag_drop: enableDragDrop,start_to_tray: startToTray && showSystemTray,+ force_internal_navigation: forceInternalNavigation,};Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions });diff --git a/bin/types.ts b/bin/types.tsindex 45592077..3a521a21 100644--- a/bin/types.ts+++ b/bin/types.ts@@ -96,6 +96,9 @@ export interface PakeCliOptions {// Start app minimized to tray, default falsestartToTray: boolean;++ // Force navigation to stay inside the Pake window even for external links+ forceInternalNavigation: boolean;}export interface PakeAppOptions extends PakeCliOptions {diff --git a/docs/cli-usage.md b/docs/cli-usage.mdindex c003a8cd..8755c6ca 100644--- a/docs/cli-usage.md+++ b/docs/cli-usage.md@@ -204,6 +204,14 @@ Sets whether to disable web shortcuts in the original Pake container, defaults t--disabled-web-shortcuts```+#### [force-internal-navigation]++Keeps every clicked link (even pointing to other domains) inside the Pake window instead of letting the OS open an external browser or helper. Default is `false`.++```shell+--force-internal-navigation+```+#### [multi-arch]Package the application to support both Intel and M1 chips, exclusively for macOS. Default is `false`.diff --git a/docs/cli-usage_CN.md b/docs/cli-usage_CN.mdindex 6ac2d6b2..6090d72f 100644--- a/docs/cli-usage_CN.md+++ b/docs/cli-usage_CN.md@@ -202,6 +202,14 @@ pake https://github.com --name GitHub--disabled-web-shortcuts```+#### [force-internal-navigation]++启用后所有点击的链接(即使是跨域)都会在 Pake 窗口内打开,不会再调用外部浏览器或辅助程序。默认 `false`。++```shell+--force-internal-navigation+```+#### [multi-arch]设置打包结果同时支持 Intel 和 M1 芯片,仅适用于 macOS,默认为 `false`。diff --git a/src-tauri/pake.json b/src-tauri/pake.jsonindex 97ad31a4..60f9b590 100644--- a/src-tauri/pake.json+++ b/src-tauri/pake.json@@ -17,7 +17,8 @@"enable_wasm": false,"enable_drag_drop": false,"maximize": false,- "start_to_tray": false+ "start_to_tray": false,+ "force_internal_navigation": false}],"user_agent": {diff --git a/src-tauri/src/app/config.rs b/src-tauri/src/app/config.rsindex 9246b7b6..2544fb52 100644--- a/src-tauri/src/app/config.rs+++ b/src-tauri/src/app/config.rs@@ -20,6 +20,8 @@ pub struct WindowConfig {pub enable_wasm: bool,pub enable_drag_drop: bool,pub start_to_tray: bool,+ #[serde(default)]+ pub force_internal_navigation: bool,}#[derive(Debug, Serialize, Deserialize)]diff --git a/src-tauri/src/inject/event.js b/src-tauri/src/inject/event.jsindex bfe6dead..54ed16d5 100644--- a/src-tauri/src/inject/event.js+++ b/src-tauri/src/inject/event.js@@ -192,6 +192,8 @@ document.addEventListener("DOMContentLoaded", () => {const tauri = window.__TAURI__;const appWindow = tauri.window.getCurrentWindow();const invoke = tauri.core.invoke;+ const pakeConfig = window["pakeConfig"] || {};+ const forceInternalNavigation = pakeConfig.force_internal_navigation === true;if (!document.getElementById("pake-top-dom")) {const topDom = document.createElement("div");@@ -394,9 +396,15 @@ document.addEventListener("DOMContentLoaded", () => {// Handle _blank links: same domain navigates in-app, cross-domain opens new windowif (target === "_blank") {+ if (forceInternalNavigation) {+ e.preventDefault();+ e.stopImmediatePropagation();+ window.location.href = absoluteUrl;+ return;+ }+if (isSameDomain(absoluteUrl)) {- // For same-domain links, let the browser/SPA handle it naturally- // This prevents full page reload in SPA apps like Discord+ // For same-domain links, let the browser handle it naturallyreturn;}@@ -413,6 +421,10 @@ document.addEventListener("DOMContentLoaded", () => {}if (target === "_new") {+ if (forceInternalNavigation) {+ return;+ }+e.preventDefault();handleExternalLink(absoluteUrl);return;@@ -435,6 +447,10 @@ document.addEventListener("DOMContentLoaded", () => {// Handle regular links: same domain allows normal navigation, cross-domain opens new windowif (!target || target === "_self") {if (!isSameDomain(absoluteUrl)) {+ if (forceInternalNavigation) {+ return;+ }+e.preventDefault();e.stopImmediatePropagation();const newWindow = originalWindowOpen.call(@@ -468,6 +484,10 @@ document.addEventListener("DOMContentLoaded", () => {const absoluteUrl = hrefUrl.href;if (!isSameDomain(absoluteUrl)) {+ if (forceInternalNavigation) {+ return originalWindowOpen.call(window, absoluteUrl, name, specs);+ }+handleExternalLink(absoluteUrl);return null;}