Skip to content

Commit

Permalink
Release 1.0.21+40
Browse files Browse the repository at this point in the history
  • Loading branch information
kmac committed Nov 21, 2021
1 parent e750467 commit b08906c
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 38 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
57 changes: 29 additions & 28 deletions lib/components/alarmservice.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ Future<bool> 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, "
Expand Down Expand Up @@ -81,7 +80,31 @@ Future<void> 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
//
Expand Down Expand Up @@ -139,27 +162,6 @@ Future<void> 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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -250,6 +250,7 @@ void shutdown() {
shutdownReceivePort();
}

/// This is only available in the alarm manager isolate
Future<AlarmManagerTimerService> getAlarmManagerTimerService() async {
await initializeAlarmService();
return AlarmManagerTimerService();
Expand Down
19 changes: 10 additions & 9 deletions lib/components/scheduler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
10 changes: 10 additions & 0 deletions metadata/en-US/changelogs/40.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit b08906c

Please sign in to comment.