From 628d17d7bc68e15b5bec69a2d10e4cf15556a587 Mon Sep 17 00:00:00 2001 From: Infi Date: Wed, 1 Jan 2025 22:23:16 +0100 Subject: [PATCH] feat: facilitate webview dependencies Signed-off-by: Infi --- .gitignore | 1 + docs/src/content/docs/contributing/setup.mdx | 24 +++++-- scripts/download_deps.ts | 71 ++++++++++++++++++++ 3 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 scripts/download_deps.ts diff --git a/.gitignore b/.gitignore index b7000d7c..7f75bc93 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ local.properties revoltbuild.properties sentry.properties /.kotlin/sessions +app/src/main/assets/embedded diff --git a/docs/src/content/docs/contributing/setup.mdx b/docs/src/content/docs/contributing/setup.mdx index 0f0ba8c3..e69c28a3 100644 --- a/docs/src/content/docs/contributing/setup.mdx +++ b/docs/src/content/docs/contributing/setup.mdx @@ -78,7 +78,11 @@ import { Tabs, TabItem, Steps } from "@astrojs/starlight/components" -3. Clone the repository. +3. Download [Deno](https://deno.com). + + _Please see the [Deno Runtime Manual](https://docs.deno.com/runtime/getting_started/installation/) for installation guidance._ + +4. Clone the repository. ```sh git clone --recursive https://github.com/revoltchat/android.git @@ -86,16 +90,22 @@ import { Tabs, TabItem, Steps } from "@astrojs/starlight/components" Specify `--recursive` to ensure that submodules are cloned as well. -4. Open the project in Android Studio. +5. Open the project in Android Studio. -5. Install the required dependencies. +6. Install the required dependencies. - Android SDK, latest version - Android NDK, latest version You can install these from the SDK Manager in Android Studio. -6. Copy the `revoltbuild.properties.example` file to `revoltbuild.properties` and fill in the required values. +7. Download required additional, embedded dependencies using the provided script. + + ```sh + deno run -A scripts/download_deps.ts + ``` + +8. Copy the `revoltbuild.properties.example` file to `revoltbuild.properties` and fill in the required values. ```sh cp revoltbuild.properties.example revoltbuild.properties @@ -110,7 +120,7 @@ import { Tabs, TabItem, Steps } from "@astrojs/starlight/components" | `build.debug.app_name` | The name of the app in debug builds, arbitrary | | `build.flavour_id` | Leave as `ZZUU` | -7. Copy the `sentry.properties.example` file to `sentry.properties` and fill in the required values. +9. Copy the `sentry.properties.example` file to `sentry.properties` and fill in the required values. ```sh cp sentry.properties.example sentry.properties @@ -127,11 +137,11 @@ import { Tabs, TabItem, Steps } from "@astrojs/starlight/components" You can get these values from the Sentry dashboard. -8. Build the project. +10. Build the project. You can build the project by clicking on the 'Run' button in Android Studio. If asked, build the `:app` module. -9. **You're all set!** You can now start contributing to Revolt on Android. +11. **You're all set!** You can now start contributing to Revolt on Android. diff --git a/scripts/download_deps.ts b/scripts/download_deps.ts new file mode 100644 index 00000000..bba8c760 --- /dev/null +++ b/scripts/download_deps.ts @@ -0,0 +1,71 @@ +import { resolve } from "jsr:@std/path" + +const outputFolderParent = resolve(Deno.cwd(), "app", "src", "main", "assets") + +try { + Deno.statSync(outputFolderParent) +} catch (_) { + console.error( + "\x1b[31m" + // red + "Did you run this script from the correct directory?" + + "\x1b[0m" + ) + console.error( + "Usage: " + + "\x1b[35m" + // magenta + "deno run -A scripts/download_deps.ts" + + "\x1b[0m" + + " from the " + + "\x1b[1;31;4m" + // bold red underline + "root" + + "\x1b[0m" + + " directory of the project." + ) + Deno.exit(1) +} + +const outputFolder = resolve(outputFolderParent, "embedded") + +// If it exists, delete it +try { + Deno.removeSync(outputFolder, { recursive: true }) +} catch (_) { + // Ignore, might not exist +} + +// Create the output folder +Deno.mkdirSync(outputFolder, { recursive: true }) + +const deps = [ + { + file: "katex.min.css", + url: "https://cdn.jsdelivr.net/npm/katex@0.16.19/dist/katex.min.css", + }, + { + file: "katex.min.js", + url: "https://cdn.jsdelivr.net/npm/katex@0.16.19/dist/katex.min.js", + }, + { + file: "micromark.bundle.js", + url: "https://esm.sh/v135/micromark@4.0.1/es2022/micromark.bundle.mjs", + }, +] + +console.log("Will download the following files:") +for (const dep of deps) { + console.log(`- ${dep.file} from ${dep.url}`) +} +if (!confirm("Continue?")) { + console.log("Aborted.") + Deno.exit(0) +} + +for (const dep of deps) { + const response = await fetch(dep.url) + const data = await response.arrayBuffer() + const file = resolve(outputFolder, dep.file) + Deno.writeFileSync(file, new Uint8Array(data)) + console.log(`Downloaded ${dep.file} to ${file}`) +} + +console.log("Done.")