Skip to content

Commit 6a30fd3

Browse files
committed
fix: Improve notification handling
Removed in-app alert for notifications received while the app is active. Simplified notification channel and importance settings for consistency.
1 parent a446164 commit 6a30fd3

File tree

3 files changed

+10
-46
lines changed

3 files changed

+10
-46
lines changed

android/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId "com.notask.app"
88
minSdkVersion rootProject.ext.minSdkVersion
99
targetSdkVersion rootProject.ext.targetSdkVersion
10-
versionCode 1518014
11-
versionName "15.18.14"
10+
versionCode 1518015
11+
versionName "15.18.15"
1212
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1313
aaptOptions {
1414
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"type": "module",
33
"name": "my-notes-and-tasks-modern",
4-
"version": "15.18.14",
4+
"version": "15.18.15",
55
"private": true,
66
"license": "Licensed CC BY-ND 4.0. No derivatives allowed.",
77
"scripts": {

src/services/notificationService.js

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -90,38 +90,7 @@ class NotificationService {
9090

9191
await LocalNotifications.addListener('localNotificationReceived', (notification) => {
9292
console.log('📱 Notification received while app active:', notification);
93-
94-
const extra = notification?.extra || notification?.notification?.extra;
95-
const itemTitle = extra?.originalReminder?.itemTitle || extra?.itemTitle || notification.body?.replace("Don't forget: ", "") || 'Untitled';
96-
const wasScheduledWhenVisible = extra?.scheduledWhenVisible;
97-
98-
// If this was scheduled when app was visible, it should be a silent notification
99-
// and we should always show the in-app alert
100-
if (wasScheduledWhenVisible || document.visibilityState === 'visible') {
101-
console.log('🔔 Showing in-app reminder alert for:', itemTitle);
102-
103-
// Show native alert dialog
104-
if (window.Capacitor?.Plugins?.Dialog) {
105-
try {
106-
window.Capacitor.Plugins.Dialog.alert({
107-
title: '⏰ Reminder',
108-
message: `Don't forget: ${itemTitle}`,
109-
buttonTitle: 'OK'
110-
}).then(() => {
111-
console.log('✅ Capacitor alert shown successfully');
112-
}).catch((error) => {
113-
console.error('❌ Capacitor alert failed, using browser alert:', error);
114-
alert(`⏰ Reminder: Don't forget: ${itemTitle}`);
115-
});
116-
} catch (error) {
117-
console.error('❌ Capacitor alert failed, using browser alert:', error);
118-
alert(`⏰ Reminder: Don't forget: ${itemTitle}`);
119-
}
120-
} else {
121-
// Fallback to browser alert
122-
alert(`⏰ Reminder: Don't forget: ${itemTitle}`);
123-
}
124-
}
93+
// Let the system notification show normally - no interference
12594
});
12695
}
12796
} else {
@@ -184,29 +153,24 @@ class NotificationService {
184153
// mapping we wouldn't know which notification ID to cancel on receipt.
185154
this.notificationIdMap[itemId] = safeId;
186155

187-
// Check if app is currently visible to determine notification behavior
188-
const isAppVisible = document.visibilityState === 'visible';
189-
190156
const notifications = [
191157
{
192158
title: '⏰ Reminder',
193159
body: `Don't forget: ${itemTitle || 'Untitled'}`,
194160
id: safeId,
195161
// Ensure alarms fire while idle on Android
196162
schedule: { at: notificationTime, allowWhileIdle: true },
197-
// Use different channel based on app visibility
198-
channelId: isAppVisible ? 'reminders_silent' : 'reminders',
199-
// Lower importance if app is visible (will prevent heads-up notification)
200-
importance: isAppVisible ? 2 : 5,
201-
// Disable sound if app is visible
202-
sound: isAppVisible ? null : null,
163+
// Always use the main reminders channel for consistent behavior
164+
channelId: 'reminders',
165+
importance: 5,
166+
// Use default sound
167+
sound: null,
203168
attachments: null,
204169
actionTypeId: 'REMINDER_ACTION',
205170
extra: {
206171
itemId,
207172
reminderId: `${itemId}-${timestamp}`,
208-
originalReminder: reminder,
209-
scheduledWhenVisible: isAppVisible
173+
originalReminder: reminder
210174
}
211175
}
212176
];

0 commit comments

Comments
 (0)