Skip to content

Commit f5ad412

Browse files
authored
Set precache flow for test app (#2894)
* Set precache flow for test app * update * update * update * update * update
1 parent a76d376 commit f5ad412

File tree

2 files changed

+104
-68
lines changed

2 files changed

+104
-68
lines changed

apps/teams-test-app/src/App.tsx

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import './App.css';
22

3-
import { app, appInitialization, initialize } from '@microsoft/teams-js';
3+
import { app, appInitialization, initialize, ResumeContext } from '@microsoft/teams-js';
44
import React, { ReactElement } from 'react';
55
import { BrowserRouter, Route, Routes } from 'react-router-dom';
66

@@ -17,7 +17,10 @@ const getOriginsParam = urlParams.has('origins') && urlParams.get('origins') ? u
1717
const validMessageOrigins: string[] | undefined = getOriginsParam ? getOriginsParam.split(',') : undefined;
1818

1919
// This is added for custom initialization when app can be initialized based upon a trigger/click.
20-
if (!urlParams.has('customInit') || !urlParams.get('customInit')) {
20+
if (
21+
(!urlParams.has('customInit') || !urlParams.get('customInit')) &&
22+
(!urlParams.has('precacheApp') || !urlParams.get('precacheApp'))
23+
) {
2124
if (isTestBackCompat()) {
2225
initialize(undefined, validMessageOrigins);
2326
} else {
@@ -29,11 +32,16 @@ if (!urlParams.has('customInit') || !urlParams.get('customInit')) {
2932
// we do it by adding appInitializationTest=true to query string
3033
if (
3134
(urlParams.has('customInit') && urlParams.get('customInit')) ||
32-
(urlParams.has(appInitializationTestQueryParameter) && urlParams.get(appInitializationTestQueryParameter))
35+
(urlParams.has(appInitializationTestQueryParameter) &&
36+
urlParams.get(appInitializationTestQueryParameter) &&
37+
(!urlParams.has('precacheApp') || !urlParams.get('precacheApp')))
3338
) {
3439
window.addEventListener('message', handleMessageFromMockedHost);
3540
console.info('Not calling appInitialization because part of App Initialization Test run');
36-
} else {
41+
} else if (
42+
(!urlParams.has('precacheApp') || !urlParams.get('precacheApp')) &&
43+
(!urlParams.has('customInit') || !urlParams.get('customInit'))
44+
) {
3745
if (isTestBackCompat()) {
3846
appInitialization.notifyAppLoaded();
3947
appInitialization.notifySuccess();
@@ -43,6 +51,25 @@ if (
4351
}
4452
}
4553

54+
if (urlParams.has('precacheApp') && urlParams.get('precacheApp')) {
55+
app.initialize(validMessageOrigins).then(() => {
56+
app.notifyAppLoaded();
57+
app.lifecycle.registerBeforeSuspendOrTerminateHandler(() => {
58+
return new Promise<void>((resolve) => {
59+
resolve();
60+
});
61+
});
62+
app.lifecycle.registerOnResumeHandler((context: ResumeContext): void => {
63+
// get the route from the context
64+
console.log(context.contentUrl);
65+
if (!urlParams.has('customInit') || !urlParams.get('customInit')) {
66+
app.notifySuccess();
67+
}
68+
});
69+
app.notifySuccess();
70+
});
71+
}
72+
4673
function handleMessageFromMockedHost(msg: MessageEvent): void {
4774
if (!msg.data) {
4875
console.warn('Unrecognized message format received by app, message being ignored. Message: %o', msg);

0 commit comments

Comments
 (0)