Support drag-and-drop configuration

This commit is contained in:
Tw93
2025-08-31 15:29:28 +08:00
parent c68daf6ed6
commit bd764f5f5f
9 changed files with 54 additions and 6 deletions

10
bin/cli.ts vendored
View File

@@ -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 <string>', 'Installer language')
.default(DEFAULT.installerLanguage)

1
bin/defaults.ts vendored
View File

@@ -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

View File

@@ -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 });

3
bin/types.ts vendored
View File

@@ -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 {

9
dist/cli.js vendored
View File

@@ -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 <string>', 'Installer language')
.default(DEFAULT_PAKE_OPTIONS.installerLanguage)
.hideHelp())

View File

@@ -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`.

View File

@@ -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]
设置窗口标题栏文本。如果未指定,窗口标题将为空。

View File

@@ -17,6 +17,7 @@ pub struct WindowConfig {
pub incognito: bool,
pub title: Option<String>,
pub enable_wasm: bool,
pub enable_drag_drop: bool,
}
#[derive(Debug, Serialize, Deserialize)]

View File

@@ -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"))