Skip to content

armgit / Pake

Public Imported from GitHub
0

Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.

feat: support managed new windows and macOS media permissions

Tw9368ca5e18de93
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 38575266..259d9b60 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -96,6 +96,7 @@ jobs:
name_zh: ${{ matrix.config.name_zh }}
url: ${{ matrix.config.url }}
icon: ${{ matrix.config.icon }}
+ new_window: ${{ matrix.config.new_window || false }}
# Publish Docker image (runs in parallel with app builds)
publish-docker:
diff --git a/.github/workflows/single-app.yaml b/.github/workflows/single-app.yaml
index cad91339..80ffd0c4 100644
--- a/.github/workflows/single-app.yaml
+++ b/.github/workflows/single-app.yaml
@@ -26,6 +26,10 @@ on:
icon:
description: "App Icon"
required: false
+ new_window:
+ description: "Allow sites to open new windows"
+ required: false
+ default: false
workflow_call:
inputs:
name:
@@ -52,6 +56,11 @@ on:
description: "App Icon"
type: string
required: false
+ new_window:
+ description: "Allow sites to open new windows"
+ type: boolean
+ required: false
+ default: false
secrets:
PAKE_SIGNING_IDENTITY:
required: false
@@ -174,6 +183,10 @@ jobs:
ARGS+=("--icon" "src-tauri/png/${{ inputs.name }}_512.png")
fi
+ if [ "${{ inputs.new_window }}" = "true" ]; then
+ ARGS+=("--new-window")
+ fi
+
# Build once with multiple targets (faster than separate builds)
node dist/cli.js "${ARGS[@]}" --targets deb,appimage
@@ -217,6 +230,10 @@ jobs:
ARGS+=("--icon" "src-tauri/icons/${{ inputs.name }}.icns")
fi
+ if [ "${{ inputs.new_window }}" = "true" ]; then
+ ARGS+=("--new-window")
+ fi
+
node dist/cli.js "${ARGS[@]}" --targets universal --multi-arch
mkdir -p output/macos
@@ -282,6 +299,10 @@ jobs:
$args += "--icon", "src-tauri\png\${{ inputs.name }}_256.ico"
}
+ if ("${{ inputs.new_window }}" -eq "true") {
+ $args += "--new-window"
+ }
+
$args += "--targets", "x64"
node dist/cli.js $args
diff --git a/bin/helpers/cli-program.ts b/bin/helpers/cli-program.ts
index ac1a1a63..a3f35f5a 100644
--- a/bin/helpers/cli-program.ts
+++ b/bin/helpers/cli-program.ts
@@ -238,7 +238,10 @@ ${green('|_| \\__,_|_|\\_\\___| can turn any webpage into a desktop app with
.hideHelp(),
)
.addOption(
- new Option('--new-window', 'Allow new window for third-party login')
+ new Option(
+ '--new-window',
+ 'Allow sites to open new windows (for auth flows, tabs, branches)',
+ )
.default(DEFAULT.newWindow)
.hideHelp(),
)
diff --git a/bin/types.ts b/bin/types.ts
index b2cd86f3..192708d7 100644
--- a/bin/types.ts
+++ b/bin/types.ts
@@ -121,7 +121,7 @@ export interface PakeCliOptions {
// Turn on rapid build mode (app only, no dmg/deb/msi), good for debugging
iterativeBuild: boolean;
- // Allow new window for third-party login, default false
+ // Allow sites to open new windows, default false
newWindow: boolean;
// Auto-install app to /Applications (macOS) after build, default false
diff --git a/default_app_list.json b/default_app_list.json
index 7ff73ea2..57cac8af 100644
--- a/default_app_list.json
+++ b/default_app_list.json
@@ -45,7 +45,8 @@
"name": "chatgpt",
"title": "ChatGPT",
"name_zh": "ChatGPT",
- "url": "https://chatgpt.com/"
+ "url": "https://chatgpt.com/",
+ "new_window": true
},
{
"name": "flomo",
diff --git a/dist/cli.js b/dist/cli.js
index b2bf0fd2..9f7976ea 100644
--- a/dist/cli.js
+++ b/dist/cli.js
@@ -2231,7 +2231,7 @@ ${green('|_| \\__,_|_|\\_\\___| can turn any webpage into a desktop app with
.addOption(new Option('--iterative-build', 'Turn on rapid build mode (app only, no dmg/deb/msi), good for debugging')
.default(DEFAULT_PAKE_OPTIONS.iterativeBuild)
.hideHelp())
- .addOption(new Option('--new-window', 'Allow new window for third-party login')
+ .addOption(new Option('--new-window', 'Allow sites to open new windows (for auth flows, tabs, branches)')
.default(DEFAULT_PAKE_OPTIONS.newWindow)
.hideHelp())
.option('--install', 'Auto-install app to /Applications (macOS) after build and remove local bundle', DEFAULT_PAKE_OPTIONS.install)
diff --git a/docs/cli-usage.md b/docs/cli-usage.md
index 0360a75f..36269434 100644
--- a/docs/cli-usage.md
+++ b/docs/cli-usage.md
@@ -528,7 +528,7 @@ Ignore TLS certificate validation errors when loading the target URL. Useful for
#### [new-window]
-Allow new window for third-party login authorization.
+Allow sites to open new windows, such as authentication popups, extra tabs, or branch views.
```shell
--new-window
diff --git a/docs/cli-usage_CN.md b/docs/cli-usage_CN.md
index d17dd6a1..4686ce7b 100644
--- a/docs/cli-usage_CN.md
+++ b/docs/cli-usage_CN.md
@@ -526,7 +526,7 @@ pake ./my-app/index.html --name "my-app" --use-local-file
#### [new-window]
-允许弹出新窗口,适用于第三方登录授权。
+允许网站打开新窗口,例如登录授权弹窗、额外标签页或分支会话页面。
```shell
--new-window
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock
index 1bbeff39..0f4a838e 100644
--- a/src-tauri/Cargo.lock
+++ b/src-tauri/Cargo.lock
@@ -2564,7 +2564,7 @@ dependencies = [
[[package]]
name = "pake"
-version = "3.10.0"
+version = "3.10.1"
dependencies = [
"serde",
"serde_json",
diff --git a/src-tauri/info.plist b/src-tauri/Info.plist
similarity index 100%
rename from src-tauri/info.plist
rename to src-tauri/Info.plist
diff --git a/src-tauri/entitlements.plist b/src-tauri/entitlements.plist
new file mode 100644
index 00000000..c2fcd7b3
--- /dev/null
+++ b/src-tauri/entitlements.plist
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+ <dict>
+ <key>com.apple.security.device.audio-input</key>
+ <true/>
+ <key>com.apple.security.device.camera</key>
+ <true/>
+ </dict>
+</plist>
diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rs
index 1ed33995..0694687e 100644
--- a/src-tauri/src/app/window.rs
+++ b/src-tauri/src/app/window.rs
@@ -1,7 +1,10 @@
use crate::app::config::PakeConfig;
use crate::util::get_data_dir;
use std::{path::PathBuf, str::FromStr, sync::Mutex};
-use tauri::{AppHandle, Config, Manager, Url, WebviewUrl, WebviewWindow, WebviewWindowBuilder};
+use tauri::{
+ webview::{NewWindowFeatures, NewWindowResponse},
+ AppHandle, Config, Manager, Url, WebviewUrl, WebviewWindow, WebviewWindowBuilder,
+};
#[cfg(target_os = "macos")]
use tauri::{Theme, TitleBarStyle};
@@ -54,6 +57,31 @@ pub fn open_additional_window(app: &AppHandle) -> tauri::Result<WebviewWindow> {
build_window_with_label(app, &state.pake_config, &state.tauri_config, &label)
}
+fn open_requested_window(
+ app: &AppHandle,
+ config: &PakeConfig,
+ tauri_config: &Config,
+ target_url: Url,
+ features: NewWindowFeatures,
+) -> tauri::Result<WebviewWindow> {
+ let state = app.state::<MultiWindowState>();
+ let label = state.next_window_label();
+ let window = build_window(
+ app,
+ config,
+ tauri_config,
+ &label,
+ WebviewUrl::External("about:blank".parse().unwrap()),
+ true,
+ Some(features),
+ )?;
+
+ let _ = window.set_title(target_url.as_str());
+ let _ = window.set_focus();
+
+ Ok(window)
+}
+
pub fn open_additional_window_safe(app: &AppHandle) {
#[cfg(target_os = "windows")]
{
@@ -81,22 +109,38 @@ fn build_window_with_label(
tauri_config: &Config,
label: &str,
) -> tauri::Result<WebviewWindow> {
- let package_name = tauri_config.clone().product_name.unwrap();
- let _data_dir = get_data_dir(app, package_name);
-
let window_config = config
.windows
.first()
.expect("At least one window configuration is required");
-
- let user_agent = config.user_agent.get();
-
let url = match window_config.url_type.as_str() {
"web" => WebviewUrl::App(window_config.url.parse().unwrap()),
"local" => WebviewUrl::App(PathBuf::from(&window_config.url)),
_ => panic!("url type can only be web or local"),
};
+ build_window(app, config, tauri_config, label, url, false, None)
+}
+
+fn build_window(
+ app: &AppHandle,
+ config: &PakeConfig,
+ tauri_config: &Config,
+ label: &str,
+ url: WebviewUrl,
+ visible: bool,
+ new_window_features: Option<NewWindowFeatures>,
+) -> tauri::Result<WebviewWindow> {
+ let package_name = tauri_config.clone().product_name.unwrap();
+ let _data_dir = get_data_dir(app, package_name);
+
+ let window_config = config
+ .windows
+ .first()
+ .expect("At least one window configuration is required");
+
+ let user_agent = config.user_agent.get();
+
let config_script = format!(
"window.pakeConfig = {}",
serde_json::to_string(&window_config).unwrap()
@@ -113,7 +157,7 @@ fn build_window_with_label(
let mut window_builder = WebviewWindowBuilder::new(app, label, url)
.title(effective_title)
- .visible(false)
+ .visible(visible)
.user_agent(user_agent)
.resizable(window_config.resizable)
.maximized(window_config.maximize);
@@ -164,8 +208,24 @@ fn build_window_with_label(
}
if window_config.new_window {
- window_builder = window_builder
- .on_new_window(move |_url, _features| tauri::webview::NewWindowResponse::Allow);
+ let app_handle = app.clone();
+ let popup_config = config.clone();
+ let popup_tauri_config = tauri_config.clone();
+ window_builder = window_builder.on_new_window(move |target_url, features| {
+ match open_requested_window(
+ &app_handle,
+ &popup_config,
+ &popup_tauri_config,
+ target_url,
+ features,
+ ) {
+ Ok(window) => NewWindowResponse::Create { window },
+ Err(error) => {
+ eprintln!("[Pake] Failed to open requested window: {error}");
+ NewWindowResponse::Deny
+ }
+ }
+ });
}
// Add initialization scripts
@@ -285,6 +345,10 @@ fn build_window_with_label(
println!("Proxy configured: {}", config.proxy_url);
}
+ if let Some(features) = new_window_features {
+ window_builder = window_builder.window_features(features).focused(true);
+ }
+
// Allow navigation to OAuth/authentication domains
window_builder = window_builder.on_navigation(|url| {
let url_str = url.as_str();
diff --git a/src-tauri/tauri.macos.conf.json b/src-tauri/tauri.macos.conf.json
index f9b7a028..5079f65a 100644
--- a/src-tauri/tauri.macos.conf.json
+++ b/src-tauri/tauri.macos.conf.json
@@ -6,6 +6,8 @@
"macOS": {
"signingIdentity": "-",
"hardenedRuntime": true,
+ "entitlements": "entitlements.plist",
+ "infoPlist": "Info.plist",
"dmg": {
"background": "assets/macos/dmg/background.png",
"windowSize": {
diff --git a/tests/release.js b/tests/release.js
index bcc115e8..a636540a 100755
--- a/tests/release.js
+++ b/tests/release.js
@@ -66,7 +66,7 @@ class ReleaseBuildTest {
// Build the app using CLI directly
this.log("DEBUG", "Building app package...");
- const commonArgs = "--iterative-build --debug";
+ const commonArgs = `${config.new_window ? "--new-window " : ""}--iterative-build --debug`;
const cmd = `node dist/cli.js ${config.url} --name ${config.name} --icon ${config.icon} ${commonArgs}`;
try {