From bd764f5f5fba52e72238a4b97d1ed09935e860ec Mon Sep 17 00:00:00 2001 From: Tw93 Date: Sun, 31 Aug 2025 15:29:28 +0800 Subject: [PATCH] :sparkles: Support drag-and-drop configuration --- bin/cli.ts | 10 +++++++++- bin/defaults.ts | 1 + bin/helpers/merge.ts | 4 +++- bin/types.ts | 3 +++ dist/cli.js | 9 +++++++-- docs/cli-usage.md | 11 +++++++++++ docs/cli-usage_CN.md | 11 +++++++++++ src-tauri/src/app/config.rs | 1 + src-tauri/src/app/window.rs | 10 ++++++++-- 9 files changed, 54 insertions(+), 6 deletions(-) diff --git a/bin/cli.ts b/bin/cli.ts index 9d63f9f..12cecbd 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -125,7 +125,10 @@ program .hideHelp(), ) .addOption( - new Option('--hide-on-close', 'Hide window on close instead of exiting (default: true for macOS, false for others)') + new Option( + '--hide-on-close', + 'Hide window on close instead of exiting (default: true for macOS, false for others)', + ) .default(DEFAULT.hideOnClose) .hideHelp(), ) @@ -140,6 +143,11 @@ program .default(DEFAULT.wasm) .hideHelp(), ) + .addOption( + new Option('--enable-drag-drop', 'Enable drag and drop functionality') + .default(DEFAULT.enableDragDrop) + .hideHelp(), + ) .addOption( new Option('--installer-language ', 'Installer language') .default(DEFAULT.installerLanguage) diff --git a/bin/defaults.ts b/bin/defaults.ts index 2597d77..72ab520 100644 --- a/bin/defaults.ts +++ b/bin/defaults.ts @@ -25,6 +25,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = { hideOnClose: undefined, // Platform-specific: true for macOS, false for others incognito: false, wasm: false, + enableDragDrop: false, }; // Just for cli development diff --git a/bin/helpers/merge.ts b/bin/helpers/merge.ts index 1d630ff..5645383 100644 --- a/bin/helpers/merge.ts +++ b/bin/helpers/merge.ts @@ -61,12 +61,13 @@ export async function mergeConfig( incognito, title, wasm, + enableDragDrop, } = options; const { platform } = process; // Platform-specific hide_on_close behavior: macOS keeps true, others default to false - const platformHideOnClose = hideOnClose ?? (platform === 'darwin'); + const platformHideOnClose = hideOnClose ?? platform === 'darwin'; // Set Windows parameters. const tauriConfWindowOptions = { @@ -83,6 +84,7 @@ export async function mergeConfig( incognito: incognito, title: title || null, enable_wasm: wasm, + enable_drag_drop: enableDragDrop, }; Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions }); diff --git a/bin/types.ts b/bin/types.ts index 02c94b9..261c6b2 100644 --- a/bin/types.ts +++ b/bin/types.ts @@ -81,6 +81,9 @@ export interface PakeCliOptions { // Enable WebAssembly support (Flutter Web, etc.), default false wasm: boolean; + + // Enable drag and drop functionality, default false + enableDragDrop: boolean; } export interface PakeAppOptions extends PakeCliOptions { diff --git a/dist/cli.js b/dist/cli.js index 960b637..61aef9e 100755 --- a/dist/cli.js +++ b/dist/cli.js @@ -348,10 +348,10 @@ async function mergeConfig(url, options, tauriConf) { await fsExtra.copy(sourcePath, destPath); } })); - const { width, height, fullscreen, hideTitleBar, alwaysOnTop, appVersion, darkMode, disabledWebShortcuts, activationShortcut, userAgent, showSystemTray, systemTrayIcon, useLocalFile, identifier, name, resizable = true, inject, proxyUrl, installerLanguage, hideOnClose, incognito, title, wasm, } = options; + const { width, height, fullscreen, hideTitleBar, alwaysOnTop, appVersion, darkMode, disabledWebShortcuts, activationShortcut, userAgent, showSystemTray, systemTrayIcon, useLocalFile, identifier, name, resizable = true, inject, proxyUrl, installerLanguage, hideOnClose, incognito, title, wasm, enableDragDrop, } = options; const { platform } = process; // Platform-specific hide_on_close behavior: macOS keeps true, others default to false - const platformHideOnClose = hideOnClose ?? (platform === 'darwin'); + const platformHideOnClose = hideOnClose ?? platform === 'darwin'; // Set Windows parameters. const tauriConfWindowOptions = { width, @@ -367,6 +367,7 @@ async function mergeConfig(url, options, tauriConf) { incognito: incognito, title: title || null, enable_wasm: wasm, + enable_drag_drop: enableDragDrop, }; Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions }); tauriConf.productName = name; @@ -1062,6 +1063,7 @@ const DEFAULT_PAKE_OPTIONS = { hideOnClose: undefined, // Platform-specific: true for macOS, false for others incognito: false, wasm: false, + enableDragDrop: false, }; async function checkUpdateTips() { @@ -1516,6 +1518,9 @@ program .addOption(new Option('--wasm', 'Enable WebAssembly support (Flutter Web, etc.)') .default(DEFAULT_PAKE_OPTIONS.wasm) .hideHelp()) + .addOption(new Option('--enable-drag-drop', 'Enable drag and drop functionality') + .default(DEFAULT_PAKE_OPTIONS.enableDragDrop) + .hideHelp()) .addOption(new Option('--installer-language ', 'Installer language') .default(DEFAULT_PAKE_OPTIONS.installerLanguage) .hideHelp()) diff --git a/docs/cli-usage.md b/docs/cli-usage.md index 5804cab..27c5757 100644 --- a/docs/cli-usage.md +++ b/docs/cli-usage.md @@ -332,6 +332,17 @@ This option adds necessary HTTP headers (`Cross-Origin-Opener-Policy: same-origi pake https://flutter.dev --name FlutterApp --wasm ``` +#### [enable-drag-drop] + +Enable native drag and drop functionality within the application. Default is `false`. When enabled, allows drag and drop operations like reordering items, file uploads, and other interactive drag behaviors that work in regular browsers. + +```shell +--enable-drag-drop + +# Example: Package an app that requires drag-drop functionality +pake https://planka.example.com --name PlankApp --enable-drag-drop +``` + #### [installer-language] Set the Windows Installer language. Options include `zh-CN`, `ja-JP`, More at [Tauri Document](https://tauri.app/distribute/windows-installer/#internationalization). Default is `en-US`. diff --git a/docs/cli-usage_CN.md b/docs/cli-usage_CN.md index e00f397..696be85 100644 --- a/docs/cli-usage_CN.md +++ b/docs/cli-usage_CN.md @@ -319,6 +319,17 @@ pake [url] [options] pake https://flutter.dev --name FlutterApp --wasm ``` +#### [enable-drag-drop] + +启用原生拖拽功能。默认为 `false`。启用后,允许在应用中进行拖拽操作,如重新排序项目、文件上传以及其他在常规浏览器中有效的交互式拖拽行为。 + +```shell +--enable-drag-drop + +# 示例:打包需要拖拽功能的应用 +pake https://planka.example.com --name PlankApp --enable-drag-drop +``` + #### [title] 设置窗口标题栏文本。如果未指定,窗口标题将为空。 diff --git a/src-tauri/src/app/config.rs b/src-tauri/src/app/config.rs index cc3d74c..b04ffa7 100644 --- a/src-tauri/src/app/config.rs +++ b/src-tauri/src/app/config.rs @@ -17,6 +17,7 @@ pub struct WindowConfig { pub incognito: bool, pub title: Option, pub enable_wasm: bool, + pub enable_drag_drop: bool, } #[derive(Debug, Serialize, Deserialize)] diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rs index 2198b4a..4ac01bf 100644 --- a/src-tauri/src/app/window.rs +++ b/src-tauri/src/app/window.rs @@ -38,8 +38,14 @@ pub fn set_window(app: &mut App, config: &PakeConfig, tauri_config: &Config) -> .fullscreen(window_config.fullscreen) .inner_size(window_config.width, window_config.height) .always_on_top(window_config.always_on_top) - .disable_drag_drop_handler() - .incognito(window_config.incognito) + .incognito(window_config.incognito); + + // Conditionally disable drag-drop handler + if !window_config.enable_drag_drop { + window_builder = window_builder.disable_drag_drop_handler(); + } + + window_builder = window_builder .initialization_script(&config_script) .initialization_script(include_str!("../inject/component.js")) .initialization_script(include_str!("../inject/event.js"))