From b08906c2c1430b9fb2fda7f3a6ed7a01d2841080 Mon Sep 17 00:00:00 2001 From: kmac <135567+kmac@users.noreply.github.com> Date: Sun, 21 Nov 2021 14:55:51 -0600 Subject: [PATCH] Release 1.0.21+40 --- CHANGELOG.md | 11 ++++++ lib/components/alarmservice.dart | 57 ++++++++++++++++---------------- lib/components/scheduler.dart | 19 ++++++----- metadata/en-US/changelogs/40.txt | 10 ++++++ pubspec.yaml | 2 +- 5 files changed, 61 insertions(+), 38 deletions(-) create mode 100644 metadata/en-US/changelogs/40.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 4905c30..cefee26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +# 1.0.21 +- Fix UI re-init issue with recreating the initial notification + when app is revisited after being killed (either on restart + or when user uses the back button to exit instead of the + home button) + - If user presses the back button the app is killed (but + the alarm service is still running, and notifications + still occur). + - This fixes the notification being re-raised/changed + when the app is again started by the user + # 1.0.20 - Issue #35: fix service disabled on app open after close - Migrate from SharedPreferences to Hive for internal data diff --git a/lib/components/alarmservice.dart b/lib/components/alarmservice.dart index 03d036a..4f4dd70 100644 --- a/lib/components/alarmservice.dart +++ b/lib/components/alarmservice.dart @@ -33,10 +33,9 @@ Future initializeAlarmService({bool bootstrap: false}) async { return alarmServiceAlreadyRunning; } - // The underlying issue is that we can't query android alarm manager - // to see if we have outstanding alarms. - // We store the next alarm time in hive db and compare - // with current time to see if we should have an alarm scheduled + // We can't query android alarm manager to see if we have outstanding alarms. + // We store the next alarm time in hive db and compare with current time to + // see if we should have an alarm scheduled try { logger.i("initializeAlarmService initializing alarm manager, " @@ -81,7 +80,31 @@ Future initializeFromAppIsolateReceivePort() async { // Register for events from the UI isolate. These messages will // be triggered from the UI side fromAppIsolateStreamSubscription = - fromAppIsolateReceivePort.listen((map) async { + fromAppIsolateReceivePort.listen(handleAppMessage, onDone: () { + logger.w("fromAppIsolateReceivePort is closed ${getCurrentIsolate()}"); + }); + + // Register our SendPort for the app to be able to send to our ReceivePort + IsolateNameServer.removePortNameMapping(constants.toAlarmServiceSendPortName); + bool result = IsolateNameServer.registerPortWithName( + fromAppIsolateReceivePort.sendPort, + constants.toAlarmServiceSendPortName, + + ); + // if (!result) { + // IsolateNameServer.removePortNameMapping( + // constants.toSchedulerSendPortName); + // result = IsolateNameServer.registerPortWithName( + // fromAppIsolateReceivePort.sendPort, + // constants.toSchedulerSendPortName, + // ); + // } + logger.d("registerPortWithName: ${constants.toAlarmServiceSendPortName}, " + "result=$result ${getCurrentIsolate()}"); + assert(result); +} + +void handleAppMessage(dynamic map) async { // // WE ARE IN THE ALARM ISOLATE // @@ -139,27 +162,6 @@ Future initializeFromAppIsolateReceivePort() async { logger.e("Unknown key: $key"); break; } - }, onDone: () { - logger.w("fromAppIsolateReceivePort is closed ${getCurrentIsolate()}"); - }); - - // Register our SendPort for the app to be able to send to our ReceivePort - IsolateNameServer.removePortNameMapping(constants.toAlarmServiceSendPortName); - bool result = IsolateNameServer.registerPortWithName( - fromAppIsolateReceivePort.sendPort, - constants.toAlarmServiceSendPortName, - ); - // if (!result) { - // IsolateNameServer.removePortNameMapping( - // constants.toSchedulerSendPortName); - // result = IsolateNameServer.registerPortWithName( - // fromAppIsolateReceivePort.sendPort, - // constants.toSchedulerSendPortName, - // ); - // } - logger.d("registerPortWithName: ${constants.toAlarmServiceSendPortName}, " - "result=$result ${getCurrentIsolate()}"); - assert(result); } void shutdownReceivePort() async { @@ -196,8 +198,6 @@ void bootstrapCallback() async { void heartbeatCallback() async { logger.i("heartbeatCallback ${getCurrentIsolate()}"); // WE ARE IN THE ALARM MANAGER ISOLATE - // This is only available in the alarm manager isolate - getAlarmManagerTimerService(); // Create and initialize the Scheduler singleton @@ -250,6 +250,7 @@ void shutdown() { shutdownReceivePort(); } +/// This is only available in the alarm manager isolate Future getAlarmManagerTimerService() async { await initializeAlarmService(); return AlarmManagerTimerService(); diff --git a/lib/components/scheduler.dart b/lib/components/scheduler.dart index 907d7d1..fcb7320 100644 --- a/lib/components/scheduler.dart +++ b/lib/components/scheduler.dart @@ -122,17 +122,18 @@ class Scheduler { // This is the notification we only want to show on: // 1) reboot // 2) first enabled by user - // 3) re-enable after config changes by user + // 3) app is restarted after GUI is killed or exited + // 4) re-enable after config changes by user delegate.scheduleNext(restart: restart); - // sendInfoMessage( - // 'Next reminder at ${formatHHMM(delegate.queryNext())}'); - String enabledReminderText = '${constants.appName} is enabled'; - if (!ds.hideNextReminder) { - enabledReminderText += - '\n\nNext reminder at ${formatHHMM(delegate.queryNext())}'; - } - Notifier().showInfoNotification(enabledReminderText); + // if (ds.reminderMessage == ScheduleDataStoreBase.defaultReminderMessage) { + // String enabledReminderText = '${constants.appName} is enabled'; + // if (!ds.hideNextReminder) { + // enabledReminderText += + // '\n\nNext reminder at ${formatHHMM(delegate.queryNext())}'; + // } + // } ds.reminderMessage = ds.randomReminder(); + Notifier().showInfoNotification(ds.reminderMessage); sendDataStoreUpdate(); } diff --git a/metadata/en-US/changelogs/40.txt b/metadata/en-US/changelogs/40.txt new file mode 100644 index 0000000..b3766ea --- /dev/null +++ b/metadata/en-US/changelogs/40.txt @@ -0,0 +1,10 @@ +# 1.0.21 +- Fix UI re-init issue with recreating the initial notification + when app is revisited after being killed (either on restart + or when user uses the back button to exit instead of the + home button) + - If user presses the back button the app is killed (but + the alarm service is still running, and notifications + still occur). + - This fixes the notification being re-raised/changed + when the app is again started by the user diff --git a/pubspec.yaml b/pubspec.yaml index 0dc8607..2eadacc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -21,7 +21,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # This number is used only to determine whether one version is more recent than another, # with higher numbers indicating more recent versions # versionName: Customer-visible version string -version: 1.0.20+39 +version: 1.0.21+40 environment: # sdk: ">=2.12.0 <3.0.0"