This commit is contained in:
Tw93
2025-11-11 16:04:43 +08:00
12 changed files with 111 additions and 18 deletions

9
bin/cli.ts vendored
View File

@@ -174,6 +174,14 @@ program
.default(DEFAULT.startToTray) .default(DEFAULT.startToTray)
.hideHelp(), .hideHelp(),
) )
.addOption(
new Option(
'--force-internal-navigation',
'Keep every link inside the Pake window instead of opening external handlers',
)
.default(DEFAULT.forceInternalNavigation)
.hideHelp(),
)
.addOption( .addOption(
new Option('--installer-language <string>', 'Installer language') new Option('--installer-language <string>', 'Installer language')
.default(DEFAULT.installerLanguage) .default(DEFAULT.installerLanguage)
@@ -204,6 +212,7 @@ program
} }
log.setDefaultLevel('info'); log.setDefaultLevel('info');
log.setLevel('info');
if (options.debug) { if (options.debug) {
log.setLevel('debug'); log.setLevel('debug');
} }

1
bin/defaults.ts vendored
View File

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

View File

@@ -73,6 +73,7 @@ export async function mergeConfig(
enableDragDrop, enableDragDrop,
multiInstance, multiInstance,
startToTray, startToTray,
forceInternalNavigation,
} = options; } = options;
const { platform } = process; const { platform } = process;
@@ -96,6 +97,7 @@ export async function mergeConfig(
enable_wasm: wasm, enable_wasm: wasm,
enable_drag_drop: enableDragDrop, enable_drag_drop: enableDragDrop,
start_to_tray: startToTray && showSystemTray, start_to_tray: startToTray && showSystemTray,
force_internal_navigation: forceInternalNavigation,
}; };
Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions }); 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 // Start app minimized to tray, default false
startToTray: boolean; startToTray: boolean;
// Force navigation to stay inside the Pake window even for external links
forceInternalNavigation: boolean;
} }
export interface PakeAppOptions extends PakeCliOptions { export interface PakeAppOptions extends PakeCliOptions {

10
dist/cli.js vendored
View File

@@ -23,7 +23,7 @@ import sharp from 'sharp';
import * as psl from 'psl'; import * as psl from 'psl';
var name = "pake-cli"; var name = "pake-cli";
var version = "3.4.3"; var version = "3.5.1";
var description = "🤱🏻 Turn any webpage into a desktop app with one command. 🤱🏻 一键打包网页生成轻量桌面应用。"; var description = "🤱🏻 Turn any webpage into a desktop app with one command. 🤱🏻 一键打包网页生成轻量桌面应用。";
var engines = { var engines = {
node: ">=18.0.0" node: ">=18.0.0"
@@ -470,7 +470,7 @@ async function mergeConfig(url, options, tauriConf) {
await fsExtra.copy(sourcePath, destPath); await fsExtra.copy(sourcePath, destPath);
} }
})); }));
const { width, height, fullscreen, maximize, hideTitleBar, alwaysOnTop, appVersion, darkMode, disabledWebShortcuts, activationShortcut, userAgent, showSystemTray, systemTrayIcon, useLocalFile, identifier, name, resizable = true, inject, proxyUrl, installerLanguage, hideOnClose, incognito, title, wasm, enableDragDrop, multiInstance, startToTray, } = options; const { width, height, fullscreen, maximize, hideTitleBar, alwaysOnTop, appVersion, darkMode, disabledWebShortcuts, activationShortcut, userAgent, showSystemTray, systemTrayIcon, useLocalFile, identifier, name, resizable = true, inject, proxyUrl, installerLanguage, hideOnClose, incognito, title, wasm, enableDragDrop, multiInstance, startToTray, forceInternalNavigation, } = options;
const { platform } = process; const { platform } = process;
const platformHideOnClose = hideOnClose ?? platform === 'darwin'; const platformHideOnClose = hideOnClose ?? platform === 'darwin';
const tauriConfWindowOptions = { const tauriConfWindowOptions = {
@@ -490,6 +490,7 @@ async function mergeConfig(url, options, tauriConf) {
enable_wasm: wasm, enable_wasm: wasm,
enable_drag_drop: enableDragDrop, enable_drag_drop: enableDragDrop,
start_to_tray: startToTray && showSystemTray, start_to_tray: startToTray && showSystemTray,
force_internal_navigation: forceInternalNavigation,
}; };
Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions }); Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions });
tauriConf.productName = name; tauriConf.productName = name;
@@ -1331,6 +1332,7 @@ const DEFAULT_PAKE_OPTIONS = {
keepBinary: false, keepBinary: false,
multiInstance: false, multiInstance: false,
startToTray: false, startToTray: false,
forceInternalNavigation: false,
}; };
async function checkUpdateTips() { async function checkUpdateTips() {
@@ -1862,6 +1864,9 @@ program
.addOption(new Option('--start-to-tray', 'Start app minimized to tray') .addOption(new Option('--start-to-tray', 'Start app minimized to tray')
.default(DEFAULT_PAKE_OPTIONS.startToTray) .default(DEFAULT_PAKE_OPTIONS.startToTray)
.hideHelp()) .hideHelp())
.addOption(new Option('--force-internal-navigation', 'Keep every link inside the Pake window instead of opening external handlers')
.default(DEFAULT_PAKE_OPTIONS.forceInternalNavigation)
.hideHelp())
.addOption(new Option('--installer-language <string>', 'Installer language') .addOption(new Option('--installer-language <string>', 'Installer language')
.default(DEFAULT_PAKE_OPTIONS.installerLanguage) .default(DEFAULT_PAKE_OPTIONS.installerLanguage)
.hideHelp()) .hideHelp())
@@ -1888,6 +1893,7 @@ program
return; return;
} }
log.setDefaultLevel('info'); log.setDefaultLevel('info');
log.setLevel('info');
if (options.debug) { if (options.debug) {
log.setLevel('debug'); log.setLevel('debug');
} }

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 --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] #### [multi-arch]
Package the application to support both Intel and M1 chips, exclusively for macOS. Default is `false`. 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 --disabled-web-shortcuts
``` ```
#### [force-internal-navigation]
启用后所有点击的链接(即使是跨域)都会在 Pake 窗口内打开,不会再调用外部浏览器或辅助程序。默认 `false`
```shell
--force-internal-navigation
```
#### [multi-arch] #### [multi-arch]
设置打包结果同时支持 Intel 和 M1 芯片,仅适用于 macOS默认为 `false` 设置打包结果同时支持 Intel 和 M1 芯片,仅适用于 macOS默认为 `false`

2
package.json vendored
View File

@@ -1,6 +1,6 @@
{ {
"name": "pake-cli", "name": "pake-cli",
"version": "3.4.3", "version": "3.5.1",
"description": "🤱🏻 Turn any webpage into a desktop app with one command. 🤱🏻 一键打包网页生成轻量桌面应用。", "description": "🤱🏻 Turn any webpage into a desktop app with one command. 🤱🏻 一键打包网页生成轻量桌面应用。",
"engines": { "engines": {
"node": ">=18.0.0" "node": ">=18.0.0"

View File

@@ -6,6 +6,7 @@ import linuxJson from "../src-tauri/tauri.linux.conf.json" with { type: "json" }
import { writeFileSync, existsSync, copyFileSync } from "fs"; import { writeFileSync, existsSync, copyFileSync } from "fs";
import os from "os"; import os from "os";
import sharp from "sharp";
/** /**
* Configuration script for Tauri app generation * Configuration script for Tauri app generation
@@ -121,20 +122,40 @@ function updateBaseConfigs() {
} }
} }
function ensureIconExists(iconPath, defaultPath, description = "icon") { async function ensureRgbaPng(iconPath) {
try {
const buffer = await sharp(iconPath)
.ensureAlpha()
.png({ force: true })
.toBuffer();
writeFileSync(iconPath, buffer);
} catch (error) {
console.warn(`Failed to normalize ${iconPath} to RGBA: ${error.message}`);
}
}
async function ensureIconExists(
iconPath,
defaultPath,
description = "icon",
ensureRgba = false,
) {
if (!existsSync(iconPath)) { if (!existsSync(iconPath)) {
// For official release apps, icons should already exist
if (process.env.PAKE_CREATE_APP === "1") { if (process.env.PAKE_CREATE_APP === "1") {
console.warn( console.warn(
`${description} for ${process.env.NAME} not found at ${iconPath}`, `${description} for ${process.env.NAME} not found at ${iconPath}`,
); );
return; // Don't auto-generate for release builds return;
} }
console.warn( console.warn(
`${description} for ${process.env.NAME} not found, using default`, `${description} for ${process.env.NAME} not found, using default`,
); );
copyFileSync(defaultPath, iconPath); copyFileSync(defaultPath, iconPath);
} }
if (ensureRgba && existsSync(iconPath)) {
await ensureRgbaPng(iconPath);
}
} }
function updatePlatformConfig(platformConfig, platformVars) { function updatePlatformConfig(platformConfig, platformVars) {
@@ -150,8 +171,13 @@ function updatePlatformConfig(platformConfig, platformVars) {
// Platform-specific handlers // Platform-specific handlers
const platformHandlers = { const platformHandlers = {
linux: (config) => { linux: async (config) => {
ensureIconExists(config.iconPath, config.defaultIcon, "Linux icon"); await ensureIconExists(
config.iconPath,
config.defaultIcon,
"Linux icon",
true,
);
// Update desktop entry // Update desktop entry
linuxJson.bundle.linux.deb.files = { linuxJson.bundle.linux.deb.files = {
@@ -162,14 +188,14 @@ const platformHandlers = {
updatePlatformConfig(linuxJson, config); updatePlatformConfig(linuxJson, config);
}, },
darwin: (config) => { darwin: async (config) => {
ensureIconExists(config.iconPath, config.defaultIcon, "macOS icon"); await ensureIconExists(config.iconPath, config.defaultIcon, "macOS icon");
updatePlatformConfig(macosJson, config); updatePlatformConfig(macosJson, config);
}, },
win32: (config) => { win32: async (config) => {
ensureIconExists(config.iconPath, config.defaultIcon, "Windows icon"); await ensureIconExists(config.iconPath, config.defaultIcon, "Windows icon");
ensureIconExists( await ensureIconExists(
config.hdIconPath, config.hdIconPath,
config.hdDefaultIcon, config.hdDefaultIcon,
"Windows HD icon", "Windows HD icon",
@@ -196,7 +222,7 @@ function saveConfigurations() {
} }
// Main execution // Main execution
function main() { async function main() {
try { try {
validateEnvironment(); validateEnvironment();
updateBaseConfigs(); updateBaseConfigs();
@@ -210,7 +236,7 @@ function main() {
const handler = platformHandlers[platform]; const handler = platformHandlers[platform];
if (handler) { if (handler) {
handler(platformConfig); await handler(platformConfig);
} }
saveConfigurations(); saveConfigurations();

3
src-tauri/pake.json vendored
View File

@@ -17,7 +17,8 @@
"enable_wasm": false, "enable_wasm": false,
"enable_drag_drop": false, "enable_drag_drop": false,
"maximize": false, "maximize": false,
"start_to_tray": false "start_to_tray": false,
"force_internal_navigation": false
} }
], ],
"user_agent": { "user_agent": {

View File

@@ -20,6 +20,8 @@ pub struct WindowConfig {
pub enable_wasm: bool, pub enable_wasm: bool,
pub enable_drag_drop: bool, pub enable_drag_drop: bool,
pub start_to_tray: bool, pub start_to_tray: bool,
#[serde(default)]
pub force_internal_navigation: bool,
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]

View File

@@ -192,6 +192,8 @@ document.addEventListener("DOMContentLoaded", () => {
const tauri = window.__TAURI__; const tauri = window.__TAURI__;
const appWindow = tauri.window.getCurrentWindow(); const appWindow = tauri.window.getCurrentWindow();
const invoke = tauri.core.invoke; const invoke = tauri.core.invoke;
const pakeConfig = window["pakeConfig"] || {};
const forceInternalNavigation = pakeConfig.force_internal_navigation === true;
if (!document.getElementById("pake-top-dom")) { if (!document.getElementById("pake-top-dom")) {
const topDom = document.createElement("div"); const topDom = document.createElement("div");
@@ -319,9 +321,13 @@ document.addEventListener("DOMContentLoaded", () => {
const url = anchorEle.href; const url = anchorEle.href;
const filename = anchorEle.download || getFilenameFromUrl(url); const filename = anchorEle.download || getFilenameFromUrl(url);
if (window.blobToUrlCaches.has(url)) { if (window.blobToUrlCaches.has(url)) {
e.preventDefault();
e.stopImmediatePropagation();
downloadFromBlobUrl(url, filename); downloadFromBlobUrl(url, filename);
// case: download from dataURL -> convert dataURL -> // case: download from dataURL -> convert dataURL ->
} else if (url.startsWith("data:")) { } else if (url.startsWith("data:")) {
e.preventDefault();
e.stopImmediatePropagation();
downloadFromDataUri(url, filename); downloadFromDataUri(url, filename);
} }
}, },
@@ -390,9 +396,15 @@ document.addEventListener("DOMContentLoaded", () => {
// Handle _blank links: same domain navigates in-app, cross-domain opens new window // Handle _blank links: same domain navigates in-app, cross-domain opens new window
if (target === "_blank") { if (target === "_blank") {
if (forceInternalNavigation) {
e.preventDefault();
e.stopImmediatePropagation();
window.location.href = absoluteUrl;
return;
}
if (isSameDomain(absoluteUrl)) { if (isSameDomain(absoluteUrl)) {
// For same-domain links, let the browser/SPA handle it naturally // For same-domain links, let the browser handle it naturally
// This prevents full page reload in SPA apps like Discord
return; return;
} }
@@ -409,6 +421,13 @@ document.addEventListener("DOMContentLoaded", () => {
} }
if (target === "_new") { if (target === "_new") {
if (forceInternalNavigation) {
e.preventDefault();
e.stopImmediatePropagation();
window.location.href = absoluteUrl;
return;
}
e.preventDefault(); e.preventDefault();
handleExternalLink(absoluteUrl); handleExternalLink(absoluteUrl);
return; return;
@@ -431,6 +450,10 @@ document.addEventListener("DOMContentLoaded", () => {
// Handle regular links: same domain allows normal navigation, cross-domain opens new window // Handle regular links: same domain allows normal navigation, cross-domain opens new window
if (!target || target === "_self") { if (!target || target === "_self") {
if (!isSameDomain(absoluteUrl)) { if (!isSameDomain(absoluteUrl)) {
if (forceInternalNavigation) {
return;
}
e.preventDefault(); e.preventDefault();
e.stopImmediatePropagation(); e.stopImmediatePropagation();
const newWindow = originalWindowOpen.call( const newWindow = originalWindowOpen.call(
@@ -464,6 +487,10 @@ document.addEventListener("DOMContentLoaded", () => {
const absoluteUrl = hrefUrl.href; const absoluteUrl = hrefUrl.href;
if (!isSameDomain(absoluteUrl)) { if (!isSameDomain(absoluteUrl)) {
if (forceInternalNavigation) {
return originalWindowOpen.call(window, absoluteUrl, name, specs);
}
handleExternalLink(absoluteUrl); handleExternalLink(absoluteUrl);
return null; return null;
} }