Fix an issue that could cause corrupted installs of EvenHub apps, and redirect corrupted installs into the update/reinstall

This commit is contained in:
James Babcock committed 2026-10-25 14:05:36 -07:00
1 parent 99f146529b
commit 247459bf99
7 files changed
+93 -7

No files matched your search

+1
View File
@@ -15,6 +15,7 @@
* Inverting Android notification-icons to indicate selectionis now gamma-correct
* Android notification icons that are full-color pictures rather than shapes no longer show as blank blocks
* Fix missing R1 ring battery indicator on iOS
* Fix a bug on iOS that would cause corrupted installs of EvenHub apps
## 0.8.4 - 2026-10-17
+15
View File
@@ -176,6 +176,21 @@ export function readEvenHubPackageManifestBytes(bytes: Uint8Array): EvenHubManif
}
}
/**
* Delete an installed EHPK that is all zeros, keeping its registry entry and
* icon so the store treats it as missing and offers Reinstall. iOS builds
* before the binary-http.ios.ts copy fix could store a large download that
* way. Returns whether the package was discarded.
*/
export function discardZeroedEvenHubPackage(packageId: string): boolean {
const path = installedEvenHubPackagePath(packageId);
const bytes = readBinaryFile(path);
if (!bytes || bytes.length === 0) return false;
for (let i = 0; i < bytes.length; i++) if (bytes[i] !== 0) return false;
deletePathRecursively(path);
return true;
}
/** Remove the stored EHPK, unpacked runtime files, and registry entry. */
export function uninstallEvenHubPackage(packageId: string): boolean {
const apps = getInstalledEvenHubApps();
+10 -4
View File
@@ -4,7 +4,7 @@ import { acceptInput, resetRingInputFilter } from "../ui/input-monitor";
import { bindIosNotifications, iosNotificationsChanged, onIosNotificationPopup, readActiveNotifications } from '../native/notification-icons.ios'
import { shouldShowNotificationOnGlasses } from '../native/notification-sources'
import { launcherEntries } from '../apps/launcher'
import { getInstalledEvenHubAppById, installedEvenHubPackageId, uninstallEvenHubPackage } from '../apps/evenhub/installed-apps'
import { discardZeroedEvenHubPackage, getInstalledEvenHubAppById, installedEvenHubPackageId, uninstallEvenHubPackage } from '../apps/evenhub/installed-apps'
import { isInstalledPackagePresent } from '../apps/evenhub/updates'
import { openEvenHubStoreForPackage } from '../apps/evenhub'
import { launchInstalledPackage, closeRunningPackage, onPhoneShownChanged, phoneUiButton, showOnPhone, type PhoneUiButton } from '../apps/evenhub/manager'
@@ -625,9 +625,15 @@ export class IosPreviewController {
const host = ALL_APPS.find(candidate => candidate.appId === 'evenhub')
if (installed && host) {
try {
if (isInstalledPackagePresent(installed.packageId))
await launchInstalledPackage(this.buildAppContext({ ...host, appId: id }), installed)
else await openEvenHubStoreForPackage(this.buildAppContext(host), installed)
if (isInstalledPackagePresent(installed.packageId)) {
try { await launchInstalledPackage(this.buildAppContext({ ...host, appId: id }), installed); return }
catch (error) {
// Checked only after a failure: it reads the whole package again.
if (!discardZeroedEvenHubPackage(installed.packageId)) throw error
console.log(`[ios-preview] Discarded zeroed package for ${installed.packageId}; opening store page`)
}
}
await openEvenHubStoreForPackage(this.buildAppContext(host), installed)
}
catch (error) { this.fail(error) }
}
+9 -2
View File
@@ -2,11 +2,18 @@ import { Http } from '@nativescript/core';
import { withUserAgent } from '../util/http';
import type { BinaryPostResponse, BinaryResponse } from './binary-http';
/** Bulk NSData -> ArrayBuffer; bypass fetch's Blob/FileReader copies. */
/**
* Bulk NSData -> ArrayBuffer; bypass fetch's Blob/FileReader copies.
*
* toArrayBuffer() is interop.bufferFromData, which in @nativescript/ios 9.0.3
* views the NSData's bytes without retaining it: once the response is
* collected, the buffer is dangling (a store EHPK was saved as 41 MB of
* zeros). Copy while the response is still alive.
*/
export async function downloadBinary(url: string, timeoutMs: number): Promise<BinaryResponse> {
const response = await Http.request({ url, method: 'GET', headers: withUserAgent(), timeout: timeoutMs });
const length = Object.entries(response.headers).find(([name]) => name.toLowerCase() === 'content-length')?.[1];
return { status: response.statusCode, bytes: new Uint8Array(response.content.toArrayBuffer()), contentLength: Number(length ?? 0) };
return { status: response.statusCode, bytes: new Uint8Array(response.content.toArrayBuffer()).slice(), contentLength: Number(length ?? 0) };
}
/** POST a binary body and read the response as text; NativeScript hands an ArrayBuffer to NSURLRequest as one NSData. */
+2 -1
View File
@@ -70,7 +70,8 @@ export class IosVoiceControlBridge {
this.native = FaceclawSpeech.new()
this.native.eventHandler = (json: string) => this.receive(JSON.parse(json))
this.native.pcmHandler = (pcm: NSData) => {
const bytes = new Uint8Array(interop.bufferFromData(pcm))
// Copied: bufferFromData doesn't retain pcm, and STT clients queue chunks.
const bytes = new Uint8Array(interop.bufferFromData(pcm)).slice()
this.cloud?.acceptPcm(bytes)
if (this.continuous) this.record(bytes)
if (this.levels.size) { const level = pcmLevel(bytes); for (const fn of [...this.levels]) fn(level) }
+24
View File
@@ -71,6 +71,30 @@ test('iOS installed apps launch, recover missing packages, and close before unin
assert.deepEqual(calls, [['launch', 'installed', 'test.app'], ['reinstall', 'test.app'], ['close', 'test.app'], ['uninstall', 'test.app']]);
});
test('iOS launch failures on a zeroed package fall back to the store page; other failures still report', async () => {
const calls = [], failures = [], app = { packageId: 'test.app', name: 'Test' };
let zeroed = true;
const modules = {
"../ui/input-monitor": load("app/ui/input-monitor.ts", {}),
'../apps/all-apps': { ALL_APPS: [{ appId: 'evenhub' }] },
'../apps/evenhub/installed-apps': { getInstalledEvenHubAppById: () => app,
discardZeroedEvenHubPackage: id => { calls.push(['discard', id]); return zeroed; } },
'../apps/evenhub/updates': { isInstalledPackagePresent: () => true },
'../apps/evenhub': { openEvenHubStoreForPackage: (_ctx, value) => calls.push(['reinstall', value.packageId]) },
'../apps/evenhub/manager': { launchInstalledPackage: async () => { calls.push(['launch']); throw new Error('Could not read the EHPK manifest.'); } },
};
const { IosPreviewController } = load('app/g2/ios-preview-controller.ts', { require: id => modules[id] ?? {} });
const host = Object.create(IosPreviewController.prototype);
host.buildAppContext = app => app; host.fail = error => failures.push(error.message); host.requestShellRender = () => {};
await host.launchApp('installed');
assert.deepEqual(calls, [['launch'], ['discard', 'test.app'], ['reinstall', 'test.app']]);
assert.deepEqual(failures, []);
calls.length = 0; zeroed = false;
await host.launchApp('installed');
assert.deepEqual(calls, [['launch'], ['discard', 'test.app']]);
assert.deepEqual(failures, ['Could not read the EHPK manifest.']);
});
test('iOS settings prompts honor password input and report cancellation', async () => {
const prompts = [], writes = [];
const { IosPreviewController } = load('app/g2/ios-preview-controller.ts', { require: id => id === '@nativescript/core' ? {
+32
View File
@@ -297,3 +297,35 @@ test('EvenHub assistant tools skip malformed names and schemas with a warning in
assert.match(warnings[4], /"union": parameters can't use oneOf, anyOf or allOf/);
h.session.close();
});
test('iOS binary downloads copy out of the response NSData, which bufferFromData does not retain', async () => {
const native = new Uint8Array([0x45, 0x48, 0x50, 0x4b, 1, 2, 3]);
const { downloadBinary } = loader({}, {
'@nativescript/core': { Http: { request: async () => ({ statusCode: 200, headers: {}, content: { toArrayBuffer: () => native.buffer } }) } },
'../util/http': { withUserAgent: headers => headers ?? {} },
})('app/native/binary-http.ios.ts');
const { bytes } = await downloadBinary('https://cdn.example/app.ehpk', 1000);
native.fill(0); // The released NSData's pages are reused or zeroed.
assert.deepEqual(Array.from(bytes), [0x45, 0x48, 0x50, 0x4b, 1, 2, 3]);
});
test('zeroed installed packages are discarded with their registry entry kept; real packages are left alone', () => {
const files = new Map(), deleted = [];
const installed = loader({}, {
fzstd: require('fzstd'),
'../../native/file-access': { readBinaryFile: path => files.get(path) ?? null, readTextFile() {}, writeBinaryFile() {},
appFilesDirPath: () => '/app', deletePathRecursively: path => { deleted.push(path); files.delete(path); } },
'../../native/settings-store': { getStringSetting: (_key, fallback) => fallback, setStringSetting() {} },
'../../native/icon-image': {}, '../../graphics/icons': {}, '../../graphics/image': {},
})('app/apps/evenhub/installed-apps.ts');
const path = installed.installedEvenHubPackagePath('test.app');
files.set(path, pack({ 'app.json': '{"package_id":"test.app"}' }));
assert.equal(installed.discardZeroedEvenHubPackage('test.app'), false);
files.set(path, new Uint8Array([...new Uint8Array(1000), 1]));
assert.equal(installed.discardZeroedEvenHubPackage('test.app'), false);
assert.equal(installed.discardZeroedEvenHubPackage('missing.app'), false);
assert.deepEqual(deleted, []);
files.set(path, new Uint8Array(4096));
assert.equal(installed.discardZeroedEvenHubPackage('test.app'), true);
assert.deepEqual(deleted, [path], 'only the EHPK goes; the icon and registry entry stay for Reinstall');
});