AppDelegate // Reconstruction.

This commit is contained in:
ShikiSuen 2022-11-18 14:55:14 +08:00
parent 5d98194076
commit 49ba507c8d
1 changed files with 20 additions and 11 deletions

View File

@ -13,23 +13,31 @@ import Uninstaller
import UpdateSputnik
@objc(AppDelegate)
class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate {
public class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate {
private var folderMonitor = FolderMonitor(
url: URL(fileURLWithPath: LMMgr.dataFolderPath(isDefaultFolder: false))
)
}
// MARK: - Private Functions
extension AppDelegate {
private func reloadOnFolderChangeHappens() {
// 100ms 使使
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) {
if PrefMgr.shared.shouldAutoReloadUserDataFiles { LMMgr.initUserLangModels() }
}
}
}
public var folderMonitor = FolderMonitor(
url: URL(fileURLWithPath: LMMgr.dataFolderPath(isDefaultFolder: false))
)
// MARK: - Public Functions
func userNotificationCenter(_: NSUserNotificationCenter, shouldPresent _: NSUserNotification) -> Bool {
extension AppDelegate {
public func userNotificationCenter(_: NSUserNotificationCenter, shouldPresent _: NSUserNotification) -> Bool {
true
}
func applicationDidFinishLaunching(_: Notification) {
public func applicationDidFinishLaunching(_: Notification) {
NSUserNotificationCenter.default.delegate = self
// 使
if PrefMgr.shared.failureFlagForUOMObservation {
@ -38,8 +46,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
PrefMgr.shared.failureFlagForUOMObservation = false
let userNotification = NSUserNotification()
userNotification.title = NSLocalizedString("vChewing", comment: "")
userNotification.informativeText =
"\(NSLocalizedString("vChewing crashed while handling previously loaded UOM observation data. These data files are cleaned now to ensure the usability.", comment: ""))"
userNotification.informativeText = NSLocalizedString(
"vChewing crashed while handling previously loaded UOM observation data. These data files are cleaned now to ensure the usability.",
comment: "")
userNotification.soundName = NSUserNotificationDefaultSoundName
NSUserNotificationCenter.default.deliver(userNotification)
}
@ -62,7 +71,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
}
}
func updateDirectoryMonitorPath() {
public func updateDirectoryMonitorPath() {
folderMonitor.stopMonitoring()
folderMonitor = FolderMonitor(
url: URL(fileURLWithPath: LMMgr.dataFolderPath(isDefaultFolder: false))
@ -73,7 +82,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
if LMMgr.userDataFolderExists { folderMonitor.startMonitoring() }
}
func selfUninstall() {
public func selfUninstall() {
let content = String(
format: NSLocalizedString(
"This will remove vChewing Input Method from this user account, requiring your confirmation.",
@ -97,7 +106,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
}
// New About Window
@IBAction func about(_: Any) {
@IBAction public func about(_: Any) {
CtlAboutWindow.show()
NSApp.activate(ignoringOtherApps: true)
}