Skip to content

Commit

Permalink
Merge pull request #328 from andreban/shortcuts-fix
Browse files Browse the repository at this point in the history
Fixed reading shortcuts from twa manifest
  • Loading branch information
andreban authored Sep 8, 2020
2 parents 3b1843b + ecdd3dd commit 4719c09
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/core/src/lib/TwaManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ export class TwaManifest {
this.signingKey = data.signingKey;
this.appVersionName = data.appVersion;
this.appVersionCode = data.appVersionCode || DEFAULT_APP_VERSION_CODE;
this.shortcuts = data.shortcuts;
this.shortcuts = (data.shortcuts || []).map((si) => {
return new ShortcutInfo(si.name, si.shortName, si.url, si.chosenIconUrl,
si.chosenMaskableIconUrl, si.chosenMonochromeIconUrl);
});
this.generatorApp = data.generatorApp || DEFAULT_GENERATOR_APP_NAME;
this.webManifestUrl = data.webManifestUrl ? new URL(data.webManifestUrl) : undefined;
this.fallbackType = data.fallbackType || 'customtabs';
Expand Down Expand Up @@ -338,7 +341,7 @@ export interface TwaManifestJson {
signingKey: SigningKeyInfo;
appVersionCode?: number; // Older Manifests may not have this field.
appVersion: string; // appVersionName - Old Manifests use `appVersion`. Keeping compatibility.
shortcuts: ShortcutInfo[];
shortcuts?: ShortcutInfo[];
generatorApp?: string;
webManifestUrl?: string;
fallbackType?: FallbackType;
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/spec/lib/TwaManifestSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import {TwaManifest, TwaManifestJson, asDisplayMode} from '../../lib/TwaManifest';
import {WebManifestJson} from '../../lib/types/WebManifest';
import Color = require('color');
import {ShortcutInfo} from '../../lib/ShortcutInfo';

describe('TwaManifest', () => {
describe('#fromWebManifestJson', () => {
Expand Down Expand Up @@ -237,7 +238,8 @@ describe('TwaManifest', () => {
expect(twaManifest.splashScreenFadeOutDuration)
.toEqual(twaManifestJson.splashScreenFadeOutDuration);
expect(twaManifest.enableNotifications).toEqual(twaManifestJson.enableNotifications);
expect(twaManifest.shortcuts).toEqual(twaManifestJson.shortcuts);
expect(twaManifest.shortcuts)
.toEqual([new ShortcutInfo('name', 'shortName', '/', 'icon.png')]);
expect(twaManifest.webManifestUrl).toEqual(new URL(twaManifestJson.webManifestUrl!));
expect(twaManifest.generatorApp).toEqual(twaManifestJson.generatorApp!);
expect(twaManifest.fallbackType).toBe('webview');
Expand Down

0 comments on commit 4719c09

Please sign in to comment.