-
-
Notifications
You must be signed in to change notification settings - Fork 927
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added notifications for the GPU module
- Loading branch information
Showing
3 changed files
with
61 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// notifications.swift | ||
// GPU | ||
// | ||
// Created by Serhiy Mytrovtsiy on 05/12/2023 | ||
// Using Swift 5.0 | ||
// Running on macOS 14.1 | ||
// | ||
// Copyright © 2023 Serhiy Mytrovtsiy. All rights reserved. | ||
// | ||
|
||
import Cocoa | ||
import Kit | ||
|
||
class Notifications: NotificationsWrapper { | ||
private let usageID: String = "usage" | ||
private var usageLevel: String = "" | ||
|
||
public init(_ module: ModuleType) { | ||
super.init(module, [self.usageID]) | ||
|
||
if Store.shared.exist(key: "\(self.module)_notificationLevel") { | ||
let value = Store.shared.string(key: "\(self.module)_notificationLevel", defaultValue: self.usageLevel) | ||
Store.shared.set(key: "\(self.module)_notifications_usage", value: value) | ||
Store.shared.remove("\(self.module)_notificationLevel") | ||
} | ||
|
||
self.usageLevel = Store.shared.string(key: "\(self.module)_notifications_usage", defaultValue: self.usageLevel) | ||
|
||
self.addArrangedSubview(selectSettingsRow( | ||
title: localizedString("Usage"), | ||
action: #selector(self.changeUsage), | ||
items: notificationLevels, | ||
selected: self.usageLevel | ||
)) | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
internal func usageCallback(_ value: Double) { | ||
let title = localizedString("GPU usage threshold") | ||
|
||
if let threshold = Double(self.usageLevel) { | ||
let subtitle = localizedString("GPU usage is", "\(Int((value)*100))%") | ||
self.checkDouble(id: self.usageID, value: value, threshold: threshold, title: title, subtitle: subtitle) | ||
} | ||
} | ||
|
||
@objc private func changeUsage(_ sender: NSMenuItem) { | ||
guard let key = sender.representedObject as? String else { return } | ||
self.usageLevel = key.isEmpty ? "" : "\(Double(key) ?? 0)" | ||
Store.shared.set(key: "\(self.module)_notifications_usage", value: self.usageLevel) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters