` });
document.querySelector('#update-later')?.addEventListener('click', () => ui.closeSheet());
- document.querySelector('#update-now')?.addEventListener('click', async () => { const b=document.querySelector('#update-now'); b.disabled=true; b.textContent='Downloading…'; try { await native.downloadAndInstall(update.downloadUrl, `dsmnru-pyq-${update.version}.apk`); } catch (e) { b.disabled=false; b.textContent='Try again'; ui.toast(e.message || 'Update failed', 'err'); } });
+ document.querySelector('#update-now')?.addEventListener('click', () => runInstall(update, ui));
+}
+
+/**
+ * One install attempt, driven by the native layer's REAL phases:
+ * Downloading… (actual bytes) → Verifying… → Starting installer… → then the
+ * button leaves the busy state for good. Every failure — download,
+ * verification, permission, or installer launch — resolves into a re-enabled
+ * retry button plus a toast, so the UI can never stick on "Downloading…".
+ */
+async function runInstall(update, ui) {
+ const b = document.querySelector('#update-now');
+ if (!b || b.dataset.busy === '1') return;
+ b.dataset.busy = '1';
+ b.disabled = true;
+ b.textContent = 'Downloading…';
+ let settled = false;
+ let watchdog = 0;
+ let stopProgress = () => {};
+ const stall = () => fail(new Error('UPDATE_WATCHDOG: update is taking too long — check your connection and try again'));
+ const arm = () => { clearTimeout(watchdog); watchdog = setTimeout(stall, watchdogMs); };
+ const settle = (after) => { if (settled) return; settled = true; clearTimeout(watchdog); stopProgress(); delete b.dataset.busy; if (after) after(); };
+ const fail = (e) => settle(() => {
+ b.disabled = false;
+ b.textContent = /INSTALL_PERMISSION_REQUIRED/.test(String((e && e.message) || '')) ? 'Enable installs & try again' : 'Try again';
+ ui.toast(humanError(e), 'err');
+ });
+ stopProgress = native.onUpdateProgress((ev) => {
+ if (settled || !ev) return;
+ if (ev.phase === 'download') b.textContent = ev.total > 0 ? `Downloading… ${mb(ev.bytes)} / ${mb(ev.total)} MB` : `Downloading… ${mb(ev.bytes)} MB`;
+ else if (ev.phase === 'verify') b.textContent = 'Verifying…';
+ else if (ev.phase === 'install') b.textContent = 'Starting installer…';
+ if (ev.phase) arm(); // native is alive — keep deferring the watchdog
+ });
+ arm();
+ try {
+ await native.downloadAndInstall(update.downloadUrl, `dsmnru-pyq-${update.version}.apk`, update.versionCode);
+ settle(() => {
+ // The system install screen is up (or the user was taken to the exact
+ // settings screen to allow installs). Reopening is instant — the
+ // verified APK stays cached — so a cancelled installer can be
+ // relaunched from this same button instead of a dead end.
+ b.disabled = false;
+ b.textContent = 'Open installer';
+ });
+ } catch (e) { fail(e); }
}
function escapeHtml(s) { return String(s).replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c])); }
From c39c78471e9cc83461e2f97f2330acb31c6ad3da Mon Sep 17 00:00:00 2001
From: Lav-developer <170819619+Lav-developer@users.noreply.github.com>
Date: Sat, 12 Sep 2026 10:32:20 +0000
Subject: [PATCH 2/3] Fix release build: read expectedVersionCode with
non-throwing JSONObject.opt
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
JSONObject.get(String) throws the checked JSONException, so
downloadAndInstall failed 'assembleRelease' with 'unreported exception
JSONException' at the expectedVersionCode read. Switch to opt(String),
which returns null when absent and never throws — behavior identical:
JS/native.js still passes the Worker-reported versionCode, and verifyApk
still rejects any package whose versionCode differs. Adds a source
regression test locking the accessor choice.
Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
---
.../src/main/java/com/dsmnru/pyq/DsmnruAppPlugin.java | 5 ++++-
android-app/test/update-install.test.mjs | 9 +++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/android-app/android/app/src/main/java/com/dsmnru/pyq/DsmnruAppPlugin.java b/android-app/android/app/src/main/java/com/dsmnru/pyq/DsmnruAppPlugin.java
index 480936e..b7e393c 100644
--- a/android-app/android/app/src/main/java/com/dsmnru/pyq/DsmnruAppPlugin.java
+++ b/android-app/android/app/src/main/java/com/dsmnru/pyq/DsmnruAppPlugin.java
@@ -426,7 +426,10 @@ public void downloadAndInstall(PluginCall call) {
String source = call.getString("url", "");
String fileName = UpdateUrlPolicy.sanitizeApkFileName(call.getString("fileName", ""), "dsmnru-update.apk");
int expectedVersionCode = 0;
- Object rawExpected = call.getData() == null ? null : call.getData().get("expectedVersionCode");
+ // `opt` (not `get`): returns null when absent and never throws the
+ // checked JSONException. JS/native.js passes the Worker-reported
+ // versionCode so verifyApk can reject any other package.
+ Object rawExpected = call.getData() == null ? null : call.getData().opt("expectedVersionCode");
if (rawExpected instanceof Number) expectedVersionCode = ((Number) rawExpected).intValue();
if (!UpdateUrlPolicy.isTrustedUpdateUrl(source)) {
diff --git a/android-app/test/update-install.test.mjs b/android-app/test/update-install.test.mjs
index c83fc89..7f370da 100644
--- a/android-app/test/update-install.test.mjs
+++ b/android-app/test/update-install.test.mjs
@@ -91,6 +91,15 @@ test('native: the plugin call is ALWAYS answered — no stuck "Downloading…"',
assert.match(policySrc, /private UpdateUrlPolicy\(\)/); // policy is static-only
});
+test('native: expectedVersionCode is read with the non-throwing JSONObject.opt (compilable)', () => {
+ // JSONObject.get(String) throws the CHECKED JSONException — a plain .get
+ // here fails `assembleRelease` with "unreported exception JSONException".
+ // .opt(String) returns null when absent and never throws.
+ assert.match(pluginSrc, /getData\(\)\s*==\s*null\s*\?\s*null\s*:\s*call\.getData\(\)\.opt\("expectedVersionCode"\)/);
+ assert.doesNotMatch(pluginSrc, /getData\(\)\.get\(/);
+ assert.match(pluginSrc, /rawExpected instanceof Number/); // typed guard preserved
+});
+
// ── FileProvider + installer Intent contract ─────────────────────────────
test('installer: FileProvider content:// URI, correct MIME and granted read permission', () => {
From 2465d72bd861430796685644950669c17ac8836e Mon Sep 17 00:00:00 2001
From: Lav-developer <170819619+Lav-developer@users.noreply.github.com>
Date: Sun, 13 Sep 2026 17:50:24 +0000
Subject: [PATCH 3/3] Restore production version 1.4.2/13 and decouple tests
from exact version pins
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Reproduced the 'App logic + Worker API tests' failure with versionName
1.4.2 / versionCode 13. Exactly two tests failed, both stale hard-coded
version pins (no production bug, no Worker coupling — worker tests are
pure fixtures and build.gradle is never read there):
1. test/fcm.test.mjs (pre-existing, predates PR #20): asserted
'versionCode 12' / versionName "1.4.1" inside a Firebase-wiring test.
Written before the repo's own bump commit d99c212, which never updated
it — incidental coupling that breaks on every legitimate bump. Now
asserts well-formed metadata (integer versionCode, semver versionName)
while keeping every Firebase/identity/signing assertion.
2. test/update-install.test.mjs: 'NO version bump' pinned 1.4.1/12 for
the temporary local-device updater test against the published v1.4.2
release. Replaced with a well-formedness invariant; the updater logic
tests remain fixture-driven (local 1.4.1/12 vs remote v1.4.2/13 as
pure data, independent of build.gradle).
build.gradle is restored to the production versionCode 13 /
versionName "1.4.2" with a comment stating the release flow owns the
values. No Worker changes, no release automation changes, existing
GitHub releases untouched.
Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
---
android-app/android/app/build.gradle | 10 ++++------
android-app/test/fcm.test.mjs | 10 ++++++++--
android-app/test/update-install.test.mjs | 24 +++++++++++++++++-------
3 files changed, 29 insertions(+), 15 deletions(-)
diff --git a/android-app/android/app/build.gradle b/android-app/android/app/build.gradle
index c738644..13e0fc0 100644
--- a/android-app/android/app/build.gradle
+++ b/android-app/android/app/build.gradle
@@ -7,12 +7,10 @@ android {
applicationId "com.dsmnru.pyq"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
- // LOCAL TEST BUILD for the updater fix: deliberately stays at
- // 1.4.1 / 12 so the already-published GitHub Release v1.4.2
- // (versionCode 13) is detected as the update target. Version bumps
- // happen only in the release flow — never in this fix.
- versionCode 12
- versionName "1.4.1"
+ // versionName/versionCode are bumped by the release flow only —
+ // tests assert well-formedness, never exact values.
+ versionCode 13
+ versionName "1.4.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
diff --git a/android-app/test/fcm.test.mjs b/android-app/test/fcm.test.mjs
index cc87e1d..8d55e51 100644
--- a/android-app/test/fcm.test.mjs
+++ b/android-app/test/fcm.test.mjs
@@ -62,8 +62,14 @@ test('Gradle wires firebase-messaging and keeps google-services conditional', ()
assert.match(gradle, /apply plugin: 'com\.google\.gms\.google-services'/,
'google-services plugin applied when google-services.json exists');
assert.match(gradle, /google-services\.json/, 'apply is guarded by the presence of google-services.json');
- assert.match(gradle, /versionCode 12/, 'current production versionCode is 12');
- assert.match(gradle, /versionName \"1\.4\.1\"/, 'current production versionName is 1.4.1');
+ // Version metadata is bumped by the release flow on purpose — pinning the
+ // exact values here made this Firebase-wiring test fail on every
+ // legitimate bump (it broke when production moved to 1.4.2/13). Assert
+ // well-formed metadata instead; which exact version ships is owned by the
+ // release process, and the updater treats versions purely as data
+ // (see update-install.test.mjs).
+ assert.match(gradle, /^ versionCode \d+$/m, 'integer versionCode present');
+ assert.match(gradle, /^ versionName "\d+\.\d+\.\d+"$/m, 'semver versionName present');
// Consistent package identity + stable debug signature (update-in-place).
assert.match(gradle, /applicationId "com\.dsmnru\.pyq"/, 'single applicationId preserved');
assert.match(gradle, /signingConfig signingConfigs\.debug/, 'debug buildType uses the shared debug signing config');
diff --git a/android-app/test/update-install.test.mjs b/android-app/test/update-install.test.mjs
index 7f370da..ed867c5 100644
--- a/android-app/test/update-install.test.mjs
+++ b/android-app/test/update-install.test.mjs
@@ -18,7 +18,8 @@
* permission-required, watchdog, retry
* 9. Optional updates keep "Later"; mandatory updates keep working
* 10. version comparison unchanged: 1.4.1 (code 12) → v1.4.2 (code 13)
- * 11. NO version bump: build.gradle stays 1.4.1 / 12
+ * 11. gradle version metadata stays well-formed (the release flow owns
+ * which exact version ships — tests never pin it)
*
* jsdom comes from worker/node_modules when installed (skips otherwise) —
* same pattern as app-native-bridge.test.mjs.
@@ -125,12 +126,21 @@ test('installer: unknown-app-install permission is detected and guided, never si
// ── version / release safety ─────────────────────────────────────────────
-test('NO version bump: the fix keeps versionName 1.4.1 / versionCode 12', () => {
- // Anchored to statement position (comments may mention other versions).
- assert.match(gradleSrc, /^\s*versionCode\s+12\s*$/m);
- assert.match(gradleSrc, /^\s*versionName\s+"1\.4\.1"\s*$/m);
- assert.doesNotMatch(gradleSrc, /^\s*versionCode\s+13\s*$/m);
- assert.doesNotMatch(gradleSrc, /^\s*versionName\s+"1\.4\.2"\s*$/m);
+test('gradle version metadata stays well-formed (release flow owns the values)', () => {
+ // PR #20's original task pinned 1.4.1/12 for a temporary local-device
+ // updater test against the already-published v1.4.2 release; that pin is
+ // gone now that production is back at its bumped version. What must hold
+ // FOREVER is only well-formedness: an integer versionCode and a semver
+ // versionName — accidental damage or garbage here breaks every build
+ // tool, while legitimate bumps must never break the test suite. The
+ // updater's version logic is fixture-driven and stays independent of
+ // build.gradle (see the tests below and update-version.test.mjs).
+ const code = gradleSrc.match(/^\s*versionCode\s+(\d+)\s*$/m);
+ const name = gradleSrc.match(/^\s*versionName\s+"(\d+)\.(\d+)\.(\d+)"\s*$/m);
+ assert.ok(code, 'integer versionCode statement present');
+ assert.ok(name, 'semver versionName statement present');
+ assert.ok(Number(code[1]) >= 1, 'versionCode is a positive integer');
+ assert.doesNotMatch(gradleSrc, /^\s*versionCode\s*$/m); // never left empty
});
test('update detection unchanged: local 1.4.1 (code 12) → GitHub v1.4.2 (code 13) = update available', async () => {