diff --git a/Source/Modules/AppDelegate.swift b/Source/Modules/AppDelegate.swift index 1f754516..96779163 100644 --- a/Source/Modules/AppDelegate.swift +++ b/Source/Modules/AppDelegate.swift @@ -15,6 +15,7 @@ import UpdateSputnik @objc(AppDelegate) public class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate { + public static let shared = AppDelegate() private var folderMonitor = FolderMonitor( url: URL(fileURLWithPath: LMMgr.dataFolderPath(isDefaultFolder: false)) ) diff --git a/Source/Modules/SessionCtl_Core.swift b/Source/Modules/SessionCtl_Core.swift index 95635d1b..48305e53 100644 --- a/Source/Modules/SessionCtl_Core.swift +++ b/Source/Modules/SessionCtl_Core.swift @@ -292,7 +292,7 @@ public extension SessionCtl { DispatchQueue.main.async { UpdateSputnik.shared.checkForUpdate(forced: false, url: kUpdateInfoSourceURL) - (NSApp.delegate as? AppDelegate)?.checkMemoryUsage() + AppDelegate.shared.checkMemoryUsage() } state = IMEState.ofEmpty() diff --git a/Source/Modules/SessionCtl_Menu.swift b/Source/Modules/SessionCtl_Menu.swift index 120da837..8765a9e7 100644 --- a/Source/Modules/SessionCtl_Menu.swift +++ b/Source/Modules/SessionCtl_Menu.swift @@ -363,7 +363,7 @@ public extension SessionCtl { } @objc func selfUninstall(_: Any? = nil) { - (NSApp.delegate as? AppDelegate)?.selfUninstall() + AppDelegate.shared.selfUninstall() } @objc func selfTerminate(_: Any? = nil) { diff --git a/Source/Modules/UIModules/PrefUI/VwrPrefPaneDictionary.swift b/Source/Modules/UIModules/PrefUI/VwrPrefPaneDictionary.swift index 51050616..4f03c3a1 100644 --- a/Source/Modules/UIModules/PrefUI/VwrPrefPaneDictionary.swift +++ b/Source/Modules/UIModules/PrefUI/VwrPrefPaneDictionary.swift @@ -86,7 +86,7 @@ struct VwrPrefPaneDictionary: View { if LMMgr.checkIfSpecifiedUserDataFolderValid(newPath) { userDataFolderSpecified = newPath BookmarkManager.shared.saveBookmark(for: url) - (NSApp.delegate as? AppDelegate)?.updateDirectoryMonitorPath() + AppDelegate.shared.updateDirectoryMonitorPath() } else { IMEApp.buzz() if !bolPreviousFolderValidity { diff --git a/Source/Modules/WindowControllers/CtlPrefWindow.swift b/Source/Modules/WindowControllers/CtlPrefWindow.swift index a7693e01..4e1d9a10 100644 --- a/Source/Modules/WindowControllers/CtlPrefWindow.swift +++ b/Source/Modules/WindowControllers/CtlPrefWindow.swift @@ -354,7 +354,7 @@ class CtlPrefWindow: NSWindowController, NSWindowDelegate { if LMMgr.checkIfSpecifiedUserDataFolderValid(newPath) { PrefMgr.shared.userDataFolderSpecified = newPath BookmarkManager.shared.saveBookmark(for: url) - (NSApp.delegate as? AppDelegate)?.updateDirectoryMonitorPath() + AppDelegate.shared.updateDirectoryMonitorPath() } else { IMEApp.buzz() if !bolPreviousFolderValidity { diff --git a/Source/Modules/main.swift b/Source/Modules/main.swift index 60a36a66..8afc7b52 100644 --- a/Source/Modules/main.swift +++ b/Source/Modules/main.swift @@ -67,7 +67,8 @@ else { public let theServer = server public let kUpdateInfoSourceURL = urlUpdateInfoSource -NSApp.run() +NSApplication.shared.delegate = AppDelegate.shared +_ = NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv) // MARK: - Top-level Enums relating to Input Mode and Language Supports.