forked from Blendman974/faceclaw
Auto-get OpenUdid rather than it being a config setting
This commit is contained in:
1 parent
8940d58bd0
commit
df85fb4072
3 files changed
+20
-28
No files matched your search
@@ -5,11 +5,8 @@
|
|||||||
* it only discovers and downloads public .ehpk packages. Authentication is
|
* it only discovers and downloads public .ehpk packages. Authentication is
|
||||||
* the same signed-header scheme used by the firmware API.
|
* the same signed-header scheme used by the firmware API.
|
||||||
*/
|
*/
|
||||||
import {
|
import { Application } from "@nativescript/core";
|
||||||
evenHubEmailSetting,
|
import { evenHubEmailSetting, evenHubPasswordSetting } from "../../ui/dashboard-settings";
|
||||||
evenHubOpenUdidSetting,
|
|
||||||
evenHubPasswordSetting,
|
|
||||||
} from "../../ui/dashboard-settings";
|
|
||||||
|
|
||||||
declare const android: any;
|
declare const android: any;
|
||||||
|
|
||||||
@@ -56,11 +53,7 @@ type DownloadMetadata = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function isEvenHubStoreConfigured(): boolean {
|
export function isEvenHubStoreConfigured(): boolean {
|
||||||
return Boolean(
|
return Boolean(evenHubEmailSetting.get().trim() && evenHubPasswordSetting.get());
|
||||||
evenHubEmailSetting.get().trim() &&
|
|
||||||
evenHubPasswordSetting.get() &&
|
|
||||||
evenHubOpenUdidSetting.get().trim(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class EvenHubApiClient {
|
export class EvenHubApiClient {
|
||||||
@@ -153,7 +146,7 @@ export class EvenHubApiClient {
|
|||||||
private ensureLogin(): Promise<string> {
|
private ensureLogin(): Promise<string> {
|
||||||
if (this.token) return Promise.resolve(this.token);
|
if (this.token) return Promise.resolve(this.token);
|
||||||
if (!isEvenHubStoreConfigured()) {
|
if (!isEvenHubStoreConfigured()) {
|
||||||
return Promise.reject(new Error("Set the EvenHub email, password, and phone openUdid in Settings > EvenHub."));
|
return Promise.reject(new Error("Set the EvenHub email and password in Settings > EvenHub."));
|
||||||
}
|
}
|
||||||
if (!this.loginPromise) {
|
if (!this.loginPromise) {
|
||||||
this.loginPromise = this.login().finally(() => {
|
this.loginPromise = this.login().finally(() => {
|
||||||
@@ -243,7 +236,10 @@ function buildCommon(version: 1 | 3): string {
|
|||||||
buildTime: "26060821",
|
buildTime: "26060821",
|
||||||
appId: "1001",
|
appId: "1001",
|
||||||
v: version,
|
v: version,
|
||||||
openUdid: evenHubOpenUdidSetting.get().trim(),
|
// This is Android's app-scoped SSAID. Even's login endpoint registers a
|
||||||
|
// previously unseen value as a terminal, so Faceclaw does not need the
|
||||||
|
// official Even app's differently-scoped ID.
|
||||||
|
openUdid: getPhoneOpenUdid(),
|
||||||
os: "1",
|
os: "1",
|
||||||
sn: "",
|
sn: "",
|
||||||
verL: "",
|
verL: "",
|
||||||
@@ -309,7 +305,7 @@ async function fetchWithTimeout(url: string, init: RequestInit, timeoutMs = REQU
|
|||||||
|
|
||||||
function unwrap(envelope: ApiEnvelope, httpStatus: number, path: string): unknown {
|
function unwrap(envelope: ApiEnvelope, httpStatus: number, path: string): unknown {
|
||||||
if (httpStatus === 401) {
|
if (httpStatus === 401) {
|
||||||
throw new Error("Even rejected the login session or phone openUdid. Check Settings > EvenHub.");
|
throw new Error("Even rejected the login session. Check Settings > EvenHub.");
|
||||||
}
|
}
|
||||||
if (httpStatus < 200 || httpStatus >= 300) {
|
if (httpStatus < 200 || httpStatus >= 300) {
|
||||||
throw new Error(`EvenHub request failed (HTTP ${httpStatus}, ${path}).`);
|
throw new Error(`EvenHub request failed (HTTP ${httpStatus}, ${path}).`);
|
||||||
@@ -321,6 +317,17 @@ function unwrap(envelope: ApiEnvelope, httpStatus: number, path: string): unknow
|
|||||||
return envelope.data;
|
return envelope.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Return this installation's Android ID, which Even calls `openUdid`. */
|
||||||
|
export function getPhoneOpenUdid(): string {
|
||||||
|
if (!global.isAndroid) throw new Error("The EvenHub storefront is currently available only on Android.");
|
||||||
|
const resolver = Application.android.context?.getContentResolver();
|
||||||
|
const openUdid = resolver
|
||||||
|
? String(android.provider.Settings.Secure.getString(resolver, android.provider.Settings.Secure.ANDROID_ID) ?? "")
|
||||||
|
: "";
|
||||||
|
if (!openUdid) throw new Error("Android did not provide a device ID for EvenHub authentication.");
|
||||||
|
return openUdid;
|
||||||
|
}
|
||||||
|
|
||||||
function parseStoreApp(value: unknown): EvenHubStoreApp | null {
|
function parseStoreApp(value: unknown): EvenHubStoreApp | null {
|
||||||
const item = asRecord(value);
|
const item = asRecord(value);
|
||||||
const version = asRecord(item.version);
|
const version = asRecord(item.version);
|
||||||
|
|||||||
@@ -522,19 +522,6 @@ export const evenHubPasswordSetting = new ConfigSettingString({
|
|||||||
"Password used to mint a short-lived Even API session. Faceclaw stores it in the same private settings store as other API credentials and never logs it.",
|
"Password used to mint a short-lived Even API session. Faceclaw stores it in the same private settings store as other API credentials and never logs it.",
|
||||||
});
|
});
|
||||||
|
|
||||||
export const evenHubOpenUdidSetting = new ConfigSettingString({
|
|
||||||
id: "evenhub-openudid",
|
|
||||||
label: "Even phone openUdid",
|
|
||||||
storageKey: "integrations.evenhub.openUdid",
|
|
||||||
defaultValue: "",
|
|
||||||
editorTitle: "Official Even app Android openUdid",
|
|
||||||
glassesEditTitle: "Edit Even openUdid",
|
|
||||||
normalize: (value) => (value ?? "").replace(/[^A-Za-z0-9_-]+/g, "").trim(),
|
|
||||||
formatValue: maskToken,
|
|
||||||
description:
|
|
||||||
"Android ID already bound to this account by the official Even app. The private API rejects a valid login token when this value is missing or belongs to another app/device.",
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Staging buffer for the Terminal app's "Add connection" flow: the worker
|
* Staging buffer for the Terminal app's "Add connection" flow: the worker
|
||||||
* asks the shell to open the phone text editor on this setting, the user
|
* asks the shell to open the phone text editor on this setting, the user
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import {
|
|||||||
batteryDisplayModeSetting,
|
batteryDisplayModeSetting,
|
||||||
brightnessSetting,
|
brightnessSetting,
|
||||||
evenHubEmailSetting,
|
evenHubEmailSetting,
|
||||||
evenHubOpenUdidSetting,
|
|
||||||
evenHubPasswordSetting,
|
evenHubPasswordSetting,
|
||||||
elevenLabsApiKeySetting,
|
elevenLabsApiKeySetting,
|
||||||
mapboxApiKeySetting,
|
mapboxApiKeySetting,
|
||||||
@@ -139,7 +138,6 @@ function settingsSections(): SettingsSection[] {
|
|||||||
items: [
|
items: [
|
||||||
textSettingMenuItem(evenHubEmailSetting),
|
textSettingMenuItem(evenHubEmailSetting),
|
||||||
textSettingMenuItem(evenHubPasswordSetting),
|
textSettingMenuItem(evenHubPasswordSetting),
|
||||||
textSettingMenuItem(evenHubOpenUdidSetting),
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user