AppDelegate // Add checkMemoryUsage().

This commit is contained in:
ShikiSuen 2022-11-18 15:49:01 +08:00
parent 49ba507c8d
commit 38713d4aa9
6 changed files with 31 additions and 1 deletions

View File

@ -9,6 +9,7 @@
// requirements defined in MIT License. // requirements defined in MIT License.
import FolderMonitor import FolderMonitor
import Shared
import Uninstaller import Uninstaller
import UpdateSputnik import UpdateSputnik
@ -48,7 +49,8 @@ extension AppDelegate {
userNotification.title = NSLocalizedString("vChewing", comment: "") userNotification.title = NSLocalizedString("vChewing", comment: "")
userNotification.informativeText = NSLocalizedString( userNotification.informativeText = NSLocalizedString(
"vChewing crashed while handling previously loaded UOM observation data. These data files are cleaned now to ensure the usability.", "vChewing crashed while handling previously loaded UOM observation data. These data files are cleaned now to ensure the usability.",
comment: "") comment: ""
)
userNotification.soundName = NSUserNotificationDefaultSoundName userNotification.soundName = NSUserNotificationDefaultSoundName
NSUserNotificationCenter.default.deliver(userNotification) NSUserNotificationCenter.default.deliver(userNotification)
} }
@ -105,6 +107,29 @@ extension AppDelegate {
NSApp.setActivationPolicy(.accessory) NSApp.setActivationPolicy(.accessory)
} }
///
/// - Returns: MiB
@discardableResult public func checkMemoryUsage() -> Double {
guard let currentMemorySizeInBytes = NSApplication.memoryFootprint else { return 0 }
let currentMemorySize: Double = (Double(currentMemorySizeInBytes) / 1024 / 1024).rounded(toPlaces: 1)
switch currentMemorySize {
case 300...:
vCLog("WARNING: EXCESSIVE MEMORY FOOTPRINT (\(currentMemorySize)MB).")
let userNotification = NSUserNotification()
userNotification.title = NSLocalizedString("vChewing", comment: "")
userNotification.informativeText = NSLocalizedString(
"vChewing is rebooted due to a memory-excessive-usage problem. If convenient, please inform the developer that you are having this issue, stating whether you are using an Intel Mac or Apple Silicon Mac. An NSLog is generated with the current memory footprint size.",
comment: ""
)
NSUserNotificationCenter.default.deliver(userNotification)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
NSApp.terminate(self)
}
default: break
}
return currentMemorySize
}
// New About Window // New About Window
@IBAction public func about(_: Any) { @IBAction public func about(_: Any) {
CtlAboutWindow.show() CtlAboutWindow.show()

View File

@ -1,4 +1,5 @@
"vChewing" = "vChewing"; "vChewing" = "vChewing";
"vChewing is rebooted due to a memory-excessive-usage problem. If convenient, please inform the developer that you are having this issue, stating whether you are using an Intel Mac or Apple Silicon Mac. An NSLog is generated with the current memory footprint size." = "vChewing is rebooted due to a memory-excessive-usage problem. If convenient, please inform the developer that you are having this issue, stating whether you are using an Intel Mac or Apple Silicon Mac. An NSLog is generated with the current memory footprint size.";
"Please manually implement the symbols of this menu \nin the user phrase file with “_punctuation_list” key." = "Please manually implement the symbols of this menu \nin the user phrase file with “_punctuation_list” key."; "Please manually implement the symbols of this menu \nin the user phrase file with “_punctuation_list” key." = "Please manually implement the symbols of this menu \nin the user phrase file with “_punctuation_list” key.";
"Wildcard key cannot be the initial key." = "Wildcard key cannot be the initial key."; "Wildcard key cannot be the initial key." = "Wildcard key cannot be the initial key.";
"CIN Cassette Mode" = "CIN Cassette Mode"; "CIN Cassette Mode" = "CIN Cassette Mode";

View File

@ -1,4 +1,5 @@
"vChewing" = "vChewing"; "vChewing" = "vChewing";
"vChewing is rebooted due to a memory-excessive-usage problem. If convenient, please inform the developer that you are having this issue, stating whether you are using an Intel Mac or Apple Silicon Mac. An NSLog is generated with the current memory footprint size." = "vChewing is rebooted due to a memory-excessive-usage problem. If convenient, please inform the developer that you are having this issue, stating whether you are using an Intel Mac or Apple Silicon Mac. An NSLog is generated with the current memory footprint size.";
"Please manually implement the symbols of this menu \nin the user phrase file with “_punctuation_list” key." = "Please manually implement the symbols of this menu \nin the user phrase file with “_punctuation_list” key."; "Please manually implement the symbols of this menu \nin the user phrase file with “_punctuation_list” key." = "Please manually implement the symbols of this menu \nin the user phrase file with “_punctuation_list” key.";
"Wildcard key cannot be the initial key." = "Wildcard key cannot be the initial key."; "Wildcard key cannot be the initial key." = "Wildcard key cannot be the initial key.";
"CIN Cassette Mode" = "CIN Cassette Mode"; "CIN Cassette Mode" = "CIN Cassette Mode";

View File

@ -1,4 +1,5 @@
"vChewing" = "威注音入力アプリ"; "vChewing" = "威注音入力アプリ";
"vChewing is rebooted due to a memory-excessive-usage problem. If convenient, please inform the developer that you are having this issue, stating whether you are using an Intel Mac or Apple Silicon Mac. An NSLog is generated with the current memory footprint size." = "威注音入力アプリはメモリー使用量多すぎたため、再起動しました。もし、よろしければ、この問題について、開発元にご連絡をし、そしてこのパソコンの CPU 種類情報Intel か、Apple Silicon か)も一緒に教えてください。今のメモリー使用量は NSLog にて記録済みである。";
"Please manually implement the symbols of this menu \nin the user phrase file with “_punctuation_list” key." = "このメニューのお用いには、ご自分でユーザー辞書で\n「_punctuation_list」キーの符号記録のご補充が必要でござる。"; "Please manually implement the symbols of this menu \nin the user phrase file with “_punctuation_list” key." = "このメニューのお用いには、ご自分でユーザー辞書で\n「_punctuation_list」キーの符号記録のご補充が必要でござる。";
"Wildcard key cannot be the initial key." = "骨牌キーは最初のキーとしてはならぬ。"; "Wildcard key cannot be the initial key." = "骨牌キーは最初のキーとしてはならぬ。";
"CIN Cassette Mode" = "CIN カセットモード"; "CIN Cassette Mode" = "CIN カセットモード";

View File

@ -1,4 +1,5 @@
"vChewing" = "威注音输入法"; "vChewing" = "威注音输入法";
"vChewing is rebooted due to a memory-excessive-usage problem. If convenient, please inform the developer that you are having this issue, stating whether you are using an Intel Mac or Apple Silicon Mac. An NSLog is generated with the current memory footprint size." = "威注音输入法因记忆体用量过大的问题而重新启动。如果您方便的话,请就这个问题知会该输入法的主程式师、且请务必说明自己在用的是 Intel 机种还是 Apple Silicon 机种。当前输入法记忆体用量已借由 NSLog 记录输出。";
"Please manually implement the symbols of this menu \nin the user phrase file with “_punctuation_list” key." = "请自行以「_punctuation_list」索引键\n在使用者自订语汇档案内扩充该符号选单的内容。";"Wildcard key cannot be the initial key." = "花牌键不得作为起始码。"; "Please manually implement the symbols of this menu \nin the user phrase file with “_punctuation_list” key." = "请自行以「_punctuation_list」索引键\n在使用者自订语汇档案内扩充该符号选单的内容。";"Wildcard key cannot be the initial key." = "花牌键不得作为起始码。";
"Wildcard key cannot be the initial key." = "花牌键不得作为起始码。"; "Wildcard key cannot be the initial key." = "花牌键不得作为起始码。";
"CIN Cassette Mode" = "CIN 磁带模式"; "CIN Cassette Mode" = "CIN 磁带模式";

View File

@ -1,4 +1,5 @@
"vChewing" = "威注音輸入法"; "vChewing" = "威注音輸入法";
"vChewing is rebooted due to a memory-excessive-usage problem. If convenient, please inform the developer that you are having this issue, stating whether you are using an Intel Mac or Apple Silicon Mac. An NSLog is generated with the current memory footprint size." = "威注音輸入法因記憶體用量過大的問題而重新啟動。如果您方便的話,請就這個問題知會該輸入法的主程式師、且請務必說明自己在用的是 Intel 機種還是 Apple Silicon 機種。當前輸入法記憶體用量已藉由 NSLog 記錄輸出。";
"Please manually implement the symbols of this menu \nin the user phrase file with “_punctuation_list” key." = "請自行以「_punctuation_list」索引鍵\n在使用者自訂語彙檔案內擴充該符號選單的內容。"; "Please manually implement the symbols of this menu \nin the user phrase file with “_punctuation_list” key." = "請自行以「_punctuation_list」索引鍵\n在使用者自訂語彙檔案內擴充該符號選單的內容。";
"Wildcard key cannot be the initial key." = "花牌鍵不得作為起始碼。"; "Wildcard key cannot be the initial key." = "花牌鍵不得作為起始碼。";
"CIN Cassette Mode" = "CIN 磁帶模式"; "CIN Cassette Mode" = "CIN 磁帶模式";