MapComplete/src/Logic/Web/AndroidPolyfill.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

39 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-11-18 20:43:19 +01:00
/**
* 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()