UNPKG

scriptable-testlab

Version:

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

187 lines 5.5 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); var notification_exports = {}; __export(notification_exports, { MockNotification: () => MockNotification }); module.exports = __toCommonJS(notification_exports); var import_scriptable_abstract = require("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 import_scriptable_abstract.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; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { MockNotification }); //# sourceMappingURL=notification.js.map