From fc001c03e66e055474f852cc930c3905c9e70af2 Mon Sep 17 00:00:00 2001 From: Rohit Kushwaha Date: Sat, 5 Dec 2026 13:47:37 +0530 Subject: [PATCH 1/3] feat: removed use of storage manager script --- .github/workflows/nightly-build.yml | 2 -- CONTRIBUTING.md | 2 +- dev/storage_manager.mjs | 20 +++---------------- .../app/src/fdroid/AndroidManifest.xml | 3 +++ 4 files changed, 7 insertions(+), 20 deletions(-) create mode 100644 platforms/android/app/src/fdroid/AndroidManifest.xml diff --git a/.github/workflows/nightly-build.yml b/.github/workflows/nightly-build.yml index 399c761d7..24a769127 100644 --- a/.github/workflows/nightly-build.yml +++ b/.github/workflows/nightly-build.yml @@ -165,7 +165,6 @@ jobs: - name: Build normal APK run: | - node dev/storage_manager.mjs y npm run build -- dev apk mv platforms/android/app/build/outputs/apk/debug/app-debug.apk ${{ env.NORMAL_APK_PATH }} @@ -178,7 +177,6 @@ jobs: - name: Build fdroid APK if: ${{ !inputs.is_PR }} run: | - node dev/storage_manager.mjs y npm run build -- dev apk fdroid mv platforms/android/app/build/outputs/apk/debug/app-debug.apk ${{ env.FDROID_APK_PATH }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 505de5cd5..5544382e9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -401,7 +401,7 @@ Release signing still reads the ignored `build.json` and keystore. Rspack compil The familiar APK/AAB paths remain available under `platforms/android/app/build/outputs/apk/{debug,release}` and `outputs/bundle/release`. -`node dev/storage_manager.mjs y` or `n` toggles all-files access in the tracked Android manifest for the next build. Build scripts read package identity without rewriting it or reinstalling plugins. +All-files access is declared permanently in the F-Droid flavor manifest. The `dev/storage_manager.mjs` script is a no-op kept for compatibility. Build scripts read package identity without rewriting it or reinstalling plugins. ## 📝 Contribution Guidelines diff --git a/dev/storage_manager.mjs b/dev/storage_manager.mjs index 10fe2e4b0..45fcf8e18 100644 --- a/dev/storage_manager.mjs +++ b/dev/storage_manager.mjs @@ -1,19 +1,5 @@ #!/usr/bin/env node -import readline from "node:readline/promises"; -import { readFile, writeFile } from "node:fs/promises"; -const manifest = new URL("../platforms/android/app/src/main/AndroidManifest.xml", import.meta.url); -const args = process.argv.slice(2); -let answer = args[0]; -if (!answer) { - const prompt = readline.createInterface({ input: process.stdin, output: process.stdout }); - answer = await prompt.question("Enable 'MANAGE_EXTERNAL_STORAGE' permission? Y/n: "); - prompt.close(); -} -if (!["y", "yes", "--yes", "-y", "n", "no", "--no", "-n"].includes(answer.toLowerCase())) throw new Error("Choose yes or no."); -const enabled = ["y", "yes", "--yes", "-y"].includes(answer.toLowerCase()); -const source = await readFile(manifest, "utf8"); -const permission = ' '; -const clean = source.replace(/\s*/g, ""); -await writeFile(manifest, enabled ? clean.replace("", `${permission}\n`) : clean); -console.log(`All-files access ${enabled ? "enabled" : "disabled"} for the next Android build.`); +console.log( + "All-files access is declared permanently in the fdroid flavor; storage_manager is a no-op.", +); diff --git a/platforms/android/app/src/fdroid/AndroidManifest.xml b/platforms/android/app/src/fdroid/AndroidManifest.xml new file mode 100644 index 000000000..44df708b2 --- /dev/null +++ b/platforms/android/app/src/fdroid/AndroidManifest.xml @@ -0,0 +1,3 @@ + + + From 4164bd28c425494e4936fb888c3c8673d5204ac1 Mon Sep 17 00:00:00 2001 From: Rohit Kushwaha Date: Sat, 5 Dec 2026 14:54:22 +0530 Subject: [PATCH 2/3] fix: debug build command --- dev/config.js | 22 +++++++++++++++++++++- dev/scripts/android.js | 4 ++-- dev/scripts/ios.js | 4 ++-- dev/scripts/native.js | 6 +++--- tests/unit/nativeBuild.test.js | 11 ++++++++++- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/dev/config.js b/dev/config.js index d9593f8b3..ff6255639 100755 --- a/dev/config.js +++ b/dev/config.js @@ -3,8 +3,28 @@ const path = require("node:path"); const ads = require("../ads.json"); const ID_PAID = "com.foxdebug.acode"; const ID_FREE = "com.foxdebug.acodefree"; +const BUILD_MODES = { + d: "dev", + dev: "dev", + debug: "dev", + p: "prod", + prod: "prod", + release: "prod", +}; -module.exports = { getAppConfig, getWebBundlePath, getAdConfig }; +module.exports = { + getAppConfig, + getWebBundlePath, + getAdConfig, + getRequestedMode, +}; + +function getRequestedMode(args) { + const modes = args + .filter((arg) => Object.hasOwn(BUILD_MODES, arg)) + .map((arg) => BUILD_MODES[arg]); + return modes.includes("prod") ? "prod" : (modes[0] ?? null); +} function getAdConfig(platform, mode) { const release = mode === "Release"; diff --git a/dev/scripts/android.js b/dev/scripts/android.js index dc4188014..ab4c67ab1 100644 --- a/dev/scripts/android.js +++ b/dev/scripts/android.js @@ -1,7 +1,7 @@ const fs = require("node:fs"); const path = require("node:path"); const { spawnSync } = require("node:child_process"); -const { getAppConfig } = require("../config"); +const { getAppConfig, getRequestedMode } = require("../config"); const { sync } = require("../sync"); const root = path.resolve(__dirname, "../.."); @@ -30,7 +30,7 @@ function parseOptions(args) { } return { ...getAppConfig("android"), - mode: args.some((arg) => ["p", "prod"].includes(arg)) ? "p" : "d", + mode: getRequestedMode(args) === "prod" ? "p" : "d", channel: args.includes("fdroid") ? "fdroid" : "store", bundle: args.includes("bundle"), skipWeb: args.includes("--skip-web"), diff --git a/dev/scripts/ios.js b/dev/scripts/ios.js index 5f7731fcc..972b80807 100644 --- a/dev/scripts/ios.js +++ b/dev/scripts/ios.js @@ -1,6 +1,6 @@ const path = require("node:path"); const { spawnSync } = require("node:child_process"); -const { getAppConfig } = require("../config"); +const { getAppConfig, getRequestedMode } = require("../config"); const { sync } = require("../sync"); const { prepareAds } = require("./iosAds"); const root = path.resolve(__dirname, "../.."); @@ -34,7 +34,7 @@ function parseOptions(args) { ); return { ...getAppConfig("ios"), - mode: args.some((arg) => ["p", "prod"].includes(arg)) ? "Release" : "Debug", + mode: getRequestedMode(args) === "prod" ? "Release" : "Debug", action: args.includes("test") ? "test" : "build", skipWeb: args.includes("--skip-web"), skipTests: args.filter((arg) => arg.startsWith("-skip-testing:")), diff --git a/dev/scripts/native.js b/dev/scripts/native.js index a7db8d84d..ab2fbd6f0 100644 --- a/dev/scripts/native.js +++ b/dev/scripts/native.js @@ -1,10 +1,10 @@ const { spawnSync } = require("node:child_process"); const path = require("node:path"); +const { getRequestedMode } = require("../config"); const args = process.argv.slice(2); const platform = args.includes("ios") ? "ios" : "android"; -if ( - !args.some((arg) => ["run", "test", "d", "dev", "p", "prod"].includes(arg)) -) { +const runsOrTests = args.some((arg) => ["run", "test"].includes(arg)); +if (!runsOrTests && !getRequestedMode(args)) { args.push("prod"); } const result = spawnSync( diff --git a/tests/unit/nativeBuild.test.js b/tests/unit/nativeBuild.test.js index 2ae42094e..fe6a3ff6f 100644 --- a/tests/unit/nativeBuild.test.js +++ b/tests/unit/nativeBuild.test.js @@ -19,7 +19,10 @@ test.each([ [["ios"], "ios", "Release"], [["ios", "--device"], "ios", "Release"], [["android", "dev"], "android", "Debug"], + [["android", "debug"], "android", "Debug"], + [["android", "release"], "android", "Release"], [["ios", "d"], "ios", "Debug"], + [["ios", "debug"], "ios", "Debug"], [["run", "ios"], "ios", "Debug"], [["run", "android"], "android", "Debug"], [["test", "ios", "--target=simulator"], "ios", "Debug"], @@ -35,7 +38,13 @@ test.each([ source, { require: (name) => - name === "node:child_process" ? { spawnSync: spawn } : require(name), + name === "node:child_process" + ? { spawnSync: spawn } + : require( + name.startsWith(".") + ? path.resolve(path.dirname(filename), name) + : name, + ), process: scriptProcess, __dirname: path.dirname(filename), }, From 7276190c7fff34964b8a8e5d995fe8f5971739f0 Mon Sep 17 00:00:00 2001 From: Rohit Kushwaha Date: Sat, 5 Dec 2026 15:03:03 +0530 Subject: [PATCH 3/3] fix: tests --- tests/setup.js | 13 +++++++++++++ tests/unit/iosLaunch.test.js | 1 + vitest.config.js | 1 + 3 files changed, 15 insertions(+) create mode 100644 tests/setup.js diff --git a/tests/setup.js b/tests/setup.js new file mode 100644 index 000000000..891453e7a --- /dev/null +++ b/tests/setup.js @@ -0,0 +1,13 @@ +import { Storage } from "happy-dom"; + +// Node 25+ defines localStorage/sessionStorage globally but leaves them +// undefined without --localstorage-file, which stops Vitest from installing +// happy-dom's implementations on the global object. +if (typeof window !== "undefined") { + for (const key of ["localStorage", "sessionStorage"]) { + Object.defineProperty(globalThis, key, { + value: new Storage(), + configurable: true, + }); + } +} diff --git a/tests/unit/iosLaunch.test.js b/tests/unit/iosLaunch.test.js index 0a231007b..1b7ba7922 100644 --- a/tests/unit/iosLaunch.test.js +++ b/tests/unit/iosLaunch.test.js @@ -135,6 +135,7 @@ function runScript(args) { if (name === "../config") return { getAppConfig: () => ({ variant: "free", targetId: "app.acode" }), + getRequestedMode: () => "dev", }; if (name === "../sync") return { sync }; if (name === "./iosAds") return { prepareAds }; diff --git a/vitest.config.js b/vitest.config.js index 6baa8c3dc..05c89aa42 100644 --- a/vitest.config.js +++ b/vitest.config.js @@ -26,6 +26,7 @@ export default defineConfig({ // inside the WebView (launched from the app commands) and depends on // Bridge/editorManager globals, so it must never be collected here. include: ["tests/**/*.test.{js,ts}"], + setupFiles: ["tests/setup.js"], exclude: [ ...configDefaults.exclude, "src/test/**",