LMInstantiator // Make async optional while loading user dicts.
This commit is contained in:
parent
25d8f7c093
commit
c932083c5f
|
@ -41,6 +41,8 @@ public extension LMAssembly {
|
||||||
public var deltaOfCalendarYears: Int = -2000
|
public var deltaOfCalendarYears: Int = -2000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static var asyncLoadingUserData: Bool = true
|
||||||
|
|
||||||
// SQLite 連線所在的記憶體位置。
|
// SQLite 連線所在的記憶體位置。
|
||||||
static var ptrSQL: OpaquePointer?
|
static var ptrSQL: OpaquePointer?
|
||||||
|
|
||||||
|
@ -107,25 +109,39 @@ public extension LMAssembly {
|
||||||
public func resetFactoryJSONModels() {}
|
public func resetFactoryJSONModels() {}
|
||||||
|
|
||||||
public func loadUserPhrasesData(path: String, filterPath: String?) {
|
public func loadUserPhrasesData(path: String, filterPath: String?) {
|
||||||
DispatchQueue.main.async {
|
func loadMain() {
|
||||||
if FileManager.default.isReadableFile(atPath: path) {
|
if FileManager.default.isReadableFile(atPath: path) {
|
||||||
self.lmUserPhrases.clear()
|
lmUserPhrases.clear()
|
||||||
self.lmUserPhrases.open(path)
|
lmUserPhrases.open(path)
|
||||||
vCLMLog("lmUserPhrases: \(self.lmUserPhrases.count) entries of data loaded from: \(path)")
|
vCLMLog("lmUserPhrases: \(lmUserPhrases.count) entries of data loaded from: \(path)")
|
||||||
} else {
|
} else {
|
||||||
vCLMLog("lmUserPhrases: File access failure: \(path)")
|
vCLMLog("lmUserPhrases: File access failure: \(path)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !Self.asyncLoadingUserData {
|
||||||
|
loadMain()
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
loadMain()
|
||||||
|
}
|
||||||
|
}
|
||||||
guard let filterPath = filterPath else { return }
|
guard let filterPath = filterPath else { return }
|
||||||
DispatchQueue.main.async {
|
func loadFilter() {
|
||||||
if FileManager.default.isReadableFile(atPath: filterPath) {
|
if FileManager.default.isReadableFile(atPath: filterPath) {
|
||||||
self.lmFiltered.clear()
|
lmFiltered.clear()
|
||||||
self.lmFiltered.open(filterPath)
|
lmFiltered.open(filterPath)
|
||||||
vCLMLog("lmFiltered: \(self.lmFiltered.count) entries of data loaded from: \(path)")
|
vCLMLog("lmFiltered: \(lmFiltered.count) entries of data loaded from: \(path)")
|
||||||
} else {
|
} else {
|
||||||
vCLMLog("lmFiltered: File access failure: \(path)")
|
vCLMLog("lmFiltered: File access failure: \(path)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !Self.asyncLoadingUserData {
|
||||||
|
loadFilter()
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
loadFilter()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 這個函式不用 GCD。
|
/// 這個函式不用 GCD。
|
||||||
|
@ -140,44 +156,65 @@ public extension LMAssembly {
|
||||||
}
|
}
|
||||||
|
|
||||||
public func loadUserSymbolData(path: String) {
|
public func loadUserSymbolData(path: String) {
|
||||||
DispatchQueue.main.async {
|
func load() {
|
||||||
if FileManager.default.isReadableFile(atPath: path) {
|
if FileManager.default.isReadableFile(atPath: path) {
|
||||||
self.lmUserSymbols.clear()
|
lmUserSymbols.clear()
|
||||||
self.lmUserSymbols.open(path)
|
lmUserSymbols.open(path)
|
||||||
vCLMLog("lmUserSymbol: \(self.lmUserSymbols.count) entries of data loaded from: \(path)")
|
vCLMLog("lmUserSymbol: \(lmUserSymbols.count) entries of data loaded from: \(path)")
|
||||||
} else {
|
} else {
|
||||||
vCLMLog("lmUserSymbol: File access failure: \(path)")
|
vCLMLog("lmUserSymbol: File access failure: \(path)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !Self.asyncLoadingUserData {
|
||||||
|
load()
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
load()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func loadUserAssociatesData(path: String) {
|
public func loadUserAssociatesData(path: String) {
|
||||||
DispatchQueue.main.async {
|
func load() {
|
||||||
if FileManager.default.isReadableFile(atPath: path) {
|
if FileManager.default.isReadableFile(atPath: path) {
|
||||||
self.lmAssociates.clear()
|
lmAssociates.clear()
|
||||||
self.lmAssociates.open(path)
|
lmAssociates.open(path)
|
||||||
vCLMLog("lmAssociates: \(self.lmAssociates.count) entries of data loaded from: \(path)")
|
vCLMLog("lmAssociates: \(lmAssociates.count) entries of data loaded from: \(path)")
|
||||||
} else {
|
} else {
|
||||||
vCLMLog("lmAssociates: File access failure: \(path)")
|
vCLMLog("lmAssociates: File access failure: \(path)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !Self.asyncLoadingUserData {
|
||||||
|
load()
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
load()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func loadReplacementsData(path: String) {
|
public func loadReplacementsData(path: String) {
|
||||||
DispatchQueue.main.async {
|
func load() {
|
||||||
if FileManager.default.isReadableFile(atPath: path) {
|
if FileManager.default.isReadableFile(atPath: path) {
|
||||||
self.lmReplacements.clear()
|
lmReplacements.clear()
|
||||||
self.lmReplacements.open(path)
|
lmReplacements.open(path)
|
||||||
vCLMLog("lmReplacements: \(self.lmReplacements.count) entries of data loaded from: \(path)")
|
vCLMLog("lmReplacements: \(lmReplacements.count) entries of data loaded from: \(path)")
|
||||||
} else {
|
} else {
|
||||||
vCLMLog("lmReplacements: File access failure: \(path)")
|
vCLMLog("lmReplacements: File access failure: \(path)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !Self.asyncLoadingUserData {
|
||||||
|
load()
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
load()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public var isCassetteDataLoaded: Bool { Self.lmCassette.isLoaded }
|
public var isCassetteDataLoaded: Bool { Self.lmCassette.isLoaded }
|
||||||
public static func loadCassetteData(path: String) {
|
public static func loadCassetteData(path: String) {
|
||||||
DispatchQueue.main.async {
|
func load() {
|
||||||
if FileManager.default.isReadableFile(atPath: path) {
|
if FileManager.default.isReadableFile(atPath: path) {
|
||||||
Self.lmCassette.clear()
|
Self.lmCassette.clear()
|
||||||
Self.lmCassette.open(path)
|
Self.lmCassette.open(path)
|
||||||
|
@ -186,6 +223,13 @@ public extension LMAssembly {
|
||||||
vCLMLog("lmCassette: File access failure: \(path)")
|
vCLMLog("lmCassette: File access failure: \(path)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !Self.asyncLoadingUserData {
|
||||||
|
load()
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
load()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - 核心函式(對外)
|
// MARK: - 核心函式(對外)
|
||||||
|
|
Loading…
Reference in New Issue