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

+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) }