Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

refactor: Fix notification initialize #70

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Pulse/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ import UserNotifications
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_: Foundation.Notification) {
UNUserNotificationCenter.current().delegate = self

Task {
do {
let userNotificationCenter = UNUserNotificationCenter.current()

guard try await userNotificationCenter.requestAuthorization(options: [.alert, .sound]) else {
Logger.shared.warning("user notification not authorized")
return
}
} catch {
Logger.shared.error("user notification authorization request error: \(error)")
}
}
}
}

Expand Down
11 changes: 0 additions & 11 deletions Pulse/Notification.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import UserNotifications

enum Notification {
static func initialize() {
let userNotificationCenter = UNUserNotificationCenter.current()

userNotificationCenter.requestAuthorization(options: [.alert, .sound]) { authorized, _ in
guard authorized else {
Logger.shared.warning("user notificationCentern not authorized")
return
}
}
}

static func notify(id: String, title: String, body: String, url: String) async {
let userNotificationCenter = UNUserNotificationCenter.current()

Expand Down
2 changes: 0 additions & 2 deletions Pulse/PulseApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ struct PulseApp: App {
}()

private func initialize() {
Notification.initialize()

let contentView = ContentView(pullRequest: pullRequest, githubToken: $githubToken)
popover.contentViewController = NSHostingController(rootView: contentView)

Expand Down
Loading