fix: import Notification from scripting, use HealthQuantityType type

- Notification is not global, must import from 'scripting'
- queryQuantitySamples expects HealthQuantityType not string
This commit is contained in:
Anthony Merlo 2026-08-22 23:00:30 +01:00
parent bcd8c1241b
commit ddc6a54d84

View file

@ -12,7 +12,7 @@
//
// Docs: https://scriptingapp.github.io/guide/Device%20Capabilities/Health/
import { Script } from "scripting"
import { Script, Notification } from "scripting"
// Variables used by Scripting app. These must be at the very top of the file.
// icon-color: deep-blue; icon-glyph: heart;
@ -30,7 +30,7 @@ const U = {
}
// Read the most recent sample of a type. Returns { value, startDate } or null.
async function readLatest(type: string, unit: HealthUnit): Promise<{ value: number; startDate: Date } | null> {
async function readLatest(type: HealthQuantityType, unit: HealthUnit): Promise<{ value: number; startDate: Date } | null> {
try {
const samples = await Health.queryQuantitySamples(type, {
limit: 1,
@ -51,7 +51,7 @@ async function readLatest(type: string, unit: HealthUnit): Promise<{ value: numb
}
// Sum all samples of a type since midnight. Returns a number or null.
async function readTodaySum(type: string, unit: HealthUnit): Promise<number | null> {
async function readTodaySum(type: HealthQuantityType, unit: HealthUnit): Promise<number | null> {
try {
const start = new Date()
start.setHours(0, 0, 0, 0)