Chore: housekeeping

This commit is contained in:
Pieter Vander Vennet 2025-02-10 02:04:58 +01:00
parent cd9e03dd6f
commit b300fffdc5
156 changed files with 4436 additions and 1318 deletions

View file

@ -7,7 +7,9 @@ import { Store, UIEventSource } from "../UIEventSource"
import { OsmConnection } from "../Osm/OsmConnection"
export interface DatabridgePlugin {
request<T extends (string | object) = string | object>(options: { key: string }): Promise<{ value: T }>;
request<T extends string | object = string | object>(options: {
key: string
}): Promise<{ value: T }>
}
const DatabridgePluginSingleton = registerPlugin<DatabridgePlugin>("Databridge", {
@ -28,17 +30,25 @@ export class AndroidPolyfill {
private static readonly databridgePlugin: DatabridgePlugin = DatabridgePluginSingleton
private static readonly _inAndroid: UIEventSource<boolean> = new UIEventSource<boolean>(false)
public static readonly inAndroid: Store<boolean> = AndroidPolyfill._inAndroid
private static readonly _geolocationPermission: UIEventSource<"granted" | "denied" | "prompt"> = new UIEventSource("prompt")
public static readonly geolocationPermission: Store<"granted" | "denied" | "prompt"> = this._geolocationPermission
private static readonly _geolocationPermission: UIEventSource<"granted" | "denied" | "prompt"> =
new UIEventSource("prompt")
public static readonly geolocationPermission: Store<"granted" | "denied" | "prompt"> =
this._geolocationPermission
/**
* Registers 'navigator.'
* @private
*/
private static backfillGeolocation(databridgePlugin: DatabridgePlugin) {
const src = UIEventSource.FromPromise(databridgePlugin.request({ key: "location:has-permission" }))
src.addCallbackAndRunD(permission => {
console.log("> Checking geopermission gave: ", JSON.stringify(permission), permission.value)
const src = UIEventSource.FromPromise(
databridgePlugin.request({ key: "location:has-permission" })
)
src.addCallbackAndRunD((permission) => {
console.log(
"> Checking geopermission gave: ",
JSON.stringify(permission),
permission.value
)
const granted = permission.value === "true"
AndroidPolyfill._geolocationPermission.set(granted ? "granted" : "denied")
})
@ -61,17 +71,25 @@ export class AndroidPolyfill {
}
public static async requestLoginCodes() {
const result = await DatabridgePluginSingleton.request<{ oauth_token: string }>({ key: "request:login" })
const result = await DatabridgePluginSingleton.request<{ oauth_token: string }>({
key: "request:login",
})
const token: string = result.value.oauth_token
console.log("AndroidPolyfill: received oauth_token; trying to pass them to the oauth lib", token)
console.log(
"AndroidPolyfill: received oauth_token; trying to pass them to the oauth lib",
token
)
return token
}
public static onBackButton(callback: () => boolean, options: {
returnToIndex: Store<boolean>
}) {
public static onBackButton(
callback: () => boolean,
options: {
returnToIndex: Store<boolean>
}
) {
console.log("Registering back button callback", callback)
DatabridgePluginSingleton.request({ key: "backbutton" }).then(ev => {
DatabridgePluginSingleton.request({ key: "backbutton" }).then((ev) => {
console.log("AndroidPolyfill: received backbutton: ", ev)
if (ev === null) {
// Probably in web environment
@ -88,28 +106,38 @@ export class AndroidPolyfill {
window.location.href = "/"
}
})
}
public static watchLocation(writeInto: UIEventSource<GeolocationCoordinates>, callback: (location) => void) {
public static watchLocation(
writeInto: UIEventSource<GeolocationCoordinates>,
callback: (location) => void
) {
DatabridgePluginSingleton.request({
key: "location:watch",
}).then((l: {
value: { latitude: number, longitude: number, accuraccy: number, altidude: number, heading: number, speed:number }
}) => {
// example l: {"value":{"latitude":51.0618627,"longitude":3.730468566666667,"accuracy":2.0393495559692383,"altitude":46.408,"heading":168.2969970703125}}
console.log("Received location from Android:", JSON.stringify(l))
const loc = l.value
writeInto.set({
latitude: loc.latitude,
longitude: loc.longitude,
heading: loc.heading,
accuracy: loc.accuraccy,
altitude: loc.altidude,
altitudeAccuracy: undefined,
speed: loc.speed,
})
})
}).then(
(l: {
value: {
latitude: number
longitude: number
accuraccy: number
altidude: number
heading: number
speed: number
}
}) => {
// example l: {"value":{"latitude":51.0618627,"longitude":3.730468566666667,"accuracy":2.0393495559692383,"altitude":46.408,"heading":168.2969970703125}}
console.log("Received location from Android:", JSON.stringify(l))
const loc = l.value
writeInto.set({
latitude: loc.latitude,
longitude: loc.longitude,
heading: loc.heading,
accuracy: loc.accuraccy,
altitude: loc.altidude,
altitudeAccuracy: undefined,
speed: loc.speed,
})
}
)
}
}

View file

@ -2,22 +2,21 @@
* Various tools and types to work with the community index (https://openstreetmap.community/; https://github.com/osmlab/osm-community-index)
*/
export interface CommunityResource {
/**
* A unique identifier for the resource
* "pattern": "^[-_.A-Za-z0-9]+$"
*/
id: string,
id: string
/**
* Type of community resource (thus: platform)
*/
type: string,
type: string
/**
* included and excluded locations for this item
* See location-conflation documentation for compatible values: https://github.com/rapideditor/location-conflation#readme
*/
locationSet?,
locationSet?
/** Array of ISO-639-1 (2 letter) or ISO-639-3 (3 letter) codes in lowercase
* */
@ -27,7 +26,5 @@ export interface CommunityResource {
*/
account?: string
resolved?: { url: string, name: string, description: string } & Record<string, string>
resolved?: { url: string; name: string; description: string } & Record<string, string>
}

View file

@ -36,14 +36,14 @@ export default class ThemeViewStateHashActor {
*
*/
constructor(state: {
featureSwitches: {featureSwitchBackToThemeOverview: Store<boolean>}
indexedFeatures: IndexedFeatureSource,
selectedElement: UIEventSource<Feature>,
guistate: MenuState,
featureSwitches: { featureSwitchBackToThemeOverview: Store<boolean> }
indexedFeatures: IndexedFeatureSource
selectedElement: UIEventSource<Feature>
guistate: MenuState
}) {
this._state = state
AndroidPolyfill.onBackButton(() => this.back(), {
returnToIndex: state.featureSwitches.featureSwitchBackToThemeOverview
returnToIndex: state.featureSwitches.featureSwitchBackToThemeOverview,
})
const hashOnLoad = Hash.hash.data
@ -81,7 +81,6 @@ export default class ThemeViewStateHashActor {
// When all is done, set the hash. This must happen last to give the code above correct info
this.setHash()
}
/**