forked from Blendman974/faceclaw
Notifications menu; UI refinements; teleprompt by sharing a text file
This commit is contained in:
1 parent
ef6cb3bf55
commit
8d6fe60c79
12 files changed
+991
-36
No files matched your search
@@ -9,6 +9,29 @@ const ICON_CACHE_MS = 5_000;
|
||||
let cachedIcons: GrayImage[] = [];
|
||||
let cachedAtMs = 0;
|
||||
|
||||
export type AndroidNotificationAction = {
|
||||
index: number;
|
||||
title: string;
|
||||
enabled: boolean;
|
||||
};
|
||||
|
||||
export type AndroidNotification = {
|
||||
key: string;
|
||||
packageName: string;
|
||||
appName: string;
|
||||
title: string;
|
||||
text: string;
|
||||
bigText: string;
|
||||
subText: string;
|
||||
infoText: string;
|
||||
summaryText: string;
|
||||
category: string;
|
||||
lines: string[];
|
||||
postTime: number;
|
||||
when: number;
|
||||
actions: AndroidNotificationAction[];
|
||||
};
|
||||
|
||||
export function readActiveNotificationIcons(maxIcons: number): GrayImage[] {
|
||||
if (!global.isAndroid || maxIcons <= 0) return [];
|
||||
|
||||
@@ -36,3 +59,76 @@ export function readActiveNotificationIcons(maxIcons: number): GrayImage[] {
|
||||
cachedAtMs = now;
|
||||
return icons.map(icon => icon.clone());
|
||||
}
|
||||
|
||||
export function readActiveNotifications(maxNotifications = 50): AndroidNotification[] {
|
||||
if (!global.isAndroid || maxNotifications <= 0) return [];
|
||||
try {
|
||||
const json = String(
|
||||
com.faceclaw.app.FaceclawMediaNotificationListenerService.getActiveNotificationsJson(
|
||||
Math.max(0, Math.round(maxNotifications)),
|
||||
),
|
||||
);
|
||||
const parsed = JSON.parse(json);
|
||||
if (!Array.isArray(parsed)) return [];
|
||||
return parsed.map(normalizeNotification).filter((item): item is AndroidNotification => Boolean(item));
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export function invokeNotificationAction(notificationKey: string, actionIndex: number): boolean {
|
||||
if (!global.isAndroid || !notificationKey) return false;
|
||||
cachedAtMs = 0;
|
||||
return Boolean(
|
||||
com.faceclaw.app.FaceclawMediaNotificationListenerService.invokeNotificationAction(
|
||||
notificationKey,
|
||||
Math.round(actionIndex),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function dismissNotification(notificationKey: string): boolean {
|
||||
if (!global.isAndroid || !notificationKey) return false;
|
||||
cachedAtMs = 0;
|
||||
return Boolean(
|
||||
com.faceclaw.app.FaceclawMediaNotificationListenerService.dismissNotification(notificationKey),
|
||||
);
|
||||
}
|
||||
|
||||
function normalizeNotification(value: any): AndroidNotification | null {
|
||||
if (!value || typeof value !== "object") return null;
|
||||
const key = String(value.key ?? "");
|
||||
if (!key) return null;
|
||||
const actions = Array.isArray(value.actions)
|
||||
? value.actions.map(normalizeAction).filter((item): item is AndroidNotificationAction => Boolean(item))
|
||||
: [];
|
||||
return {
|
||||
key,
|
||||
packageName: String(value.packageName ?? ""),
|
||||
appName: String(value.appName ?? value.packageName ?? ""),
|
||||
title: String(value.title ?? ""),
|
||||
text: String(value.text ?? ""),
|
||||
bigText: String(value.bigText ?? ""),
|
||||
subText: String(value.subText ?? ""),
|
||||
infoText: String(value.infoText ?? ""),
|
||||
summaryText: String(value.summaryText ?? ""),
|
||||
category: String(value.category ?? ""),
|
||||
lines: Array.isArray(value.lines) ? value.lines.map((line: unknown) => String(line)).filter(Boolean) : [],
|
||||
postTime: Number(value.postTime) || 0,
|
||||
when: Number(value.when) || 0,
|
||||
actions,
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeAction(value: any): AndroidNotificationAction | null {
|
||||
if (!value || typeof value !== "object") return null;
|
||||
const title = String(value.title ?? "");
|
||||
if (!title) return null;
|
||||
const index = Number(value.index);
|
||||
if (!Number.isFinite(index)) return null;
|
||||
return {
|
||||
index,
|
||||
title,
|
||||
enabled: Boolean(value.enabled),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user