MOBILE-4359 localnotifications: Fix open local notif when app is dead

main
Dani Palou 2024-09-04 15:18:42 +02:00
parent 0e6058a242
commit 4f1db0e639
2 changed files with 27 additions and 2 deletions

View File

@ -444,6 +444,7 @@ export class CorePushNotificationsProvider {
async notificationClicked(data: CorePushNotificationsNotificationBasicData): Promise<void> { async notificationClicked(data: CorePushNotificationsNotificationBasicData): Promise<void> {
await ApplicationInit.donePromise; await ApplicationInit.donePromise;
// This code is also done when clicking local notifications. If it's modified, it should be modified in there too.
if (CoreSites.isLoggedIn()) { if (CoreSites.isLoggedIn()) {
CoreSites.runAfterLoginNavigation({ CoreSites.runAfterLoginNavigation({
priority: 600, priority: 600,

View File

@ -23,7 +23,7 @@ import { CoreText } from '@singletons/text';
import { CoreQueueRunner } from '@classes/queue-runner'; import { CoreQueueRunner } from '@classes/queue-runner';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
import { CoreConstants } from '@/core/constants'; import { CoreConstants } from '@/core/constants';
import { makeSingleton, NgZone, Translate, LocalNotifications } from '@singletons'; import { makeSingleton, NgZone, Translate, LocalNotifications, ApplicationInit } from '@singletons';
import { CoreLogger } from '@singletons/logger'; import { CoreLogger } from '@singletons/logger';
import { import {
APP_SCHEMA, APP_SCHEMA,
@ -42,6 +42,9 @@ import { AsyncInstance, asyncInstance } from '@/core/utils/async-instance';
import { CoreDatabaseTable } from '@classes/database/database-table'; import { CoreDatabaseTable } from '@classes/database/database-table';
import { CoreDatabaseCachingStrategy, CoreDatabaseTableProxy } from '@classes/database/database-table-proxy'; import { CoreDatabaseCachingStrategy, CoreDatabaseTableProxy } from '@classes/database/database-table-proxy';
import { CoreDomUtils } from './utils/dom'; import { CoreDomUtils } from './utils/dom';
import { CoreSites } from './sites';
import { CoreNavigator } from './navigator';
import { CoreWait } from '@singletons/wait';
/** /**
* Service to handle local notifications. * Service to handle local notifications.
@ -87,7 +90,28 @@ export class CoreLocalNotificationsProvider {
this.handleEvent('trigger', notification); this.handleEvent('trigger', notification);
}); });
this.clickSubscription = LocalNotifications.on('click').subscribe((notification: ILocalNotification) => { this.clickSubscription = LocalNotifications.on('click').subscribe(async (notification: ILocalNotification) => {
await ApplicationInit.donePromise;
// This code is also done when clicking push notifications. If it's modified, it should be modified in there too.
if (CoreSites.isLoggedIn()) {
CoreSites.runAfterLoginNavigation({
priority: 0, // Use a low priority because the execution of this process doesn't block the next ones.
callback: async () => {
this.handleEvent('click', notification);
},
});
return;
}
// User not logged in, wait for the path to be a "valid" path (not a parent path used when starting the app).
await CoreWait.waitFor(() => {
const currentPath = CoreNavigator.getCurrentPath();
return currentPath !== '/' && currentPath !== '/login';
}, { timeout: 400 });
this.handleEvent('click', notification); this.handleEvent('click', notification);
}); });