Skip to content

Commit

Permalink
refactor: Fix notification initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
winebarrel committed Dec 11, 2024
1 parent 126bdb9 commit 6b7d9ce
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
13 changes: 13 additions & 0 deletions PagerCall/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 PagerCall/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 notification 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 PagerCall/PagerCallApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ struct PagerCallApp: App {
}()

private func initialize() {
Notification.initialize()

let contentView = ContentView(pagerDuty: pagerDuty, apiKey: $apiKey)
popover.contentViewController = NSHostingController(rootView: contentView)

Expand Down

0 comments on commit 6b7d9ce

Please sign in to comment.