import type { ReadOnlyReference } from "model/ref" ; import type { DateTime } from "model/time" ; import { App , Modal } from "obsidian" ; import { SETTINGS } from "settings" ; import type { Reminder } from "../model/reminder" ; import type { Later } from "../model/time" ; import ReminderView from "./components/Reminder.svelte" ; const electron = require ( "electron" ) ; export class ReminderModal { constructor ( private app , private useSystemNotification , private laters ) { } public show ( reminder , onRemindMeLater , onDone , onMute , onOpenFile ) { if ( ! this . isSystemNotification ( ) ) { this . showBuiltinReminder ( reminder , onRemindMeLater , onDone , onMute , onOpenFile ) ; } else { const Notification = electron . remote . Notification ; const n = new Notification ( { title : "Obsidian Reminder" , body : reminder . title , } ) ; n . on ( "click" , ( ) => { n . close ( ) ; this . showBuiltinReminder ( reminder , onRemindMeLater , onDone , onMute , onOpenFile ) ; } ) ; n . on ( "close" , ( ) => { onMute ( ) ; } ) ; { const laters = SETTINGS . laters . value ; n . on ( "action" , ( _ , index ) => { if ( index === 0 ) { onDone ( ) ; return ; } const later = laters [ index - 1 ] ! ; onRemindMeLater ( later . later ( ) ) ; } ) ; const actions = [ { type : "button" , text : "Mark as Done" } ] ; laters . forEach ( later => { actions . push ( { type : "button" , text : later . label } ) ; } ) ; n . actions = actions as any ; } n . show ( ) ; } } private showBuiltinReminder ( reminder , onRemindMeLater , onDone , onCancel , onOpenFile ) { new NotificationModal ( this . app , this . laters . value , reminder , onRemindMeLater , onDone , onCancel , onOpenFile ) . open ( ) ; } private isSystemNotification ( ) { if ( this . isMobile ( ) ) { return false ; } return this . useSystemNotification . value ; } private isMobile ( ) { return electron === undefined ; } } class NotificationModal extends Modal { canceled : boolean = true ; constructor ( app , private laters , private reminder , private onRemindMeLater , private onDone , private onCancel , private onOpenFile ) { super ( app ) ; } override onOpen ( ) { let { contentEl } = this ; new ReminderView ( { target : contentEl , props : { reminder : this . reminder , laters : this . laters , component : this , onRemindMeLater : ( time ) => { this . onRemindMeLater ( time ) ; this . canceled = false ; this . close ( ) ; } , onDone : ( ) => { this . canceled = false ; this . onDone ( ) ; this . close ( ) ; } , onOpenFile : ( ) => { this . canceled = true ; this . onOpenFile ( ) ; this . close ( ) ; } , onMute : ( ) => { this . canceled = true ; this . close ( ) ; } , } , } ) ; } override onClose ( ) { let { contentEl } = this ; contentEl . empty ( ) ; if ( this . canceled ) { this . onCancel ( ) ; } } }