LMMgr // Use GCD in loadDataModelsOnAppDelegate().

This commit is contained in:
ShikiSuen 2022-09-21 14:33:00 +08:00
parent f80c13331d
commit 2a22117bad
3 changed files with 46 additions and 27 deletions

View File

@ -51,6 +51,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
NSUserNotificationCenter.default.deliver(userNotification) NSUserNotificationCenter.default.deliver(userNotification)
} }
LMMgr.loadDataModelsOnAppDelegate()
DispatchQueue.main.async { DispatchQueue.main.async {
LMMgr.initUserLangModels() LMMgr.initUserLangModels()
self.folderMonitor.folderDidChange = { [weak self] in self.folderMonitor.folderDidChange = { [weak self] in

View File

@ -70,42 +70,60 @@ public enum LMMgr {
lm.loadLanguageModel(path: dataPath) lm.loadLanguageModel(path: dataPath)
} }
public static func loadDataModels() { public static func loadDataModelsOnAppDelegate() {
if !Self.lmCHT.isCNSDataLoaded { let globalQuene = DispatchQueue.global(qos: .default)
Self.lmCHT.loadCNSData(path: getBundleDataPath("data-cns")) var showFinishNotification = false
} let group = DispatchGroup()
if !Self.lmCHT.isMiscDataLoaded { group.enter()
Self.lmCHT.loadMiscData(path: getBundleDataPath("data-zhuyinwen")) DispatchQueue.main.async {
} if !Self.lmCHT.isCNSDataLoaded {
if !Self.lmCHT.isSymbolDataLoaded { Self.lmCHT.loadCNSData(path: getBundleDataPath("data-cns"))
Self.lmCHT.loadSymbolData(path: getBundleDataPath("data-symbols")) }
} if !Self.lmCHT.isMiscDataLoaded {
if !Self.lmCHS.isCNSDataLoaded { Self.lmCHT.loadMiscData(path: getBundleDataPath("data-zhuyinwen"))
Self.lmCHS.loadCNSData(path: getBundleDataPath("data-cns")) }
} if !Self.lmCHT.isSymbolDataLoaded {
if !Self.lmCHS.isMiscDataLoaded { Self.lmCHT.loadSymbolData(path: getBundleDataPath("data-symbols"))
Self.lmCHS.loadMiscData(path: getBundleDataPath("data-zhuyinwen")) }
} if !Self.lmCHS.isCNSDataLoaded {
if !Self.lmCHS.isSymbolDataLoaded { Self.lmCHS.loadCNSData(path: getBundleDataPath("data-cns"))
Self.lmCHS.loadSymbolData(path: getBundleDataPath("data-symbols")) }
if !Self.lmCHS.isMiscDataLoaded {
Self.lmCHS.loadMiscData(path: getBundleDataPath("data-zhuyinwen"))
}
if !Self.lmCHS.isSymbolDataLoaded {
Self.lmCHS.loadSymbolData(path: getBundleDataPath("data-symbols"))
}
group.leave()
} }
if !Self.lmCHT.isLanguageModelLoaded { if !Self.lmCHT.isLanguageModelLoaded {
showFinishNotification = true
NotifierController.notify( NotifierController.notify(
message: NSLocalizedString("Loading CHT Core Dict...", comment: "") message: NSLocalizedString("Loading CHT Core Dict...", comment: "")
) )
loadCoreLanguageModelFile(filenameSansExtension: "data-cht", langModel: &Self.lmCHT) group.enter()
NotifierController.notify( globalQuene.async {
message: NSLocalizedString("Core Dict loading complete.", comment: "") loadCoreLanguageModelFile(filenameSansExtension: "data-cht", langModel: &Self.lmCHT)
) group.leave()
}
} }
if !Self.lmCHS.isLanguageModelLoaded { if !Self.lmCHS.isLanguageModelLoaded {
showFinishNotification = true
NotifierController.notify( NotifierController.notify(
message: NSLocalizedString("Loading CHS Core Dict...", comment: "") message: NSLocalizedString("Loading CHS Core Dict...", comment: "")
) )
loadCoreLanguageModelFile(filenameSansExtension: "data-chs", langModel: &Self.lmCHS) group.enter()
NotifierController.notify( globalQuene.async {
message: NSLocalizedString("Core Dict loading complete.", comment: "") loadCoreLanguageModelFile(filenameSansExtension: "data-chs", langModel: &Self.lmCHS)
) group.leave()
}
}
group.notify(queue: DispatchQueue.main) {
if showFinishNotification {
NotifierController.notify(
message: NSLocalizedString("Core Dict loading complete.", comment: "")
)
}
} }
} }

View File

@ -177,7 +177,7 @@ class ctlInputMethod: IMKInputController {
default: default:
newInputMode = .imeModeNULL newInputMode = .imeModeNULL
} }
LMMgr.loadDataModel(newInputMode) // LMMgr.loadDataModel(newInputMode)
if inputMode != newInputMode { if inputMode != newInputMode {
UserDefaults.standard.synchronize() UserDefaults.standard.synchronize()