merge
This commit is contained in:
9
bin/cli.ts
vendored
9
bin/cli.ts
vendored
@@ -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)
|
||||
@@ -204,6 +212,7 @@ program
|
||||
}
|
||||
|
||||
log.setDefaultLevel('info');
|
||||
log.setLevel('info');
|
||||
if (options.debug) {
|
||||
log.setLevel('debug');
|
||||
}
|
||||
|
||||
1
bin/defaults.ts
vendored
1
bin/defaults.ts
vendored
@@ -30,6 +30,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {
|
||||
keepBinary: false,
|
||||
multiInstance: false,
|
||||
startToTray: false,
|
||||
forceInternalNavigation: false,
|
||||
};
|
||||
|
||||
// Just for cli development
|
||||
|
||||
2
bin/helpers/merge.ts
vendored
2
bin/helpers/merge.ts
vendored
@@ -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
3
bin/types.ts
vendored
@@ -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 {
|
||||
|
||||
10
dist/cli.js
vendored
10
dist/cli.js
vendored
@@ -23,7 +23,7 @@ import sharp from 'sharp';
|
||||
import * as psl from 'psl';
|
||||
|
||||
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 engines = {
|
||||
node: ">=18.0.0"
|
||||
@@ -470,7 +470,7 @@ async function mergeConfig(url, options, tauriConf) {
|
||||
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 platformHideOnClose = hideOnClose ?? platform === 'darwin';
|
||||
const tauriConfWindowOptions = {
|
||||
@@ -490,6 +490,7 @@ async function mergeConfig(url, options, tauriConf) {
|
||||
enable_wasm: wasm,
|
||||
enable_drag_drop: enableDragDrop,
|
||||
start_to_tray: startToTray && showSystemTray,
|
||||
force_internal_navigation: forceInternalNavigation,
|
||||
};
|
||||
Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions });
|
||||
tauriConf.productName = name;
|
||||
@@ -1331,6 +1332,7 @@ const DEFAULT_PAKE_OPTIONS = {
|
||||
keepBinary: false,
|
||||
multiInstance: false,
|
||||
startToTray: false,
|
||||
forceInternalNavigation: false,
|
||||
};
|
||||
|
||||
async function checkUpdateTips() {
|
||||
@@ -1862,6 +1864,9 @@ program
|
||||
.addOption(new Option('--start-to-tray', 'Start app minimized to tray')
|
||||
.default(DEFAULT_PAKE_OPTIONS.startToTray)
|
||||
.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')
|
||||
.default(DEFAULT_PAKE_OPTIONS.installerLanguage)
|
||||
.hideHelp())
|
||||
@@ -1888,6 +1893,7 @@ program
|
||||
return;
|
||||
}
|
||||
log.setDefaultLevel('info');
|
||||
log.setLevel('info');
|
||||
if (options.debug) {
|
||||
log.setLevel('debug');
|
||||
}
|
||||
|
||||
8
docs/cli-usage.md
vendored
8
docs/cli-usage.md
vendored
@@ -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`.
|
||||
|
||||
8
docs/cli-usage_CN.md
vendored
8
docs/cli-usage_CN.md
vendored
@@ -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`。
|
||||
|
||||
2
package.json
vendored
2
package.json
vendored
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pake-cli",
|
||||
"version": "3.4.3",
|
||||
"version": "3.5.1",
|
||||
"description": "🤱🏻 Turn any webpage into a desktop app with one command. 🤱🏻 一键打包网页生成轻量桌面应用。",
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
|
||||
50
scripts/configure-tauri.mjs
vendored
50
scripts/configure-tauri.mjs
vendored
@@ -6,6 +6,7 @@ import linuxJson from "../src-tauri/tauri.linux.conf.json" with { type: "json" }
|
||||
|
||||
import { writeFileSync, existsSync, copyFileSync } from "fs";
|
||||
import os from "os";
|
||||
import sharp from "sharp";
|
||||
|
||||
/**
|
||||
* 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)) {
|
||||
// For official release apps, icons should already exist
|
||||
if (process.env.PAKE_CREATE_APP === "1") {
|
||||
console.warn(
|
||||
`${description} for ${process.env.NAME} not found at ${iconPath}`,
|
||||
);
|
||||
return; // Don't auto-generate for release builds
|
||||
return;
|
||||
}
|
||||
console.warn(
|
||||
`${description} for ${process.env.NAME} not found, using default`,
|
||||
);
|
||||
copyFileSync(defaultPath, iconPath);
|
||||
}
|
||||
|
||||
if (ensureRgba && existsSync(iconPath)) {
|
||||
await ensureRgbaPng(iconPath);
|
||||
}
|
||||
}
|
||||
|
||||
function updatePlatformConfig(platformConfig, platformVars) {
|
||||
@@ -150,8 +171,13 @@ function updatePlatformConfig(platformConfig, platformVars) {
|
||||
|
||||
// Platform-specific handlers
|
||||
const platformHandlers = {
|
||||
linux: (config) => {
|
||||
ensureIconExists(config.iconPath, config.defaultIcon, "Linux icon");
|
||||
linux: async (config) => {
|
||||
await ensureIconExists(
|
||||
config.iconPath,
|
||||
config.defaultIcon,
|
||||
"Linux icon",
|
||||
true,
|
||||
);
|
||||
|
||||
// Update desktop entry
|
||||
linuxJson.bundle.linux.deb.files = {
|
||||
@@ -162,14 +188,14 @@ const platformHandlers = {
|
||||
updatePlatformConfig(linuxJson, config);
|
||||
},
|
||||
|
||||
darwin: (config) => {
|
||||
ensureIconExists(config.iconPath, config.defaultIcon, "macOS icon");
|
||||
darwin: async (config) => {
|
||||
await ensureIconExists(config.iconPath, config.defaultIcon, "macOS icon");
|
||||
updatePlatformConfig(macosJson, config);
|
||||
},
|
||||
|
||||
win32: (config) => {
|
||||
ensureIconExists(config.iconPath, config.defaultIcon, "Windows icon");
|
||||
ensureIconExists(
|
||||
win32: async (config) => {
|
||||
await ensureIconExists(config.iconPath, config.defaultIcon, "Windows icon");
|
||||
await ensureIconExists(
|
||||
config.hdIconPath,
|
||||
config.hdDefaultIcon,
|
||||
"Windows HD icon",
|
||||
@@ -196,7 +222,7 @@ function saveConfigurations() {
|
||||
}
|
||||
|
||||
// Main execution
|
||||
function main() {
|
||||
async function main() {
|
||||
try {
|
||||
validateEnvironment();
|
||||
updateBaseConfigs();
|
||||
@@ -210,7 +236,7 @@ function main() {
|
||||
|
||||
const handler = platformHandlers[platform];
|
||||
if (handler) {
|
||||
handler(platformConfig);
|
||||
await handler(platformConfig);
|
||||
}
|
||||
|
||||
saveConfigurations();
|
||||
|
||||
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)]
|
||||
|
||||
31
src-tauri/src/inject/event.js
vendored
31
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");
|
||||
@@ -319,9 +321,13 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
const url = anchorEle.href;
|
||||
const filename = anchorEle.download || getFilenameFromUrl(url);
|
||||
if (window.blobToUrlCaches.has(url)) {
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
downloadFromBlobUrl(url, filename);
|
||||
// case: download from dataURL -> convert dataURL ->
|
||||
} else if (url.startsWith("data:")) {
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
downloadFromDataUri(url, filename);
|
||||
}
|
||||
},
|
||||
@@ -390,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;
|
||||
}
|
||||
|
||||
@@ -409,6 +421,13 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
}
|
||||
|
||||
if (target === "_new") {
|
||||
if (forceInternalNavigation) {
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
window.location.href = absoluteUrl;
|
||||
return;
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
handleExternalLink(absoluteUrl);
|
||||
return;
|
||||
@@ -431,6 +450,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(
|
||||
@@ -464,6 +487,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