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.

add zoom,min-height,min-width params

Tw93f7a24bb26ffd
diff --git a/bin/cli.ts b/bin/cli.ts
index 5a7f1263..88860f6f 100644
--- a/bin/cli.ts
+++ b/bin/cli.ts
@@ -187,6 +187,47 @@ program
.default(DEFAULT.installerLanguage)
.hideHelp(),
)
+ .addOption(
+ new Option(
+ '--zoom <number>',
+ 'Initial page zoom level (50-200)',
+ )
+ .default(DEFAULT.zoom)
+ .argParser((value) => {
+ const zoom = parseInt(value);
+ if (isNaN(zoom) || zoom < 50 || zoom > 200) {
+ throw new Error('--zoom must be a number between 50 and 200');
+ }
+ return zoom;
+ })
+ .hideHelp(),
+ )
+ .addOption(
+ new Option(
+ '--min-width <number>',
+ 'Minimum window width',
+ )
+ .default(DEFAULT.minWidth)
+ .argParser(validateNumberInput)
+ .hideHelp(),
+ )
+ .addOption(
+ new Option(
+ '--min-height <number>',
+ 'Minimum window height',
+ )
+ .default(DEFAULT.minHeight)
+ .argParser(validateNumberInput)
+ .hideHelp(),
+ )
+ .addOption(
+ new Option(
+ '--ignore-certificate-errors',
+ 'Ignore certificate errors (for self-signed certificates)',
+ )
+ .default(DEFAULT.ignoreCertificateErrors)
+ .hideHelp(),
+ )
.version(packageJson.version, '-v, --version')
.configureHelp({
sortSubcommands: true,
diff --git a/bin/defaults.ts b/bin/defaults.ts
index fed0e1c6..4a6b3576 100644
--- a/bin/defaults.ts
+++ b/bin/defaults.ts
@@ -31,6 +31,10 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {
multiInstance: false,
startToTray: false,
forceInternalNavigation: false,
+ zoom: 100,
+ minWidth: 0,
+ minHeight: 0,
+ ignoreCertificateErrors: false,
};
// Just for cli development
diff --git a/bin/helpers/merge.ts b/bin/helpers/merge.ts
index dbb36300..7cb07ffc 100644
--- a/bin/helpers/merge.ts
+++ b/bin/helpers/merge.ts
@@ -74,6 +74,10 @@ export async function mergeConfig(
multiInstance,
startToTray,
forceInternalNavigation,
+ zoom,
+ minWidth,
+ minHeight,
+ ignoreCertificateErrors,
} = options;
const { platform } = process;
@@ -98,6 +102,10 @@ export async function mergeConfig(
enable_drag_drop: enableDragDrop,
start_to_tray: startToTray && showSystemTray,
force_internal_navigation: forceInternalNavigation,
+ zoom,
+ min_width: minWidth,
+ min_height: minHeight,
+ ignore_certificate_errors: ignoreCertificateErrors,
};
Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions });
diff --git a/bin/types.ts b/bin/types.ts
index 3a521a21..50379f02 100644
--- a/bin/types.ts
+++ b/bin/types.ts
@@ -99,6 +99,18 @@ export interface PakeCliOptions {
// Force navigation to stay inside the Pake window even for external links
forceInternalNavigation: boolean;
+
+ // Initial page zoom level (50-200), default 100
+ zoom: number;
+
+ // Minimum window width, default 0 (no limit)
+ minWidth: number;
+
+ // Minimum window height, default 0 (no limit)
+ minHeight: number;
+
+ // Ignore certificate errors (for self-signed certs), default false
+ ignoreCertificateErrors: boolean;
}
export interface PakeAppOptions extends PakeCliOptions {
diff --git a/dist/cli.js b/dist/cli.js
index ebd9ce97..3d12b585 100755
--- a/dist/cli.js
+++ b/dist/cli.js
@@ -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, forceInternalNavigation, } = 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, zoom, minWidth, minHeight, ignoreCertificateErrors, } = options;
const { platform } = process;
const platformHideOnClose = hideOnClose ?? platform === 'darwin';
const tauriConfWindowOptions = {
@@ -491,6 +491,10 @@ async function mergeConfig(url, options, tauriConf) {
enable_drag_drop: enableDragDrop,
start_to_tray: startToTray && showSystemTray,
force_internal_navigation: forceInternalNavigation,
+ zoom,
+ min_width: minWidth,
+ min_height: minHeight,
+ ignore_certificate_errors: ignoreCertificateErrors,
};
Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions });
tauriConf.productName = name;
@@ -1363,6 +1367,10 @@ const DEFAULT_PAKE_OPTIONS = {
multiInstance: false,
startToTray: false,
forceInternalNavigation: false,
+ zoom: 100,
+ minWidth: 0,
+ minHeight: 0,
+ ignoreCertificateErrors: false,
};
async function checkUpdateTips() {
@@ -1900,6 +1908,27 @@ program
.addOption(new Option('--installer-language <string>', 'Installer language')
.default(DEFAULT_PAKE_OPTIONS.installerLanguage)
.hideHelp())
+ .addOption(new Option('--zoom <number>', 'Initial page zoom level (50-200)')
+ .default(DEFAULT_PAKE_OPTIONS.zoom)
+ .argParser((value) => {
+ const zoom = parseInt(value);
+ if (isNaN(zoom) || zoom < 50 || zoom > 200) {
+ throw new Error('--zoom must be a number between 50 and 200');
+ }
+ return zoom;
+})
+ .hideHelp())
+ .addOption(new Option('--min-width <number>', 'Minimum window width')
+ .default(DEFAULT_PAKE_OPTIONS.minWidth)
+ .argParser(validateNumberInput)
+ .hideHelp())
+ .addOption(new Option('--min-height <number>', 'Minimum window height')
+ .default(DEFAULT_PAKE_OPTIONS.minHeight)
+ .argParser(validateNumberInput)
+ .hideHelp())
+ .addOption(new Option('--ignore-certificate-errors', 'Ignore certificate errors (for self-signed certificates)')
+ .default(DEFAULT_PAKE_OPTIONS.ignoreCertificateErrors)
+ .hideHelp())
.version(packageJson.version, '-v, --version')
.configureHelp({
sortSubcommands: true,
diff --git a/docs/cli-usage.md b/docs/cli-usage.md
index 8755c6ca..213f7999 100644
--- a/docs/cli-usage.md
+++ b/docs/cli-usage.md
@@ -138,6 +138,32 @@ Set the width of the application window. Default is `1200px`.
--width <number>
```
+#### [min-width]
+
+Set the minimum width that the window can be resized to. Keeps layouts usable when the window is dragged small.
+
+```shell
+--min-width <number>
+```
+
+#### [min-height]
+
+Set the minimum height that the window can be resized to. Prevents UI breakage caused by very short windows.
+
+```shell
+--min-height <number>
+```
+
+#### [zoom]
+
+Set initial page zoom level (50-200). Default is `100`. Users can still adjust with `Cmd/Ctrl +/-/0` shortcuts.
+
+```shell
+--zoom <number>
+--zoom 80 # 80%
+--zoom 120 # 120%
+```
+
#### [hide-title-bar]
Enable or disable immersive header. Default is `false`. Use the following command to enable this feature, macOS only.
@@ -439,6 +465,14 @@ Enable developer tools and detailed logging for debugging.
--debug
```
+#### [ignore-certificate-errors]
+
+Ignore TLS certificate validation errors when loading the target URL. Useful for intranet apps, dev servers, or self-signed certificates.
+
+```shell
+--ignore-certificate-errors
+```
+
### Packaging Complete
After completing the above steps, your application should be successfully packaged. Please note that the packaging process may take some time depending on your system configuration and network conditions. Be patient, and once the packaging is complete, you can find the application installer in the specified directory.
diff --git a/docs/cli-usage_CN.md b/docs/cli-usage_CN.md
index 6090d72f..cb2add62 100644
--- a/docs/cli-usage_CN.md
+++ b/docs/cli-usage_CN.md
@@ -138,6 +138,32 @@ pake https://github.com --name GitHub
--width <number>
```
+#### [min-width]
+
+设置窗口可以缩放到的最小宽度,防止窗口被拖得过小导致控件错位。
+
+```shell
+--min-width <number>
+```
+
+#### [min-height]
+
+设置窗口可以缩放到的最小高度,避免界面内容因高度过小而错乱。
+
+```shell
+--min-height <number>
+```
+
+#### [zoom]
+
+设置初始页面缩放级别(50-200),默认为 `100`。用户仍可通过快捷键(`Cmd/Ctrl +/-/0`)调整。
+
+```shell
+--zoom <number>
+--zoom 80 # 80%
+--zoom 120 # 120%
+```
+
#### [hide-title-bar]
设置是否启用沉浸式头部,默认为 `false`(不启用)。当前只对 macOS 上有效。
@@ -437,6 +463,14 @@ pake ./my-app/index.html --name "my-app" --use-local-file
--debug
```
+#### [ignore-certificate-errors]
+
+忽略目标 URL 的 TLS 证书校验错误,适用于内网应用、开发环境、自签名证书。
+
+```shell
+--ignore-certificate-errors
+```
+
### 打包完成
完成上述步骤后,您的应用程序应该已经成功打包。请注意,根据您的系统配置和网络状况,打包过程可能需要一些时间。请耐心等待,一旦打包完成,您就可以在指定的目录中找到应用程序安装包。
diff --git a/src-tauri/src/app/config.rs b/src-tauri/src/app/config.rs
index 2544fb52..ca4c7546 100644
--- a/src-tauri/src/app/config.rs
+++ b/src-tauri/src/app/config.rs
@@ -22,6 +22,18 @@ pub struct WindowConfig {
pub start_to_tray: bool,
#[serde(default)]
pub force_internal_navigation: bool,
+ #[serde(default = "default_zoom")]
+ pub zoom: u32,
+ #[serde(default)]
+ pub min_width: f64,
+ #[serde(default)]
+ pub min_height: f64,
+ #[serde(default)]
+ pub ignore_certificate_errors: bool,
+}
+
+fn default_zoom() -> u32 {
+ 100
}
#[derive(Debug, Serialize, Deserialize)]
diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rs
index 373357ba..42d4d97f 100644
--- a/src-tauri/src/app/window.rs
+++ b/src-tauri/src/app/window.rs
@@ -64,6 +64,12 @@ pub fn set_window(app: &mut App, config: &PakeConfig, tauri_config: &Config) ->
.always_on_top(window_config.always_on_top)
.incognito(window_config.incognito);
+ if window_config.min_width > 0.0 || window_config.min_height > 0.0 {
+ let min_w = if window_config.min_width > 0.0 { window_config.min_width } else { window_config.width };
+ let min_h = if window_config.min_height > 0.0 { window_config.min_height } else { window_config.height };
+ window_builder = window_builder.min_inner_size(min_w, min_h);
+ }
+
if !window_config.enable_drag_drop {
window_builder = window_builder.disable_drag_drop_handler();
}
@@ -82,6 +88,23 @@ pub fn set_window(app: &mut App, config: &PakeConfig, tauri_config: &Config) ->
#[cfg(all(not(target_os = "windows"), not(target_os = "macos")))]
let mut linux_browser_args = String::from("--disable-blink-features=AutomationControlled");
+ if window_config.ignore_certificate_errors {
+ #[cfg(target_os = "windows")]
+ {
+ windows_browser_args.push_str(" --ignore-certificate-errors");
+ }
+
+ #[cfg(all(not(target_os = "windows"), not(target_os = "macos")))]
+ {
+ linux_browser_args.push_str(" --ignore-certificate-errors");
+ }
+
+ #[cfg(target_os = "macos")]
+ {
+ window_builder = window_builder.additional_browser_args("--ignore-certificate-errors");
+ }
+ }
+
if window_config.enable_wasm {
#[cfg(target_os = "windows")]
{
diff --git a/src-tauri/src/inject/event.js b/src-tauri/src/inject/event.js
index 6796867d..313c9dde 100644
--- a/src-tauri/src/inject/event.js
+++ b/src-tauri/src/inject/event.js
@@ -896,6 +896,8 @@ function setDefaultZoom() {
const htmlZoom = window.localStorage.getItem("htmlZoom");
if (htmlZoom) {
setZoom(htmlZoom);
+ } else if (window.pakeConfig?.zoom && window.pakeConfig.zoom !== 100) {
+ setZoom(`${window.pakeConfig.zoom}%`);
}
}