feat(workspace): refresh desktop editing experience and prepare 0.1.2
Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s
Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s
This commit is contained in:
1 parent
aa5255d1e4
commit
2e0033ce2d
260 files changed
+43963
-5591
No files matched your search
@@ -6,6 +6,7 @@ Cutdex workspace 内部 Flutter 原生插件,暂不发布。
|
||||
| --- | --- | --- |
|
||||
| 窗口标题栏、拖动区域与关闭请求拦截 | 支持 | 支持 |
|
||||
| 本地文件拖放区域 | 支持 | 支持 |
|
||||
| 附着主窗口的异步文件选择弹窗 | 支持 | 由应用使用 Filegate |
|
||||
| 原生上下文菜单 | 支持 | 由 UI 包回退为 Flutter 菜单 |
|
||||
| 原生窗口全屏会话 | 支持 | 未提供 |
|
||||
|
||||
@@ -23,6 +24,8 @@ macOS 宿主窗口继承 `CutdexNativeWindow`,导入 `cutdex_native` 后按 Fl
|
||||
|
||||
## 文件拖放
|
||||
|
||||
`NativeFilePicker.pickFiles` 在 macOS 使用主窗口的异步 `NSOpenPanel` sheet,支持多选和扩展名过滤,返回本地路径;取消返回空列表。窗口不存在或已有弹窗时返回平台异常。原生选择器不进入 `runModal` 的同步嵌套事件循环,导入与聊天附件共用此入口。
|
||||
|
||||
`NativeFileDropRegion` 接收稳定的 `regionId`、`NativeDropConfiguration`、启用状态与回调,回调中的文件是原始路径列表。扩展名白名单与数量上限由调用方提供。
|
||||
|
||||
两端均拒绝目录和不存在的文件,并在落下时重新检查文件引用。
|
||||
@@ -51,6 +54,7 @@ macOS 标题栏手势使用真实 AppKit 响应链,文件引用策略使用临
|
||||
python3 tool/build.py macos --mode debug --flavor development
|
||||
bash packages/cutdex_native/tool/macos/test_header_control_gestures.sh
|
||||
bash packages/cutdex_native/tool/macos/test_file_drop_policy.sh
|
||||
bash packages/cutdex_native/tool/macos/test_file_picker.sh
|
||||
```
|
||||
|
||||
Windows 标题栏回归验证真实 HWND、命中区域、最大化、DPI 与标题栏恢复;先准备 Flutter C++ wrapper:
|
||||
|
||||
@@ -4,6 +4,7 @@ export 'src/window_chrome_session.dart';
|
||||
export 'src/window_header_layout.dart';
|
||||
export 'src/fullscreen.dart';
|
||||
export 'src/file_drop.dart';
|
||||
export 'src/file_picker.dart';
|
||||
export 'src/file_drop_region.dart';
|
||||
export 'src/context_menu.dart';
|
||||
export 'src/device_info.dart';
|
||||
@@ -0,0 +1,16 @@
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
/// Selects local files in a sheet attached to the macOS host window.
|
||||
abstract final class NativeFilePicker {
|
||||
static const _channel = MethodChannel('cutdex_native/file_picker');
|
||||
|
||||
/// Returns an empty list when the user cancels the selection.
|
||||
static Future<List<String>> pickFiles({
|
||||
required List<String> allowedExtensions,
|
||||
}) async {
|
||||
final paths = await _channel.invokeListMethod<String>('pickFiles', {
|
||||
'allowedExtensions': allowedExtensions,
|
||||
});
|
||||
return paths ?? const [];
|
||||
}
|
||||
}
|
||||
+8
@@ -5,12 +5,14 @@ public final class CutdexNativePlugin: NSObject, FlutterPlugin {
|
||||
private let view: NSView
|
||||
private let messenger: FlutterBinaryMessenger
|
||||
private let menu: NativeContextMenuBridge
|
||||
private let filePicker: NativeFilePickerBridge
|
||||
private var drops: [String: NativeFileDropView] = [:]
|
||||
|
||||
private init(view: NSView, messenger: FlutterBinaryMessenger) {
|
||||
self.view = view
|
||||
self.messenger = messenger
|
||||
menu = NativeContextMenuBridge(view: view, messenger: messenger)
|
||||
filePicker = NativeFilePickerBridge(view: view)
|
||||
super.init()
|
||||
(view.window as? CutdexNativeWindow)?.configureNative(messenger: messenger)
|
||||
}
|
||||
@@ -23,9 +25,15 @@ public final class CutdexNativePlugin: NSObject, FlutterPlugin {
|
||||
registrar.addMethodCallDelegate(instance, channel: channel)
|
||||
registrar.addMethodCallDelegate(instance, channel: FlutterMethodChannel(
|
||||
name: "cutdex_native/device_info", binaryMessenger: registrar.messenger))
|
||||
registrar.addMethodCallDelegate(instance, channel: FlutterMethodChannel(
|
||||
name: "cutdex_native/file_picker", binaryMessenger: registrar.messenger))
|
||||
}
|
||||
|
||||
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
|
||||
if call.method == "pickFiles" {
|
||||
filePicker.pickFiles(arguments: call.arguments, result: result)
|
||||
return
|
||||
}
|
||||
if call.method == "getApplicationInfo" {
|
||||
result(["appVersion": Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "unknown",
|
||||
"appBuild": Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "unknown"])
|
||||
|
||||
+2
-1
@@ -304,7 +304,8 @@ open class CutdexNativeWindow: NSWindow {
|
||||
target.mouseDown(with: event)
|
||||
return
|
||||
}
|
||||
if top >= 0, top < headerHeight, point.x >= 88 {
|
||||
// Matches the Flutter reservation for the native button group (x=0...68).
|
||||
if top >= 0, top < headerHeight, point.x >= 68 {
|
||||
if event.clickCount == 2 {
|
||||
switch UserDefaults.standard.string(forKey: "AppleActionOnDoubleClick") {
|
||||
case "Minimize": miniaturize(nil)
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
import Cocoa
|
||||
import FlutterMacOS
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
final class NativeFilePickerBridge {
|
||||
private weak var view: NSView?
|
||||
private var activePanel: NSOpenPanel?
|
||||
private let makePanel: () -> NSOpenPanel
|
||||
|
||||
init(view: NSView, makePanel: @escaping () -> NSOpenPanel = { NSOpenPanel() }) {
|
||||
self.view = view
|
||||
self.makePanel = makePanel
|
||||
}
|
||||
|
||||
func pickFiles(arguments: Any?, result: @escaping FlutterResult) {
|
||||
DispatchQueue.main.async { [self] in
|
||||
guard activePanel == nil else {
|
||||
return result(FlutterError(code: "picker_active",
|
||||
message: "A file selection is already open.", details: nil))
|
||||
}
|
||||
guard let window = view?.window else {
|
||||
return result(FlutterError(code: "window_unavailable",
|
||||
message: "The file picker requires a host window.", details: nil))
|
||||
}
|
||||
guard window.attachedSheet == nil else {
|
||||
return result(FlutterError(code: "picker_active",
|
||||
message: "The host window already has an open sheet.", details: nil))
|
||||
}
|
||||
guard let args = arguments as? [String: Any],
|
||||
let extensions = args["allowedExtensions"] as? [String] else {
|
||||
return result(FlutterError(code: "invalid_args",
|
||||
message: "File extensions are required.", details: nil))
|
||||
}
|
||||
let panel = makePanel()
|
||||
panel.canChooseFiles = true
|
||||
panel.canChooseDirectories = false
|
||||
panel.allowsMultipleSelection = true
|
||||
panel.canCreateDirectories = false
|
||||
let types = extensions.compactMap { UTType(filenameExtension: $0) }
|
||||
if !types.isEmpty {
|
||||
panel.allowedContentTypes = types
|
||||
panel.allowsOtherFileTypes = false
|
||||
}
|
||||
activePanel = panel
|
||||
// An owned, asynchronous sheet stays with the editor, including fullscreen,
|
||||
// without entering runModal's nested application event loop.
|
||||
panel.beginSheetModal(for: window) { [self, panel] response in
|
||||
DispatchQueue.main.async { [self, panel] in
|
||||
activePanel = nil
|
||||
result(response == .OK ? panel.urls.map { $0.path } : nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import Cocoa
|
||||
import FlutterMacOS
|
||||
|
||||
final class TestOpenPanel: NSOpenPanel {
|
||||
var owner: NSWindow?
|
||||
var reply: ((NSApplication.ModalResponse) -> Void)?
|
||||
override var urls: [URL] { [URL(fileURLWithPath: "/tmp/a b.mp4")] }
|
||||
override func beginSheetModal(for window: NSWindow,
|
||||
completionHandler handler: @escaping (NSApplication.ModalResponse) -> Void) {
|
||||
owner = window
|
||||
reply = handler
|
||||
}
|
||||
override func runModal() -> NSApplication.ModalResponse {
|
||||
fatalError("The picker must not block the application event loop")
|
||||
}
|
||||
}
|
||||
|
||||
@main
|
||||
struct FilePickerTest {
|
||||
static func main() {
|
||||
_ = NSApplication.shared
|
||||
let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 640, height: 480),
|
||||
styleMask: [.titled], backing: .buffered, defer: false)
|
||||
let view = NSView()
|
||||
window.contentView = view
|
||||
let panel = TestOpenPanel()
|
||||
let picker = NativeFilePickerBridge(view: view, makePanel: { panel })
|
||||
let args = ["allowedExtensions": ["mp4", "wav"]]
|
||||
|
||||
func waitUntil(_ condition: () -> Bool) {
|
||||
let deadline = Date().addingTimeInterval(2)
|
||||
while !condition(), Date() < deadline {
|
||||
RunLoop.current.run(until: Date().addingTimeInterval(0.01))
|
||||
}
|
||||
precondition(condition(), "The asynchronous picker did not respond")
|
||||
}
|
||||
|
||||
var replies = 0
|
||||
var selected: [String]?
|
||||
picker.pickFiles(arguments: args) { result in
|
||||
replies += 1
|
||||
selected = result as? [String]
|
||||
}
|
||||
waitUntil { panel.reply != nil }
|
||||
precondition(panel.owner === window && replies == 0)
|
||||
precondition(panel.canChooseFiles && !panel.canChooseDirectories)
|
||||
precondition(panel.allowsMultipleSelection && !panel.allowedContentTypes.isEmpty)
|
||||
var duplicateError: FlutterError?
|
||||
picker.pickFiles(arguments: args) { duplicateError = $0 as? FlutterError }
|
||||
waitUntil { duplicateError != nil }
|
||||
precondition(duplicateError?.code == "picker_active" && replies == 0)
|
||||
// Completion may arrive from AppKit off the main queue.
|
||||
let reply = panel.reply!
|
||||
DispatchQueue.global().async { reply(.OK) }
|
||||
waitUntil { replies == 1 }
|
||||
precondition(selected == ["/tmp/a b.mp4"])
|
||||
|
||||
panel.reply = nil
|
||||
picker.pickFiles(arguments: args) { result in
|
||||
precondition(Thread.isMainThread && result == nil)
|
||||
replies += 1
|
||||
}
|
||||
waitUntil { panel.reply != nil }
|
||||
panel.reply?(.cancel)
|
||||
waitUntil { replies == 2 }
|
||||
|
||||
let detached = NSView()
|
||||
let orphanPicker = NativeFilePickerBridge(view: detached)
|
||||
var missingWindowError: FlutterError?
|
||||
orphanPicker.pickFiles(arguments: args) { missingWindowError = $0 as? FlutterError }
|
||||
waitUntil { missingWindowError != nil }
|
||||
precondition(missingWindowError?.code == "window_unavailable")
|
||||
print("Native file picker ownership, asynchronous completion, cancellation and busy guards passed")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
task_root=$(cd "$(dirname "$0")/../.." && pwd)
|
||||
task_workspace_root=$(cd "$task_root/../.." && pwd)
|
||||
task_framework_dir=${1:-"$task_workspace_root/build/macos/Build/Products/Debug-development"}
|
||||
task_test_dir=$(mktemp -d)
|
||||
trap 'rm -rf "$task_test_dir"' EXIT HUP INT TERM
|
||||
|
||||
xcrun swiftc -F "$task_framework_dir" -framework FlutterMacOS -framework Cocoa \
|
||||
-Xlinker -rpath -Xlinker "$task_framework_dir" \
|
||||
"$task_root/macos/cutdex_native/Sources/cutdex_native/NativeFilePickerBridge.swift" \
|
||||
"$task_root/tool/macos/file_picker_test.swift" \
|
||||
-o "$task_test_dir/file-picker"
|
||||
"$task_test_dir/file-picker"
|
||||
Reference in new issue
Block a user