|
|
@@ -1,4 +1,4 @@
|
|
|
|
import * as Notifications from "expo-notifications";
|
|
|
|
import type * as NotificationsType from "expo-notifications";
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
loadNotifSettings,
|
|
|
|
loadNotifSettings,
|
|
|
|
loadNotifThresholdLastFired,
|
|
|
|
loadNotifThresholdLastFired,
|
|
|
@@ -7,6 +7,11 @@ import {
|
|
|
|
import type { ClaudeUsageResponse } from "@/types/claude";
|
|
|
|
import type { ClaudeUsageResponse } from "@/types/claude";
|
|
|
|
import type { CodexUsageResponse } from "@/types/codex";
|
|
|
|
import type { CodexUsageResponse } from "@/types/codex";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// expo-notifications push notifications were removed from Expo Go in SDK 53.
|
|
|
|
|
|
|
|
// Use require() so the initialization error is caught gracefully in Expo Go.
|
|
|
|
|
|
|
|
let Notifications: typeof NotificationsType | null = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Notifications = require("expo-notifications") as typeof NotificationsType;
|
|
|
|
Notifications.setNotificationHandler({
|
|
|
|
Notifications.setNotificationHandler({
|
|
|
|
handleNotification: async () => ({
|
|
|
|
handleNotification: async () => ({
|
|
|
|
shouldShowAlert: true,
|
|
|
|
shouldShowAlert: true,
|
|
|
@@ -16,13 +21,18 @@ Notifications.setNotificationHandler({
|
|
|
|
shouldSetBadge: false,
|
|
|
|
shouldSetBadge: false,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
|
|
// Running in Expo Go or native module unavailable — notifications disabled.
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export async function requestPermissions(): Promise<boolean> {
|
|
|
|
export async function requestPermissions(): Promise<boolean> {
|
|
|
|
|
|
|
|
if (!Notifications) return false;
|
|
|
|
const { status } = await Notifications.requestPermissionsAsync();
|
|
|
|
const { status } = await Notifications.requestPermissionsAsync();
|
|
|
|
return status === "granted";
|
|
|
|
return status === "granted";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export async function getPermissionStatus(): Promise<string> {
|
|
|
|
export async function getPermissionStatus(): Promise<string> {
|
|
|
|
|
|
|
|
if (!Notifications) return "undetermined";
|
|
|
|
const { status } = await Notifications.getPermissionsAsync();
|
|
|
|
const { status } = await Notifications.getPermissionsAsync();
|
|
|
|
return status;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -35,6 +45,7 @@ export async function scheduleDailyDigest(
|
|
|
|
claudeUsage: ClaudeUsageResponse | null,
|
|
|
|
claudeUsage: ClaudeUsageResponse | null,
|
|
|
|
codexUsage: CodexUsageResponse | null
|
|
|
|
codexUsage: CodexUsageResponse | null
|
|
|
|
): Promise<void> {
|
|
|
|
): Promise<void> {
|
|
|
|
|
|
|
|
if (!Notifications) return;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
await Notifications.cancelScheduledNotificationAsync(DAILY_ID);
|
|
|
|
await Notifications.cancelScheduledNotificationAsync(DAILY_ID);
|
|
|
|
} catch {}
|
|
|
|
} catch {}
|
|
|
@@ -68,6 +79,7 @@ export async function scheduleDailyDigest(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export async function cancelDailyDigest(): Promise<void> {
|
|
|
|
export async function cancelDailyDigest(): Promise<void> {
|
|
|
|
|
|
|
|
if (!Notifications) return;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
await Notifications.cancelScheduledNotificationAsync(DAILY_ID);
|
|
|
|
await Notifications.cancelScheduledNotificationAsync(DAILY_ID);
|
|
|
|
} catch {}
|
|
|
|
} catch {}
|
|
|
@@ -128,7 +140,7 @@ export async function onUsageDataLoaded(
|
|
|
|
claudeUsage,
|
|
|
|
claudeUsage,
|
|
|
|
codexUsage
|
|
|
|
codexUsage
|
|
|
|
);
|
|
|
|
);
|
|
|
|
if (alerts.length > 0) {
|
|
|
|
if (alerts.length > 0 && Notifications) {
|
|
|
|
await Notifications.scheduleNotificationAsync({
|
|
|
|
await Notifications.scheduleNotificationAsync({
|
|
|
|
content: {
|
|
|
|
content: {
|
|
|
|
title: "Low quota warning",
|
|
|
|
title: "Low quota warning",
|
|
|
|