Repo // Dump wrecked UOM data on crash when debug mode is ON.
This commit is contained in:
parent
339cfb0ad4
commit
a4cd1fb69e
|
@ -66,21 +66,25 @@ public extension AppDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
// 一旦發現與使用者半衰模組的觀察行為有關的崩潰標記被開啟,就清空既有的半衰記憶資料檔案。
|
||||
// 一旦發現與使用者半衰模組的觀察行為有關的崩潰標記被開啟:
|
||||
// 如果有開啟 Debug 模式的話,就將既有的半衰記憶資料檔案更名+打上當時的時間戳。
|
||||
// 如果沒有開啟 Debug 模式的話,則將半衰記憶資料直接清空。
|
||||
if PrefMgr.shared.failureFlagForUOMObservation {
|
||||
DispatchQueue.main.async {
|
||||
if PrefMgr.shared.isDebugModeEnabled {
|
||||
LMMgr.relocateWreckedUOMData()
|
||||
} else {
|
||||
LMMgr.clearUserOverrideModelData(.imeModeCHS)
|
||||
LMMgr.clearUserOverrideModelData(.imeModeCHT)
|
||||
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.soundName = NSUserNotificationDefaultSoundName
|
||||
NSUserNotificationCenter.default.deliver(userNotification)
|
||||
}
|
||||
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.soundName = NSUserNotificationDefaultSoundName
|
||||
NSUserNotificationCenter.default.deliver(userNotification)
|
||||
}
|
||||
|
||||
if !PrefMgr.shared.onlyLoadFactoryLangModelsIfNeeded { LMMgr.loadDataModelsOnAppDelegate() }
|
||||
|
|
|
@ -382,6 +382,24 @@ public class LMMgr {
|
|||
}
|
||||
}
|
||||
|
||||
public static func relocateWreckedUOMData() {
|
||||
func dateStringTag(date givenDate: Date) -> String {
|
||||
let dateFormatter = DateFormatter()
|
||||
dateFormatter.dateFormat = "yyyyMMdd-HHmm"
|
||||
dateFormatter.timeZone = .current
|
||||
let strDate = dateFormatter.string(from: givenDate)
|
||||
return strDate
|
||||
}
|
||||
|
||||
let urls: [URL] = [userOverrideModelDataURL(.imeModeCHS), userOverrideModelDataURL(.imeModeCHT)]
|
||||
let folderURL = URL(fileURLWithPath: dataFolderPath(isDefaultFolder: true)).deletingLastPathComponent()
|
||||
urls.forEach { oldURL in
|
||||
let newFileName = "[UOM-CRASH][\(dateStringTag(date: .init()))]\(oldURL.lastPathComponent)"
|
||||
let newURL = folderURL.appendingPathComponent(newFileName)
|
||||
try? FileManager.default.moveItem(at: oldURL, to: newURL)
|
||||
}
|
||||
}
|
||||
|
||||
public static func clearUserOverrideModelData(_ mode: Shared.InputMode = .imeModeNULL) {
|
||||
switch mode {
|
||||
case .imeModeCHS:
|
||||
|
|
Loading…
Reference in New Issue