Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/nightly-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 21 additions & 1 deletion dev/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions dev/scripts/android.js
Original file line number Diff line number Diff line change
@@ -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, "../..");

Expand Down Expand Up @@ -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"),
Expand Down
4 changes: 2 additions & 2 deletions dev/scripts/ios.js
Original file line number Diff line number Diff line change
@@ -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, "../..");
Expand Down Expand Up @@ -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:")),
Expand Down
6 changes: 3 additions & 3 deletions dev/scripts/native.js
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
20 changes: 3 additions & 17 deletions dev/storage_manager.mjs
Original file line number Diff line number Diff line change
@@ -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 = ' <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />';
const clean = source.replace(/\s*<uses-permission android:name="android\.permission\.MANAGE_EXTERNAL_STORAGE"\s*\/>/g, "");
await writeFile(manifest, enabled ? clean.replace("</manifest>", `${permission}\n</manifest>`) : 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.",
);
Comment thread
UnschooledGamer marked this conversation as resolved.
Resolved
3 changes: 3 additions & 0 deletions platforms/android/app/src/fdroid/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
</manifest>
13 changes: 13 additions & 0 deletions tests/setup.js
Original file line number Diff line number Diff line change
@@ -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,
});
}
}
1 change: 1 addition & 0 deletions tests/unit/iosLaunch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
11 changes: 10 additions & 1 deletion tests/unit/nativeBuild.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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),
},
Expand Down
1 change: 1 addition & 0 deletions vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/**",
Expand Down
Loading