mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-11-29 09:11:17 +01:00
- New "Floating window (Picture-in-Picture)" overlay setting (iOS 16+). Default follows the per-device auto behavior (on for iPad / non-DI iPhones, off for Dynamic-Island iPhones); DI-iPhone users can opt in. The Live Activity keeps running alongside it (additive). - iPad: start PiP immediately on activation (foreground) instead of only when backgrounded — there's screen room (DeviceCapabilities.prefersForegroundPip + scheduleForegroundStart poll). - DeviceCapabilities.isPipCapable (any iOS 16+ PiP device) + bike_control/pip_ios "isCapable"; settings.getOverlayUsePip/setOverlayUsePip; show() resolves the preference. - requiresLinearPlayback = true to drop the PiP skip/scrub (next/prev) controls (it's a live HUD; central play/pause is system chrome, harmless no-op). - overlayUsePip + overlayUsePipSubtitle in all 6 languages; changelog updated. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
136 lines
4.7 KiB
Swift
136 lines
4.7 KiB
Swift
import Flutter
|
|
import UIKit
|
|
|
|
@main
|
|
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
|
|
/// Channel that delivers Live Activity button taps from the Widget
|
|
/// Extension into the main Flutter engine. `IosOverlayController` registers
|
|
/// a MethodCallHandler on this channel; native code below forwards Darwin
|
|
/// notifications posted by the extension's `AppIntent`s.
|
|
private static let overlayActionsChannel = "bike_control/overlay_actions_ios"
|
|
private static let pipChannelName = "bike_control/pip_ios"
|
|
|
|
private var actionChannel: FlutterMethodChannel?
|
|
private var pipChannel: FlutterMethodChannel?
|
|
|
|
override func application(
|
|
_ application: UIApplication,
|
|
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
|
|
) -> Bool {
|
|
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
|
|
|
|
// The Darwin observer can be registered before the Flutter engine exists.
|
|
// Invocations are guarded by `actionChannel != nil`; we just queue work
|
|
// until the channel is wired up in `didInitializeImplicitFlutterEngine`.
|
|
registerOverlayActionObservers()
|
|
|
|
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
|
|
}
|
|
|
|
func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
|
|
GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
|
|
|
|
// Scene-based apps don't expose a FlutterViewController via AppDelegate's
|
|
// `window` (the scene delegate owns the window), so wire the MethodChannel
|
|
// off the implicit engine's plugin registry instead — that's where the
|
|
// binary messenger lives in this lifecycle.
|
|
if actionChannel == nil,
|
|
let registrar = engineBridge.pluginRegistry.registrar(forPlugin: "BikeControlOverlayActions") {
|
|
actionChannel = FlutterMethodChannel(
|
|
name: AppDelegate.overlayActionsChannel,
|
|
binaryMessenger: registrar.messenger()
|
|
)
|
|
}
|
|
|
|
if pipChannel == nil,
|
|
let registrar = engineBridge.pluginRegistry.registrar(forPlugin: "BikeControlPip") {
|
|
let channel = FlutterMethodChannel(
|
|
name: AppDelegate.pipChannelName,
|
|
binaryMessenger: registrar.messenger()
|
|
)
|
|
channel.setMethodCallHandler { call, result in
|
|
switch call.method {
|
|
case "isSupported":
|
|
if #available(iOS 16.0, *) {
|
|
result(DeviceCapabilities.pipEligible)
|
|
} else {
|
|
result(false)
|
|
}
|
|
case "isCapable":
|
|
if #available(iOS 16.0, *) {
|
|
result(DeviceCapabilities.isPipCapable)
|
|
} else {
|
|
result(false)
|
|
}
|
|
case "start":
|
|
if #available(iOS 16.0, *) {
|
|
PipGearController.shared.start(initial: call.arguments as? [String: Any] ?? [:])
|
|
}
|
|
result(nil)
|
|
case "update":
|
|
if #available(iOS 16.0, *) {
|
|
PipGearController.shared.update(call.arguments as? [String: Any] ?? [:])
|
|
}
|
|
result(nil)
|
|
case "stop":
|
|
if #available(iOS 16.0, *) {
|
|
PipGearController.shared.stop()
|
|
}
|
|
result(nil)
|
|
default:
|
|
result(FlutterMethodNotImplemented)
|
|
}
|
|
}
|
|
pipChannel = channel
|
|
}
|
|
}
|
|
|
|
// MARK: - Live Activity Darwin notification bridge
|
|
|
|
private func registerOverlayActionObservers() {
|
|
let center = CFNotificationCenterGetDarwinNotifyCenter()
|
|
let observer = Unmanaged.passUnretained(self).toOpaque()
|
|
|
|
let names: [CFString] = [
|
|
"de.jonasbark.swiftcontrol.overlay.action.decrement" as CFString,
|
|
"de.jonasbark.swiftcontrol.overlay.action.increment" as CFString,
|
|
"de.jonasbark.swiftcontrol.overlay.action.stop" as CFString,
|
|
]
|
|
|
|
for name in names {
|
|
CFNotificationCenterAddObserver(
|
|
center,
|
|
observer,
|
|
{ _, observer, name, _, _ in
|
|
guard let observer = observer, let name = name else { return }
|
|
let self_ = Unmanaged<AppDelegate>.fromOpaque(observer).takeUnretainedValue()
|
|
let nameString = name.rawValue as String
|
|
let action: String
|
|
if nameString.hasSuffix("decrement") {
|
|
action = "primaryDecrement"
|
|
} else if nameString.hasSuffix("increment") {
|
|
action = "primaryIncrement"
|
|
} else if nameString.hasSuffix("stop") {
|
|
action = "stop"
|
|
} else {
|
|
return
|
|
}
|
|
DispatchQueue.main.async {
|
|
self_.actionChannel?.invokeMethod("action", arguments: action)
|
|
}
|
|
},
|
|
name,
|
|
nil,
|
|
.deliverImmediately
|
|
)
|
|
}
|
|
}
|
|
|
|
deinit {
|
|
CFNotificationCenterRemoveEveryObserver(
|
|
CFNotificationCenterGetDarwinNotifyCenter(),
|
|
Unmanaged.passUnretained(self).toOpaque()
|
|
)
|
|
}
|
|
}
|