alarm icon indicating copy to clipboard operation
alarm copied to clipboard

Alarm auto-stop feature

Open tattuu opened this issue 1 year ago • 6 comments

Sorry for the repetitiveness.

I don't think this alarm has an auto-stop feature yet.

As an example, we imagine the following approach.

final alarmSettings = AlarmSettings(
    dateTime: DateTime(2023, 3, 1, 8, 10),
    // ...
    autoStopDuration: Duration(minutes: 5), // Elapsed time from the time specified by dateTime
);

I guess I could throw a pull request on my end to shoulder the work.

However, I am not very familiar with swift, so I would be happy if you use it only as a reference when creating a pull request.

tattuu avatar Feb 28 '23 00:02 tattuu

Hi @tattuu !

Thank you so much for your suggestions ! A autoStop parameter could be totally relevant to this package.

I've been doing some research for the other issues you opened earlier it will be more difficult than I thought... The Android part is easy because it can be made with Flutter code, but the iOS part is more tricky because it looks like it's not possible to run Swift code in the background.

I'll let you know when I come up will a potential solution. I could take some time though... don't hesitate if you want to do some quick research, maybe I'm missing something.

gdelataillade avatar Feb 28 '23 04:02 gdelataillade

Hi @gdelataillade

Thanks for the reply!

Thanks for looking into it.

Understood.

If I find a good solution, I will make a comment or pull request for other issues as well.

tattuu avatar Feb 28 '23 04:02 tattuu

@gdelataillade I might have a workaround for this issue. It has some catches, but it does the work. Here's how:

The maximum alarm ID is 2 ^ 32 - 1 = 4294967295. We preserve the first half 0 to 2147483647 for scheduling the intended alarm. The second half 2147483648 to 4294967295 to schedule the alarm to cancel the previous alarm at the predefined timestamp via a callback when this "cancelling" fired.

Let say we schedule the alarm A with ID 35 for the duration of 5 mins, a cancelling alarm A' with ID (35 + 2147483648). When alarm A' fired, we will able to get both alarm A and A' IDs, and stop them both.

The catch is that alarm A' has to be silent. I can set the vibrate = false and volume = 0, but sometime alarm A' notification still display in a short moment. If you can have the option to hide the on-screen notification for an alarm. That would be great.

The second catch is that, there's a slightly chance that this canceling alarm is override with another alarm with the same timestamp. However, since you just updated the comparison down to second, there's less chance this collision happens if the app handle the case carefully.

hoangan avatar Dec 21 '23 15:12 hoangan

Hi @hoangan

Indeed, setting another alarm that will override the main one could be a temporary workaround.

Maybe some day I'll find the time to develop this feature.

gdelataillade avatar Dec 22 '23 16:12 gdelataillade

you can use timer for the auto stop feature i also used in my ring screen

singhcreations avatar Apr 25 '24 05:04 singhcreations

Another way to do it is to set loop parameter to false, then the alarm will stop ringing & vibrating when the audio is finished playing. The alarm will last 30 seconds if the audio duration is 30 seconds.

Maybe someday I'll add a more robust way to implement it.

gdelataillade avatar Apr 25 '24 11:04 gdelataillade