|
| 1 | +import { |
| 2 | + ConfigPlugin, |
| 3 | + withAndroidManifest, |
| 4 | + withInfoPlist, |
| 5 | + AndroidConfig, |
| 6 | +} from '@expo/config-plugins'; |
| 7 | + |
| 8 | +type WebGPUPluginOptions = { |
| 9 | + enableToggles?: string[]; |
| 10 | + disableToggles?: string[]; |
| 11 | +}; |
| 12 | + |
| 13 | +const withWebGPUAndroid: ConfigPlugin<WebGPUPluginOptions> = ( |
| 14 | + config, |
| 15 | + { enableToggles = [], disableToggles = [] } = {} |
| 16 | +) => { |
| 17 | + return withAndroidManifest(config, (config) => { |
| 18 | + const app = AndroidConfig.Manifest.getMainApplicationOrThrow( |
| 19 | + config.modResults |
| 20 | + ); |
| 21 | + if (!app['meta-data']) app['meta-data'] = []; |
| 22 | + |
| 23 | + if (enableToggles.length > 0) { |
| 24 | + app['meta-data'].push({ |
| 25 | + $: { |
| 26 | + 'android:name': 'com.webgpu.enable_toggles', |
| 27 | + 'android:value': enableToggles.join(','), |
| 28 | + }, |
| 29 | + }); |
| 30 | + } |
| 31 | + if (disableToggles.length > 0) { |
| 32 | + app['meta-data'].push({ |
| 33 | + $: { |
| 34 | + 'android:name': 'com.webgpu.disable_toggles', |
| 35 | + 'android:value': disableToggles.join(','), |
| 36 | + }, |
| 37 | + }); |
| 38 | + } |
| 39 | + return config; |
| 40 | + }); |
| 41 | +}; |
| 42 | + |
| 43 | +const withWebGPUIos: ConfigPlugin<WebGPUPluginOptions> = ( |
| 44 | + config, |
| 45 | + { enableToggles = [], disableToggles = [] } = {} |
| 46 | +) => { |
| 47 | + return withInfoPlist(config, (config) => { |
| 48 | + if (enableToggles.length > 0) { |
| 49 | + config.modResults['RNWebGPUEnableToggles'] = enableToggles; |
| 50 | + } |
| 51 | + if (disableToggles.length > 0) { |
| 52 | + config.modResults['RNWebGPUDisableToggles'] = disableToggles; |
| 53 | + } |
| 54 | + return config; |
| 55 | + }); |
| 56 | +}; |
| 57 | + |
| 58 | +const withWebGPU: ConfigPlugin<WebGPUPluginOptions> = ( |
| 59 | + config, |
| 60 | + options = {} |
| 61 | +) => { |
| 62 | + config = withWebGPUAndroid(config, options); |
| 63 | + config = withWebGPUIos(config, options); |
| 64 | + return config; |
| 65 | +}; |
| 66 | + |
| 67 | +export default withWebGPU; |
0 commit comments