Skip to content

Commit 0dfed74

Browse files
Merge pull request #932 from GoogleChromeLabs/launch_handler_client_mode
Store launch_handler clinet_mode to AndroidManifest
2 parents feb6c6f + 76243f4 commit 0dfed74

File tree

6 files changed

+27
-0
lines changed

6 files changed

+27
-0
lines changed

packages/cli/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ Fields:
394394
|minSdkVersion|number|false|The minimum [Android API Level](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) required for the application to run. Defaults to `23`, if `isMetaQuest` is `true`, and `19` otherwise.|
395395
|protocolHandlers|[ProtocolHandler](#protocolhandlers)[]|false|List of [Protocol Handlers](#protocolhandlers) supported by the app.|
396396
|fileHandlers|[FileHandler](#fileHandlers)[]|false|List of [File Hanlders](#fileHandlers) supported by the app.|
397+
|launchHandlerClientMode|string|false|launch_handler [client_mode](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Manifest/Reference/launch_handler#client_mode) of the app.|
397398

398399
### Features
399400

@@ -483,6 +484,10 @@ List of File Handlers registered for the application. These entries may not exac
483484
|actionUrl|string|true|URL to be navigated to in case of file handler launch matching the according MIME types|
484485
|mimeTypes|string[]|true|The list of MIME types for the file handler|
485486

487+
### LaunchHandler
488+
A string, which specifies the context in which the app should be loaded when launched. Possible values are: "auto", "focus-existing", "navigate-existing", "navigate-new".
489+
See [launch_handler](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Manifest/Reference/launch_handler) for more information.
490+
486491

487492
## Manually setting up the Environment
488493

packages/core/src/lib/TwaManifest.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ export class TwaManifest {
173173
retainedBundles: number[];
174174
protocolHandlers?: ProtocolHandler[];
175175
fileHandlers?: FileHandler[];
176+
launchHandlerClientMode?: string;
176177

177178
private static log = new ConsoleLog('twa-manifest');
178179

@@ -225,6 +226,7 @@ export class TwaManifest {
225226
this.retainedBundles = data.retainedBundles || [];
226227
this.protocolHandlers = data.protocolHandlers;
227228
this.fileHandlers = data.fileHandlers;
229+
this.launchHandlerClientMode = data.launchHandlerClientMode;
228230
}
229231

230232
/**
@@ -363,6 +365,7 @@ export class TwaManifest {
363365
fullScopeUrl: fullScopeUrl.toString(),
364366
protocolHandlers: processedProtocolHandlers,
365367
fileHandlers,
368+
launchHandlerClientMode: webManifest['launch_handler']?.['client_mode'] || '',
366369
});
367370
return twaManifest;
368371
}
@@ -550,6 +553,9 @@ export class TwaManifest {
550553
shortcuts: shortcuts,
551554
protocolHandlers: protocolHandlers,
552555
fileHandlers,
556+
launchHandlerClientMode: this.getNewFieldValue('launchHandlerClientMode', fieldsToIgnore,
557+
oldTwaManifest.launchHandlerClientMode,
558+
webManifest['launch_handler']?.['client_mode'] || ''),
553559
});
554560
return twaManifest;
555561
}
@@ -607,6 +613,7 @@ export interface TwaManifestJson {
607613
retainedBundles?: number[];
608614
protocolHandlers?: ProtocolHandler[];
609615
fileHandlers?: FileHandler[];
616+
launchHandlerClientMode?: string;
610617
}
611618

612619
export interface SigningKeyInfo {

packages/core/src/lib/types/WebManifest.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,7 @@ export interface WebManifestJson {
7272
orientation?: OrientationLock;
7373
protocol_handlers?: Array<ProtocolHandler>;
7474
file_handlers?: Array<FileHandlerJson>;
75+
launch_handler?: {
76+
client_mode?: string;
77+
};
7578
}

packages/core/src/spec/lib/TwaManifestSpec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ describe('TwaManifest', () => {
381381
};
382382
const twaManifest = new TwaManifest({
383383
'packageId': 'id',
384+
'launchHandlerClientMode': 'navigate_existing',
384385
'host': 'host',
385386
'name': 'name',
386387
'launcherName': 'name',
@@ -472,6 +473,7 @@ describe('TwaManifest', () => {
472473
};
473474
const twaManifest = new TwaManifest({
474475
'packageId': 'id',
476+
'launchHandlerClientMode': 'navigate_existing',
475477
'host': 'host',
476478
'name': 'name',
477479
'launcherName': 'name',

packages/core/template_project/app/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ android {
7070
def launchUrl = "https://" + twaManifest.hostName + twaManifest.launchUrl
7171
resValue "string", "launchUrl", launchUrl
7272

73+
<% if (launchHandlerClientMode) { %>
74+
resValue "string", "launchHandlerClientMode", '<%= launchHandlerClientMode %>'
75+
<% } %>
76+
7377
<% if (webManifestUrl) { %>
7478
// The URL the Web Manifest for the Progressive Web App that the TWA points to. This
7579
// is used by Chrome OS and Meta Quest to open the Web version of the PWA instead of

packages/core/template_project/app/src/main/AndroidManifest.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@
109109
android:name="android.support.customtabs.trusted.STATUS_BAR_COLOR"
110110
android:resource="@color/colorPrimary" />
111111

112+
<% if (launchHandlerClientMode) { %>
113+
<meta-data
114+
android:name="android.support.customtabs.trusted.LAUNCH_HANDLER_CLIENT_MODE"
115+
android:value="@string/launchHandlerClientMode" />
116+
<% } %>
117+
112118
<meta-data
113119
android:name="android.support.customtabs.trusted.STATUS_BAR_COLOR_DARK"
114120
android:resource="@color/colorPrimaryDark" />

0 commit comments

Comments
 (0)