forked from Blendman974/faceclaw
Use ANCS notification categories for icons
This commit is contained in:
1 parent
84baee9c76
commit
d6180e4457
4 files changed
+90
-7
No files matched your search
@@ -70,6 +70,25 @@ export const ICON_SVGS = {
|
||||
'<svg viewBox="0 0 24 24" fill="none"><path d="M10.268 21a2 2 0 0 0 3.464 0"/><path d="M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326"/></svg>',
|
||||
calendar:
|
||||
'<svg viewBox="0 0 24 24" fill="none"><path d="M8 2v4"/><path d="M16 2v4"/><rect width="18" height="18" x="3" y="4" rx="2"/><path d="M3 10h18"/></svg>',
|
||||
// iOS notification categories (with bell, message-circle and calendar).
|
||||
"phone-incoming":
|
||||
'<svg viewBox="0 0 24 24" fill="none"><path d="M16 2v6h6"/><path d="m22 2-6 6"/><path d="M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384"/></svg>',
|
||||
"phone-missed":
|
||||
'<svg viewBox="0 0 24 24" fill="none"><path d="m16 2 6 6"/><path d="m22 2-6 6"/><path d="M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384"/></svg>',
|
||||
voicemail:
|
||||
'<svg viewBox="0 0 24 24" fill="none"><circle cx="6" cy="12" r="4"/><circle cx="18" cy="12" r="4"/><line x1="6" x2="18" y1="16" y2="16"/></svg>',
|
||||
mail:
|
||||
'<svg viewBox="0 0 24 24" fill="none"><path d="m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7"/><rect x="2" y="4" width="20" height="16" rx="2"/></svg>',
|
||||
newspaper:
|
||||
'<svg viewBox="0 0 24 24" fill="none"><path d="M15 18h-5"/><path d="M18 14h-8"/><path d="M4 22h16a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2H8a2 2 0 0 0-2 2v16a2 2 0 0 1-4 0v-9a2 2 0 0 1 2-2h2"/><rect width="8" height="4" x="10" y="6" rx="1"/></svg>',
|
||||
"heart-pulse":
|
||||
'<svg viewBox="0 0 24 24" fill="none"><path d="M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5"/><path d="M3.22 13H9.5l.5-1 2 4.5 2-7 1.5 3.5h5.27"/></svg>',
|
||||
briefcase:
|
||||
'<svg viewBox="0 0 24 24" fill="none"><path d="M16 20V4a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v16"/><rect width="20" height="14" x="2" y="6" rx="2"/></svg>',
|
||||
"map-pin":
|
||||
'<svg viewBox="0 0 24 24" fill="none"><path d="M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0"/><circle cx="12" cy="10" r="3"/></svg>',
|
||||
tv:
|
||||
'<svg viewBox="0 0 24 24" fill="none"><path d="m17 2-5 5-5-5"/><rect width="20" height="15" x="2" y="7" rx="2"/></svg>',
|
||||
"cloud-sun":
|
||||
'<svg viewBox="0 0 24 24" fill="none"><path d="M12 2v2"/><path d="m4.93 4.93 1.42 1.42"/><path d="M20 12h2"/><path d="m19.07 4.93-1.42 1.42"/><path d="M15.947 12.65a4 4 0 0 0-5.925-4.128"/><path d="M13 22H7a5 5 0 1 1 4.9-6H13a3 3 0 0 1 0 6Z"/></svg>',
|
||||
"flask-conical":
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { GrayImage } from '../graphics/image'
|
||||
import { renderIcon, type IconName } from '../graphics/icons'
|
||||
import { AncsClient, ANCS_CONNECT_MESSAGE, type AncsState } from '../g2/ancs-client'
|
||||
import { rememberNotificationSources } from './notification-sources'
|
||||
import type { AndroidNotification } from './notification-types'
|
||||
export type { AndroidNotification, AndroidNotificationAction } from './notification-types'
|
||||
export type { NotificationIconsResult, NotificationIconResult } from './notification-icons'
|
||||
|
||||
@@ -26,8 +28,17 @@ export function dismissNotification(key: string): boolean { return active?.dismi
|
||||
export function onAndroidNotificationPosted(listener: (key: string) => void): () => void {
|
||||
listeners.add(listener); return () => { listeners.delete(listener) }
|
||||
}
|
||||
// ANCS does not provide app icons. Use a local bell; never fetch notification
|
||||
// sources or content from a third-party icon service.
|
||||
// ANCS does not provide app icons, so show one for the notification's ANCS
|
||||
// category; never fetch notification sources or content from a third-party
|
||||
// icon service. Indexed by CategoryID: Other, IncomingCall, MissedCall,
|
||||
// Voicemail, Social, Schedule, Email, News, HealthAndFitness,
|
||||
// BusinessAndFinance, Location, Entertainment.
|
||||
const CATEGORY_ICONS: readonly IconName[] = ['bell','phone-incoming','phone-missed','voicemail','message-circle',
|
||||
'calendar','mail','newspaper','heart-pulse','briefcase','map-pin','tv']
|
||||
function categoryIcon(category: string): GrayImage {
|
||||
return renderIcon(CATEGORY_ICONS[Number(category)] ?? 'bell',24)?.clone() ?? bell()
|
||||
}
|
||||
// Drawn fallback for when the SVG rasterizer fails.
|
||||
function bell(): GrayImage {
|
||||
const image = new GrayImage(24,24,0)
|
||||
image.fillRoundedRect(6,5,12,13,220,5)
|
||||
@@ -37,11 +48,12 @@ function bell(): GrayImage {
|
||||
}
|
||||
export function readActiveNotificationIcons(maxIcons: number, _allowStale: boolean) {
|
||||
// One icon per source, standing for its first notification.
|
||||
const sources = new Map<string, string>()
|
||||
for (const n of readActiveNotifications(ALL_NOTIFICATIONS)) if (!sources.has(n.packageName)) sources.set(n.packageName, n.key)
|
||||
const keys = Array.from(sources.values()).slice(0,Math.max(0,maxIcons))
|
||||
return {icons: keys.map(() => bell()),keys,stale:false}
|
||||
const sources = new Map<string, AndroidNotification>()
|
||||
for (const n of readActiveNotifications(ALL_NOTIFICATIONS)) if (!sources.has(n.packageName)) sources.set(n.packageName, n)
|
||||
const shown = Array.from(sources.values()).slice(0,Math.max(0,maxIcons))
|
||||
return {icons: shown.map(n => categoryIcon(n.category)),keys: shown.map(n => n.key),stale:false}
|
||||
}
|
||||
export function readNotificationIconByKey(key: string, _allowStale: boolean) {
|
||||
return {icon: readActiveNotifications(ALL_NOTIFICATIONS).some(n => n.key === key) ? bell() : null,stale:false}
|
||||
const notification = readActiveNotifications(ALL_NOTIFICATIONS).find(n => n.key === key)
|
||||
return {icon: notification ? categoryIcon(notification.category) : null,stale:false}
|
||||
}
|
||||
Reference in new issue
Block a user