UNPKG

scriptable-testlab

Version:

A lightweight, efficient tool designed to manage and update scripts for Scriptable.

165 lines 4.47 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); import { AbsNotification } from "scriptable-abstract"; const DEFAULT_STATE = { identifier: `notification_${Date.now()}_${Math.random()}`, title: "", subtitle: "", body: "", threadIdentifier: "", preferredContentHeight: 0, badge: 0, userInfo: {}, sound: "default", openURL: "", deliveryDate: /* @__PURE__ */ new Date(0), nextTriggerDate: /* @__PURE__ */ new Date(0), scriptName: "", actions: { title: "", url: "" } }; const _MockNotification = class _MockNotification extends AbsNotification { constructor() { super(DEFAULT_STATE); } get asNotification() { return this; } // Basic properties get identifier() { return this.state.identifier; } get title() { return this.state.title; } set title(value) { this.setState({ title: value }); } get body() { return this.state.body; } set body(value) { this.setState({ body: value }); } get subtitle() { return this.state.subtitle; } set subtitle(value) { this.setState({ subtitle: value }); } get threadIdentifier() { return this.state.threadIdentifier; } set threadIdentifier(value) { this.setState({ threadIdentifier: value }); } get preferredContentHeight() { return this.state.preferredContentHeight; } set preferredContentHeight(value) { this.setState({ preferredContentHeight: value }); } get badge() { return this.state.badge; } set badge(value) { this.setState({ badge: value }); } get userInfo() { return { ...this.state.userInfo }; } set userInfo(value) { this.setState({ userInfo: { ...value } }); } get sound() { return this.state.sound; } set sound(value) { this.setState({ sound: value }); } get openURL() { return this.state.openURL; } set openURL(value) { this.setState({ openURL: value }); } get deliveryDate() { return new Date(this.state.deliveryDate); } get nextTriggerDate() { return new Date(this.state.nextTriggerDate); } get scriptName() { return this.state.scriptName; } set scriptName(value) { this.setState({ scriptName: value }); } get actions() { return { ...this.state.actions }; } // Core functionality setTriggerDate(date) { this.setState({ deliveryDate: new Date(date), nextTriggerDate: new Date(date) }); } setDailyTrigger(hour, minute, _repeats = false) { const now = /* @__PURE__ */ new Date(); const next = new Date(now); next.setHours(hour, minute, 0, 0); if (next <= now) next.setDate(next.getDate() + 1); this.setTriggerDate(next); } setWeeklyTrigger(weekday, hour, minute, _repeats = false) { const now = /* @__PURE__ */ new Date(); const next = new Date(now); next.setHours(hour, minute, 0, 0); while (next.getDay() !== weekday || next <= now) { next.setDate(next.getDate() + 1); } this.setTriggerDate(next); } addAction(title, url) { this.setState({ actions: { title, url } }); } async remove() { const index = _MockNotification.schedules.indexOf(this); if (index > -1) _MockNotification.schedules.splice(index, 1); } async schedule() { _MockNotification.schedules.push(this); } // Static methods static async allPending() { return this.schedules.map((notification) => notification.asNotification); } static async removePending() { this.schedules = []; } static async removePendingNotification(identifier) { this.schedules = this.schedules.filter((n) => n.identifier !== identifier); } static getLastDelivered() { return this.lastDelivered?.asNotification ?? null; } static reset() { this.schedules = []; this.lastDelivered = null; } async scheduleNotification(date, _repeats = false) { await this.scheduleNotificationAt(date); } async scheduleNotificationAt(date, _repeats = false) { this.setTriggerDate(date); await this.schedule(); } }; __publicField(_MockNotification, "schedules", []); __publicField(_MockNotification, "lastDelivered", null); let MockNotification = _MockNotification; export { MockNotification }; //# sourceMappingURL=notification.js.map