From a8257168af13936a814edf0e81aea07649ba6c04 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Thu, 24 Feb 2022 19:38:10 +0800 Subject: [PATCH] AppDelegate // Make Debug Print Function Global, etc. --- Source/Modules/AppDelegate.swift | 23 +++++- .../Modules/ControllerModules/KeyHandler.mm | 81 +++++++++---------- 2 files changed, 55 insertions(+), 49 deletions(-) diff --git a/Source/Modules/AppDelegate.swift b/Source/Modules/AppDelegate.swift index 461b836b..3c5133b1 100644 --- a/Source/Modules/AppDelegate.swift +++ b/Source/Modules/AppDelegate.swift @@ -24,6 +24,7 @@ private let kCheckUpdateAutomatically = "CheckUpdateAutomatically" private let kNextUpdateCheckDateKey = "NextUpdateCheckDate" private let kUpdateInfoEndpointKey = "UpdateInfoEndpoint" private let kUpdateInfoSiteKey = "UpdateInfoSite" +private let kVersionDescription = "VersionDescription" private let kNextCheckInterval: TimeInterval = 86400.0 private let kTimeoutInterval: TimeInterval = 60.0 @@ -93,21 +94,23 @@ struct VersionUpdateApi { DispatchQueue.main.async { forced ? callback(.success(.noNeedToUpdate)) : callback(.success(.ignored)) } + IME.prtDebugIntel("vChewingDebug: Update // Order is not Ascending, assuming that there's no new version available.") return } - + IME.prtDebugIntel("vChewingDebug: Update // New version detected, proceeding to the next phase.") guard let siteInfoURLString = plist[kUpdateInfoSiteKey] as? String, let siteInfoURL = URL(string: siteInfoURLString) else { DispatchQueue.main.async { forced ? callback(.success(.noNeedToUpdate)) : callback(.success(.ignored)) } + IME.prtDebugIntel("vChewingDebug: Update // Failed from retrieving / parsing URL intel.") return } - + IME.prtDebugIntel("vChewingDebug: Update // URL intel retrieved, proceeding to the next phase.") var report = VersionUpdateReport(siteUrl: siteInfoURL) var versionDescription = "" - let versionDescriptions = plist["Description"] as? [AnyHashable: Any] + let versionDescriptions = plist[kVersionDescription] as? [AnyHashable: Any] if let versionDescriptions = versionDescriptions { var locale = "en" let supportedLocales = ["en", "zh-Hant", "zh-Hans", "ja"] @@ -128,6 +131,7 @@ struct VersionUpdateApi { DispatchQueue.main.async { callback(.success(.shouldUpdate(report: report))) } + IME.prtDebugIntel("vChewingDebug: Update // Callbck Complete.") } catch { DispatchQueue.main.async { forced ? callback(.success(.noNeedToUpdate)) : callback(.success(.ignored)) @@ -248,6 +252,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelega report.remoteShortVersion, report.remoteVersion, report.versionDescription) + IME.prtDebugIntel("vChewingDebug: \(content)") ctlNonModalAlertWindow.shared.show(title: NSLocalizedString("New Version Available", comment: ""), content: content, confirmButtonTitle: NSLocalizedString("Visit Website", comment: ""), cancelButtonTitle: NSLocalizedString("Not Now", comment: ""), cancelAsDefault: false, delegate: self) case .noNeedToUpdate, .ignored: break @@ -258,6 +263,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelega let title = NSLocalizedString("Update Check Failed", comment: "") let content = String(format: NSLocalizedString("There may be no internet connection or the server failed to respond.\n\nError message: %@", comment: ""), message) let buttonTitle = NSLocalizedString("Dismiss", comment: "") + IME.prtDebugIntel("vChewingDebug: \(content)") ctlNonModalAlertWindow.shared.show(title: title, content: content, confirmButtonTitle: buttonTitle, cancelButtonTitle: nil, cancelAsDefault: false, delegate: nil) default: break @@ -276,10 +282,19 @@ class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelega func ctlNonModalAlertWindowDidCancel(_ controller: ctlNonModalAlertWindow) { updateNextStepURL = nil } - + // New About Window @IBAction func about(_ sender: Any) { (NSApp.delegate as? AppDelegate)?.showAbout() NSApplication.shared.activate(ignoringOtherApps: true) } } + +@objc public class IME: NSObject { + // Print debug information to the console. + @objc static func prtDebugIntel(_ strPrint: String) { + if Preferences.isDebugModeEnabled { + NSLog("vChewingErrorCallback: %@", strPrint) + } + } +} diff --git a/Source/Modules/ControllerModules/KeyHandler.mm b/Source/Modules/ControllerModules/KeyHandler.mm index e81d5b5d..82770558 100644 --- a/Source/Modules/ControllerModules/KeyHandler.mm +++ b/Source/Modules/ControllerModules/KeyHandler.mm @@ -354,7 +354,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; // see if we have a unigram for this if (!_languageModel->hasUnigramsForKey(reading)) { - [self errorCallbackConsolePrint:@"B49C0979"]; + [IME prtDebugIntel:@"B49C0979"]; errorCallback(); InputStateInputting *inputting = (InputStateInputting *)[self buildInputtingState]; stateCallback(inputting); @@ -578,7 +578,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; // strange behavior if we don't do this, "thinking" the key is not // actually consumed) if ([state isKindOfClass:[InputStateNotEmpty class]] || !_bpmfReadingBuffer->isEmpty()) { - [self errorCallbackConsolePrint:@"A9BFF20E"]; + [IME prtDebugIntel:@"A9BFF20E"]; errorCallback(); stateCallback(state); return YES; @@ -629,7 +629,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; } if (!_bpmfReadingBuffer->isEmpty()) { - [self errorCallbackConsolePrint:@"6ED95318"]; + [IME prtDebugIntel:@"6ED95318"]; errorCallback(); stateCallback(state); return YES; @@ -645,7 +645,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; marking.tooltipForInputting = currentState.tooltip; stateCallback(marking); } else { - [self errorCallbackConsolePrint:@"D326DEA3"]; + [IME prtDebugIntel:@"D326DEA3"]; errorCallback(); stateCallback(state); } @@ -655,7 +655,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; InputStateInputting *inputting = (InputStateInputting *)[self buildInputtingState]; stateCallback(inputting); } else { - [self errorCallbackConsolePrint:@"7045E6F3"]; + [IME prtDebugIntel:@"7045E6F3"]; errorCallback(); stateCallback(state); } @@ -670,7 +670,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; } if (!_bpmfReadingBuffer->isEmpty()) { - [self errorCallbackConsolePrint:@"B3BA5257"]; + [IME prtDebugIntel:@"B3BA5257"]; errorCallback(); stateCallback(state); return YES; @@ -686,7 +686,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; marking.tooltipForInputting = currentState.tooltip; stateCallback(marking); } else { - [self errorCallbackConsolePrint:@"BB7F6DB9"]; + [IME prtDebugIntel:@"BB7F6DB9"]; errorCallback(); stateCallback(state); } @@ -696,7 +696,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; InputStateInputting *inputting = (InputStateInputting *)[self buildInputtingState]; stateCallback(inputting); } else { - [self errorCallbackConsolePrint:@"A96AAD58"]; + [IME prtDebugIntel:@"A96AAD58"]; errorCallback(); stateCallback(state); } @@ -712,7 +712,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; } if (!_bpmfReadingBuffer->isEmpty()) { - [self errorCallbackConsolePrint:@"ABC44080"]; + [IME prtDebugIntel:@"ABC44080"]; errorCallback(); stateCallback(state); return YES; @@ -723,7 +723,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; InputStateInputting *inputting = (InputStateInputting *)[self buildInputtingState]; stateCallback(inputting); } else { - [self errorCallbackConsolePrint:@"66D97F90"]; + [IME prtDebugIntel:@"66D97F90"]; errorCallback(); stateCallback(state); } @@ -738,7 +738,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; } if (!_bpmfReadingBuffer->isEmpty()) { - [self errorCallbackConsolePrint:@"9B69908D"]; + [IME prtDebugIntel:@"9B69908D"]; errorCallback(); stateCallback(state); return YES; @@ -749,7 +749,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; InputStateInputting *inputting = (InputStateInputting *)[self buildInputtingState]; stateCallback(inputting); } else { - [self errorCallbackConsolePrint:@"9B69908E"]; + [IME prtDebugIntel:@"9B69908E"]; errorCallback(); stateCallback(state); } @@ -764,7 +764,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; } if (!_bpmfReadingBuffer->isEmpty()) { - [self errorCallbackConsolePrint:@"9B6F908D"]; + [IME prtDebugIntel:@"9B6F908D"]; errorCallback(); } stateCallback(state); @@ -782,7 +782,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; _builder->deleteReadingBeforeCursor(); [self _walk]; } else { - [self errorCallbackConsolePrint:@"9D69908D"]; + [IME prtDebugIntel:@"9D69908D"]; errorCallback(); stateCallback(state); return YES; @@ -819,12 +819,12 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; stateCallback(inputting); } } else { - [self errorCallbackConsolePrint:@"9B69938D"]; + [IME prtDebugIntel:@"9B69938D"]; errorCallback(); stateCallback(state); } } else { - [self errorCallbackConsolePrint:@"9C69908D"]; + [IME prtDebugIntel:@"9C69908D"]; errorCallback(); stateCallback(state); } @@ -878,7 +878,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; _builder->insertReadingAtCursor(customPunctuation); poppedText = [self _popOverflowComposingTextAndWalk]; } else { // If there is still unfinished bpmf reading, ignore the punctuation - [self errorCallbackConsolePrint:@"A9B69908D"]; + [IME prtDebugIntel:@"A9B69908D"]; errorCallback(); stateCallback(state); return YES; @@ -920,7 +920,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; // Enter if ([input isEnter]) { if (![self.delegate keyHandler:self didRequestWriteUserPhraseWithState:state]) { - [self errorCallbackConsolePrint:@"5B69CC8D"]; + [IME prtDebugIntel:@"5B69CC8D"]; errorCallback(); return YES; } @@ -945,7 +945,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; stateCallback(marking); } } else { - [self errorCallbackConsolePrint:@"1149908D"]; + [IME prtDebugIntel:@"1149908D"]; errorCallback(); stateCallback(state); } @@ -967,7 +967,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; stateCallback(marking); } } else { - [self errorCallbackConsolePrint:@"9B51408D"]; + [IME prtDebugIntel:@"9B51408D"]; errorCallback(); stateCallback(state); } @@ -984,8 +984,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; { NSString *inputText = input.inputText; UniChar charCode = input.charCode; - NSString *char2Print = [NSString stringWithCharacters:&charCode length:1]; - NSLog(@"vChewingCandidateKeyDebug: %@", char2Print); VTCandidateController *gCurrentCandidateController = [self.delegate candidateControllerForKeyHandler:self]; BOOL cancelCandidateKey = [input isBackSpace] || [input isESC] || [input isDelete]; @@ -1032,7 +1030,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; ([input isShiftHold] ? [gCurrentCandidateController highlightPreviousCandidate] : [gCurrentCandidateController highlightNextCandidate]) ; if (!updated) { - [self errorCallbackConsolePrint:@"9B691919"]; + [IME prtDebugIntel:@"9B691919"]; errorCallback(); } return YES; @@ -1041,7 +1039,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if ([input isSpace] || [input isPageDown] || input.emacsKey == vChewingEmacsKeyNextPage) { BOOL updated = [gCurrentCandidateController showNextPage]; if (!updated) { - [self errorCallbackConsolePrint:@"9B691919"]; + [IME prtDebugIntel:@"9B691919"]; errorCallback(); } return YES; @@ -1050,7 +1048,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if ([input isPageUp]) { BOOL updated = [gCurrentCandidateController showPreviousPage]; if (!updated) { - [self errorCallbackConsolePrint:@"9569955D"]; + [IME prtDebugIntel:@"9569955D"]; errorCallback(); } return YES; @@ -1060,13 +1058,13 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if ([gCurrentCandidateController isKindOfClass:[VTHorizontalCandidateController class]]) { BOOL updated = [gCurrentCandidateController highlightPreviousCandidate]; if (!updated) { - [self errorCallbackConsolePrint:@"1145148D"]; + [IME prtDebugIntel:@"1145148D"]; errorCallback(); } } else { BOOL updated = [gCurrentCandidateController showPreviousPage]; if (!updated) { - [self errorCallbackConsolePrint:@"1919810D"]; + [IME prtDebugIntel:@"1919810D"]; errorCallback(); } } @@ -1076,7 +1074,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if (input.emacsKey == vChewingEmacsKeyBackward) { BOOL updated = [gCurrentCandidateController highlightPreviousCandidate]; if (!updated) { - [self errorCallbackConsolePrint:@"9B89308D"]; + [IME prtDebugIntel:@"9B89308D"]; errorCallback(); } return YES; @@ -1086,13 +1084,13 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if ([gCurrentCandidateController isKindOfClass:[VTHorizontalCandidateController class]]) { BOOL updated = [gCurrentCandidateController highlightNextCandidate]; if (!updated) { - [self errorCallbackConsolePrint:@"9B65138D"]; + [IME prtDebugIntel:@"9B65138D"]; errorCallback(); } } else { BOOL updated = [gCurrentCandidateController showNextPage]; if (!updated) { - [self errorCallbackConsolePrint:@"9244908D"]; + [IME prtDebugIntel:@"9244908D"]; errorCallback(); } } @@ -1102,7 +1100,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if (input.emacsKey == vChewingEmacsKeyForward) { BOOL updated = [gCurrentCandidateController highlightNextCandidate]; if (!updated) { - [self errorCallbackConsolePrint:@"9B2428D"]; + [IME prtDebugIntel:@"9B2428D"]; errorCallback(); } return YES; @@ -1112,13 +1110,13 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if ([gCurrentCandidateController isKindOfClass:[VTHorizontalCandidateController class]]) { BOOL updated = [gCurrentCandidateController showPreviousPage]; if (!updated) { - [self errorCallbackConsolePrint:@"9B614524"]; + [IME prtDebugIntel:@"9B614524"]; errorCallback(); } } else { BOOL updated = [gCurrentCandidateController highlightPreviousCandidate]; if (!updated) { - [self errorCallbackConsolePrint:@"ASD9908D"]; + [IME prtDebugIntel:@"ASD9908D"]; errorCallback(); } } @@ -1129,13 +1127,13 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if ([gCurrentCandidateController isKindOfClass:[VTHorizontalCandidateController class]]) { BOOL updated = [gCurrentCandidateController showNextPage]; if (!updated) { - [self errorCallbackConsolePrint:@"92B990DD"]; + [IME prtDebugIntel:@"92B990DD"]; errorCallback(); } } else { BOOL updated = [gCurrentCandidateController highlightNextCandidate]; if (!updated) { - [self errorCallbackConsolePrint:@"6B99908D"]; + [IME prtDebugIntel:@"6B99908D"]; errorCallback(); } } @@ -1144,7 +1142,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if ([input isHome] || input.emacsKey == vChewingEmacsKeyHome) { if (gCurrentCandidateController.selectedCandidateIndex == 0) { - [self errorCallbackConsolePrint:@"9B6EDE8D"]; + [IME prtDebugIntel:@"9B6EDE8D"]; errorCallback(); } else { gCurrentCandidateController.selectedCandidateIndex = 0; @@ -1167,7 +1165,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if (([input isEnd] || input.emacsKey == vChewingEmacsKeyEnd) && candidates.count > 0) { if (gCurrentCandidateController.selectedCandidateIndex == candidates.count - 1) { - [self errorCallbackConsolePrint:@"9B69AAAD"]; + [IME prtDebugIntel:@"9B69AAAD"]; errorCallback(); } else { gCurrentCandidateController.selectedCandidateIndex = candidates.count - 1; @@ -1245,7 +1243,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; } } - [self errorCallbackConsolePrint:@"172A0F81"]; + [IME prtDebugIntel:@"172A0F81"]; errorCallback(); return YES; } @@ -1443,11 +1441,4 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; return nil; } --(void)errorCallbackConsolePrint:(NSString *)strPrint -{ - if (Preferences.isDebugModeEnabled) { - NSLog(@"vChewingErrorCallback: %@", strPrint); - } -} - @end