Support force internal navigation parameter

This commit is contained in:
Tw93
2025-11-11 15:40:10 +08:00
parent aa65c7cd19
commit eb829ca85c
9 changed files with 56 additions and 3 deletions

8
bin/cli.ts vendored
View File

@@ -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)

1
bin/defaults.ts vendored
View File

@@ -30,6 +30,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {
keepBinary: false,
multiInstance: false,
startToTray: false,
forceInternalNavigation: false,
};
// Just for cli development

View File

@@ -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 });

3
bin/types.ts vendored
View File

@@ -96,6 +96,9 @@ export interface PakeCliOptions {
// Start app minimized to tray, default false
startToTray: boolean;
// Force navigation to stay inside the Pake window even for external links
forceInternalNavigation: boolean;
}
export interface PakeAppOptions extends PakeCliOptions {

8
docs/cli-usage.md vendored
View File

@@ -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`.

View File

@@ -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`

3
src-tauri/pake.json vendored
View File

@@ -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": {

View File

@@ -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)]

View File

@@ -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 window
if (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 naturally
return;
}
@@ -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 window
if (!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;
}