Skip to content
Open
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
16 changes: 14 additions & 2 deletions MacThrottle/Services/ThermalMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SwiftUI
import UserNotifications

@Observable
final class ThermalMonitor {
final class ThermalMonitor: NSObject, UNUserNotificationCenterDelegate {
// MARK: - Constants
private static let historyDurationSeconds: TimeInterval = 600 // 10 minutes
private static let pollIntervalSeconds: TimeInterval = 2.0
Expand Down Expand Up @@ -74,11 +74,23 @@ final class ThermalMonitor {
return Date().timeIntervalSince(first.timestamp)
}

init() {
override init() {
super.init()
UNUserNotificationCenter.current().delegate = self
requestNotificationPermission()
startMonitoring()
}

// MARK: - UNUserNotificationCenterDelegate

func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
) {
completionHandler([.banner, .sound])
}

deinit {
timer?.invalidate()
}
Expand Down