File size: 2,530 Bytes
b450976
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import {registerWebModule, NativeModule} from "expo"

import {CrustModuleEvents} from "./Crust.types"

class CrustModule extends NativeModule<CrustModuleEvents> {
  PI = Math.PI
  private readonly httpRequests = new Map<string, AbortController>()
  async setValueAsync(value: string): Promise<void> {
    this.emit("onChange", {value})
  }
  async nativeHttpRequest(requestId: string, method: string, url: string, headers: Record<string, string>, body?: string | null) {
    const controller = new AbortController()
    this.httpRequests.set(requestId, controller)
    try {
      const response = await fetch(url, {method, headers, body, signal: controller.signal})
      return {
        status: response.status,
        statusText: response.statusText,
        headers: Object.fromEntries(response.headers.entries()),
        body: await response.text(),
      }
    } finally {
      this.httpRequests.delete(requestId)
    }
  }
  async cancelNativeHttpRequest(requestId: string): Promise<void> {
    this.httpRequests.get(requestId)?.abort()
    this.httpRequests.delete(requestId)
  }
  /** The web has no local files to resolve. */
  canonicalFilePath(_path: string): string | null {
    return null
  }
  hello() {
    return "Hello world! 👋"
  }
  showAVRoutePicker(_tintColor?: string | null) {}
  async setDeferredSystemGestures(_edges: string[]): Promise<void> {}
  async setNotificationConfig(_listenerEnabled: boolean, _blocklist: string[]): Promise<void> {}
  async getInstalledApps() {
    return []
  }
  async getInstalledAppsForNotifications() {
    return []
  }
  async hasNotificationListenerPermission() {
    return false
  }
  async refreshNotificationListener() {
    return false
  }
  async openNotificationListenerSettings() {
    return false
  }
  async isBetaBuild() {
    return false
  }
  async mentraJsSpawn(_pkg: string, _polyfill: string, _miniappJs: string) {
    return false
  }
  async mentraJsEvaluate(_pkg: string, _src: string) {
    return null
  }
  async mentraJsKill(_pkg: string) {
    return
  }
  async mentraJsDispatchToJs(_pkg: string, _env: Record<string, unknown>) {
    return
  }
  async mentraJsSetManifest(_pkg: string, _perms: string[]) {
    return
  }
  mentraJsAlivePackages() {
    return []
  }
  async mentraJsDebugForceGC(_pkg: string) {
    return false
  }
  mentraJsLoadPolyfillBundle() {
    return ""
  }
}

export default registerWebModule(CrustModule, "CrustModule")