From 081864a2d798276aa987e292fe9ff8ebdda1e797 Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 18 Jun 2024 11:39:00 -0700 Subject: [PATCH 01/11] dismiss from notification --- MeetingBar/AppDelegate.swift | 14 ++++++++------ MeetingBar/Notifications.swift | 8 ++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/MeetingBar/AppDelegate.swift b/MeetingBar/AppDelegate.swift index bc09b00a..73e6ee7f 100644 --- a/MeetingBar/AppDelegate.swift +++ b/MeetingBar/AppDelegate.swift @@ -224,12 +224,14 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele func userNotificationCenter(_: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { 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() - } + case "JOIN_ACTION", "DISMISS_ACTION", UNNotificationDefaultActionIdentifier: + if ["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 }) { + if response.actionIdentifier == "JOIN_ACTION" { + event.openMeeting() + } else { + statusBarItem.dismiss(event: event) } } case NotificationEventTimeAction.untilStart.rawValue: diff --git a/MeetingBar/Notifications.swift b/MeetingBar/Notifications.swift index dc2704f1..ba91de6a 100644 --- a/MeetingBar/Notifications.swift +++ b/MeetingBar/Notifications.swift @@ -20,6 +20,10 @@ func registerNotificationCategories() { let acceptAction = UNNotificationAction(identifier: "JOIN_ACTION", 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(), @@ -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]) From def011622ac0557540c2feb4827385eee0099b61 Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 18 Jun 2024 11:39:37 -0700 Subject: [PATCH 02/11] dismiss function --- MeetingBar/StatusBarItemController.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/MeetingBar/StatusBarItemController.swift b/MeetingBar/StatusBarItemController.swift index bc587547..dbcf2b77 100644 --- a/MeetingBar/StatusBarItemController.swift +++ b/MeetingBar/StatusBarItemController.swift @@ -940,13 +940,17 @@ 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) { From 4d026ddc9fd5d74991b24eb7cbf2e03c5a54cca2 Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 18 Jun 2024 11:39:46 -0700 Subject: [PATCH 03/11] typo --- MeetingBar/StatusBarItemController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MeetingBar/StatusBarItemController.swift b/MeetingBar/StatusBarItemController.swift index dbcf2b77..6f7ac4bb 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) From a6e3f65efe7d0f3487d9d3833eaf904977aab9c8 Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 25 Jun 2024 12:27:05 -0700 Subject: [PATCH 04/11] typo --- MeetingBar/AppDelegate.swift | 4 ++-- MeetingBar/StatusBarItemController.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MeetingBar/AppDelegate.swift b/MeetingBar/AppDelegate.swift index 73e6ee7f..d4b0954b 100644 --- a/MeetingBar/AppDelegate.swift +++ b/MeetingBar/AppDelegate.swift @@ -337,7 +337,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele } @objc - func openPrefecencesWindow(_: NSStatusBarButton?) { + func openPreferencesWindow(_: NSStatusBarButton?) { let contentView = PreferencesView() if let preferencesWindow { @@ -404,7 +404,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/StatusBarItemController.swift b/MeetingBar/StatusBarItemController.swift index 6f7ac4bb..eb69f25c 100644 --- a/MeetingBar/StatusBarItemController.swift +++ b/MeetingBar/StatusBarItemController.swift @@ -842,7 +842,7 @@ class StatusBarItemController { statusItemMenu.addItem( withTitle: "\("status_bar_preferences".loco())…", - action: #selector(AppDelegate.openPrefecencesWindow), + action: #selector(AppDelegate.openPreferencesWindow), keyEquivalent: "," ) From ca1e71ed1915f47d9c7966021aa27045f47101f2 Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 25 Jun 2024 12:32:31 -0700 Subject: [PATCH 05/11] minor --- MeetingBar/AppDelegate.swift | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/MeetingBar/AppDelegate.swift b/MeetingBar/AppDelegate.swift index d4b0954b..8f62a27e 100644 --- a/MeetingBar/AppDelegate.swift +++ b/MeetingBar/AppDelegate.swift @@ -252,12 +252,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele } 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) - } - } + if ["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 }) { + snoozeEventNotification(event, action) } } From e7980238f292414581b9f08e38187f06c1a2468b Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 25 Jun 2024 12:33:55 -0700 Subject: [PATCH 06/11] minor --- MeetingBar/Notifications.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MeetingBar/Notifications.swift b/MeetingBar/Notifications.swift index ba91de6a..009ac830 100644 --- a/MeetingBar/Notifications.swift +++ b/MeetingBar/Notifications.swift @@ -22,8 +22,8 @@ func registerNotificationCategories() { options: .foreground) let dismissAction = UNNotificationAction(identifier: "DISMISS_ACTION", - title: "notifications_meetingbar_dismiss_event_action".loco(), - options: .foreground) + title: "notifications_meetingbar_dismiss_event_action".loco(), + options: .foreground) let snoozeUntilStartTime = UNNotificationAction(identifier: NotificationEventTimeAction.untilStart.rawValue, title: "notifications_snooze_until_start".loco(), From e8eaf376b6576a406866c22cd8c05eaa6b11ce3c Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 25 Jun 2024 12:35:20 -0700 Subject: [PATCH 07/11] localize --- MeetingBar/Resources /Localization /en.lproj/Localizable.strings | 1 + 1 file changed, 1 insertion(+) 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 From ba7437f626acb027424e1c97988ce7c9753c2eec Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 25 Jun 2024 12:44:23 -0700 Subject: [PATCH 08/11] fix UNNotificationDefaultActionIdentifier and clean up handling --- MeetingBar/AppDelegate.swift | 43 ++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/MeetingBar/AppDelegate.swift b/MeetingBar/AppDelegate.swift index 8f62a27e..09fea446 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", "DISMISS_ACTION", UNNotificationDefaultActionIdentifier: - if ["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 }) { - if response.actionIdentifier == "JOIN_ACTION" { - event.openMeeting() - } else { - statusBarItem.dismiss(event: event) - } - } + case "JOIN_ACTION", UNNotificationDefaultActionIdentifier: + 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 ["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 }) { - snoozeEventNotification(event, action) - } } /* From 168d6288f9b92997f9f0030d890f9eb99017671b Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 25 Jun 2024 15:34:15 -0700 Subject: [PATCH 09/11] typo --- MeetingBar/I18N.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 } From deb0ece174e30ce7a133ff150e987b5dfcb7d01b Mon Sep 17 00:00:00 2001 From: Greg Date: Wed, 20 Nov 2024 10:57:28 -0800 Subject: [PATCH 10/11] changelog --- CHANGELOG.md | 6 ++++++ MeetingBar/Views/Changelog/Changelog.swift | 5 +++++ 2 files changed, 11 insertions(+) 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/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) From 962c8708778706277d347ed2182b10a2f500231d Mon Sep 17 00:00:00 2001 From: Greg Date: Mon, 25 Nov 2024 10:31:48 -0800 Subject: [PATCH 11/11] whitespace only lines --- MeetingBar/AppDelegate.swift | 4 ++-- MeetingBar/Notifications.swift | 2 +- MeetingBar/StatusBarItemController.swift | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/MeetingBar/AppDelegate.swift b/MeetingBar/AppDelegate.swift index 09fea446..6f437223 100644 --- a/MeetingBar/AppDelegate.swift +++ b/MeetingBar/AppDelegate.swift @@ -223,11 +223,11 @@ 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 { diff --git a/MeetingBar/Notifications.swift b/MeetingBar/Notifications.swift index 009ac830..85f370a2 100644 --- a/MeetingBar/Notifications.swift +++ b/MeetingBar/Notifications.swift @@ -20,7 +20,7 @@ func registerNotificationCategories() { let acceptAction = UNNotificationAction(identifier: "JOIN_ACTION", title: "notifications_meetingbar_join_event_action".loco(), options: .foreground) - + let dismissAction = UNNotificationAction(identifier: "DISMISS_ACTION", title: "notifications_meetingbar_dismiss_event_action".loco(), options: .foreground) diff --git a/MeetingBar/StatusBarItemController.swift b/MeetingBar/StatusBarItemController.swift index eb69f25c..a39adfa7 100644 --- a/MeetingBar/StatusBarItemController.swift +++ b/MeetingBar/StatusBarItemController.swift @@ -943,11 +943,11 @@ class StatusBarItemController { 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() }