Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a generator_app metatag to AndroidManifest.xml #90

Merged
merged 2 commits into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/cli/cmds/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {TwaGenerator} from '../../lib/TwaGenerator';
import {TwaManifest} from '../../lib/TwaManifest';
import {validateColor, validatePassword, validateUrl, notEmpty} from '../inputHelpers';
import {ParsedArgs} from 'minimist';
import {APP_NAME} from '../constants';

const log = new Log('init');

Expand Down Expand Up @@ -127,6 +128,7 @@ async function confirmTwaConfig(twaManifest: TwaManifest): Promise<TwaManifest>
alias: result.keyAlias,
path: result.keyPath,
};
twaManifest.generatorApp = APP_NAME;
return twaManifest;
}

Expand Down
2 changes: 2 additions & 0 deletions src/cli/cmds/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ import * as path from 'path';
import {TwaGenerator} from '../../lib/TwaGenerator';
import {TwaManifest} from '../../lib/TwaManifest';
import {ParsedArgs} from 'minimist';
import {APP_NAME} from '../constants';

export async function update(args: ParsedArgs): Promise<void> {
const targetDirectory = args.directory || process.cwd();
const manifestFile = args.manifest || path.join(process.cwd(), 'twa-manifest.json');
const twaManifest = await TwaManifest.fromFile(manifestFile);
twaManifest.generatorApp = APP_NAME;
const twaGenerator = new TwaGenerator();
return await twaGenerator.createTwaProject(targetDirectory, twaManifest);
}
17 changes: 17 additions & 0 deletions src/cli/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2019 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export const APP_NAME = 'llama-pack-cli';
38 changes: 27 additions & 11 deletions src/lib/TwaManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ const DISALLOWED_ANDROID_PACKAGE_CHARS_REGEX = /[^ a-zA-Z0-9_\.]/;
// The minimum size needed for the app icon.
const MIN_ICON_SIZE = 512;

// Default values used on the Twa Manifest
const DEFAULT_SPLASHSCREEN_FADEOUT_DURATION = 300;
const DEFAULT_APP_NAME = 'My TWA';
const DEFAULT_THEME_COLOR = '#FFFFFF';
const DEFAULT_NAVIGATION_COLOR = '#000000';
const DEFAULT_BACKGROUND_COLOR = '#FFFFFF';
const DEFAULT_APP_VERSION = '1.0.0';
const DEFAULT_SIGNING_KEY_PATH = './android.keystore';
const DEFAULT_SIGNING_KEY_ALIAS = 'android';
const DEFAULT_USE_BROWSER_ON_CHROMEOS = true;
const DEFAULT_ENABLE_NOTIFICATIONS = false;
const DEFAULT_GENERATOR_APP_NAME = 'unknown';

/**
* Generates an Android Application Id / Package Name, using the reverse hostname as a base
* and appending `.twa` to the end.
Expand Down Expand Up @@ -120,6 +133,7 @@ export class TwaManifest {
signingKey: SigningKeyInfo;
appVersion: string;
shortcuts: string;
generatorApp: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the subject of constants, can any of these members be constant?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not the members. But moving sone of the "magic values" throughout the code to consts sound like a good idea.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the default values to consts. Not sure what the best practice for JSON field names is.


constructor(data: TwaManifestJson) {
this.packageId = data.packageId;
Expand All @@ -138,6 +152,7 @@ export class TwaManifest {
this.signingKey = data.signingKey;
this.appVersion = data.appVersion;
this.shortcuts = data.shortcuts;
this.generatorApp = data.generatorApp || DEFAULT_GENERATOR_APP_NAME;
}

/**
Expand Down Expand Up @@ -211,23 +226,23 @@ export class TwaManifest {
const twaManifest = new TwaManifest({
packageId: generatePackageId(webManifestUrl.host),
host: webManifestUrl.host,
name: webManifest['name'] || webManifest['short_name'] || 'My TWA',
launcherName: webManifest['short_name'] || webManifest['name'] || 'My TWA',
themeColor: webManifest['theme_color'] || '#FFFFFF',
navigationColor: '#000000',
backgroundColor: webManifest['background_color'] || '#FFFFFF',
name: webManifest['name'] || webManifest['short_name'] || DEFAULT_APP_NAME,
launcherName: webManifest['short_name'] || webManifest['name'] || DEFAULT_APP_NAME,
themeColor: webManifest['theme_color'] || DEFAULT_THEME_COLOR,
navigationColor: DEFAULT_NAVIGATION_COLOR,
backgroundColor: webManifest['background_color'] || DEFAULT_BACKGROUND_COLOR,
startUrl: fullStartUrl.pathname + fullStartUrl.search,
iconUrl: icon ? new URL(icon.src, webManifestUrl).toString() : undefined,
maskableIconUrl:
maskableIcon ? new URL(maskableIcon.src, webManifestUrl).toString() : undefined,
appVersion: '1.0.0',
appVersion: DEFAULT_APP_VERSION,
signingKey: {
path: './android.keystore',
alias: 'android',
path: DEFAULT_SIGNING_KEY_PATH,
alias: DEFAULT_SIGNING_KEY_ALIAS,
},
useBrowserOnChromeOS: true,
splashScreenFadeOutDuration: 300,
enableNotifications: false,
useBrowserOnChromeOS: DEFAULT_USE_BROWSER_ON_CHROMEOS,
splashScreenFadeOutDuration: DEFAULT_SPLASHSCREEN_FADEOUT_DURATION,
enableNotifications: DEFAULT_ENABLE_NOTIFICATIONS,
shortcuts: JSON.stringify(shortcuts, undefined, 2),
});
return twaManifest;
Expand Down Expand Up @@ -277,6 +292,7 @@ export interface TwaManifestJson {
signingKey: SigningKeyInfo;
appVersion: string;
shortcuts: string;
generatorApp?: string;
}

export interface SigningKeyInfo {
Expand Down
5 changes: 4 additions & 1 deletion template_project/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def twaManifest = [
// - icon: Name of the resource in the drawable folder to use as an icon.
shortcuts: <%= generateShortcuts() %>,
// The duration of fade out animation in milliseconds to be played when removing splash screen.
splashScreenFadeOutDuration: <%= splashScreenFadeOutDuration %>
splashScreenFadeOutDuration: <%= splashScreenFadeOutDuration %>,
generatorApp: '<%= generatorApp %>' // Apllication that generated the Android Project
]

android {
Expand Down Expand Up @@ -108,6 +109,8 @@ android {
// The splashScreenFadeOutDuration resource is used to set the duration of fade out animation in milliseconds
// to be played when removing splash screen. The default is 0 (no animation).
resValue "integer", "splashScreenFadeOutDuration", twaManifest.splashScreenFadeOutDuration.toString()

resValue "string", "generatorApp", twaManifest.generatorApp
}
buildTypes {
release {
Expand Down
4 changes: 4 additions & 0 deletions template_project/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
android:name="cros_web_alternative"
android:value="@string/crosLaunchUrl" />

<meta-data
android:name="twa_generator"
android:value="@string/generatorApp" />

<activity android:name="com.google.androidbrowserhelper.trusted.LauncherActivity"
android:label="@string/launcherName">
<meta-data android:name="android.support.customtabs.trusted.DEFAULT_URL"
Expand Down