0 | module Web.Internal.PermissionsTypes
  1 |
  2 | import JS
  3 |
  4 | %default total
  5 |
  6 |
  7 | --------------------------------------------------------------------------------
  8 | --          Enums
  9 | --------------------------------------------------------------------------------
 10 |
 11 | namespace PermissionState
 12 |
 13 |   public export
 14 |   data PermissionState = Granted | Denied | Prompt
 15 |
 16 |   public export
 17 |   Show PermissionState where
 18 |     show Granted = "granted"
 19 |     show Denied = "denied"
 20 |     show Prompt = "prompt"
 21 |
 22 |   public export
 23 |   Eq PermissionState where
 24 |     (==) = (==) `on` show
 25 |
 26 |   public export
 27 |   Ord PermissionState where
 28 |     compare = compare `on` show
 29 |
 30 |   public export
 31 |   read : String -> Maybe PermissionState
 32 |   read "granted" = Just Granted
 33 |   read "denied" = Just Denied
 34 |   read "prompt" = Just Prompt
 35 |   read _ = Nothing
 36 |
 37 |   export
 38 |   ToFFI PermissionState String where
 39 |     toFFI = show
 40 |
 41 |   export
 42 |   FromFFI PermissionState String where
 43 |     fromFFI = read
 44 |
 45 |
 46 | namespace PermissionName
 47 |
 48 |   public export
 49 |   data PermissionName =
 50 |       Geolocation
 51 |     | Notifications
 52 |     | Push
 53 |     | Midi
 54 |     | Camera
 55 |     | Microphone
 56 |     | SpeakerSelection
 57 |     | DeviceInfo
 58 |     | BackgroundFetch
 59 |     | BackgroundSync
 60 |     | Bluetooth
 61 |     | PersistentStorage
 62 |     | AmbientLightSensor
 63 |     | Accelerometer
 64 |     | Gyroscope
 65 |     | Magnetometer
 66 |     | ClipboardRead
 67 |     | ClipboardWrite
 68 |     | DisplayCapture
 69 |     | Nfc
 70 |
 71 |   public export
 72 |   Show PermissionName where
 73 |     show Geolocation = "geolocation"
 74 |     show Notifications = "notifications"
 75 |     show Push = "push"
 76 |     show Midi = "midi"
 77 |     show Camera = "camera"
 78 |     show Microphone = "microphone"
 79 |     show SpeakerSelection = "speaker-selection"
 80 |     show DeviceInfo = "device-info"
 81 |     show BackgroundFetch = "background-fetch"
 82 |     show BackgroundSync = "background-sync"
 83 |     show Bluetooth = "bluetooth"
 84 |     show PersistentStorage = "persistent-storage"
 85 |     show AmbientLightSensor = "ambient-light-sensor"
 86 |     show Accelerometer = "accelerometer"
 87 |     show Gyroscope = "gyroscope"
 88 |     show Magnetometer = "magnetometer"
 89 |     show ClipboardRead = "clipboard-read"
 90 |     show ClipboardWrite = "clipboard-write"
 91 |     show DisplayCapture = "display-capture"
 92 |     show Nfc = "nfc"
 93 |
 94 |   public export
 95 |   Eq PermissionName where
 96 |     (==) = (==) `on` show
 97 |
 98 |   public export
 99 |   Ord PermissionName where
100 |     compare = compare `on` show
101 |
102 |   public export
103 |   read : String -> Maybe PermissionName
104 |   read "geolocation" = Just Geolocation
105 |   read "notifications" = Just Notifications
106 |   read "push" = Just Push
107 |   read "midi" = Just Midi
108 |   read "camera" = Just Camera
109 |   read "microphone" = Just Microphone
110 |   read "speaker-selection" = Just SpeakerSelection
111 |   read "device-info" = Just DeviceInfo
112 |   read "background-fetch" = Just BackgroundFetch
113 |   read "background-sync" = Just BackgroundSync
114 |   read "bluetooth" = Just Bluetooth
115 |   read "persistent-storage" = Just PersistentStorage
116 |   read "ambient-light-sensor" = Just AmbientLightSensor
117 |   read "accelerometer" = Just Accelerometer
118 |   read "gyroscope" = Just Gyroscope
119 |   read "magnetometer" = Just Magnetometer
120 |   read "clipboard-read" = Just ClipboardRead
121 |   read "clipboard-write" = Just ClipboardWrite
122 |   read "display-capture" = Just DisplayCapture
123 |   read "nfc" = Just Nfc
124 |   read _ = Nothing
125 |
126 |   export
127 |   ToFFI PermissionName String where
128 |     toFFI = show
129 |
130 |   export
131 |   FromFFI PermissionName String where
132 |     fromFFI = read
133 |
134 |
135 |
136 | --------------------------------------------------------------------------------
137 | --          Interfaces
138 | --------------------------------------------------------------------------------
139 |
140 | export data PermissionStatus : Type where [external]
141 |
142 | export
143 | ToFFI PermissionStatus PermissionStatus where toFFI = id
144 |
145 | export
146 | FromFFI PermissionStatus PermissionStatus where fromFFI = Just
147 |
148 | export
149 | SafeCast PermissionStatus where
150 |   safeCast = unsafeCastOnPrototypeName "PermissionStatus"
151 |
152 | export data Permissions : Type where [external]
153 |
154 | export
155 | ToFFI Permissions Permissions where toFFI = id
156 |
157 | export
158 | FromFFI Permissions Permissions where fromFFI = Just
159 |
160 | export
161 | SafeCast Permissions where
162 |   safeCast = unsafeCastOnPrototypeName "Permissions"
163 |
164 |
165 | --------------------------------------------------------------------------------
166 | --          Dictionaries
167 | --------------------------------------------------------------------------------
168 |
169 | export data CameraDevicePermissionDescriptor : Type where [external]
170 |
171 | export
172 | ToFFI CameraDevicePermissionDescriptor CameraDevicePermissionDescriptor where toFFI = id
173 |
174 | export
175 | FromFFI CameraDevicePermissionDescriptor CameraDevicePermissionDescriptor where fromFFI = Just
176 |
177 | export data DevicePermissionDescriptor : Type where [external]
178 |
179 | export
180 | ToFFI DevicePermissionDescriptor DevicePermissionDescriptor where toFFI = id
181 |
182 | export
183 | FromFFI DevicePermissionDescriptor DevicePermissionDescriptor where fromFFI = Just
184 |
185 | export data MidiPermissionDescriptor : Type where [external]
186 |
187 | export
188 | ToFFI MidiPermissionDescriptor MidiPermissionDescriptor where toFFI = id
189 |
190 | export
191 | FromFFI MidiPermissionDescriptor MidiPermissionDescriptor where fromFFI = Just
192 |
193 | export data PermissionDescriptor : Type where [external]
194 |
195 | export
196 | ToFFI PermissionDescriptor PermissionDescriptor where toFFI = id
197 |
198 | export
199 | FromFFI PermissionDescriptor PermissionDescriptor where fromFFI = Just
200 |
201 | export data PermissionSetParameters : Type where [external]
202 |
203 | export
204 | ToFFI PermissionSetParameters PermissionSetParameters where toFFI = id
205 |
206 | export
207 | FromFFI PermissionSetParameters PermissionSetParameters where fromFFI = Just
208 |
209 | export data PushPermissionDescriptor : Type where [external]
210 |
211 | export
212 | ToFFI PushPermissionDescriptor PushPermissionDescriptor where toFFI = id
213 |
214 | export
215 | FromFFI PushPermissionDescriptor PushPermissionDescriptor where fromFFI = Just
216 |