Support force internal navigation parameter
This commit is contained in:
3
src-tauri/pake.json
vendored
3
src-tauri/pake.json
vendored
@@ -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": {
|
||||
|
||||
@@ -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)]
|
||||
|
||||
24
src-tauri/src/inject/event.js
vendored
24
src-tauri/src/inject/event.js
vendored
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user