From 15caadbd3decbefc97cf2b2f8ce5e50141154696 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Sun, 12 Jan 2025 01:53:58 +0100 Subject: [PATCH] Android: docs, app landing page --- app/app.vite.config.js | 7 ++++-- app/index.html | 18 ++++++++++++++++ scripts/prepareAndroid.sh | 1 + src/Logic/Web/AndroidPolyfill.ts | 27 ++++++++++++++++++++---- src/Logic/Web/ThemeViewStateHashActor.ts | 24 +++++++++++++++++---- 5 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 app/index.html diff --git a/app/app.vite.config.js b/app/app.vite.config.js index 2231f8eea..8abdd7f6e 100644 --- a/app/app.vite.config.js +++ b/app/app.vite.config.js @@ -1,9 +1,12 @@ import { defineConfig } from "vite" import { svelte } from "@sveltejs/vite-plugin-svelte" -import fs from "fs" import basicSsl from "@vitejs/plugin-basic-ssl" -const input = { "land": "./app/land.html", passthrough: "./app/passthrough.html" } +const input = { + land: "./app/land.html", + index: "./app/index.html", + passthrough: "./app/passthrough.html" +} console.log("Args:", process.argv) diff --git a/app/index.html b/app/index.html new file mode 100644 index 000000000..5e620ef23 --- /dev/null +++ b/app/index.html @@ -0,0 +1,18 @@ + + + + + MapComplete App + + + +Hi! + +MapComplete will soon (TM) be available as Android App in the play store and on FDroid. + +In the meantime, there isn't a lot to see here. + +Go back to mapcomplete + + + diff --git a/scripts/prepareAndroid.sh b/scripts/prepareAndroid.sh index f0d83c503..d3bde23be 100755 --- a/scripts/prepareAndroid.sh +++ b/scripts/prepareAndroid.sh @@ -22,6 +22,7 @@ const config: CapacitorConfig = { export default config; ''' > capacitor.config.ts +# copy distribution files rm -rf dist-full mkdir dist-full cp dist/*.html dist-full/ diff --git a/src/Logic/Web/AndroidPolyfill.ts b/src/Logic/Web/AndroidPolyfill.ts index 41b71cbe1..a1aee80d3 100644 --- a/src/Logic/Web/AndroidPolyfill.ts +++ b/src/Logic/Web/AndroidPolyfill.ts @@ -14,10 +14,12 @@ const DatabridgePluginSingleton = registerPlugin("Databridge", web: () => { return { async request(options: { key: string }): Promise<{ value: string | object }> { - return { value: "web" } - }, + if (options.key === "meta") { + return { value: "web" } + } + } } - }, + } }) export class AndroidPolyfill { @@ -32,7 +34,6 @@ export class AndroidPolyfill { * @private */ private backfillGeolocation(databridgePlugin: DatabridgePlugin) { - const origQueryFunc = navigator?.permissions?.query const src = UIEventSource.FromPromise(databridgePlugin.request({ key: "location:request-permission" })) src.addCallbackAndRunD(permission => { AndroidPolyfill._geolocationPermission.set(<"granted" | "denied">permission.value) @@ -57,5 +58,23 @@ export class AndroidPolyfill { 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 + }) { + console.log("Registering back button callback", callback) + DatabridgePluginSingleton.request({ key: "backbutton" }).then(ev => { + console.log("AndroidPolyfill: received backbutton: ", ev) + if (callback()) { + return + } + // Nothing more to close - we return (if not a single theme) to the index + if (options.returnToIndex) { + console.log("Back to the index!") + window.location.href = "/" + } + }) + + } } diff --git a/src/Logic/Web/ThemeViewStateHashActor.ts b/src/Logic/Web/ThemeViewStateHashActor.ts index 6142c0394..6d6e555f7 100644 --- a/src/Logic/Web/ThemeViewStateHashActor.ts +++ b/src/Logic/Web/ThemeViewStateHashActor.ts @@ -1,6 +1,7 @@ import ThemeViewState from "../../Models/ThemeViewState" import Hash from "./Hash" import { MenuState } from "../../Models/MenuState" +import { AndroidPolyfill } from "./AndroidPolyfill" export default class ThemeViewStateHashActor { private readonly _state: ThemeViewState @@ -22,7 +23,7 @@ export default class ThemeViewStateHashActor { /** * Converts the hash to the appropriate theme-view state and, vice versa, sets the hash. * - * As the navigator-back-button changes the hash first, this class thus also handles the 'back'-button events. + * As the navigator-back-button changes the hash first, this class thus also handles the (browser) 'back'-button events. * * Note that there is no "real" way to intercept the back button, we can only detect the removal of the hash. * As such, we use a change in the hash to close the appropriate windows @@ -30,6 +31,9 @@ export default class ThemeViewStateHashActor { */ constructor(state: ThemeViewState) { this._state = state + AndroidPolyfill.onBackButton(() => this.back(), { + returnToIndex: state.featureSwitches.featureSwitchBackToThemeOverview + }) const hashOnLoad = Hash.hash.data const containsMenu = this.loadStateFromHash(hashOnLoad) @@ -66,6 +70,7 @@ export default class ThemeViewStateHashActor { // When all is done, set the hash. This must happen last to give the code above correct info this.setHash() + } /** @@ -137,15 +142,26 @@ export default class ThemeViewStateHashActor { } } + /** + * Returns 'true' if an action was taken + * @private + */ private back() { + console.log("Received back!") const state = this._state if (state.previewedImage.data) { state.previewedImage.setData(undefined) - return + return true } if (state.guistate.closeAll()) { - return + return true } - state.selectedElement.setData(undefined) + if (state.selectedElement.data) { + state.selectedElement.setData(undefined) + return true + } + return false + + } }