From a4c0d366f2a475e64179137862a12db05d6b5e09 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Mon, 13 Nov 2023 19:29:06 +0100 Subject: [PATCH] Remove NSNotificationCenter warnings --- NvimView/Sources/NvimView/NvimView.swift | 1 + VimR/VimR/AdvencedPref.swift | 2 +- VimR/VimR/AppDelegate.swift | 11 ++++++----- VimR/VimR/Defs.swift | 2 +- VimR/VimR/MainWindow.swift | 20 +++++++++++++------- VimR/VimR/PrefMiddleware.swift | 18 +++++++++++++----- VimR/VimR/PrefUtils.swift | 2 +- VimR/VimR/Resources.swift | 2 +- 8 files changed, 37 insertions(+), 21 deletions(-) diff --git a/NvimView/Sources/NvimView/NvimView.swift b/NvimView/Sources/NvimView/NvimView.swift index ca392e2e..44a6f0e9 100644 --- a/NvimView/Sources/NvimView/NvimView.swift +++ b/NvimView/Sources/NvimView/NvimView.swift @@ -14,6 +14,7 @@ import RxSwift import SpriteKit import Tabs import UniformTypeIdentifiers +import UserNotifications public enum FontSmoothing: String, Codable, CaseIterable { case systemSetting diff --git a/VimR/VimR/AdvencedPref.swift b/VimR/VimR/AdvencedPref.swift index 239d7003..1033cfcf 100644 --- a/VimR/VimR/AdvencedPref.swift +++ b/VimR/VimR/AdvencedPref.swift @@ -90,7 +90,7 @@ final class AdvancedPref: PrefPane, UiComponent, NSTextFieldDelegate { self.useInteractiveZshCheckbox.boolState = self.useInteractiveZsh self.useLiveResizeCheckbox.boolState = self.useLiveResize self.drawsParallelCheckbox.boolState = self.drawsParallel - self.nvimBinaryField.string = self.nvimBinary + self.nvimBinaryField.string = self.nvimBinary } private func addViews() { diff --git a/VimR/VimR/AppDelegate.swift b/VimR/VimR/AppDelegate.swift index 743c9425..fe11c84d 100644 --- a/VimR/VimR/AppDelegate.swift +++ b/VimR/VimR/AppDelegate.swift @@ -11,6 +11,7 @@ import os import PureLayout import RxSwift import Sparkle +import UserNotifications let debugMenuItemIdentifier = NSUserInterfaceItemIdentifier("debug-menu-item") @@ -27,7 +28,7 @@ final class UpdaterDelegate: NSObject, SPUUpdaterDelegate { } @main -final class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate { +final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDelegate { struct OpenConfig { var urls: [URL] var cwd: URL @@ -77,7 +78,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCent super.init() - NSUserNotificationCenter.default.delegate = self + UNUserNotificationCenter.current().delegate = self } override func awakeFromNib() { @@ -440,9 +441,9 @@ extension AppDelegate { extension AppDelegate { func userNotificationCenter( - _: NSUserNotificationCenter, - shouldPresent _: NSUserNotification - ) -> Bool { true } + _: UNUserNotificationCenter, + willPresent _: UNNotification + ) async -> UNNotificationPresentationOptions { .banner } } // Keep the rawValues in sync with Action in the `vimr` Python script. diff --git a/VimR/VimR/Defs.swift b/VimR/VimR/Defs.swift index 19268d74..f23f20a2 100644 --- a/VimR/VimR/Defs.swift +++ b/VimR/VimR/Defs.swift @@ -6,7 +6,7 @@ import Foundation import WebKit -struct Defs { +enum Defs { static let loggerSubsystem = Bundle.main.bundleIdentifier! enum LoggerCategory { diff --git a/VimR/VimR/MainWindow.swift b/VimR/VimR/MainWindow.swift index 6b417eb3..3fc75e93 100644 --- a/VimR/VimR/MainWindow.swift +++ b/VimR/VimR/MainWindow.swift @@ -9,6 +9,7 @@ import os import PureLayout import RxSwift import Tabs +import UserNotifications import Workspace final class MainWindow: NSObject, @@ -574,16 +575,21 @@ final class MainWindow: NSObject, } private func showInitError() { - let notification = NSUserNotification() - notification.identifier = UUID().uuidString - notification.title = "Error during initialization" - notification.informativeText = + let content = UNMutableNotificationContent() + content.title = "Error during initialization" + content.body = """ - There was an error during the initialization of NeoVim. - Use :messages to view the error messages. + There was an error during the initialization of NeoVim. Use :messages to view the error messages. """ + content.sound = .default - NSUserNotificationCenter.default.deliver(notification) + let request = UNNotificationRequest( + identifier: UUID().uuidString, + content: content, + trigger: nil + ) + + UNUserNotificationCenter.current().add(request) } private func show(warning: NvimView.Warning) { diff --git a/VimR/VimR/PrefMiddleware.swift b/VimR/VimR/PrefMiddleware.swift index 5730f984..e3c4c305 100644 --- a/VimR/VimR/PrefMiddleware.swift +++ b/VimR/VimR/PrefMiddleware.swift @@ -6,6 +6,7 @@ import Cocoa import DictionaryCoding import os +import UserNotifications final class PrefMiddleware: MiddlewareType { typealias StateType = AppState @@ -48,12 +49,19 @@ final class PrefMiddleware: MiddlewareType { } if !traits.contains(.monoSpace) { - let notification = NSUserNotification() - notification.identifier = UUID().uuidString - notification.title = "No monospaced font" - notification.informativeText = "The font you selected\(newFontNameText) does not seem " + let content = UNMutableNotificationContent() + content.title = "No monospaced font" + content.body = "The font you selected\(newFontNameText) does not seem " + "to be a monospaced font. The rendering will most likely be broken." - NSUserNotificationCenter.default.deliver(notification) + content.sound = .default + + let request = UNNotificationRequest( + identifier: UUID().uuidString, + content: content, + trigger: nil + ) + + UNUserNotificationCenter.current().add(request) } } diff --git a/VimR/VimR/PrefUtils.swift b/VimR/VimR/PrefUtils.swift index 37849f6a..527df68c 100644 --- a/VimR/VimR/PrefUtils.swift +++ b/VimR/VimR/PrefUtils.swift @@ -6,7 +6,7 @@ import Cocoa import NvimView -final class PrefUtils { +enum PrefUtils { static func value(from dict: [String: Any], for key: String) -> T? { dict[key] as? T } diff --git a/VimR/VimR/Resources.swift b/VimR/VimR/Resources.swift index aece1d9d..be28ec6f 100644 --- a/VimR/VimR/Resources.swift +++ b/VimR/VimR/Resources.swift @@ -5,7 +5,7 @@ import Foundation -final class Resources { +enum Resources { static let resourceUrl = Bundle.main.resourceURL! static let previewUrl = resourceUrl.appendingPathComponent("preview")