Skip to content

Commit d7c3c37

Browse files
authored
Merge pull request #4168 from dpalou/MOBILE-4359
Mobile 4359
2 parents 3278d5a + aa5cf7d commit d7c3c37

File tree

18 files changed

+191
-96
lines changed

18 files changed

+191
-96
lines changed

package-lock.json

Lines changed: 20 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
"@moodlehq/cordova-plugin-inappbrowser": "5.0.0-moodle.3",
8282
"@moodlehq/cordova-plugin-intent": "2.2.0-moodle.3",
8383
"@moodlehq/cordova-plugin-ionic-webview": "5.0.0-moodle.4",
84-
"@moodlehq/cordova-plugin-local-notification": "0.9.0-moodle.12",
8584
"@moodlehq/cordova-plugin-qrscanner": "3.0.1-moodle.5",
8685
"@moodlehq/cordova-plugin-statusbar": "4.0.0-moodle.3",
8786
"@moodlehq/cordova-plugin-zip": "3.1.0-moodle.1",
@@ -106,6 +105,7 @@
106105
"cordova-plugin-file": "^8.0.1",
107106
"cordova-plugin-geolocation": "^5.0.0",
108107
"cordova-plugin-ionic-keyboard": "^2.2.0",
108+
"cordova-plugin-local-notification": "1.0.0",
109109
"cordova-plugin-media-capture": "^5.0.0",
110110
"cordova-plugin-network-information": "^3.0.0",
111111
"cordova-plugin-prevent-override": "^1.0.1",
@@ -201,9 +201,6 @@
201201
"@moodlehq/cordova-plugin-inappbrowser": {},
202202
"@moodlehq/cordova-plugin-intent": {},
203203
"@moodlehq/cordova-plugin-ionic-webview": {},
204-
"@moodlehq/cordova-plugin-local-notification": {
205-
"ANDROID_SUPPORT_V4_VERSION": "26.+"
206-
},
207204
"@moodlehq/cordova-plugin-qrscanner": {},
208205
"@moodlehq/cordova-plugin-statusbar": {},
209206
"@moodlehq/cordova-plugin-zip": {},
@@ -227,6 +224,9 @@
227224
"GPS_REQUIRED": "false"
228225
},
229226
"cordova-plugin-ionic-keyboard": {},
227+
"cordova-plugin-local-notification": {
228+
"ANDROID_SUPPORT_V4_VERSION": "26.+"
229+
},
230230
"cordova-plugin-media-capture": {},
231231
"cordova-plugin-moodleapp": {},
232232
"cordova-plugin-network-information": {},

src/addons/blog/pages/index/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import { AddonBlogOffline, AddonBlogOfflineEntry } from '@addons/blog/services/b
2929
import { AddonBlogSync } from '@addons/blog/services/blog-sync';
3030
import { Component, computed, OnDestroy, OnInit, signal } from '@angular/core';
3131
import { CoreComments } from '@features/comments/services/comments';
32-
import { CoreMainMenuDeepLinkManager } from '@features/mainmenu/classes/deep-link-manager';
3332
import { CoreTag } from '@features/tag/services/tag';
3433
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
3534
import { CoreNavigator } from '@services/navigator';
@@ -202,8 +201,7 @@ export class AddonBlogIndexPage implements OnInit, OnDestroy {
202201
this.commentsEnabled = CoreComments.areCommentsEnabledInSite();
203202
this.tagsEnabled = CoreTag.areTagsAvailableInSite();
204203

205-
const deepLinkManager = new CoreMainMenuDeepLinkManager();
206-
deepLinkManager.treatLink();
204+
CoreSites.loginNavigationFinished();
207205

208206
await this.fetchEntries(false, false, true);
209207
this.optionsAvailable = await AddonBlog.isEditingEnabled();

src/addons/calendar/pages/index/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import { AddonCalendarCalendarComponent } from '../../components/calendar/calend
3030
import { AddonCalendarUpcomingEventsComponent } from '../../components/upcoming-events/upcoming-events';
3131
import { CoreNavigator } from '@services/navigator';
3232
import { CoreConstants } from '@/core/constants';
33-
import { CoreMainMenuDeepLinkManager } from '@features/mainmenu/classes/deep-link-manager';
3433
import { CoreModals } from '@services/modals';
3534

3635
/**
@@ -178,8 +177,7 @@ export class AddonCalendarIndexPage implements OnInit, OnDestroy {
178177
}
179178
});
180179

181-
const deepLinkManager = new CoreMainMenuDeepLinkManager();
182-
deepLinkManager.treatLink();
180+
CoreSites.loginNavigationFinished();
183181
}
184182

185183
/**

src/addons/messages/pages/discussions-35/discussions.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import { Subscription } from 'rxjs';
3030
import { Translate } from '@singletons';
3131
import { CoreNavigator } from '@services/navigator';
3232
import { CoreScreen } from '@services/screen';
33-
import { CoreMainMenuDeepLinkManager } from '@features/mainmenu/classes/deep-link-manager';
3433
import { CorePlatform } from '@services/platform';
3534
import { CoreSplitViewComponent } from '@components/split-view/split-view';
3635
import { CoreKeyboard } from '@singletons/keyboard';
@@ -145,17 +144,15 @@ export class AddonMessagesDiscussions35Page implements OnInit, OnDestroy {
145144
this.discussionUserId = CoreNavigator.getRouteNumberParam('userId', { params }) ?? this.discussionUserId;
146145
});
147146

148-
const deepLinkManager = new CoreMainMenuDeepLinkManager();
149-
150147
await this.fetchData();
151148

152149
if (!this.discussionUserId && this.discussions.length > 0 && CoreScreen.isTablet && this.discussions[0].message) {
153150
// Take first and load it.
154151
await this.gotoDiscussion(this.discussions[0].message.user);
155152
}
156153

157-
// Treat deep link now that the conversation route has been loaded if needed.
158-
deepLinkManager.treatLink();
154+
// Mark login navigation finished now that the conversation route has been loaded if needed.
155+
CoreSites.loginNavigationFinished();
159156
}
160157

161158
/**

src/addons/messages/pages/group-conversations/group-conversations.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import { ActivatedRoute, Params } from '@angular/router';
3838
import { CoreUtils } from '@services/utils/utils';
3939
import { CoreNavigator } from '@services/navigator';
4040
import { CoreScreen } from '@services/screen';
41-
import { CoreMainMenuDeepLinkManager } from '@features/mainmenu/classes/deep-link-manager';
4241
import { CorePlatform } from '@services/platform';
4342
import { CoreSplitViewComponent } from '@components/split-view/split-view';
4443

@@ -312,8 +311,6 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
312311
}
313312
});
314313

315-
const deepLinkManager = new CoreMainMenuDeepLinkManager();
316-
317314
await this.fetchData();
318315

319316
if (!this.selectedConversationId && !this.selectedUserId && CoreScreen.isTablet) {
@@ -326,8 +323,8 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
326323
}
327324
}
328325

329-
// Treat deep link now that the conversation route has been loaded if needed.
330-
deepLinkManager.treatLink();
326+
// Mark login navigation finished now that the conversation route has been loaded if needed.
327+
CoreSites.loginNavigationFinished();
331328
}
332329

333330
/**

src/addons/notifications/pages/list/list.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import { CoreSplitViewComponent } from '@components/split-view/split-view';
2626
import { CoreRoutedItemsManagerSourcesTracker } from '@classes/items-management/routed-items-manager-sources-tracker';
2727
import { CorePushNotificationsDelegate } from '@features/pushnotifications/services/push-delegate';
2828
import { CoreSites } from '@services/sites';
29-
import { CoreMainMenuDeepLinkManager } from '@features/mainmenu/classes/deep-link-manager';
3029
import { CoreTimeUtils } from '@services/utils/time';
3130
import { AddonNotificationsNotificationsSource } from '@addons/notifications/classes/notifications-source';
3231
import { CoreListItemsManager } from '@classes/items-management/list-items-manager';
@@ -130,8 +129,7 @@ export class AddonNotificationsListPage implements AfterViewInit, OnDestroy {
130129
this.loadMarkAllAsReadButton();
131130
});
132131

133-
const deepLinkManager = new CoreMainMenuDeepLinkManager();
134-
deepLinkManager.treatLink();
132+
CoreSites.loginNavigationFinished();
135133
}
136134

137135
/**

src/core/classes/queue-runner.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ export type CoreQueueRunnerItem<T = any> = {
3939
* Deferred with a promise resolved/rejected with the result of the function.
4040
*/
4141
deferred: CorePromisedValue<T>;
42+
43+
/**
44+
* Item's priority. Only used if usePriority=true.
45+
*/
46+
priority: number;
4247
};
4348

4449
/**
@@ -49,6 +54,12 @@ export type CoreQueueRunnerAddOptions = {
4954
* Whether to allow having multiple entries with same ID in the queue.
5055
*/
5156
allowRepeated?: boolean;
57+
58+
/**
59+
* If usePriority=true, the priority of the item. Higher priority means it will be executed first.
60+
* Please notice that the first item is always run immediately, so it's not affected by the priority.
61+
*/
62+
priority?: number;
5263
};
5364

5465
/**
@@ -60,7 +71,13 @@ export class CoreQueueRunner {
6071
protected orderedQueue: CoreQueueRunnerItem[] = [];
6172
protected numberRunning = 0;
6273

63-
constructor(protected maxParallel: number = 1) { }
74+
/**
75+
* Constructor.
76+
*
77+
* @param maxParallel Max number of parallel executions.
78+
* @param usePriority If true, the queue will be ordered by priority.
79+
*/
80+
constructor(protected maxParallel: number = 1, protected usePriority = false) { }
6481

6582
/**
6683
* Get unique ID.
@@ -147,10 +164,14 @@ export class CoreQueueRunner {
147164
id,
148165
fn,
149166
deferred: new CorePromisedValue<T>(),
167+
priority: options.priority ?? 0,
150168
};
151169

152170
this.queue[id] = item;
153171
this.orderedQueue.push(item);
172+
if (this.usePriority) {
173+
this.orderedQueue.sort((a, b) => b.priority - a.priority);
174+
}
154175

155176
// Process next item if we haven't reached the max yet.
156177
this.processNextItem();

src/core/features/courses/pages/my/my.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { CoreBlockComponent } from '@features/block/components/block/block';
2121
import { CoreBlockDelegate } from '@features/block/services/block-delegate';
2222
import { CoreCourseBlock } from '@features/course/services/course';
2323
import { CoreCoursesDashboard, CoreCoursesDashboardProvider } from '@features/courses/services/dashboard';
24-
import { CoreMainMenuDeepLinkManager } from '@features/mainmenu/classes/deep-link-manager';
2524
import { CoreSites } from '@services/sites';
2625
import { CoreDomUtils } from '@services/utils/dom';
2726
import { CoreUtils } from '@services/utils/utils';
@@ -97,8 +96,7 @@ export class CoreCoursesMyPage implements OnInit, OnDestroy, AsyncDirective {
9796
async ngOnInit(): Promise<void> {
9897
this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite();
9998

100-
const deepLinkManager = new CoreMainMenuDeepLinkManager();
101-
deepLinkManager.treatLink();
99+
CoreSites.loginNavigationFinished();
102100

103101
await this.loadSiteName();
104102

src/core/features/mainmenu/classes/deep-link-manager.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ export class CoreMainMenuDeepLinkManager {
5050
/**
5151
* Treat a deep link if there's any to treat.
5252
*/
53-
treatLink(): void {
54-
if (!this.pendingRedirect) {
53+
async treatLink(): Promise<void> {
54+
const pendingRedirect = this.pendingRedirect;
55+
if (!pendingRedirect) {
5556
return;
5657
}
5758

58-
if (this.pendingRedirect.redirectPath) {
59-
this.treatPath(this.pendingRedirect.redirectPath, this.pendingRedirect.redirectOptions);
60-
} else if (this.pendingRedirect.urlToOpen) {
61-
this.treatUrlToOpen(this.pendingRedirect.urlToOpen);
62-
}
63-
6459
delete this.pendingRedirect;
60+
if (pendingRedirect.redirectPath) {
61+
await this.treatPath(pendingRedirect.redirectPath, pendingRedirect.redirectOptions);
62+
} else if (pendingRedirect.urlToOpen) {
63+
await this.treatUrlToOpen(pendingRedirect.urlToOpen);
64+
}
6565
}
6666

6767
/**
@@ -70,18 +70,18 @@ export class CoreMainMenuDeepLinkManager {
7070
* @param path Path.
7171
* @param navOptions Navigation options.
7272
*/
73-
protected treatPath(path: string, navOptions: CoreNavigationOptions = {}): void {
73+
protected async treatPath(path: string, navOptions: CoreNavigationOptions = {}): Promise<void> {
7474
const params = navOptions.params;
7575
const coursePathMatches = path.match(/^course\/(\d+)\/?$/);
7676

7777
if (coursePathMatches) {
7878
if (!params?.course) {
79-
CoreCourseHelper.getAndOpenCourse(Number(coursePathMatches[1]), params);
79+
await CoreCourseHelper.getAndOpenCourse(Number(coursePathMatches[1]), params);
8080
} else {
81-
CoreCourse.openCourse(params.course, navOptions);
81+
await CoreCourse.openCourse(params.course, navOptions);
8282
}
8383
} else {
84-
CoreNavigator.navigateToSitePath(path, {
84+
await CoreNavigator.navigateToSitePath(path, {
8585
...navOptions,
8686
preferCurrentTab: false,
8787
});
@@ -96,7 +96,7 @@ export class CoreMainMenuDeepLinkManager {
9696
protected async treatUrlToOpen(url: string): Promise<void> {
9797
const action = await CoreContentLinksHelper.getFirstValidActionFor(url);
9898
if (action?.sites?.[0]) {
99-
action.action(action.sites[0]);
99+
await action.action(action.sites[0]);
100100
}
101101
}
102102

0 commit comments

Comments
 (0)