Skip to content

Commit

Permalink
Release 1.0.22+42
Browse files Browse the repository at this point in the history
  • Loading branch information
kmac committed Nov 27, 2021
1 parent b08906c commit 59f97ec
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 49 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.0.22
- Fix issue where new notification is generated instead
of showing existing notification (after app is restarted).

# 1.0.21
- Fix UI re-init issue with recreating the initial notification
when app is revisited after being killed (either on restart
Expand Down
6 changes: 4 additions & 2 deletions lib/components/alarmservice.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Future<bool> initializeAlarmService({bool bootstrap: false}) async {
if (IsolateNameServer.lookupPortByName(
constants.toAlarmServiceSendPortName) !=
null) {
logger.i("initializeAlarmService bootstrap:$bootstrap, "
logger.d("initializeAlarmService bootstrap:$bootstrap, "
"already initialized: ${constants.toAlarmServiceSendPortName} "
"${getCurrentIsolate()}");
alarmServiceAlreadyRunning = true;
Expand Down Expand Up @@ -252,7 +252,9 @@ void shutdown() {

/// This is only available in the alarm manager isolate
Future<AlarmManagerTimerService> getAlarmManagerTimerService() async {
await initializeAlarmService();
if (!alarmServiceAlreadyRunning) {
await initializeAlarmService();
}
return AlarmManagerTimerService();
}

Expand Down
7 changes: 7 additions & 0 deletions lib/components/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ const String toAlarmServiceSendPortName = 'toAlarmServiceIsolate';
const String tagApplicationDocumentsDirectory = 'ApplicationDocumentsDirectory';
const String tagExternalStorageDirectory = 'ExternalStorageDirectory';
const String tagAlarmServiceAlreadyRunning = 'AlarmServiceAlreadyRunning';

// Messages
const String reminderMessageQuietHours = 'In quiet hours';
const String reminderMessageDisabled = 'Not Enabled';
const String reminderMessageWaiting = 'Enabled. Waiting for notification...';
const String infoMessageDisabled = 'Disabled';
const String infoMessageWaiting = 'Enabled. Waiting for notification.';
5 changes: 3 additions & 2 deletions lib/components/datastore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:shared_preferences/shared_preferences.dart';

import 'package:equatable/equatable.dart';

import 'package:mindfulnotifier/components/constants.dart' as constants;
import 'package:mindfulnotifier/components/logging.dart';

var logger = createLogger('datastore');
Expand Down Expand Up @@ -247,8 +248,8 @@ abstract class ScheduleDataStoreBase {
static const int defaultQuietHoursEndHour = 9;
static const int defaultQuietHoursEndMinute = 0;
static const bool defaultNotifyQuietHours = false;
static const String defaultReminderMessage = 'Not Enabled';
static const String defaultInfoMessage = 'Disabled';
static const String defaultReminderMessage = constants.reminderMessageDisabled;
static const String defaultInfoMessage = constants.infoMessageDisabled;
static const String defaultControlMessage = '';
static const String defaultTheme = 'Default';
static const String defaultBellId = 'bell1';
Expand Down
10 changes: 10 additions & 0 deletions lib/components/notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ class Notifier {
showNotification(notifText, mute: mute, vibrate: vibrate);
}

Future<bool> isNotificationActive() async {
final List<ActiveNotification> activeNotifications =
await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.getActiveNotifications();
logger.d("isNotificationActive: $activeNotifications");
return activeNotifications.length > 0;
}

void showNotification(String notifText,
{bool mute = false, bool vibrate, bool useStickyNotification}) async {
// Some reference links:
Expand Down
3 changes: 2 additions & 1 deletion lib/components/quiethours.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:mindfulnotifier/components/alarmservice.dart';
import 'package:mindfulnotifier/components/constants.dart' as constants;
import 'package:mindfulnotifier/components/logging.dart';
import 'package:mindfulnotifier/components/notifier.dart';
import 'package:mindfulnotifier/components/scheduler.dart';
Expand Down Expand Up @@ -162,7 +163,7 @@ class QuietHours {
void quietStart() async {
logger.i("Quiet hours start");
Scheduler scheduler = await Scheduler.getScheduler();
scheduler.sendReminderMessage('In quiet hours.');
scheduler.sendReminderMessage(constants.reminderMessageQuietHours);
if (notifyQuietHours) {
Notifier().showQuietHoursNotification(true);
}
Expand Down
59 changes: 23 additions & 36 deletions lib/components/scheduler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ enum ScheduleType { PERIODIC, RANDOM }

const bool rescheduleAfterQuietHours = true;
const int scheduleAlarmID = 10;
bool initialNotificationTriggered = false;

// Design notes:
/// - scheduler owns the data
Expand Down Expand Up @@ -112,7 +111,7 @@ class Scheduler {
}
}

void enable({bool restart = false}) {
Future<void> enable({bool restart = false}) async {
logger.i("enable");
ds.enabled = true;

Expand All @@ -125,51 +124,37 @@ class Scheduler {
// 3) app is restarted after GUI is killed or exited
// 4) re-enable after config changes by user
delegate.scheduleNext(restart: restart);
// 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();
if (ds.reminderMessage == constants.reminderMessageDisabled ||
ds.reminderMessage == constants.reminderMessageQuietHours ||
ds.reminderMessage == constants.reminderMessageWaiting) {
ds.reminderMessage = ds.randomReminder();
}
if (!await Notifier().isNotificationActive()) {
Notifier().showInfoNotification(ds.reminderMessage);
}
await sendDataStoreUpdate();
}

// bool enableIfNecessary() {
// if (ds.enabled) {
// if (initialNotificationTriggered) {
// logger.i("initialNotificationTriggered: not re-enabling on init");
// } else {
// logger.i("re-enabling on init");
// enable(kickSchedule: true);
// }
// return true;
// }
// return false;
// }

void disable({bool sendUpdate = true, bool restart = false}) async {
Future<void> disable({bool sendUpdate = true, bool restart = false}) async {
logger.i("disable");
delegate?.cancel();
Notifier().shutdown();
running = false;
ds.enabled = false;
ds.reminderMessage = ScheduleDataStoreBase.defaultReminderMessage;
if (!restart) {
Notifier().shutdown();
ds.reminderMessage = ScheduleDataStoreBase.defaultReminderMessage;
ds.nextAlarm = '';
}
if (sendUpdate) {
sendDataStoreUpdate();
await sendDataStoreUpdate();
}
}

void restart() {
Future<void> restart() async {
logger.i("restart");
disable(sendUpdate: false, restart: true);
sleep(Duration(milliseconds: 500));
enable(restart: true);
await disable(sendUpdate: false, restart: true);
sleep(Duration(milliseconds: 250));
await enable(restart: true);
}

void playSound(var fileOrPath) {
Expand Down Expand Up @@ -251,8 +236,10 @@ class Scheduler {
try {
if (isQuiet) {
// Note: this could happen if enabled in quiet hours:
logger.i("In quiet hours (missed alarm)... ignoring notification");
sendInfoMessage("In quiet hours ${formatHHMM(now)} NA");
logger.i(
"${constants.reminderMessageQuietHours} (missed alarm)... ignoring notification");
sendInfoMessage(
"${constants.reminderMessageQuietHours} ${formatHHMM(now)} NA");
return;
}
String reminder = ds.randomReminder();
Expand Down Expand Up @@ -311,7 +298,7 @@ abstract class DelegatedScheduler {
fromTime: quietHours.getNextQuietEnd(), adjustFromQuiet: true);
logger.i("Scheduling next reminder, past quiet hours: $_nextDate");
scheduler.sendInfoMessage(
"In quiet hours, next reminder at ${formatHHMMSS(_nextDate)}");
"${constants.reminderMessageQuietHours}, next reminder at ${formatHHMMSS(_nextDate)}");
} else {
logger.i("Scheduling next reminder at $_nextDate");
scheduler.sendInfoMessage("Next reminder at ${formatHHMMSS(_nextDate)}");
Expand Down
9 changes: 2 additions & 7 deletions lib/screens/mindfulnotifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,10 @@ class MindfulNotifierWidgetController extends GetxController {
return;
}
if (enabled) {
if (_reminderMessage.value ==
ScheduleDataStoreBase.defaultReminderMessage ||
_reminderMessage.value == 'In quiet hours') {
_reminderMessage.value = 'Enabled. Waiting for notification...';
}
_infoMessage.value = 'Enabled. Waiting for notification.';
_infoMessage.value = constants.infoMessageWaiting;
sendToAlarmService({'enable': _infoMessage.value});
} else {
_infoMessage.value = 'Disabled';
_infoMessage.value = constants.infoMessageDisabled;
sendToAlarmService({'disable': _infoMessage.value});
}
}
Expand Down
3 changes: 3 additions & 0 deletions metadata/en-US/changelogs/42.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 1.0.22
- Fix issue where new notification is generated instead
of showing existing notification (after app is restarted).
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.21+40
version: 1.0.22+42

environment:
# sdk: ">=2.12.0 <3.0.0"
Expand Down

0 comments on commit 59f97ec

Please sign in to comment.