forked from Blendman974/faceclaw
EvenHub API extensions: Set package name, fix some bugs
This commit is contained in:
1 parent
1e64a32c55
commit
4ee0af86cc
20 files changed
+3416
-458
No files matched your search
@@ -14,7 +14,7 @@ import { isCompassCalibrated } from "../compass/calibration";
|
||||
import { refreshDeclination } from "../compass/declination";
|
||||
import { resolveHeading } from "../compass/heading";
|
||||
|
||||
/** Wire shape of the `compass` extension event (faceclaw-extensions `CompassReading`). */
|
||||
/** Wire shape of the `compass` extension event (@faceclaw/evenhub-extensions `CompassReading`). */
|
||||
export type EvenHubCompassReading = {
|
||||
headingDegrees: number;
|
||||
magneticHeadingDegrees: number;
|
||||
|
||||
@@ -130,6 +130,17 @@ export function readString(obj: Record<string, unknown>, key: string, fallback:
|
||||
return fallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* A 0/1 protobuf flag. Stock apps send numbers; extension layouts may send
|
||||
* booleans (the extension types allow both), and numeric strings show up in
|
||||
* the wild.
|
||||
*/
|
||||
function readFlag(obj: Record<string, unknown>, key: string): boolean {
|
||||
const value = pickLoose(obj, key);
|
||||
if (typeof value === "boolean") return value;
|
||||
return readNumber(obj, key, 0) !== 0;
|
||||
}
|
||||
|
||||
export function asRecord(value: unknown): Record<string, unknown> {
|
||||
return value && typeof value === "object" && !Array.isArray(value) ? (value as Record<string, unknown>) : {};
|
||||
}
|
||||
@@ -150,9 +161,9 @@ function parseTextContainer(json: Record<string, unknown>): EvenHubTextContainer
|
||||
borderWidth: readBorderWidth(json),
|
||||
borderRadius: readNumber(json, "borderRadius", 0),
|
||||
paddingLength: readNumber(json, "paddingLength", 0),
|
||||
isEventCapture: readNumber(json, "isEventCapture", 0) !== 0,
|
||||
isEventCapture: readFlag(json, "isEventCapture"),
|
||||
zOrderIndex: readOptionalNumber(json, "zOrderIndex"),
|
||||
preserve: readNumber(json, "preserve", 0) !== 0,
|
||||
preserve: readFlag(json, "preserve"),
|
||||
content: readString(json, "content", ""),
|
||||
textColor: readTextBrightness(json),
|
||||
};
|
||||
@@ -220,7 +231,7 @@ function parseImageContainer(json: Record<string, unknown>): EvenHubImageContain
|
||||
width: readNumber(json, "width", 0),
|
||||
height: readNumber(json, "height", 0),
|
||||
zOrderIndex: readOptionalNumber(json, "zOrderIndex"),
|
||||
preserve: readNumber(json, "preserve", 0) !== 0,
|
||||
preserve: readFlag(json, "preserve"),
|
||||
pixels: null,
|
||||
pixelsWidth: 0,
|
||||
pixelsHeight: 0,
|
||||
@@ -242,12 +253,12 @@ function parseListContainer(json: Record<string, unknown>): EvenHubListContainer
|
||||
borderWidth: readBorderWidth(json),
|
||||
borderRadius: readNumber(json, "borderRadius", 0),
|
||||
paddingLength: readNumber(json, "paddingLength", 0),
|
||||
isEventCapture: readNumber(json, "isEventCapture", 0) !== 0,
|
||||
isEventCapture: readFlag(json, "isEventCapture"),
|
||||
zOrderIndex: readOptionalNumber(json, "zOrderIndex"),
|
||||
preserve: readNumber(json, "preserve", 0) !== 0,
|
||||
preserve: readFlag(json, "preserve"),
|
||||
itemNames,
|
||||
itemWidth: readNumber(itemContainer, "itemWidth", 0),
|
||||
selectBorder: readNumber(itemContainer, "isItemSelectBorderEn", 0) !== 0,
|
||||
selectBorder: readFlag(itemContainer, "isItemSelectBorderEn"),
|
||||
selectedIndex: 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -226,9 +226,15 @@ export const EVENHUB_BRIDGE_INJECT_SCRIPT = `
|
||||
/**
|
||||
* Injected at document-start (after the stock bridge shim): defines
|
||||
* `window.getFaceclawExtensions`, the single entry point for Faceclaw-only
|
||||
* capabilities (see the faceclaw-extensions package). It never touches the
|
||||
* standard SDK or any prototype — everything lives behind this one global, so
|
||||
* apps stay compatible with the stock Even app (where the global is absent).
|
||||
* capabilities. Its public contract (the `FaceclawExtensions` interface) is
|
||||
* the @faceclaw/evenhub-extensions package in evenhub-extensions/. Keep the
|
||||
* two in step (tests/evenhub-extensions-shim.test.cjs checks the member list).
|
||||
* When adding members, bump API_VERSION and tag them `@since apiVersion N` in
|
||||
* the package.
|
||||
*
|
||||
* It never touches the standard SDK or any prototype — everything lives behind
|
||||
* this one global, so apps stay compatible with the stock Even app (where the
|
||||
* global is absent).
|
||||
*
|
||||
* RPC uses its own id-keyed promise map and `__fcExtResolve`, kept separate
|
||||
* from the stock `__fcResolve` channel. Events arrive via `__fcExtEvent`.
|
||||
@@ -239,13 +245,15 @@ export function buildFaceclawExtensionsScript(versionString: string): string {
|
||||
(function () {
|
||||
if (window.getFaceclawExtensions) return;
|
||||
var VERSION = ${JSON.stringify(versionString)};
|
||||
var API_VERSION = 1;
|
||||
var pending = {};
|
||||
var nextId = 1;
|
||||
window.__fcExtResolve = function (id, ok, value) {
|
||||
var entry = pending[id];
|
||||
if (!entry) return;
|
||||
delete pending[id];
|
||||
(ok ? entry[0] : entry[1])(value);
|
||||
if (ok) entry[0](value);
|
||||
else entry[1](new Error(String(value)));
|
||||
};
|
||||
function call(method, params) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
@@ -260,9 +268,10 @@ export function buildFaceclawExtensionsScript(versionString: string): string {
|
||||
}
|
||||
var listeners = {};
|
||||
window.__fcExtEvent = function (name, data) {
|
||||
var arr = listeners[name];
|
||||
if (!arr) return;
|
||||
for (var i = 0; i < arr.slice().length; i++) {
|
||||
// Iterate a snapshot, so a listener that unsubscribes mid-dispatch
|
||||
// doesn't make the next one get skipped.
|
||||
var arr = (listeners[name] || []).slice();
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
try { arr[i](data); } catch (e) { if (window.console) console.error(e); }
|
||||
}
|
||||
};
|
||||
@@ -318,6 +327,7 @@ export function buildFaceclawExtensionsScript(versionString: string): string {
|
||||
send("setAssistantTools", [specs]);
|
||||
}
|
||||
var extensions = {
|
||||
apiVersion: API_VERSION,
|
||||
getVersion: function () { return VERSION; },
|
||||
returnToAppSwitcher: function () { send("returnToAppSwitcher"); },
|
||||
quit: function () { send("quit"); },
|
||||
|
||||
Reference in new issue
Block a user