diff --git a/CHANGELOG.md b/CHANGELOG.md index 8132510c..bac52a19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ For next releases info look here: +## Version 4.11.0 + +> (released) + +* Added action to dismiss the event from the notification + ## Version 4.0.0 > (released) diff --git a/MeetingBar/AppDelegate.swift b/MeetingBar/AppDelegate.swift index bc09b00a..6f437223 100644 --- a/MeetingBar/AppDelegate.swift +++ b/MeetingBar/AppDelegate.swift @@ -223,40 +223,35 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele } func userNotificationCenter(_: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { + + defer { + completionHandler() + } + + guard ["EVENT", "SNOOZE_EVENT"].contains(response.notification.request.content.categoryIdentifier), + let eventID = response.notification.request.content.userInfo["eventID"] as? String, + let event = statusBarItem.events.first(where: { $0.ID == eventID }) else { + return + } switch response.actionIdentifier { case "JOIN_ACTION", UNNotificationDefaultActionIdentifier: - if response.notification.request.content.categoryIdentifier == "EVENT" || response.notification.request.content.categoryIdentifier == "SNOOZE_EVENT" { - if let eventID = response.notification.request.content.userInfo["eventID"] as? String { - if let event = statusBarItem.events.first(where: { $0.ID == eventID }) { - event.openMeeting() - } - } - } + event.openMeeting() + case "DISMISS_ACTION": + statusBarItem.dismiss(event: event) case NotificationEventTimeAction.untilStart.rawValue: - handleSnoozeEvent(response, NotificationEventTimeAction.untilStart) + snoozeEventNotification(event, NotificationEventTimeAction.untilStart) case NotificationEventTimeAction.fiveMinuteLater.rawValue: - handleSnoozeEvent(response, NotificationEventTimeAction.fiveMinuteLater) + snoozeEventNotification(event, NotificationEventTimeAction.fiveMinuteLater) case NotificationEventTimeAction.tenMinuteLater.rawValue: - handleSnoozeEvent(response, NotificationEventTimeAction.tenMinuteLater) + snoozeEventNotification(event, NotificationEventTimeAction.tenMinuteLater) case NotificationEventTimeAction.fifteenMinuteLater.rawValue: - handleSnoozeEvent(response, NotificationEventTimeAction.fifteenMinuteLater) + snoozeEventNotification(event, NotificationEventTimeAction.fifteenMinuteLater) case NotificationEventTimeAction.thirtyMinuteLater.rawValue: - handleSnoozeEvent(response, NotificationEventTimeAction.thirtyMinuteLater) + snoozeEventNotification(event, NotificationEventTimeAction.thirtyMinuteLater) default: break } - completionHandler() - } - - func handleSnoozeEvent(_ response: UNNotificationResponse, _ action: NotificationEventTimeAction) { - if response.notification.request.content.categoryIdentifier == "EVENT" || response.notification.request.content.categoryIdentifier == "SNOOZE_EVENT" { - if let eventID = response.notification.request.content.userInfo["eventID"] as? String { - if let event = statusBarItem.events.first(where: { $0.ID == eventID }) { - snoozeEventNotification(event, action) - } - } - } } /* @@ -335,7 +330,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele } @objc - func openPrefecencesWindow(_: NSStatusBarButton?) { + func openPreferencesWindow(_: NSStatusBarButton?) { let contentView = PreferencesView() if let preferencesWindow { @@ -402,7 +397,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele if let string = event.paramDescriptor(forKeyword: keyDirectObject)?.stringValue, let url = URL(string: string) { if url == URL(string: "meetingbar://preferences") { - openPrefecencesWindow(nil) + openPreferencesWindow(nil) } else { GCEventStore.shared .currentAuthorizationFlow?.resumeExternalUserAgentFlow(with: url) diff --git a/MeetingBar/I18N.swift b/MeetingBar/I18N.swift index 6181d91b..55b09591 100644 --- a/MeetingBar/I18N.swift +++ b/MeetingBar/I18N.swift @@ -23,8 +23,8 @@ final class I18N { if appLanguage == .system { resetToDefault() return true - } else if let newBunlde = checkLanguageAvailability(appLanguage.rawValue) { - bundle = newBunlde + } else if let newBundle = checkLanguageAvailability(appLanguage.rawValue) { + bundle = newBundle locale = Locale(identifier: appLanguage.rawValue) return true } diff --git a/MeetingBar/Notifications.swift b/MeetingBar/Notifications.swift index dc2704f1..85f370a2 100644 --- a/MeetingBar/Notifications.swift +++ b/MeetingBar/Notifications.swift @@ -21,6 +21,10 @@ func registerNotificationCategories() { title: "notifications_meetingbar_join_event_action".loco(), options: .foreground) + let dismissAction = UNNotificationAction(identifier: "DISMISS_ACTION", + title: "notifications_meetingbar_dismiss_event_action".loco(), + options: .foreground) + let snoozeUntilStartTime = UNNotificationAction(identifier: NotificationEventTimeAction.untilStart.rawValue, title: "notifications_snooze_until_start".loco(), options: .foreground) @@ -42,13 +46,13 @@ func registerNotificationCategories() { options: .foreground) let eventCategory = UNNotificationCategory(identifier: "EVENT", - actions: [acceptAction, snoozeUntilStartTime, snooze5Min, snooze10Min, snooze15Min, snooze30Min], + actions: [acceptAction, dismissAction, snoozeUntilStartTime, snooze5Min, snooze10Min, snooze15Min, snooze30Min], intentIdentifiers: [], hiddenPreviewsBodyPlaceholder: "", options: [.customDismissAction, .hiddenPreviewsShowTitle]) let snoozeEventCategory = UNNotificationCategory(identifier: "SNOOZE_EVENT", - actions: [acceptAction, snooze5Min, snooze10Min, snooze15Min, snooze30Min], + actions: [acceptAction, dismissAction, snooze5Min, snooze10Min, snooze15Min, snooze30Min], intentIdentifiers: [], hiddenPreviewsBodyPlaceholder: "", options: [.customDismissAction, .hiddenPreviewsShowTitle]) diff --git a/MeetingBar/Resources /Localization /en.lproj/Localizable.strings b/MeetingBar/Resources /Localization /en.lproj/Localizable.strings index 00787a12..356f5f60 100644 --- a/MeetingBar/Resources /Localization /en.lproj/Localizable.strings +++ b/MeetingBar/Resources /Localization /en.lproj/Localizable.strings @@ -325,6 +325,7 @@ "notifications_event_ends_one_minute_body" = "The event ends in one minute"; "notifications_event_ends_three_minutes_body" = "The event ends in three minutes"; "notifications_event_ends_five_minutes_body" = "The event ends in five minutes"; +"notifications_meetingbar_dismiss_event_action" = "Dismiss"; // MARK: - Link open diff --git a/MeetingBar/StatusBarItemController.swift b/MeetingBar/StatusBarItemController.swift index bc587547..a39adfa7 100644 --- a/MeetingBar/StatusBarItemController.swift +++ b/MeetingBar/StatusBarItemController.swift @@ -758,7 +758,7 @@ class StatusBarItemController { quickActionsItem.submenu!.addItem(toggleMeetingTitleVisibilityItem) } - // MENU ITEM: QUICK ACTIONS: Refresh soruces + // MENU ITEM: QUICK ACTIONS: Refresh sources let refreshSourcesItem = NSMenuItem() refreshSourcesItem.title = "status_bar_section_refresh_sources".loco() refreshSourcesItem.action = #selector(refreshSources) @@ -842,7 +842,7 @@ class StatusBarItemController { statusItemMenu.addItem( withTitle: "\("status_bar_preferences".loco())…", - action: #selector(AppDelegate.openPrefecencesWindow), + action: #selector(AppDelegate.openPreferencesWindow), keyEquivalent: "," ) @@ -940,14 +940,18 @@ class StatusBarItemController { @objc func dismissEvent(sender: NSMenuItem) { if let event: MBEvent = sender.representedObject as? MBEvent { - let dismissedEvent = ProcessedEvent(id: event.ID, lastModifiedDate: event.lastModifiedDate, eventEndDate: event.endDate) - Defaults[.dismissedEvents].append(dismissedEvent) - - updateTitle() - updateMenu() + dismiss(event: event) } } + func dismiss(event: MBEvent) { + let dismissedEvent = ProcessedEvent(id: event.ID, lastModifiedDate: event.lastModifiedDate, eventEndDate: event.endDate) + Defaults[.dismissedEvents].append(dismissedEvent) + + updateTitle() + updateMenu() + } + @objc func undismissEvent(sender: NSMenuItem) { if let event: MBEvent = sender.representedObject as? MBEvent { diff --git a/MeetingBar/Views/Changelog/Changelog.swift b/MeetingBar/Views/Changelog/Changelog.swift index 19c2aa49..d27e1318 100644 --- a/MeetingBar/Views/Changelog/Changelog.swift +++ b/MeetingBar/Views/Changelog/Changelog.swift @@ -178,6 +178,11 @@ struct ChangelogView: View { Text("🌍 Translation into Slovak and Dutch") } } + if compareVersions("4.11.0", lastRevisedVersionInChangelog) { + Section(header: Text("Version 4.11")) { + Text("Added action to dismiss the event from the notification") + } + } } }.listStyle(SidebarListStyle()) Button("general_close".loco(), action: close)