forked from Blendman974/faceclaw
Allow backgrounding EvenHub apps
This commit is contained in:
1 parent
cde29cc4d0
commit
b9f48c8e16
10 files changed
+376
-252
No files matched your search
@@ -7,74 +7,21 @@
|
||||
*
|
||||
* Design notes: notes/evenhub_compatibility.txt.
|
||||
*/
|
||||
import { Frame } from "@nativescript/core";
|
||||
import { type AppContext, type AppDefinition } from "../app-definition";
|
||||
import { shell } from "../../ui/shell/shell";
|
||||
import {
|
||||
appFilesDirPath,
|
||||
deletePathRecursively,
|
||||
readBinaryFile,
|
||||
writeBinaryFile,
|
||||
} from "../../native/file-access";
|
||||
import { parseEhpk, parseManifest, utf8Decode } from "./ehpk";
|
||||
import { EvenHubSession } from "./session";
|
||||
import { createEvenHubWindow } from "./evenhub-window";
|
||||
import { EvenHubStoreLayer } from "./store-layer";
|
||||
import { launchPackage } from "./manager";
|
||||
import { createInProcessWindow, type InProcessWindow } from "../../ui/shell/in-process-window";
|
||||
|
||||
const EVENHUB_WINDOW_ID = "evenhub:app";
|
||||
const EVENHUB_STORE_WINDOW_ID = "evenhub:store";
|
||||
const EVENHUB_STORE_SURFACE_ID = "window:evenhub:store";
|
||||
|
||||
let activeSession: EvenHubSession | null = null;
|
||||
|
||||
export function getActiveEvenHubSession(): EvenHubSession | null {
|
||||
return activeSession;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpack an .ehpk and launch it: glasses window plus the phone WebView page.
|
||||
* Only one EvenHub app runs at a time for now; opening another closes the
|
||||
* previous one.
|
||||
* Unpack an .ehpk and launch it as a concurrent EvenHub app (own glasses
|
||||
* window + persistent WebView). The phone stays on the dashboard; see manager.
|
||||
*/
|
||||
export async function openEvenHubPackage(ctx: AppContext, ehpkPath: string): Promise<void> {
|
||||
const data = readBinaryFile(ehpkPath);
|
||||
if (!data) {
|
||||
ctx.appendLog(`evenhub: could not read ${ehpkPath}`);
|
||||
return;
|
||||
}
|
||||
const archive = parseEhpk(data);
|
||||
const appJson = archive.files.get("app.json");
|
||||
if (!appJson) {
|
||||
ctx.appendLog("evenhub: package has no app.json");
|
||||
return;
|
||||
}
|
||||
const manifest = parseManifest(utf8Decode(appJson));
|
||||
|
||||
if (activeSession && !activeSession.isClosed()) {
|
||||
activeSession.close();
|
||||
}
|
||||
|
||||
// Unpack fresh into app-private storage, keyed by package id.
|
||||
const safeId = manifest.packageId.replace(/[^A-Za-z0-9._-]/g, "_");
|
||||
const baseDir = `${appFilesDirPath()}/evenhub-apps/${safeId}`;
|
||||
deletePathRecursively(baseDir);
|
||||
for (const [name, content] of archive.files) {
|
||||
if (!writeBinaryFile(`${baseDir}/${name}`, content)) {
|
||||
ctx.appendLog(`evenhub: failed to write ${name}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const session = new EvenHubSession(manifest, `${baseDir}/dist`, ctx.appendLog);
|
||||
activeSession = session;
|
||||
ctx.appendLog(`evenhub: launching ${manifest.name} ${manifest.version} (${manifest.packageId})`);
|
||||
|
||||
await ctx.launchInProcessApp(EVENHUB_WINDOW_ID, `window:${EVENHUB_WINDOW_ID}`, (options) =>
|
||||
createEvenHubWindow(EVENHUB_WINDOW_ID, session, options),
|
||||
);
|
||||
|
||||
Frame.topmost()?.navigate({ moduleName: "phone-ui/evenhub-page" });
|
||||
export function openEvenHubPackage(ctx: AppContext, ehpkPath: string): Promise<void> {
|
||||
return launchPackage(ctx, ehpkPath);
|
||||
}
|
||||
|
||||
const evenhubApp: AppDefinition = {
|
||||
|
||||
Reference in new issue
Block a user