fix: Android app icon after init and Windows in-app link navigation

This commit is contained in:
2026-05-29 15:28:20 +08:00
parent ef0e406ec8
commit fa083c5ddc
10 changed files with 4724 additions and 45 deletions

4569
template/src-tauri/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -1 +1 @@
{"default":{"identifier":"default","description":"Capability for the main window","local":true,"windows":["main"],"permissions":["core:default","core:window:allow-start-dragging","core:window:allow-show","core:window:allow-hide","core:window:allow-set-focus","core:window:allow-set-size","core:window:allow-close","allow-fetch-tickers","allow-coin-settings","allow-api-settings"]}}
{"default":{"identifier":"default","description":"Default capability for the main window","local":true,"windows":["main"],"permissions":["core:default"]}}

View File

@@ -176,24 +176,6 @@
"Identifier": {
"description": "Permission identifier",
"oneOf": [
{
"description": "Enables API config commands",
"type": "string",
"const": "allow-api-settings",
"markdownDescription": "Enables API config commands"
},
{
"description": "Enables coin list and refresh interval commands",
"type": "string",
"const": "allow-coin-settings",
"markdownDescription": "Enables coin list and refresh interval commands"
},
{
"description": "Enables the fetch_tickers command",
"type": "string",
"const": "allow-fetch-tickers",
"markdownDescription": "Enables the fetch_tickers command"
},
{
"description": "Default core plugins set.\n#### This default permission set includes:\n\n- `core:path:default`\n- `core:event:default`\n- `core:window:default`\n- `core:webview:default`\n- `core:app:default`\n- `core:image:default`\n- `core:resources:default`\n- `core:menu:default`\n- `core:tray:default`",
"type": "string",

View File

@@ -176,24 +176,6 @@
"Identifier": {
"description": "Permission identifier",
"oneOf": [
{
"description": "Enables API config commands",
"type": "string",
"const": "allow-api-settings",
"markdownDescription": "Enables API config commands"
},
{
"description": "Enables coin list and refresh interval commands",
"type": "string",
"const": "allow-coin-settings",
"markdownDescription": "Enables coin list and refresh interval commands"
},
{
"description": "Enables the fetch_tickers command",
"type": "string",
"const": "allow-fetch-tickers",
"markdownDescription": "Enables the fetch_tickers command"
},
{
"description": "Default core plugins set.\n#### This default permission set includes:\n\n- `core:path:default`\n- `core:event:default`\n- `core:window:default`\n- `core:webview:default`\n- `core:app:default`\n- `core:image:default`\n- `core:resources:default`\n- `core:menu:default`\n- `core:tray:default`",
"type": "string",

View File

@@ -1,6 +1,82 @@
use tauri::Manager;
const IN_APP_NAV_SCRIPT: &str = r##"
(function () {
if (window.__web2appNavInstalled) return;
window.__web2appNavInstalled = true;
function shouldHandleLink(anchor) {
if (!anchor || !anchor.href) return false;
const href = anchor.getAttribute("href");
if (!href || href.startsWith("#") || href.startsWith("javascript:")) return false;
try {
const url = new URL(anchor.href, window.location.href);
return url.protocol === "http:" || url.protocol === "https:";
} catch (_) {
return false;
}
}
function navigateInApp(url) {
window.location.assign(url);
}
document.addEventListener(
"click",
function (e) {
const anchor = e.target && e.target.closest ? e.target.closest("a") : null;
if (!shouldHandleLink(anchor)) return;
if (anchor.hasAttribute("download")) return;
if (
anchor.target === "_blank" ||
anchor.target === "_top" ||
location.protocol === "file:" ||
location.protocol === "tauri:" ||
location.hostname === "asset.localhost"
) {
e.preventDefault();
navigateInApp(anchor.href);
return;
}
try {
const target = new URL(anchor.href, window.location.href);
const current = new URL(window.location.href);
if (target.origin !== current.origin) {
e.preventDefault();
navigateInApp(anchor.href);
}
} catch (_) {
/* keep default */
}
},
true,
);
const originalOpen = window.open;
window.open = function (url, target, features) {
if (url && (!target || target === "_blank")) {
navigateInApp(url);
return null;
}
return originalOpen.call(window, url, target, features);
};
})();
"##;
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.setup(|app| {
if let Some(window) = app.get_webview_window("main") {
let _ = window.eval(IN_APP_NAV_SCRIPT);
}
Ok(())
})
.on_page_load(|webview, payload| {
if payload.event() == tauri::webview::PageLoadEvent::Finished {
let _ = webview.eval(IN_APP_NAV_SCRIPT);
}
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}