forked from Blendman974/faceclaw
Rewrite the Timer app
This commit is contained in:
1 parent
99a8b97169
commit
f601a62c75
14 files changed
+2990
-826
No files matched your search
@@ -2,28 +2,35 @@ import { Utils } from "@nativescript/core";
|
||||
|
||||
declare const com: any;
|
||||
|
||||
/**
|
||||
* Bridge to FaceclawTimerNotifications.java: the durable Android alarm and
|
||||
* phone notification behind every Timers-app expiry (countdown timers and
|
||||
* alarms alike, keyed by the item's id). The phone posts the notification at
|
||||
* `triggerAtMs` even if the app process is asleep or gone.
|
||||
*/
|
||||
|
||||
function getContext(): android.content.Context | null {
|
||||
if (!global.isAndroid) return null;
|
||||
return Utils.android.getApplicationContext() ?? null;
|
||||
}
|
||||
|
||||
/** Schedule the durable Android alarm backing one on-glasses timer. */
|
||||
export function scheduleTimerNotification(timerId: number, triggerAtMs: number, durationLabel: string): void {
|
||||
/** Schedule (or move) the Android alarm that posts `title` / `text` at triggerAtMs. */
|
||||
export function scheduleTimerNotification(itemId: number, triggerAtMs: number, title: string, text: string): void {
|
||||
const context = getContext();
|
||||
if (!context) return;
|
||||
com.faceclaw.app.FaceclawTimerNotifications.schedule(context, timerId, triggerAtMs, durationLabel);
|
||||
com.faceclaw.app.FaceclawTimerNotifications.schedule(context, itemId, triggerAtMs, title, text);
|
||||
}
|
||||
|
||||
/** Cancel both a pending alarm and any already-posted notification. */
|
||||
export function cancelTimerNotification(timerId: number): void {
|
||||
export function cancelTimerNotification(itemId: number): void {
|
||||
const context = getContext();
|
||||
if (!context) return;
|
||||
com.faceclaw.app.FaceclawTimerNotifications.cancel(context, timerId);
|
||||
com.faceclaw.app.FaceclawTimerNotifications.cancel(context, itemId);
|
||||
}
|
||||
|
||||
/** Prompt worker-side expiry path; Java deduplicates it against the alarm. */
|
||||
export function fireTimerNotification(timerId: number, durationLabel: string): void {
|
||||
/** The engine's own expiry path; Java deduplicates it against the alarm's. */
|
||||
export function fireTimerNotification(itemId: number, title: string, text: string): void {
|
||||
const context = getContext();
|
||||
if (!context) return;
|
||||
com.faceclaw.app.FaceclawTimerNotifications.fireNow(context, timerId, durationLabel);
|
||||
com.faceclaw.app.FaceclawTimerNotifications.fireNow(context, itemId, title, text);
|
||||
}
|
||||
Reference in new issue
Block a user