Skip to content

Commit 48156da

Browse files
Sophia Zhangfacebook-github-bot
authored andcommitted
Enable 2D PWA mode
Summary: Adds the ability to create 2D PWAs to the bubblewrap cli tool Reviewed By: zjm-meta Differential Revision: D71768320 fbshipit-source-id: 7a2691d831578a1ea7bb9cfc811fa708682bf8ce
1 parent 7c0a06a commit 48156da

File tree

7 files changed

+27
-31
lines changed

7 files changed

+27
-31
lines changed

bubblewrap/packages/cli/src/lib/cmds/init.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ export interface InitArgs {
3434
directory?: string;
3535
chromeosonly?: boolean;
3636
metaquest?: boolean;
37-
// temporary flag to set 2D OS App Mode before the functionality is ready for use.
38-
flat?: boolean;
3937
alphaDependencies?: boolean;
4038
}
4139

@@ -181,6 +179,7 @@ async function confirmTwaConfig(twaManifest: TwaManifest, prompt: Prompt): Promi
181179
...twaManifest.features,
182180
horizonBilling: {
183181
enabled: true,
182+
horizonOSAppMode: twaManifest.horizonOSAppMode,
184183
},
185184
};
186185
}
@@ -298,17 +297,13 @@ export async function init(
298297
twaManifest.minSdkVersion = 23;
299298
// Warn about increasing the minimum Android API Level
300299
prompt.printMessage(messages.warnIncreasingMinSdkVersion);
301-
if (args.flat){
302-
// Temporary until 2d app mode is available in store
303-
twaManifest.horizonOSAppMode = '2d';
304-
} else {
305-
twaManifest.horizonOSAppMode = await prompt.promptChoice(
306-
messages.promptHorizonOSAppMode,
307-
HorizonOsAppModes,
308-
twaManifest.horizonOSAppMode,
309-
validateHorizonOSAppMode,
310-
);
311-
}
300+
twaManifest.horizonOSAppMode = await prompt.promptChoice(
301+
messages.promptHorizonOSAppMode,
302+
HorizonOsAppModes,
303+
twaManifest.horizonOSAppMode,
304+
validateHorizonOSAppMode,
305+
);
306+
312307
twaManifest.features = {
313308
...twaManifest.features,
314309
horizonPlatformSDK: {

bubblewrap/packages/core/package-lock.json

Lines changed: 1 addition & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bubblewrap/packages/core/src/lib/TwaManifest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function asOrientation(input?: string): Orientation | null {
6565
}
6666

6767
// Supported launch modes for TWA on Meta Quest
68-
const HORIZONOS_APP_MODE_VALUES = ['immersive'];
68+
const HORIZONOS_APP_MODE_VALUES = ['immersive', '2D'];
6969
export type HorizonOSAppMode = typeof HORIZONOS_APP_MODE_VALUES[number];
7070
export const HorizonOsAppModes: HorizonOSAppMode[] = [...HORIZONOS_APP_MODE_VALUES];
7171

bubblewrap/packages/core/src/lib/features/FeatureManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class FeatureManager {
8080

8181
if (twaManifest.features.horizonBilling?.enabled) {
8282
if (twaManifest.alphaDependencies?.enabled) {
83-
this.addFeature(new HorizonBillingFeature());
83+
this.addFeature(new HorizonBillingFeature(twaManifest.features.horizonBilling));
8484
} else {
8585
log.error('Skipping HorizonBillingFeature. '+
8686
'Enable alphaDependencies to add HorizonBillingFeature.');

bubblewrap/packages/core/src/lib/features/HorizonBillingFeature.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,23 @@
1515
* limitations under the License.
1616
*/
1717

18+
import { HorizonOSAppMode } from '../TwaManifest';
1819
import {EmptyFeature} from './EmptyFeature';
1920

2021
export type HorizonBillingConfig = {
2122
enabled: boolean;
23+
horizonOSAppMode: HorizonOSAppMode;
2224
}
2325

2426
export class HorizonBillingFeature extends EmptyFeature {
25-
constructor() {
27+
constructor(config: HorizonBillingConfig) {
2628
super('horizonbilling');
2729

2830
this.buildGradle.dependencies.push('com.meta.androidbrowserhelper:horizonbilling:1.0.0-alpha11');
2931

30-
this.androidManifest.components.push(`
32+
const category = config.horizonOSAppMode == '2D' ? '' : '<category android:name="com.oculus.intent.category.VR" />';
33+
34+
this.androidManifest.components.push(`
3135
<activity
3236
android:name="com.meta.androidbrowserhelper.horizonbilling.provider.PaymentActivity"
3337
android:theme="@android:style/Theme.Translucent.NoTitleBar"
@@ -36,7 +40,7 @@ export class HorizonBillingFeature extends EmptyFeature {
3640
3741
<intent-filter>
3842
<action android:name="org.chromium.intent.action.PAY" />
39-
<category android:name="com.oculus.intent.category.VR" />
43+
${category}
4044
</intent-filter>
4145
4246
<meta-data

bubblewrap/packages/core/src/spec/lib/features/FeatureManagerSpec.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {AppsFlyerConfig, AppsFlyerFeature} from '../../../lib/features/AppsFlyer
2020
import {FirstRunFlagConfig, FirstRunFlagFeature} from '../../../lib/features/FirstRunFlagFeature';
2121
import {LocationDelegationFeature} from '../../../lib/features/LocationDelegationFeature';
2222
import {PlayBillingFeature} from '../../../lib/features/PlayBillingFeature';
23-
import {HorizonBillingFeature} from '../../../lib/features/HorizonBillingFeature';
23+
import { HorizonBillingConfig, HorizonBillingFeature } from '../../../lib/features/HorizonBillingFeature';
2424
import {TwaManifest} from '../../../lib/TwaManifest';
2525
import {Feature} from '../../../lib/features/Feature';
2626

@@ -184,18 +184,20 @@ describe('FeatureManager', () => {
184184
});
185185

186186
it('Enables the Horizon Billing feature', () => {
187+
const horizonBillingConfig = {
188+
enabled: true,
189+
horizonOSAppMode: 'immersive',
190+
} as HorizonBillingConfig;
187191
const manifest = {
188192
features: {
189-
horizonBilling: {
190-
enabled: true,
191-
},
193+
horizonBilling: horizonBillingConfig,
192194
},
193195
alphaDependencies: {
194196
enabled: true,
195197
},
196198
} as TwaManifest;
197199

198-
const horizonBillingFeature = new HorizonBillingFeature();
200+
const horizonBillingFeature = new HorizonBillingFeature(horizonBillingConfig);
199201
const features = new FeatureManager(manifest);
200202

201203
horizonBillingFeature.androidManifest.components.forEach((component) => {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
<meta-data
163163
android:name="horizonos.pwa.APP_MODE"
164164
android:value="@string/horizonOSAppMode" />
165-
<% if (horizonOSAppMode === '2d') { %>
165+
<% if (horizonOSAppMode === '2D') { %>
166166
<meta-data android:name="com.oculus.vrshell.uses_secure_layer"
167167
android:value="secure"/>
168168
<% } %>
@@ -209,7 +209,7 @@
209209
<% if (horizonOSAppMode === 'immersive') { %>
210210
<category android:name="com.oculus.intent.category.VR" />
211211
<% } %>
212-
<% if (horizonOSAppMode === '2d') { %>
212+
<% if (horizonOSAppMode === '2D') { %>
213213
<category android:name="com.oculus.intent.category.2D" />
214214
<% } %>
215215
</intent-filter>

0 commit comments

Comments
 (0)