import 'package:flutter/services.dart'; /// Dart side of the single MethodChannel the Kotlin ring path exposes. /// /// One channel for the whole feature (see `AlarmChannel.kt`): the alarm must /// never depend on a pub plugin compiling against AGP 9. class AlarmScheduler { /// Creates a scheduler; [channel] is injectable so tests need no platform. AlarmScheduler({MethodChannel? channel}) : _channel = channel ?? const MethodChannel(channelName); /// Channel name, matching `AlarmActivity.CHANNEL` on the Kotlin side. static const String channelName = 'com.kuhy.wake_alarm_sync/alarm'; final MethodChannel _channel; /// Arms the alarm for the next occurrence of [hour]:[minute] in local time. /// /// The phone rings **daily**, matching the PC's `ALARM_DAYS` which is /// currently all seven days. The two are deliberately not synced — a shared /// day set is item 8's shape, and diverging defaults would have the halves /// firing on different days. Future schedule(int hour, int minute) => _channel.invokeMethod('schedule', { 'hour': hour, 'minute': minute, }); /// Cancels the armed alarm and forgets the stored time. Future cancel() => _channel.invokeMethod('cancel'); /// Re-arms from the stored time; false when no alarm was ever set. /// /// Called from the app's init seam because the store has no change stream: /// without this, an app restart that does not touch the picker would leave /// nothing armed. Future rearm() async => await _channel.invokeMethod('rearm') ?? false; /// Stops the ring and immediately re-arms for tomorrow. Future dismiss() => _channel.invokeMethod('dismiss'); /// Whether the system will honour the full-screen intent. /// /// False from API 34 unless granted. The caller must treat this as a hard /// failure: without it the alarm posts a notification the sleeper never sees. Future canUseFullScreenIntent() async => await _channel.invokeMethod('canUseFullScreenIntent') ?? false; /// Starts the ring immediately, without waiting for the alarm instant. /// /// Exists so the foreground-service and full-screen-intent path can be /// exercised on an emulator; it arms nothing and changes no stored time. Future ringNow() => _channel.invokeMethod('ringNow'); /// Captures the step baseline for this ring. Future beginStepCount() => _channel.invokeMethod('beginStepCount'); /// Steps since [beginStepCount], or -1 when unavailable. Future stepsSinceRingStart() async => await _channel.invokeMethod('stepCount') ?? -1; }