Android: WIP

This commit is contained in:
Pieter Vander Vennet 2024-11-18 20:43:19 +01:00
parent 2e5ab74114
commit e7eb4bde18
5 changed files with 45 additions and 1 deletions

View file

@ -0,0 +1,38 @@
/**
* The Android Polyfill will attempt to communicate with the Anrdoid Shell.
* If this is successful, it will patch some webAPIs
*/
import { registerPlugin } from "@capacitor/core"
export class AndroidPolyfill {
private readonly databridgePlugin: DatabridgePlugin
constructor() {
this.databridgePlugin = registerPlugin<DatabridgePlugin>("Databridge", {
web: () => {
return <DatabridgePlugin>{
async request(options: { key: string }): Promise<{ value: string }> {
return { value: "web" }
},
}
},
})
}
public async init(){
const shell = await this.databridgePlugin.request({ key: "meta" })
if(shell.value === "web"){
console.log("Not initing Android polyfill; web detected")
return
}
console.log("Detected shell:", shell.value)
}
}
export interface DatabridgePlugin {
request(options: { key: string }): Promise<{ value: string }>;
}
new AndroidPolyfill().init()