Files
lingjhf 27e77fff39 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.
2026-10-05 23:36:23 +08:00

56 lines
2.1 KiB
Swift

import Cocoa
import FlutterMacOS
@main
class AppDelegate: FlutterAppDelegate {
private var lifecycleChannel: FlutterMethodChannel?
private var flutterReady = false
private var preparingToQuit = false
func configureLifecycle(messenger: FlutterBinaryMessenger) {
let channel = FlutterMethodChannel(name: "cutdex/lifecycle", binaryMessenger: messenger)
lifecycleChannel = channel
channel.setMethodCallHandler { [weak self] call, result in
if call.method == "ready" {
self?.flutterReady = true
result(nil)
} else {
result(FlutterMethodNotImplemented)
}
}
}
// Sparkle's install/relaunch and ordinary Quit both pass through this gate.
// Never terminate on a failed save or a missing Flutter response.
override func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
guard flutterReady, let channel = lifecycleChannel else { return .terminateCancel }
guard !preparingToQuit else { return .terminateLater }
preparingToQuit = true
channel.invokeMethod("prepareToQuit", arguments: nil) { [weak self] response in
guard let self else { return }
self.preparingToQuit = false
let ready = response as? Bool == true
if !ready {
let alert = NSAlert()
let busy = (response as? FlutterError)?.code == "workspaceBusy"
let chinese = Bundle.main.preferredLocalizations.first?.hasPrefix("zh") == true
alert.messageText = chinese ? "暂时无法退出 Cutdex" : "Cutdex cannot quit yet"
alert.informativeText = busy
? (chinese ? "请等待后台任务完成后重试。" : "Wait for background tasks to finish, then try again.")
: (chinese ? "项目未能安全保存,请重试。" : "The project could not be saved safely. Please try again.")
alert.runModal()
}
sender.reply(toApplicationShouldTerminate: ready)
}
return .terminateLater
}
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
}
override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
return true
}
}