feat: initial Cutdex application

Add the Flutter video editing application with project management, media
import, timeline editing, preview, AI assistance, diagnostics and settings.

Include shared UI and native host packages, platform runners, application
tests and release tooling.

Provide usage and contribution guides, the MIT license and third-party
notices. Exclude local credentials, build outputs and validation data.
This commit is contained in:
lingjhf committed 2026-10-05 23:36:23 +08:00
commit 27e77fff39
718 files changed
+183958

No files matched your search

@@ -0,0 +1,43 @@
import Cocoa
import FlutterMacOS
@main
struct FileDropPolicyTests {
static func main() throws {
let files = FileManager.default
let root = files.temporaryDirectory.appendingPathComponent(UUID().uuidString)
try files.createDirectory(at: root, withIntermediateDirectories: true)
defer { try? files.removeItem(at: root) }
let file = root.appendingPathComponent("input.WAV")
try Data([0]).write(to: file)
let directory = root.appendingPathComponent("directory.wav")
try files.createDirectory(at: directory, withIntermediateDirectories: true)
let missing = root.appendingPathComponent("missing.wav")
let unrestricted = NativeFileDropPolicy(arguments: [
"allowedExtensions": NSNull(), "maximumFileCount": NSNull()
])!
let audio = NativeFileDropPolicy(arguments: [
"allowedExtensions": ["wav"], "maximumFileCount": 1
])!
var failures = 0
func check(_ condition: Bool, _ label: String) {
if !condition {
failures += 1
fputs("FAIL: \(label)\n", stderr)
}
}
check(audio.accepts([file]), "existing file with uppercase extension")
check(unrestricted.accepts([file]), "existing file without extension restrictions")
check(!audio.accepts([directory]), "directory with a permitted extension")
check(!unrestricted.accepts([directory]), "directory without extension restrictions")
check(!audio.accepts([missing]), "missing file with a permitted extension")
check(!unrestricted.accepts([missing]), "missing file without extension restrictions")
check(!audio.accepts([file, file]), "file count limit")
check(!audio.accepts([]), "empty input")
check(!unrestricted.accepts([URL(string: "https://example.com/input.wav")!]), "non-file URL")
try files.removeItem(at: file)
check(!audio.accepts([file]), "file deleted after entering the drop destination")
if failures > 0 { exit(1) }
print("Native file drop policy passed")
}
}
@@ -0,0 +1,88 @@
import Cocoa
import FlutterMacOS
// The harness exercises a window without initializing plugins or showing it.
final class HiddenTestWindow: CutdexNativeWindow {
var emptyDrags = 0
override var isKeyWindow: Bool { true }
override func performDrag(with event: NSEvent) {
if isMovable {
emptyDrags += 1
return // Observe the explicit native drag entry without a blocking tracking loop.
}
super.performDrag(with: event)
}
override func makeKeyAndOrderFront(_ sender: Any?) {}
}
final class BubblingControlView: NSView {
var downs = 0
var drags = 0
var ups = 0
override func mouseDown(with event: NSEvent) {
downs += 1
precondition(window?.isMovable == false)
// Exercise responder fallback and direct native actions during the gesture.
window?.mouseDown(with: event)
window?.performZoom(nil)
window?.zoom(nil)
window?.performDrag(with: event)
}
override func mouseDragged(with event: NSEvent) {
drags += 1
precondition(window?.isMovable == false)
window?.mouseDragged(with: event)
window?.performDrag(with: event)
}
override func mouseUp(with event: NSEvent) {
ups += 1
precondition(window?.isMovable == false)
window?.mouseUp(with: event)
}
}
@main
struct HeaderGestureTest {
static func main() {
_ = NSApplication.shared
let window = HiddenTestWindow(contentRect: NSRect(x: 100, y: 100, width: 640, height: 480),
styleMask: [.titled, .closable, .miniaturizable, .resizable], backing: .buffered, defer: false)
let control = BubblingControlView(frame: NSRect(x: 0, y: 0, width: 640, height: 480))
let controller = NSViewController()
controller.view = control
window.contentViewController = controller
window.isMovable = true
window.isMovableByWindowBackground = true
window.configureChrome(true)
window.headerControlRegions["control"] = NSRect(x: 88, y: 0, width: 140, height: 40)
precondition(!window.isMovable && !window.isMovableByWindowBackground)
let original = window.frame
func event(_ type: NSEvent.EventType, x: CGFloat, top: CGFloat, clicks: Int = 1) -> NSEvent {
let view = window.contentView!
let p = NSPoint(x: x, y: view.isFlipped ? top : view.bounds.height - top)
return NSEvent.mouseEvent(with: type, location: view.convert(p, to: nil),
modifierFlags: [], timestamp: ProcessInfo.processInfo.systemUptime,
windowNumber: window.windowNumber, context: nil, eventNumber: 0,
clickCount: clicks, pressure: 1)!
}
window.sendEvent(event(.leftMouseDown, x: 110, top: 20))
// A route change caused by the press must not release native protection.
window.configureChrome(true)
window.sendEvent(event(.leftMouseDragged, x: 400, top: 150))
window.sendEvent(event(.leftMouseUp, x: 400, top: 150))
precondition(!window.isMovable)
precondition(window.frame == original)
window.sendEvent(event(.leftMouseDown, x: 110, top: 20, clicks: 2))
window.sendEvent(event(.leftMouseUp, x: 110, top: 20, clicks: 2))
precondition(!window.isMovable)
precondition(window.frame == original)
precondition(control.downs == 2 && control.drags == 1 && control.ups == 2)
precondition(window.emptyDrags == 0)
window.sendEvent(event(.leftMouseDown, x: 400, top: 20))
precondition(window.emptyDrags == 1)
precondition(!window.isMovable)
window.configureChrome(false)
precondition(window.isMovable && window.isMovableByWindowBackground)
print("Native header control gestures passed")
}
}
@@ -0,0 +1,25 @@
#!/bin/sh
set -eu
if [ "$#" -eq 1 ] && { [ "$1" = "--help" ] || [ "$1" = "-h" ]; }; then
echo "Usage: $0 [flutter-framework-directory]"
exit 0
fi
if [ "$#" -gt 1 ]; then
echo "Usage: $0 [flutter-framework-directory]" >&2
exit 2
fi
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/NativeBridges.swift" \
"$task_root/tool/macos/file_drop_policy_test.swift" \
-o "$task_test_dir/file-drop-policy"
"$task_test_dir/file-drop-policy"
@@ -0,0 +1,25 @@
#!/bin/sh
set -eu
if [ "$#" -eq 1 ] && { [ "$1" = "--help" ] || [ "$1" = "-h" ]; }; then
echo "Usage: $0 [flutter-framework-directory]"
exit 0
fi
if [ "$#" -gt 1 ]; then
echo "Usage: $0 [flutter-framework-directory]" >&2
exit 2
fi
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/CutdexNativeWindow.swift" \
"$task_root/tool/macos/header_control_gestures_test.swift" \
-o "$task_test_dir/header-gestures"
"$task_test_dir/header-gestures"
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.14)
project(window_chrome_tests LANGUAGES CXX)
set(PACKAGE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../..")
set(NATIVE_SOURCES "${PACKAGE_ROOT}/windows")
set(WRAPPER "${PACKAGE_ROOT}/../../windows/flutter/ephemeral/cpp_client_wrapper")
if(NOT EXISTS "${WRAPPER}/standard_codec.cc")
message(FATAL_ERROR "Run flutter build windows once to prepare the Flutter wrapper")
endif()
add_executable(window_chrome_tests
"window_chrome_tests.cpp" "${NATIVE_SOURCES}/window_chrome.cpp" "${WRAPPER}/standard_codec.cc"
"${WRAPPER}/core_implementations.cc")
target_include_directories(window_chrome_tests PRIVATE "${NATIVE_SOURCES}" "${WRAPPER}/include" "${WRAPPER}/..")
target_compile_features(window_chrome_tests PRIVATE cxx_std_17)
target_compile_definitions(window_chrome_tests PRIVATE UNICODE _UNICODE NOMINMAX)
target_compile_options(window_chrome_tests PRIVATE /W4 /WX /wd4100 /EHsc)
target_link_libraries(window_chrome_tests PRIVATE dwmapi comctl32 "${WRAPPER}/../flutter_windows.dll.lib")
add_custom_command(TARGET window_chrome_tests POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${WRAPPER}/../flutter_windows.dll" "$<TARGET_FILE_DIR:window_chrome_tests>")
enable_testing()
add_test(NAME window_chrome COMMAND window_chrome_tests)
@@ -0,0 +1,227 @@
#include "window_chrome.h"
#include <flutter/standard_method_codec.h>
#include <windowsx.h>
#include <cstdlib>
#include <iostream>
#include <vector>
namespace {
using Value = flutter::EncodableValue;
using Map = flutter::EncodableMap;
int checks = 0;
void Check(bool condition, const char* message) {
++checks;
if (!condition) { std::cerr << "FAIL: " << message << '\n'; std::exit(1); }
}
class Messenger : public flutter::BinaryMessenger {
public:
std::map<std::string, flutter::BinaryMessageHandler> handlers;
mutable std::vector<std::string> notifications;
void Send(const std::string&, const uint8_t* bytes, size_t size,
flutter::BinaryReply reply) const override {
auto call = flutter::StandardMethodCodec::GetInstance().DecodeMethodCall(bytes, size);
notifications.push_back(call->method_name());
}
void SetMessageHandler(const std::string& channel,
flutter::BinaryMessageHandler handler) override {
handlers[channel] = std::move(handler);
}
void Call(const char* channel, const char* method, Value args) {
const auto bytes = flutter::StandardMethodCodec::GetInstance().EncodeMethodCall(
flutter::MethodCall<Value>(method, std::make_unique<Value>(std::move(args))));
bool success = false;
handlers.at(channel)(bytes->data(), bytes->size(),
[&](const uint8_t* data, size_t size) { success = size > 0 && data[0] == 0; });
Check(success, method);
}
};
WindowChrome* chrome = nullptr;
HWND view = nullptr;
LRESULT CALLBACK WindowProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) {
if (chrome) {
auto result = chrome->HandleMessage(message, wparam, lparam);
if (result) return *result;
}
if (message == WM_GETMINMAXINFO) {
DefWindowProc(window, message, wparam, lparam);
const auto dpi = static_cast<int>(GetDpiForWindow(window));
auto limits = reinterpret_cast<MINMAXINFO*>(lparam);
limits->ptMinTrackSize.x = MulDiv(520, dpi, 96);
limits->ptMinTrackSize.y = MulDiv(360, dpi, 96);
return 0;
}
if (message == WM_SIZE && view) {
RECT rect{};
GetClientRect(window, &rect);
MoveWindow(view, 0, 0, rect.right, rect.bottom, FALSE);
return 0;
}
return DefWindowProc(window, message, wparam, lparam);
}
LPARAM Position(HWND window, double x, double y) {
const double scale = GetDpiForWindow(window) / 96.0;
POINT point{static_cast<LONG>(x * scale), static_cast<LONG>(y * scale)};
ClientToScreen(window, &point);
return MAKELPARAM(point.x, point.y);
}
void Configure(Messenger& messenger, bool enabled = true, bool intercept_close = false) {
messenger.Call("cutdex_native/window", "configureChrome", Value(Map{
{Value("enabled"), Value(enabled)}, {Value("headerHeight"), Value(46.0)},
{Value("interceptClose"), Value(intercept_close)}}));
}
void ReportControl(Messenger& messenger, const char* id, double x, double width,
const char* role = "control") {
messenger.Call("cutdex_native/window_controls", "setHeaderControlRegion", Value(Map{
{Value("id"), Value(id)}, {Value("role"), Value(role)},
{Value("rect"), Value(Map{
{Value("x"), Value(x)}, {Value("y"), Value(0.0)},
{Value("width"), Value(width)}, {Value("height"), Value(46.0)}})}}));
}
} // namespace
int main() {
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
WNDCLASS window_class{};
window_class.lpfnWndProc = WindowProc;
window_class.hInstance = GetModuleHandle(nullptr);
window_class.lpszClassName = L"CutdexChromeTest";
RegisterClass(&window_class);
const HWND window = CreateWindow(window_class.lpszClassName, L"Chrome test",
WS_OVERLAPPEDWINDOW, -350, -100, 900, 600, nullptr, nullptr,
window_class.hInstance, nullptr);
Check(window != nullptr, "create window at negative screen coordinates");
WNDCLASS view_class{};
view_class.lpfnWndProc = DefWindowProc;
view_class.hInstance = window_class.hInstance;
view_class.lpszClassName = L"CutdexChromeTestView";
RegisterClass(&view_class);
view = CreateWindow(view_class.lpszClassName, L"", WS_CHILD | WS_VISIBLE, 0, 0, 800, 500, window,
nullptr, window_class.hInstance, nullptr);
Messenger messenger;
auto owner = std::make_unique<WindowChrome>(window, view, &messenger);
chrome = owner.get();
Configure(messenger);
const LONG_PTR style = GetWindowLongPtr(window, GWL_STYLE);
Check((style & WS_THICKFRAME) != 0 && (style & WS_SYSMENU) != 0 &&
(style & WS_MAXIMIZEBOX) != 0, "retain Windows frame and commands");
Check(SendMessage(window, WM_NCHITTEST, 0, Position(view, 300, 22)) == HTCAPTION,
"empty header drags");
Check(SendMessage(view, WM_NCHITTEST, 0, Position(view, 300, 22)) == HTTRANSPARENT,
"Flutter child passes native header hits to parent");
Check(SendMessage(window, WM_NCHITTEST, 0, Position(view, 300, 100)) == HTCLIENT,
"body stays in Flutter");
messenger.Call("cutdex_native/window_controls", "setHeaderControlRegion", Value(Map{
{Value("id"), Value("button")}, {Value("rect"), Value(Map{
{Value("x"), Value(270.0)}, {Value("y"), Value(0.0)},
{Value("width"), Value(60.0)}, {Value("height"), Value(46.0)}})}}));
Check(SendMessage(window, WM_NCHITTEST, 0, Position(view, 300, 22)) == HTCLIENT,
"buttons and inputs do not drag");
Check(SendMessage(view, WM_NCHITTEST, 0, Position(view, 300, 22)) != HTTRANSPARENT,
"Flutter child keeps control hits");
messenger.Call("cutdex_native/window_controls", "setHeaderControlRegion", Value(Map{
{Value("id"), Value("button")}, {Value("rect"), Value()}}));
Check(SendMessage(window, WM_NCHITTEST, 0, Position(view, 300, 22)) == HTCAPTION,
"disposed control removes its exclusion");
RECT client{};
GetClientRect(view, &client);
const double width = client.right * 96.0 / GetDpiForWindow(window);
Check(SendMessage(window, WM_NCHITTEST, 0, Position(view, width - 69, 22)) == HTCAPTION,
"no guessed caption hit targets before Flutter reports bounds");
// Deliberately differ from the current UI's 46-pixel buttons. Win32 must use
// the reported geometry, even if button widths or their positions change.
ReportControl(messenger, "minimize", width - 218, 68);
ReportControl(messenger, "maximize", width - 150, 74, "maximize");
ReportControl(messenger, "close", width - 76, 76);
LPARAM max_position = Position(view, width - 113, 22);
Check(SendMessage(window, WM_NCHITTEST, 0, max_position) == HTMAXBUTTON,
"maximize advertises Snap Layouts hit target");
Check(SendMessage(view, WM_NCHITTEST, 0, max_position) == HTTRANSPARENT,
"maximize hit reaches native parent");
ReportControl(messenger, "a-clipped-control", width - 150, 74);
Check(SendMessage(window, WM_NCHITTEST, 0, max_position) == HTMAXBUTTON,
"maximize takes precedence over overlapping workspace control bounds");
messenger.Call("cutdex_native/window_controls", "setHeaderControlRegion", Value(Map{
{Value("id"), Value("a-clipped-control")}, {Value("rect"), Value()}}));
Check(SendMessage(window, WM_NCHITTEST, 0, Position(view, width - 23, 22)) == HTCLIENT,
"close button stays in Flutter");
Check(SendMessage(window, WM_NCHITTEST, 0, Position(view, width - 184, 22)) == HTCLIENT,
"minimize button stays in Flutter");
Check(SendMessage(window, WM_NCHITTEST, 0, Position(view, width - 69, 22)) == HTCLIENT,
"old hardcoded maximize slot is a reported close control");
ReportControl(messenger, "maximize", width - 310, 74, "maximize");
Check(SendMessage(window, WM_NCHITTEST, 0, max_position) == HTCAPTION,
"moving the maximize button removes its old hit target");
max_position = Position(view, width - 273, 22);
Check(SendMessage(window, WM_NCHITTEST, 0, max_position) == HTMAXBUTTON,
"moving the maximize button updates its native hit target");
ReportControl(messenger, "maximize", width - 310, 74);
Check(SendMessage(window, WM_NCHITTEST, 0, max_position) == HTCLIENT,
"a changed role updates hit behavior without moving the control");
ReportControl(messenger, "maximize", width - 310, 74, "maximize");
RECT bounds{};
GetWindowRect(window, &bounds);
Check(SendMessage(window, WM_NCHITTEST, 0, MAKELPARAM(bounds.left + 1, bounds.top + 1)) == HTTOPLEFT,
"top-left edge resizes");
Check(SendMessage(window, WM_NCHITTEST, 0, MAKELPARAM(bounds.right - 1, bounds.bottom - 1)) == HTBOTTOMRIGHT,
"bottom-right edge resizes");
Check(SendMessage(window, WM_NCHITTEST, 0, MAKELPARAM(bounds.left + 100, bounds.top + 1)) == HTTOP,
"top edge resizes");
messenger.Call("cutdex_native/window", "setHeaderInteractive", Value(false));
Check(SendMessage(window, WM_NCHITTEST, 0, Position(view, 300, 22)) == HTCLIENT,
"modal route blocks native header drag");
Check(SendMessage(window, WM_NCHITTEST, 0, max_position) == HTCLIENT,
"modal route blocks maximize hit target");
messenger.Call("cutdex_native/window", "setHeaderInteractive", Value(true));
SendMessage(window, WM_NCLBUTTONDOWN, HTMAXBUTTON, max_position);
Check(GetCapture() == window, "maximize captures the press");
SendMessage(window, WM_CANCELMODE, 0, 0);
ReleaseCapture();
Check(!IsZoomed(window), "cancelled maximize press leaves state unchanged");
POINT max_point{GET_X_LPARAM(max_position), GET_Y_LPARAM(max_position)};
ScreenToClient(window, &max_point);
SendMessage(window, WM_NCLBUTTONDOWN, HTMAXBUTTON, max_position);
SendMessage(window, WM_LBUTTONUP, 0, MAKELPARAM(max_point.x, max_point.y));
ShowWindow(window, SW_HIDE);
Check(IsZoomed(window) != FALSE, "native maximize mouse press and release");
SendMessage(window, WM_NCLBUTTONDBLCLK, HTCAPTION, Position(view, 300, 22));
ShowWindow(window, SW_HIDE);
Check(!IsZoomed(window), "double-click empty caption restores");
messenger.Call("cutdex_native/window", "toggleMaximize", Value());
ShowWindow(window, SW_HIDE);
Check(IsZoomed(window) != FALSE, "maximize command");
RECT max_bounds{}, max_client{};
GetWindowRect(window, &max_bounds);
GetClientRect(window, &max_client);
POINT origin{};
ClientToScreen(window, &origin);
Check(origin.y > max_bounds.top, "maximized client avoids invisible top frame");
Check(SendMessage(window, WM_NCHITTEST, 0, Position(view, 300, 1)) == HTCAPTION,
"maximized top is caption instead of resize");
messenger.Call("cutdex_native/window", "toggleMaximize", Value());
ShowWindow(window, SW_HIDE);
Check(!IsZoomed(window), "restore command");
MINMAXINFO limits{};
SendMessage(window, WM_GETMINMAXINFO, 0, reinterpret_cast<LPARAM>(&limits));
Check(limits.ptMinTrackSize.x == MulDiv(520, static_cast<int>(GetDpiForWindow(window)), 96) &&
limits.ptMinTrackSize.y == MulDiv(360, static_cast<int>(GetDpiForWindow(window)), 96),
"host minimum size survives native chrome and follows monitor DPI");
Configure(messenger, true, true);
const auto before = messenger.notifications.size();
SendMessage(window, WM_CLOSE, 0, 0);
Check(IsWindow(window) && messenger.notifications.size() == before + 1 &&
messenger.notifications.back() == "requestClose", "close callback is intercepted");
Configure(messenger, false);
POINT standard_origin{};
ClientToScreen(window, &standard_origin);
GetWindowRect(window, &bounds);
Check(standard_origin.y > bounds.top, "disable restores system titlebar");
chrome = nullptr;
owner.reset();
Check(!messenger.handlers["cutdex_native/window"] &&
!messenger.handlers["cutdex_native/window_controls"], "channel handlers unregister");
view = nullptr;
DestroyWindow(window);
std::cout << checks << " native window checks passed at " << GetDpiForSystem() << " DPI\n";
}