diff --git a/packages/cli/src/lib/cmds/init.ts b/packages/cli/src/lib/cmds/init.ts index 4d06194c..0a485cee 100644 --- a/packages/cli/src/lib/cmds/init.ts +++ b/packages/cli/src/lib/cmds/init.ts @@ -17,9 +17,9 @@ import * as fs from 'fs'; import Color = require('color'); import * as inquirer from 'inquirer'; -import {Config, JdkHelper, KeyTool, Log, TwaGenerator, TwaManifest, util} from '@bubblewrap/core'; -import {validateColor, validateDisplayMode, validateKeyPassword, validateUrl, - notEmpty} from '../inputHelpers'; +import {Config, DISPLAY_MODES, JdkHelper, KeyTool, Log, TwaGenerator, TwaManifest, + util} from '@bubblewrap/core'; +import {validateColor, validateKeyPassword, validateUrl, notEmpty} from '../inputHelpers'; import {ParsedArgs} from 'minimist'; import {APP_NAME} from '../constants'; @@ -52,10 +52,10 @@ async function confirmTwaConfig(twaManifest: TwaManifest): Promise validate: async (input): Promise => notEmpty(input, 'Launcher name'), }, { name: 'display', - type: 'input', + type: 'list', message: 'Display mode to be used:', default: twaManifest.display, - validate: validateDisplayMode, + choices: DISPLAY_MODES, }, { name: 'themeColor', type: 'input', diff --git a/packages/cli/src/lib/inputHelpers.ts b/packages/cli/src/lib/inputHelpers.ts index 422d6de0..7d54658e 100644 --- a/packages/cli/src/lib/inputHelpers.ts +++ b/packages/cli/src/lib/inputHelpers.ts @@ -50,11 +50,3 @@ export async function validateUrl(url: string): Promise { } return true; } - -export async function validateDisplayMode(displayMode: string): Promise { - const validModes = ['browser', 'minimal-ui', 'standalone', 'fullscreen']; - if (!validModes.includes(displayMode)) { - throw new Error(`${displayMode} is not a valid display mode (${validModes.join(', ')})`); - } - return true; -} diff --git a/packages/cli/src/spec/inputHelpersSpec.ts b/packages/cli/src/spec/inputHelpersSpec.ts index 7cc1d5b1..b9ed2207 100644 --- a/packages/cli/src/spec/inputHelpersSpec.ts +++ b/packages/cli/src/spec/inputHelpersSpec.ts @@ -61,17 +61,4 @@ describe('inputHelpers', () => { inputHelpers.validateColor('rgb(23, 0 30')).toBeRejectedWithError(); }); }); - - describe('#validateDisplayMode', () => { - it('returns true for valid colors', async () => { - expect(await inputHelpers.validateDisplayMode('browser')); - expect(await inputHelpers.validateDisplayMode('minimal-ui')); - expect(await inputHelpers.validateDisplayMode('standalone')); - expect(await inputHelpers.validateDisplayMode('fullscreen')); - }); - - it('throws Error for invalid display modes', async () => { - await expectAsync(inputHelpers.validateColor('bogus')).toBeRejectedWithError(); - }); - }); }); diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 0fe2e10a..71757007 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -20,7 +20,7 @@ import {GradleWrapper} from './lib/GradleWrapper'; import Log from './lib/Log'; import {JdkHelper} from './lib/jdk/JdkHelper'; import {KeyTool} from './lib/jdk/KeyTool'; -import {TwaManifest} from './lib/TwaManifest'; +import {TwaManifest, DISPLAY_MODES} from './lib/TwaManifest'; import {TwaGenerator} from './lib/TwaGenerator'; import {DigitalAssetLinks} from './lib/DigitalAssetLinks'; import * as util from './lib/util'; @@ -34,5 +34,6 @@ export {AndroidSdkTools, Log, TwaGenerator, TwaManifest, + DISPLAY_MODES, util, };