@bubblewrap/core 1.13.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +203 -0
- package/README.md +63 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +56 -0
- package/dist/lib/BufferedLog.d.ts +20 -0
- package/dist/lib/BufferedLog.js +83 -0
- package/dist/lib/Config.d.ts +9 -0
- package/dist/lib/Config.js +50 -0
- package/dist/lib/DigitalAssetLinks.d.ts +3 -0
- package/dist/lib/DigitalAssetLinks.js +37 -0
- package/dist/lib/FetchUtils.d.ts +17 -0
- package/dist/lib/FetchUtils.js +79 -0
- package/dist/lib/GooglePlay.d.ts +41 -0
- package/dist/lib/GooglePlay.js +92 -0
- package/dist/lib/GradleWrapper.d.ts +31 -0
- package/dist/lib/GradleWrapper.js +62 -0
- package/dist/lib/ImageHelper.d.ts +37 -0
- package/dist/lib/ImageHelper.js +112 -0
- package/dist/lib/Log.d.ts +88 -0
- package/dist/lib/Log.js +114 -0
- package/dist/lib/Result.d.ts +46 -0
- package/dist/lib/Result.js +97 -0
- package/dist/lib/ShortcutInfo.d.ts +32 -0
- package/dist/lib/ShortcutInfo.js +84 -0
- package/dist/lib/TwaGenerator.d.ts +39 -0
- package/dist/lib/TwaGenerator.js +362 -0
- package/dist/lib/TwaManifest.d.ts +234 -0
- package/dist/lib/TwaManifest.js +384 -0
- package/dist/lib/androidSdk/AndroidSdkTools.d.ts +87 -0
- package/dist/lib/androidSdk/AndroidSdkTools.js +226 -0
- package/dist/lib/errors/ValidatePathError.d.ts +9 -0
- package/dist/lib/errors/ValidatePathError.js +16 -0
- package/dist/lib/features/AppsFlyerFeature.d.ts +8 -0
- package/dist/lib/features/AppsFlyerFeature.js +70 -0
- package/dist/lib/features/EmptyFeature.d.ts +28 -0
- package/dist/lib/features/EmptyFeature.js +44 -0
- package/dist/lib/features/Feature.d.ts +120 -0
- package/dist/lib/features/Feature.js +17 -0
- package/dist/lib/features/FeatureManager.d.ts +36 -0
- package/dist/lib/features/FeatureManager.js +137 -0
- package/dist/lib/features/FirstRunFlagFeature.d.ts +8 -0
- package/dist/lib/features/FirstRunFlagFeature.js +43 -0
- package/dist/lib/features/LocationDelegationFeature.d.ts +7 -0
- package/dist/lib/features/LocationDelegationFeature.js +32 -0
- package/dist/lib/features/PlayBillingFeature.d.ts +7 -0
- package/dist/lib/features/PlayBillingFeature.js +53 -0
- package/dist/lib/jdk/JarSigner.d.ts +13 -0
- package/dist/lib/jdk/JarSigner.js +55 -0
- package/dist/lib/jdk/JdkHelper.d.ts +55 -0
- package/dist/lib/jdk/JdkHelper.js +127 -0
- package/dist/lib/jdk/KeyTool.d.ts +57 -0
- package/dist/lib/jdk/KeyTool.js +136 -0
- package/dist/lib/mock/MockLog.d.ts +37 -0
- package/dist/lib/mock/MockLog.js +70 -0
- package/dist/lib/types/WebManifest.d.ts +44 -0
- package/dist/lib/types/WebManifest.js +17 -0
- package/dist/lib/util.d.ts +82 -0
- package/dist/lib/util.js +279 -0
- package/dist/lib/wrappers/svg2img.d.ts +14 -0
- package/dist/lib/wrappers/svg2img.js +39 -0
- package/package.json +58 -0
- package/template_project/app/.gitignore +1 -0
- package/template_project/app/build.gradle +211 -0
- package/template_project/app/src/main/AndroidManifest.xml +204 -0
- package/template_project/app/src/main/java/Application.java +35 -0
- package/template_project/app/src/main/java/DelegationService.java +18 -0
- package/template_project/app/src/main/java/LauncherActivity.java +62 -0
- package/template_project/app/src/main/res/drawable-anydpi/shortcut_legacy_background.xml +25 -0
- package/template_project/app/src/main/res/drawable-anydpi/shortcut_monochrome.xml +27 -0
- package/template_project/app/src/main/res/drawable-anydpi-v26/shortcut_maskable.xml +32 -0
- package/template_project/app/src/main/res/drawable-anydpi-v26/shortcut_monochrome.xml +26 -0
- package/template_project/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +33 -0
- package/template_project/app/src/main/res/values/colors.xml +18 -0
- package/template_project/app/src/main/res/values/strings.xml +50 -0
- package/template_project/app/src/main/res/xml/filepaths.xml +18 -0
- package/template_project/app/src/main/res/xml/shortcuts.xml +16 -0
- package/template_project/build.gradle +42 -0
- package/template_project/enable-debug.sh +27 -0
- package/template_project/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/template_project/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/template_project/gradle.properties +14 -0
- package/template_project/gradlew +188 -0
- package/template_project/gradlew.bat +100 -0
- package/template_project/settings.gradle +1 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import Color = require('color');
|
|
2
|
+
import { ShareTarget, WebManifestIcon, WebManifestJson } from './types/WebManifest';
|
|
3
|
+
import { ShortcutInfo } from './ShortcutInfo';
|
|
4
|
+
import { AppsFlyerConfig } from './features/AppsFlyerFeature';
|
|
5
|
+
import { LocationDelegationConfig } from './features/LocationDelegationFeature';
|
|
6
|
+
import { PlayBillingConfig } from './features/PlayBillingFeature';
|
|
7
|
+
import { FirstRunFlagConfig } from './features/FirstRunFlagFeature';
|
|
8
|
+
declare const DISPLAY_MODE_VALUES: string[];
|
|
9
|
+
export declare type DisplayMode = typeof DISPLAY_MODE_VALUES[number];
|
|
10
|
+
export declare const DisplayModes: DisplayMode[];
|
|
11
|
+
export declare function asDisplayMode(input: string): DisplayMode | null;
|
|
12
|
+
declare const ORIENTATION_VALUES: string[];
|
|
13
|
+
export declare type Orientation = typeof ORIENTATION_VALUES[number];
|
|
14
|
+
export declare const Orientations: Orientation[];
|
|
15
|
+
export declare function asOrientation(input?: string): Orientation | null;
|
|
16
|
+
export declare type FallbackType = 'customtabs' | 'webview';
|
|
17
|
+
declare type Features = {
|
|
18
|
+
appsFlyer?: AppsFlyerConfig;
|
|
19
|
+
locationDelegation?: LocationDelegationConfig;
|
|
20
|
+
playBilling?: PlayBillingConfig;
|
|
21
|
+
firstRunFlag?: FirstRunFlagConfig;
|
|
22
|
+
};
|
|
23
|
+
declare type alphaDependencies = {
|
|
24
|
+
enabled: boolean;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* A Manifest used to generate the TWA Project
|
|
28
|
+
*
|
|
29
|
+
* applicationId: '<%= packageId %>',
|
|
30
|
+
* hostName: '<%= host %>', // The domain being opened in the TWA.
|
|
31
|
+
* launchUrl: '<%= startUrl %>', // The start path for the TWA. Must be relative to the domain.
|
|
32
|
+
* name: '<%= name %>', // The name shown on the Android Launcher.
|
|
33
|
+
* display: '<%= display %>', // The display mode for the TWA.
|
|
34
|
+
* themeColor: '<%= themeColor %>', // The color used for the status bar.
|
|
35
|
+
* navigationColor: '<%= themeColor %>', // The color used for the navigation bar.
|
|
36
|
+
* navigationColorDark: '<%= navigationColorDark %>', // The color used for the dark navbar.
|
|
37
|
+
* navigationDividerColor: '<%= navigationDividerColor %>', // The color used for the
|
|
38
|
+
* navbar divider.
|
|
39
|
+
* navigationDividerColorDark: '<%= navigationDividerColorDark %>', // The color used for the dark
|
|
40
|
+
* navbar divider.
|
|
41
|
+
* backgroundColor: '<%= backgroundColor %>', // The color used for the splash screen background.
|
|
42
|
+
* enableNotifications: false, // Set to true to enable notification delegation.
|
|
43
|
+
* enableSiteSettingsShortcut: true, // Set to false to disable the shortcut into site settings.
|
|
44
|
+
* // Add shortcuts for your app here. Every shortcut must include the following fields:
|
|
45
|
+
* // - name: String that will show up in the shortcut.
|
|
46
|
+
* // - short_name: Shorter string used if |name| is too long.
|
|
47
|
+
* // - url: Absolute path of the URL to launch the app with (e.g '/create').
|
|
48
|
+
* // - icon: Name of the resource in the drawable folder to use as an icon.
|
|
49
|
+
* shortcuts: [
|
|
50
|
+
* // Insert shortcuts here, for example:
|
|
51
|
+
* // [name: 'Open SVG', short_name: 'Open', url: '/open', icon: 'splash']
|
|
52
|
+
* ],
|
|
53
|
+
* // The duration of fade out animation in milliseconds to be played when removing splash screen.
|
|
54
|
+
* splashScreenFadeOutDuration: 300
|
|
55
|
+
* isChromeOSOnly: false, // Setting to true will enable a feature that prevents non-ChromeOS devices
|
|
56
|
+
* from installing the app.
|
|
57
|
+
* serviceAccountJsonFile: '<%= serviceAccountJsonFile %>', // The service account used to communicate with
|
|
58
|
+
* Google Play.
|
|
59
|
+
*
|
|
60
|
+
*/
|
|
61
|
+
export declare class TwaManifest {
|
|
62
|
+
packageId: string;
|
|
63
|
+
host: string;
|
|
64
|
+
name: string;
|
|
65
|
+
launcherName: string;
|
|
66
|
+
display: DisplayMode;
|
|
67
|
+
themeColor: Color;
|
|
68
|
+
navigationColor: Color;
|
|
69
|
+
navigationColorDark: Color;
|
|
70
|
+
navigationDividerColor: Color;
|
|
71
|
+
navigationDividerColorDark: Color;
|
|
72
|
+
backgroundColor: Color;
|
|
73
|
+
enableNotifications: boolean;
|
|
74
|
+
startUrl: string;
|
|
75
|
+
iconUrl: string | undefined;
|
|
76
|
+
maskableIconUrl: string | undefined;
|
|
77
|
+
monochromeIconUrl: string | undefined;
|
|
78
|
+
splashScreenFadeOutDuration: number;
|
|
79
|
+
signingKey: SigningKeyInfo;
|
|
80
|
+
appVersionCode: number;
|
|
81
|
+
appVersionName: string;
|
|
82
|
+
shortcuts: ShortcutInfo[];
|
|
83
|
+
generatorApp: string;
|
|
84
|
+
webManifestUrl?: URL;
|
|
85
|
+
fallbackType: FallbackType;
|
|
86
|
+
features: Features;
|
|
87
|
+
alphaDependencies: alphaDependencies;
|
|
88
|
+
enableSiteSettingsShortcut: boolean;
|
|
89
|
+
isChromeOSOnly: boolean;
|
|
90
|
+
shareTarget?: ShareTarget;
|
|
91
|
+
orientation: Orientation;
|
|
92
|
+
fingerprints: Fingerprint[];
|
|
93
|
+
serviceAccountJsonFile: string | undefined;
|
|
94
|
+
additionalTrustedOrigins: string[];
|
|
95
|
+
private static log;
|
|
96
|
+
constructor(data: TwaManifestJson);
|
|
97
|
+
/**
|
|
98
|
+
* Turns an TwaManifest into a TwaManifestJson.
|
|
99
|
+
*
|
|
100
|
+
* @returns {TwaManifestJson}
|
|
101
|
+
*/
|
|
102
|
+
toJson(): TwaManifestJson;
|
|
103
|
+
/**
|
|
104
|
+
* Saves the TWA Manifest to the file-system.
|
|
105
|
+
*
|
|
106
|
+
* @param {String} filename the location where the TWA Manifest will be saved.
|
|
107
|
+
*/
|
|
108
|
+
saveToFile(filename: string): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Validates if the Manifest has all the fields needed to generate a TWA project and if the
|
|
111
|
+
* values for those fields are valid.
|
|
112
|
+
*
|
|
113
|
+
* @returns {string | null} the error, if any field has an error or null if all fields are valid.
|
|
114
|
+
*/
|
|
115
|
+
validate(): string | null;
|
|
116
|
+
generateShortcuts(): string;
|
|
117
|
+
/**
|
|
118
|
+
* Creates a new TwaManifest, using the URL for the Manifest as a base URL and uses the content
|
|
119
|
+
* of the Web Manifest to generate the fields for the TWA Manifest.
|
|
120
|
+
*
|
|
121
|
+
* @param {URL} webManifestUrl the URL where the webmanifest is available.
|
|
122
|
+
* @param {WebManifest} webManifest the Web Manifest, used as a base for the TWA Manifest.
|
|
123
|
+
* @returns {TwaManifest}
|
|
124
|
+
*/
|
|
125
|
+
static fromWebManifestJson(webManifestUrl: URL, webManifest: WebManifestJson): TwaManifest;
|
|
126
|
+
private static verifyShareTarget;
|
|
127
|
+
/**
|
|
128
|
+
* Fetches a Web Manifest from the url and uses it as a base for the TWA Manifest.
|
|
129
|
+
*
|
|
130
|
+
* @param {String} url the URL where the webmanifest is available
|
|
131
|
+
* @returns {TwaManifest}
|
|
132
|
+
*/
|
|
133
|
+
static fromWebManifest(url: string): Promise<TwaManifest>;
|
|
134
|
+
/**
|
|
135
|
+
* Loads a TWA Manifest from the file system.
|
|
136
|
+
*
|
|
137
|
+
* @param {String} fileName the location of the TWA Manifest file
|
|
138
|
+
*/
|
|
139
|
+
static fromFile(fileName: string): Promise<TwaManifest>;
|
|
140
|
+
/**
|
|
141
|
+
* Given a field name, returns the new value of the field.
|
|
142
|
+
*
|
|
143
|
+
* @param {string} fieldName the name of the given field.
|
|
144
|
+
* @param {string[]} fieldsToIgnore the fields which needs to be ignored.
|
|
145
|
+
* @param {T} oldValue the old value of the field.
|
|
146
|
+
* @param {T} newValue the new value of the field.
|
|
147
|
+
* @returns {T}
|
|
148
|
+
*/
|
|
149
|
+
static getNewFieldValue<T>(fieldName: string, fieldsToIgnore: string[], oldValue: T, newValue: T): T;
|
|
150
|
+
/**
|
|
151
|
+
* Gets the shortcuts from the web manifest.
|
|
152
|
+
*
|
|
153
|
+
* @param {URL} webManifestUrl the URL where the webManifest is available.
|
|
154
|
+
* @param {WebManifest} webManifest the Web Manifest.
|
|
155
|
+
* @returns {ShortcutInfo[]}
|
|
156
|
+
*/
|
|
157
|
+
static getShortcuts(webManifestUrl: URL, webManifest: WebManifestJson): ShortcutInfo[];
|
|
158
|
+
/**
|
|
159
|
+
* @param {string[]} fieldsToIgnore the fields which needs to be ignored.
|
|
160
|
+
* @param {string} fieldName the name of the given field.
|
|
161
|
+
* @param {string} oldUrl the url of the old twaManifest.
|
|
162
|
+
* @param {WebManifestIcon[]} icons the list of icons from the web manifest.
|
|
163
|
+
* @param {string} iconType the type of the requested icon.
|
|
164
|
+
* @param {number} iconSize the size of the requested icon.
|
|
165
|
+
* @param {URL} webManifestUrl the URL where the webManifest is available.
|
|
166
|
+
* @returns {string | undefined} the new icon url.
|
|
167
|
+
*/
|
|
168
|
+
static getNewIconUrl(fieldsToIgnore: string[], fieldName: string, oldUrl: string, icons: WebManifestIcon[], iconType: string, iconSize: number, webManifestUrl: URL): string | undefined;
|
|
169
|
+
/**
|
|
170
|
+
* Merges the Twa Manifest with the web manifest. Ignores the specified fields.
|
|
171
|
+
*
|
|
172
|
+
* @param {string[]} fieldsToIgnore the fields which needs to be ignored.
|
|
173
|
+
* @param {URL} webManifestUrl the URL where the webManifest is available.
|
|
174
|
+
* @param {WebManifest} webManifest the Web Manifest, used as a base for the update of
|
|
175
|
+
* the TWA Manifest.
|
|
176
|
+
* @param {TwaManifest} oldTwaManifest current Twa Manifest.
|
|
177
|
+
* @returns {Promise<TwaManifest>} the new and merged Twa manifest.
|
|
178
|
+
*/
|
|
179
|
+
static merge(fieldsToIgnore: string[], webManifestUrl: URL, webManifest: WebManifestJson, oldTwaManifest: TwaManifest): Promise<TwaManifest>;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* A JSON representation of the TWA Manifest. Used when loading and saving the Manifest
|
|
183
|
+
*/
|
|
184
|
+
export interface TwaManifestJson {
|
|
185
|
+
packageId: string;
|
|
186
|
+
host: string;
|
|
187
|
+
name: string;
|
|
188
|
+
launcherName?: string;
|
|
189
|
+
display?: string;
|
|
190
|
+
themeColor: string;
|
|
191
|
+
navigationColor: string;
|
|
192
|
+
navigationColorDark?: string;
|
|
193
|
+
navigationDividerColor?: string;
|
|
194
|
+
navigationDividerColorDark?: string;
|
|
195
|
+
backgroundColor: string;
|
|
196
|
+
enableNotifications: boolean;
|
|
197
|
+
startUrl: string;
|
|
198
|
+
iconUrl?: string;
|
|
199
|
+
maskableIconUrl?: string;
|
|
200
|
+
monochromeIconUrl?: string;
|
|
201
|
+
splashScreenFadeOutDuration: number;
|
|
202
|
+
signingKey: SigningKeyInfo;
|
|
203
|
+
appVersionCode?: number;
|
|
204
|
+
appVersion: string;
|
|
205
|
+
shortcuts?: ShortcutInfo[];
|
|
206
|
+
generatorApp?: string;
|
|
207
|
+
webManifestUrl?: string;
|
|
208
|
+
fallbackType?: FallbackType;
|
|
209
|
+
features?: {
|
|
210
|
+
appsFlyer?: AppsFlyerConfig;
|
|
211
|
+
locationDelegation?: LocationDelegationConfig;
|
|
212
|
+
playBilling?: PlayBillingConfig;
|
|
213
|
+
firstRunFlag?: FirstRunFlagConfig;
|
|
214
|
+
};
|
|
215
|
+
alphaDependencies?: {
|
|
216
|
+
enabled: boolean;
|
|
217
|
+
};
|
|
218
|
+
enableSiteSettingsShortcut?: boolean;
|
|
219
|
+
isChromeOSOnly?: boolean;
|
|
220
|
+
shareTarget?: ShareTarget;
|
|
221
|
+
orientation?: Orientation;
|
|
222
|
+
fingerprints?: Fingerprint[];
|
|
223
|
+
serviceAccountJsonFile?: string;
|
|
224
|
+
additionalTrustedOrigins?: string[];
|
|
225
|
+
}
|
|
226
|
+
export interface SigningKeyInfo {
|
|
227
|
+
path: string;
|
|
228
|
+
alias: string;
|
|
229
|
+
}
|
|
230
|
+
export declare type Fingerprint = {
|
|
231
|
+
name?: string;
|
|
232
|
+
value: string;
|
|
233
|
+
};
|
|
234
|
+
export {};
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2019 Google Inc. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
'use strict';
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.TwaManifest = exports.asOrientation = exports.Orientations = exports.asDisplayMode = exports.DisplayModes = void 0;
|
|
19
|
+
const fs = require("fs");
|
|
20
|
+
const FetchUtils_1 = require("./FetchUtils");
|
|
21
|
+
const util_1 = require("./util");
|
|
22
|
+
const Color = require("color");
|
|
23
|
+
const Log_1 = require("./Log");
|
|
24
|
+
const ShortcutInfo_1 = require("./ShortcutInfo");
|
|
25
|
+
// The minimum size needed for the app icon.
|
|
26
|
+
const MIN_ICON_SIZE = 512;
|
|
27
|
+
// As described on https://developer.chrome.com/apps/manifest/name#short_name
|
|
28
|
+
const SHORT_NAME_MAX_SIZE = 12;
|
|
29
|
+
// The minimum size needed for the notification icon
|
|
30
|
+
const MIN_NOTIFICATION_ICON_SIZE = 48;
|
|
31
|
+
// Supported display modes for TWA
|
|
32
|
+
const DISPLAY_MODE_VALUES = ['standalone', 'fullscreen', 'fullscreen-sticky'];
|
|
33
|
+
exports.DisplayModes = [...DISPLAY_MODE_VALUES];
|
|
34
|
+
function asDisplayMode(input) {
|
|
35
|
+
return DISPLAY_MODE_VALUES.includes(input) ? input : null;
|
|
36
|
+
}
|
|
37
|
+
exports.asDisplayMode = asDisplayMode;
|
|
38
|
+
// Possible values for screen orientation, as defined in `android-browser-helper`:
|
|
39
|
+
// https://github.com/GoogleChrome/android-browser-helper/blob/alpha/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/LauncherActivityMetadata.java#L191-L216
|
|
40
|
+
const ORIENTATION_VALUES = ['default', 'any', 'natural', 'landscape', 'portrait',
|
|
41
|
+
'portrait-primary', 'portrait-secondary', 'landscape-primary', 'landscape-secondary'];
|
|
42
|
+
exports.Orientations = [...ORIENTATION_VALUES];
|
|
43
|
+
function asOrientation(input) {
|
|
44
|
+
if (!input) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return ORIENTATION_VALUES.includes(input) ? input : null;
|
|
48
|
+
}
|
|
49
|
+
exports.asOrientation = asOrientation;
|
|
50
|
+
// Default values used on the Twa Manifest
|
|
51
|
+
const DEFAULT_SPLASHSCREEN_FADEOUT_DURATION = 300;
|
|
52
|
+
const DEFAULT_APP_NAME = 'My TWA';
|
|
53
|
+
const DEFAULT_DISPLAY_MODE = 'standalone';
|
|
54
|
+
const DEFAULT_THEME_COLOR = '#FFFFFF';
|
|
55
|
+
const DEFAULT_NAVIGATION_COLOR = '#000000';
|
|
56
|
+
const DEFAULT_NAVIGATION_DIVIDER_COLOR = '#00000000';
|
|
57
|
+
const DEFAULT_BACKGROUND_COLOR = '#FFFFFF';
|
|
58
|
+
const DEFAULT_APP_VERSION_CODE = 1;
|
|
59
|
+
const DEFAULT_APP_VERSION_NAME = DEFAULT_APP_VERSION_CODE.toString();
|
|
60
|
+
const DEFAULT_SIGNING_KEY_PATH = './android.keystore';
|
|
61
|
+
const DEFAULT_SIGNING_KEY_ALIAS = 'android';
|
|
62
|
+
const DEFAULT_ENABLE_NOTIFICATIONS = true;
|
|
63
|
+
const DEFAULT_GENERATOR_APP_NAME = 'unknown';
|
|
64
|
+
const DEFAULT_ORIENTATION = 'default';
|
|
65
|
+
/**
|
|
66
|
+
* A Manifest used to generate the TWA Project
|
|
67
|
+
*
|
|
68
|
+
* applicationId: '<%= packageId %>',
|
|
69
|
+
* hostName: '<%= host %>', // The domain being opened in the TWA.
|
|
70
|
+
* launchUrl: '<%= startUrl %>', // The start path for the TWA. Must be relative to the domain.
|
|
71
|
+
* name: '<%= name %>', // The name shown on the Android Launcher.
|
|
72
|
+
* display: '<%= display %>', // The display mode for the TWA.
|
|
73
|
+
* themeColor: '<%= themeColor %>', // The color used for the status bar.
|
|
74
|
+
* navigationColor: '<%= themeColor %>', // The color used for the navigation bar.
|
|
75
|
+
* navigationColorDark: '<%= navigationColorDark %>', // The color used for the dark navbar.
|
|
76
|
+
* navigationDividerColor: '<%= navigationDividerColor %>', // The color used for the
|
|
77
|
+
* navbar divider.
|
|
78
|
+
* navigationDividerColorDark: '<%= navigationDividerColorDark %>', // The color used for the dark
|
|
79
|
+
* navbar divider.
|
|
80
|
+
* backgroundColor: '<%= backgroundColor %>', // The color used for the splash screen background.
|
|
81
|
+
* enableNotifications: false, // Set to true to enable notification delegation.
|
|
82
|
+
* enableSiteSettingsShortcut: true, // Set to false to disable the shortcut into site settings.
|
|
83
|
+
* // Add shortcuts for your app here. Every shortcut must include the following fields:
|
|
84
|
+
* // - name: String that will show up in the shortcut.
|
|
85
|
+
* // - short_name: Shorter string used if |name| is too long.
|
|
86
|
+
* // - url: Absolute path of the URL to launch the app with (e.g '/create').
|
|
87
|
+
* // - icon: Name of the resource in the drawable folder to use as an icon.
|
|
88
|
+
* shortcuts: [
|
|
89
|
+
* // Insert shortcuts here, for example:
|
|
90
|
+
* // [name: 'Open SVG', short_name: 'Open', url: '/open', icon: 'splash']
|
|
91
|
+
* ],
|
|
92
|
+
* // The duration of fade out animation in milliseconds to be played when removing splash screen.
|
|
93
|
+
* splashScreenFadeOutDuration: 300
|
|
94
|
+
* isChromeOSOnly: false, // Setting to true will enable a feature that prevents non-ChromeOS devices
|
|
95
|
+
* from installing the app.
|
|
96
|
+
* serviceAccountJsonFile: '<%= serviceAccountJsonFile %>', // The service account used to communicate with
|
|
97
|
+
* Google Play.
|
|
98
|
+
*
|
|
99
|
+
*/
|
|
100
|
+
class TwaManifest {
|
|
101
|
+
constructor(data) {
|
|
102
|
+
var _a, _b, _c;
|
|
103
|
+
this.packageId = data.packageId;
|
|
104
|
+
this.host = data.host;
|
|
105
|
+
this.name = data.name;
|
|
106
|
+
// Older manifests may not have this field:
|
|
107
|
+
this.launcherName = data.launcherName || data.name;
|
|
108
|
+
// Older manifests may not have this field:
|
|
109
|
+
this.display = asDisplayMode(data.display) || DEFAULT_DISPLAY_MODE;
|
|
110
|
+
this.themeColor = new Color(data.themeColor);
|
|
111
|
+
this.navigationColor = new Color(data.navigationColor);
|
|
112
|
+
this.navigationColorDark = new Color((_a = data.navigationColorDark) !== null && _a !== void 0 ? _a : DEFAULT_NAVIGATION_COLOR);
|
|
113
|
+
this.navigationDividerColor = new Color((_b = data.navigationDividerColor) !== null && _b !== void 0 ? _b : DEFAULT_NAVIGATION_DIVIDER_COLOR);
|
|
114
|
+
this.navigationDividerColorDark = new Color((_c = data.navigationDividerColorDark) !== null && _c !== void 0 ? _c : DEFAULT_NAVIGATION_COLOR);
|
|
115
|
+
this.backgroundColor = new Color(data.backgroundColor);
|
|
116
|
+
this.enableNotifications = data.enableNotifications;
|
|
117
|
+
this.startUrl = data.startUrl;
|
|
118
|
+
this.iconUrl = data.iconUrl;
|
|
119
|
+
this.maskableIconUrl = data.maskableIconUrl;
|
|
120
|
+
this.monochromeIconUrl = data.monochromeIconUrl;
|
|
121
|
+
this.splashScreenFadeOutDuration = data.splashScreenFadeOutDuration;
|
|
122
|
+
this.signingKey = data.signingKey;
|
|
123
|
+
this.appVersionName = data.appVersion;
|
|
124
|
+
this.appVersionCode = data.appVersionCode || DEFAULT_APP_VERSION_CODE;
|
|
125
|
+
this.shortcuts = (data.shortcuts || []).map((si) => {
|
|
126
|
+
return new ShortcutInfo_1.ShortcutInfo(si.name, si.shortName, si.url, si.chosenIconUrl, si.chosenMaskableIconUrl, si.chosenMonochromeIconUrl);
|
|
127
|
+
});
|
|
128
|
+
this.generatorApp = data.generatorApp || DEFAULT_GENERATOR_APP_NAME;
|
|
129
|
+
this.webManifestUrl = data.webManifestUrl ? new URL(data.webManifestUrl) : undefined;
|
|
130
|
+
this.fallbackType = data.fallbackType || 'customtabs';
|
|
131
|
+
this.features = data.features || {};
|
|
132
|
+
this.alphaDependencies = data.alphaDependencies || { enabled: false };
|
|
133
|
+
this.enableSiteSettingsShortcut = data.enableSiteSettingsShortcut != undefined ?
|
|
134
|
+
data.enableSiteSettingsShortcut : true;
|
|
135
|
+
this.isChromeOSOnly = data.isChromeOSOnly != undefined ? data.isChromeOSOnly : false;
|
|
136
|
+
this.shareTarget = data.shareTarget;
|
|
137
|
+
this.orientation = data.orientation || DEFAULT_ORIENTATION;
|
|
138
|
+
this.fingerprints = data.fingerprints || [];
|
|
139
|
+
this.serviceAccountJsonFile = data.serviceAccountJsonFile;
|
|
140
|
+
this.additionalTrustedOrigins = data.additionalTrustedOrigins || [];
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Turns an TwaManifest into a TwaManifestJson.
|
|
144
|
+
*
|
|
145
|
+
* @returns {TwaManifestJson}
|
|
146
|
+
*/
|
|
147
|
+
toJson() {
|
|
148
|
+
return Object.assign({}, this, {
|
|
149
|
+
themeColor: this.themeColor.hex(),
|
|
150
|
+
navigationColor: this.navigationColor.hex(),
|
|
151
|
+
navigationColorDark: this.navigationColorDark.hex(),
|
|
152
|
+
navigationDividerColor: this.navigationDividerColor.hex(),
|
|
153
|
+
navigationDividerColorDark: this.navigationDividerColorDark.hex(),
|
|
154
|
+
backgroundColor: this.backgroundColor.hex(),
|
|
155
|
+
appVersion: this.appVersionName,
|
|
156
|
+
webManifestUrl: this.webManifestUrl ? this.webManifestUrl.toString() : undefined,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Saves the TWA Manifest to the file-system.
|
|
161
|
+
*
|
|
162
|
+
* @param {String} filename the location where the TWA Manifest will be saved.
|
|
163
|
+
*/
|
|
164
|
+
async saveToFile(filename) {
|
|
165
|
+
const json = this.toJson();
|
|
166
|
+
await fs.promises.writeFile(filename, JSON.stringify(json, null, 2));
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Validates if the Manifest has all the fields needed to generate a TWA project and if the
|
|
170
|
+
* values for those fields are valid.
|
|
171
|
+
*
|
|
172
|
+
* @returns {string | null} the error, if any field has an error or null if all fields are valid.
|
|
173
|
+
*/
|
|
174
|
+
validate() {
|
|
175
|
+
let error;
|
|
176
|
+
error = util_1.validateNotEmpty(this.host, 'host');
|
|
177
|
+
if (error != null) {
|
|
178
|
+
return error;
|
|
179
|
+
}
|
|
180
|
+
error = util_1.validateNotEmpty(this.name, 'name');
|
|
181
|
+
if (error != null) {
|
|
182
|
+
return error;
|
|
183
|
+
}
|
|
184
|
+
error = util_1.validateNotEmpty(this.startUrl, 'startUrl');
|
|
185
|
+
if (error != null) {
|
|
186
|
+
return error;
|
|
187
|
+
}
|
|
188
|
+
if (!this.iconUrl) {
|
|
189
|
+
return 'iconUrl cannot be empty';
|
|
190
|
+
}
|
|
191
|
+
error = util_1.validateNotEmpty(this.iconUrl, 'iconUrl');
|
|
192
|
+
if (error != null) {
|
|
193
|
+
return error;
|
|
194
|
+
}
|
|
195
|
+
return error;
|
|
196
|
+
}
|
|
197
|
+
generateShortcuts() {
|
|
198
|
+
return '[' + this.shortcuts.map((shortcut, i) => shortcut.toString(i)).join(',') + ']';
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Creates a new TwaManifest, using the URL for the Manifest as a base URL and uses the content
|
|
202
|
+
* of the Web Manifest to generate the fields for the TWA Manifest.
|
|
203
|
+
*
|
|
204
|
+
* @param {URL} webManifestUrl the URL where the webmanifest is available.
|
|
205
|
+
* @param {WebManifest} webManifest the Web Manifest, used as a base for the TWA Manifest.
|
|
206
|
+
* @returns {TwaManifest}
|
|
207
|
+
*/
|
|
208
|
+
static fromWebManifestJson(webManifestUrl, webManifest) {
|
|
209
|
+
var _a;
|
|
210
|
+
const icon = util_1.findSuitableIcon(webManifest.icons, 'any', MIN_ICON_SIZE);
|
|
211
|
+
const maskableIcon = util_1.findSuitableIcon(webManifest.icons, 'maskable', MIN_ICON_SIZE);
|
|
212
|
+
const monochromeIcon = util_1.findSuitableIcon(webManifest.icons, 'monochrome', MIN_NOTIFICATION_ICON_SIZE);
|
|
213
|
+
const fullStartUrl = new URL(webManifest['start_url'] || '/', webManifestUrl);
|
|
214
|
+
const shortcuts = this.getShortcuts(webManifestUrl, webManifest);
|
|
215
|
+
function resolveIconUrl(icon) {
|
|
216
|
+
return icon ? new URL(icon.src, webManifestUrl).toString() : undefined;
|
|
217
|
+
}
|
|
218
|
+
const twaManifest = new TwaManifest({
|
|
219
|
+
packageId: util_1.generatePackageId(webManifestUrl.host) || '',
|
|
220
|
+
host: webManifestUrl.host,
|
|
221
|
+
name: webManifest['name'] || webManifest['short_name'] || DEFAULT_APP_NAME,
|
|
222
|
+
launcherName: webManifest['short_name'] || ((_a = webManifest['name']) === null || _a === void 0 ? void 0 : _a.substring(0, SHORT_NAME_MAX_SIZE)) || DEFAULT_APP_NAME,
|
|
223
|
+
display: asDisplayMode(webManifest['display']) || DEFAULT_DISPLAY_MODE,
|
|
224
|
+
themeColor: webManifest['theme_color'] || DEFAULT_THEME_COLOR,
|
|
225
|
+
navigationColor: DEFAULT_NAVIGATION_COLOR,
|
|
226
|
+
navigationColorDark: DEFAULT_NAVIGATION_COLOR,
|
|
227
|
+
navigationDividerColor: DEFAULT_NAVIGATION_DIVIDER_COLOR,
|
|
228
|
+
navigationDividerColorDark: DEFAULT_NAVIGATION_DIVIDER_COLOR,
|
|
229
|
+
backgroundColor: webManifest['background_color'] || DEFAULT_BACKGROUND_COLOR,
|
|
230
|
+
startUrl: fullStartUrl.pathname + fullStartUrl.search,
|
|
231
|
+
iconUrl: resolveIconUrl(icon),
|
|
232
|
+
maskableIconUrl: resolveIconUrl(maskableIcon),
|
|
233
|
+
monochromeIconUrl: resolveIconUrl(monochromeIcon),
|
|
234
|
+
appVersion: DEFAULT_APP_VERSION_NAME,
|
|
235
|
+
signingKey: {
|
|
236
|
+
path: DEFAULT_SIGNING_KEY_PATH,
|
|
237
|
+
alias: DEFAULT_SIGNING_KEY_ALIAS,
|
|
238
|
+
},
|
|
239
|
+
splashScreenFadeOutDuration: DEFAULT_SPLASHSCREEN_FADEOUT_DURATION,
|
|
240
|
+
enableNotifications: DEFAULT_ENABLE_NOTIFICATIONS,
|
|
241
|
+
shortcuts: shortcuts,
|
|
242
|
+
webManifestUrl: webManifestUrl.toString(),
|
|
243
|
+
features: {},
|
|
244
|
+
shareTarget: TwaManifest.verifyShareTarget(webManifestUrl, webManifest.share_target),
|
|
245
|
+
orientation: asOrientation(webManifest.orientation) || DEFAULT_ORIENTATION,
|
|
246
|
+
});
|
|
247
|
+
return twaManifest;
|
|
248
|
+
}
|
|
249
|
+
static verifyShareTarget(webManifestUrl, shareTarget) {
|
|
250
|
+
var _a;
|
|
251
|
+
if (!(shareTarget === null || shareTarget === void 0 ? void 0 : shareTarget.action)) {
|
|
252
|
+
return undefined;
|
|
253
|
+
}
|
|
254
|
+
if ((_a = shareTarget === null || shareTarget === void 0 ? void 0 : shareTarget.params) === null || _a === void 0 ? void 0 : _a.files) {
|
|
255
|
+
for (const file of shareTarget.params.files) {
|
|
256
|
+
if (!file.accept) {
|
|
257
|
+
return undefined;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
...shareTarget,
|
|
263
|
+
// Ensure action is an absolute URL.
|
|
264
|
+
action: new URL(shareTarget.action, webManifestUrl).toString(),
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Fetches a Web Manifest from the url and uses it as a base for the TWA Manifest.
|
|
269
|
+
*
|
|
270
|
+
* @param {String} url the URL where the webmanifest is available
|
|
271
|
+
* @returns {TwaManifest}
|
|
272
|
+
*/
|
|
273
|
+
static async fromWebManifest(url) {
|
|
274
|
+
const response = await FetchUtils_1.fetchUtils.fetch(url);
|
|
275
|
+
const webManifest = await response.json();
|
|
276
|
+
const webManifestUrl = new URL(url);
|
|
277
|
+
return TwaManifest.fromWebManifestJson(webManifestUrl, webManifest);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Loads a TWA Manifest from the file system.
|
|
281
|
+
*
|
|
282
|
+
* @param {String} fileName the location of the TWA Manifest file
|
|
283
|
+
*/
|
|
284
|
+
static async fromFile(fileName) {
|
|
285
|
+
const json = JSON.parse((await fs.promises.readFile(fileName)).toString());
|
|
286
|
+
return new TwaManifest(json);
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Given a field name, returns the new value of the field.
|
|
290
|
+
*
|
|
291
|
+
* @param {string} fieldName the name of the given field.
|
|
292
|
+
* @param {string[]} fieldsToIgnore the fields which needs to be ignored.
|
|
293
|
+
* @param {T} oldValue the old value of the field.
|
|
294
|
+
* @param {T} newValue the new value of the field.
|
|
295
|
+
* @returns {T}
|
|
296
|
+
*/
|
|
297
|
+
static getNewFieldValue(fieldName, fieldsToIgnore, oldValue, newValue) {
|
|
298
|
+
if (fieldsToIgnore.includes(fieldName)) {
|
|
299
|
+
return oldValue;
|
|
300
|
+
}
|
|
301
|
+
return newValue || oldValue;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Gets the shortcuts from the web manifest.
|
|
305
|
+
*
|
|
306
|
+
* @param {URL} webManifestUrl the URL where the webManifest is available.
|
|
307
|
+
* @param {WebManifest} webManifest the Web Manifest.
|
|
308
|
+
* @returns {ShortcutInfo[]}
|
|
309
|
+
*/
|
|
310
|
+
static getShortcuts(webManifestUrl, webManifest) {
|
|
311
|
+
const shortcuts = [];
|
|
312
|
+
for (let i = 0; i < (webManifest.shortcuts || []).length; i++) {
|
|
313
|
+
const s = webManifest.shortcuts[i];
|
|
314
|
+
try {
|
|
315
|
+
const shortcutInfo = ShortcutInfo_1.ShortcutInfo.fromShortcutJson(webManifestUrl, s);
|
|
316
|
+
if (shortcutInfo != null) {
|
|
317
|
+
shortcuts.push(shortcutInfo);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
catch (err) {
|
|
321
|
+
TwaManifest.log.warn(`Skipping shortcut[${i}] for ${err.message}.`);
|
|
322
|
+
}
|
|
323
|
+
if (shortcuts.length === 4) {
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return shortcuts;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* @param {string[]} fieldsToIgnore the fields which needs to be ignored.
|
|
331
|
+
* @param {string} fieldName the name of the given field.
|
|
332
|
+
* @param {string} oldUrl the url of the old twaManifest.
|
|
333
|
+
* @param {WebManifestIcon[]} icons the list of icons from the web manifest.
|
|
334
|
+
* @param {string} iconType the type of the requested icon.
|
|
335
|
+
* @param {number} iconSize the size of the requested icon.
|
|
336
|
+
* @param {URL} webManifestUrl the URL where the webManifest is available.
|
|
337
|
+
* @returns {string | undefined} the new icon url.
|
|
338
|
+
*/
|
|
339
|
+
static getNewIconUrl(fieldsToIgnore, fieldName, oldUrl, icons, iconType, iconSize, webManifestUrl) {
|
|
340
|
+
function resolveIconUrl(icon) {
|
|
341
|
+
return icon ? new URL(icon.src, webManifestUrl).toString() : undefined;
|
|
342
|
+
}
|
|
343
|
+
return (fieldsToIgnore.includes(fieldName)) ? oldUrl :
|
|
344
|
+
resolveIconUrl(util_1.findSuitableIcon(icons, iconType, iconSize));
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Merges the Twa Manifest with the web manifest. Ignores the specified fields.
|
|
348
|
+
*
|
|
349
|
+
* @param {string[]} fieldsToIgnore the fields which needs to be ignored.
|
|
350
|
+
* @param {URL} webManifestUrl the URL where the webManifest is available.
|
|
351
|
+
* @param {WebManifest} webManifest the Web Manifest, used as a base for the update of
|
|
352
|
+
* the TWA Manifest.
|
|
353
|
+
* @param {TwaManifest} oldTwaManifest current Twa Manifest.
|
|
354
|
+
* @returns {Promise<TwaManifest>} the new and merged Twa manifest.
|
|
355
|
+
*/
|
|
356
|
+
static async merge(fieldsToIgnore, webManifestUrl, webManifest, oldTwaManifest) {
|
|
357
|
+
var _a;
|
|
358
|
+
let shortcuts = oldTwaManifest.shortcuts;
|
|
359
|
+
if (!(fieldsToIgnore.includes('shortcuts'))) {
|
|
360
|
+
shortcuts = this.getShortcuts(webManifestUrl, webManifest);
|
|
361
|
+
}
|
|
362
|
+
const oldTwaManifestJson = oldTwaManifest.toJson();
|
|
363
|
+
const iconUrl = this.getNewIconUrl(fieldsToIgnore, 'icons', oldTwaManifestJson.iconUrl, webManifest.icons, 'any', MIN_ICON_SIZE, webManifestUrl);
|
|
364
|
+
const maskableIconUrl = this.getNewIconUrl(fieldsToIgnore, 'maskableIcons', oldTwaManifestJson.iconUrl, webManifest.icons, 'maskable', MIN_ICON_SIZE, webManifestUrl);
|
|
365
|
+
const monochromeIconUrl = this.getNewIconUrl(fieldsToIgnore, 'monochromeIcons', oldTwaManifestJson.iconUrl, webManifest.icons, 'monochrome', MIN_NOTIFICATION_ICON_SIZE, webManifestUrl);
|
|
366
|
+
const fullStartUrl = new URL(webManifest['start_url'] || '/', webManifestUrl);
|
|
367
|
+
const twaManifest = new TwaManifest({
|
|
368
|
+
...oldTwaManifestJson,
|
|
369
|
+
name: this.getNewFieldValue('name', fieldsToIgnore, oldTwaManifest.name, webManifest['name'] || webManifest['short_name']),
|
|
370
|
+
launcherName: this.getNewFieldValue('short_name', fieldsToIgnore, oldTwaManifest.launcherName, webManifest['short_name'] || ((_a = webManifest['name']) === null || _a === void 0 ? void 0 : _a.substring(0, SHORT_NAME_MAX_SIZE))),
|
|
371
|
+
display: this.getNewFieldValue('display', fieldsToIgnore, oldTwaManifest.display, asDisplayMode(webManifest['display'])),
|
|
372
|
+
themeColor: this.getNewFieldValue('themeColor', fieldsToIgnore, oldTwaManifest.themeColor.hex(), webManifest['theme_color']),
|
|
373
|
+
backgroundColor: this.getNewFieldValue('backgroundColor', fieldsToIgnore, oldTwaManifest.backgroundColor.hex(), webManifest['background_color']),
|
|
374
|
+
startUrl: this.getNewFieldValue('startUrl', fieldsToIgnore, oldTwaManifest.startUrl, fullStartUrl.pathname + fullStartUrl.search),
|
|
375
|
+
iconUrl: iconUrl || oldTwaManifestJson.iconUrl,
|
|
376
|
+
maskableIconUrl: maskableIconUrl || oldTwaManifestJson.maskableIconUrl,
|
|
377
|
+
monochromeIconUrl: monochromeIconUrl || oldTwaManifestJson.monochromeIconUrl,
|
|
378
|
+
shortcuts: shortcuts,
|
|
379
|
+
});
|
|
380
|
+
return twaManifest;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
exports.TwaManifest = TwaManifest;
|
|
384
|
+
TwaManifest.log = new Log_1.ConsoleLog('twa-manifest');
|