LMMgr // Also use GCD in loadDataModels() per input mode.
This commit is contained in:
parent
2a22117bad
commit
d5ce4f29ad
|
@ -71,11 +71,11 @@ public enum LMMgr {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func loadDataModelsOnAppDelegate() {
|
public static func loadDataModelsOnAppDelegate() {
|
||||||
let globalQuene = DispatchQueue.global(qos: .default)
|
let globalQueue = DispatchQueue.global(qos: .default)
|
||||||
var showFinishNotification = false
|
var showFinishNotification = false
|
||||||
let group = DispatchGroup()
|
let group = DispatchGroup()
|
||||||
group.enter()
|
group.enter()
|
||||||
DispatchQueue.main.async {
|
globalQueue.async {
|
||||||
if !Self.lmCHT.isCNSDataLoaded {
|
if !Self.lmCHT.isCNSDataLoaded {
|
||||||
Self.lmCHT.loadCNSData(path: getBundleDataPath("data-cns"))
|
Self.lmCHT.loadCNSData(path: getBundleDataPath("data-cns"))
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ public enum LMMgr {
|
||||||
message: NSLocalizedString("Loading CHT Core Dict...", comment: "")
|
message: NSLocalizedString("Loading CHT Core Dict...", comment: "")
|
||||||
)
|
)
|
||||||
group.enter()
|
group.enter()
|
||||||
globalQuene.async {
|
globalQueue.async {
|
||||||
loadCoreLanguageModelFile(filenameSansExtension: "data-cht", langModel: &Self.lmCHT)
|
loadCoreLanguageModelFile(filenameSansExtension: "data-cht", langModel: &Self.lmCHT)
|
||||||
group.leave()
|
group.leave()
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ public enum LMMgr {
|
||||||
message: NSLocalizedString("Loading CHS Core Dict...", comment: "")
|
message: NSLocalizedString("Loading CHS Core Dict...", comment: "")
|
||||||
)
|
)
|
||||||
group.enter()
|
group.enter()
|
||||||
globalQuene.async {
|
globalQueue.async {
|
||||||
loadCoreLanguageModelFile(filenameSansExtension: "data-chs", langModel: &Self.lmCHS)
|
loadCoreLanguageModelFile(filenameSansExtension: "data-chs", langModel: &Self.lmCHS)
|
||||||
group.leave()
|
group.leave()
|
||||||
}
|
}
|
||||||
|
@ -128,47 +128,69 @@ public enum LMMgr {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func loadDataModel(_ mode: Shared.InputMode) {
|
public static func loadDataModel(_ mode: Shared.InputMode) {
|
||||||
|
let globalQueue = DispatchQueue.global(qos: .default)
|
||||||
|
var showFinishNotification = false
|
||||||
|
let group = DispatchGroup()
|
||||||
|
group.enter()
|
||||||
|
globalQueue.async {
|
||||||
switch mode {
|
switch mode {
|
||||||
case .imeModeCHS:
|
case .imeModeCHS:
|
||||||
|
if !Self.lmCHS.isCNSDataLoaded {
|
||||||
|
Self.lmCHS.loadCNSData(path: getBundleDataPath("data-cns"))
|
||||||
|
}
|
||||||
if !Self.lmCHS.isMiscDataLoaded {
|
if !Self.lmCHS.isMiscDataLoaded {
|
||||||
Self.lmCHS.loadMiscData(path: getBundleDataPath("data-zhuyinwen"))
|
Self.lmCHS.loadMiscData(path: getBundleDataPath("data-zhuyinwen"))
|
||||||
}
|
}
|
||||||
if !Self.lmCHS.isSymbolDataLoaded {
|
if !Self.lmCHS.isSymbolDataLoaded {
|
||||||
Self.lmCHS.loadSymbolData(path: getBundleDataPath("data-symbols"))
|
Self.lmCHS.loadSymbolData(path: getBundleDataPath("data-symbols"))
|
||||||
}
|
}
|
||||||
if !Self.lmCHS.isCNSDataLoaded {
|
|
||||||
Self.lmCHS.loadCNSData(path: getBundleDataPath("data-cns"))
|
|
||||||
}
|
|
||||||
if !Self.lmCHS.isLanguageModelLoaded {
|
|
||||||
NotifierController.notify(
|
|
||||||
message: NSLocalizedString("Loading CHS Core Dict...", comment: "")
|
|
||||||
)
|
|
||||||
loadCoreLanguageModelFile(filenameSansExtension: "data-chs", langModel: &Self.lmCHS)
|
|
||||||
NotifierController.notify(
|
|
||||||
message: NSLocalizedString("Core Dict loading complete.", comment: "")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
case .imeModeCHT:
|
case .imeModeCHT:
|
||||||
|
if !Self.lmCHT.isCNSDataLoaded {
|
||||||
|
Self.lmCHT.loadCNSData(path: getBundleDataPath("data-cns"))
|
||||||
|
}
|
||||||
if !Self.lmCHT.isMiscDataLoaded {
|
if !Self.lmCHT.isMiscDataLoaded {
|
||||||
Self.lmCHT.loadMiscData(path: getBundleDataPath("data-zhuyinwen"))
|
Self.lmCHT.loadMiscData(path: getBundleDataPath("data-zhuyinwen"))
|
||||||
}
|
}
|
||||||
if !Self.lmCHT.isSymbolDataLoaded {
|
if !Self.lmCHT.isSymbolDataLoaded {
|
||||||
Self.lmCHT.loadSymbolData(path: getBundleDataPath("data-symbols"))
|
Self.lmCHT.loadSymbolData(path: getBundleDataPath("data-symbols"))
|
||||||
}
|
}
|
||||||
if !Self.lmCHT.isCNSDataLoaded {
|
default: break
|
||||||
Self.lmCHT.loadCNSData(path: getBundleDataPath("data-cns"))
|
|
||||||
}
|
}
|
||||||
|
group.leave()
|
||||||
|
}
|
||||||
|
switch mode {
|
||||||
|
case .imeModeCHS:
|
||||||
|
if !Self.lmCHS.isLanguageModelLoaded {
|
||||||
|
showFinishNotification = true
|
||||||
|
NotifierController.notify(
|
||||||
|
message: NSLocalizedString("Loading CHS Core Dict...", comment: "")
|
||||||
|
)
|
||||||
|
group.enter()
|
||||||
|
globalQueue.async {
|
||||||
|
loadCoreLanguageModelFile(filenameSansExtension: "data-chs", langModel: &Self.lmCHS)
|
||||||
|
group.leave()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case .imeModeCHT:
|
||||||
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: "")
|
||||||
)
|
)
|
||||||
|
group.enter()
|
||||||
|
globalQueue.async {
|
||||||
loadCoreLanguageModelFile(filenameSansExtension: "data-cht", langModel: &Self.lmCHT)
|
loadCoreLanguageModelFile(filenameSansExtension: "data-cht", langModel: &Self.lmCHT)
|
||||||
|
group.leave()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default: break
|
||||||
|
}
|
||||||
|
group.notify(queue: DispatchQueue.main) {
|
||||||
|
if showFinishNotification {
|
||||||
NotifierController.notify(
|
NotifierController.notify(
|
||||||
message: NSLocalizedString("Core Dict loading complete.", comment: "")
|
message: NSLocalizedString("Core Dict loading complete.", comment: "")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
case .imeModeNULL:
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -576,15 +598,15 @@ public enum LMMgr {
|
||||||
// MARK: UOM
|
// MARK: UOM
|
||||||
|
|
||||||
public static func saveUserOverrideModelData() {
|
public static func saveUserOverrideModelData() {
|
||||||
let globalQuene = DispatchQueue.global(qos: .default)
|
let globalQueue = DispatchQueue.global(qos: .default)
|
||||||
let group = DispatchGroup()
|
let group = DispatchGroup()
|
||||||
group.enter()
|
group.enter()
|
||||||
globalQuene.async {
|
globalQueue.async {
|
||||||
Self.uomCHT.saveData(toURL: userOverrideModelDataURL(.imeModeCHT))
|
Self.uomCHT.saveData(toURL: userOverrideModelDataURL(.imeModeCHT))
|
||||||
group.leave()
|
group.leave()
|
||||||
}
|
}
|
||||||
group.enter()
|
group.enter()
|
||||||
globalQuene.async {
|
globalQueue.async {
|
||||||
Self.uomCHS.saveData(toURL: userOverrideModelDataURL(.imeModeCHS))
|
Self.uomCHS.saveData(toURL: userOverrideModelDataURL(.imeModeCHS))
|
||||||
group.leave()
|
group.leave()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue