From 6078b5bbc1bee6d285269c4d71b18b1134491f34 Mon Sep 17 00:00:00 2001 From: Zonble Yang Date: Fri, 19 Nov 2021 22:59:12 +0800 Subject: [PATCH 01/18] Also applies Chinese conversion on popped text. Fixes issue #172. --- Source/InputMethodController.mm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/InputMethodController.mm b/Source/InputMethodController.mm index 7d664553..fead0f12 100644 --- a/Source/InputMethodController.mm +++ b/Source/InputMethodController.mm @@ -394,6 +394,7 @@ public: return; } + // Chinese conversion. NSString *buffer = _composingBuffer; if (_chineseConversionEnabled) { buffer = [OpenCCBridge convert:_composingBuffer]; @@ -528,6 +529,10 @@ public: if (_walkedNodes.size() > 0) { NodeAnchor &anchor = _walkedNodes[0]; NSString *popedText = [NSString stringWithUTF8String:anchor.node->currentKeyValue().value.c_str()]; + // Chinese conversion. + if (_chineseConversionEnabled) { + popedText = [OpenCCBridge convert:popedText]; + } [client insertText:popedText replacementRange:NSMakeRange(NSNotFound, NSNotFound)]; _builder->removeHeadReadings(anchor.spanningLength); } From 0182bc608c3b363782577d6038f9d5b4d2eb01b7 Mon Sep 17 00:00:00 2001 From: Zonble Yang Date: Thu, 11 Nov 2021 02:22:19 +0800 Subject: [PATCH 02/18] Allows commit the first canidate while typing a punctuation in plain BPMF mode. --- Source/InputMethodController.mm | 65 ++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/Source/InputMethodController.mm b/Source/InputMethodController.mm index fead0f12..fe3f3eb1 100644 --- a/Source/InputMethodController.mm +++ b/Source/InputMethodController.mm @@ -547,6 +547,35 @@ public: NSBeep(); } +- (string)currentLayout +{ + string layout = string("Standard_");; + NSInteger keyboardLayout = [[NSUserDefaults standardUserDefaults] integerForKey:kKeyboardLayoutPreferenceKey]; + switch (keyboardLayout) { + case 0: + layout = string("Standard_"); + break; + case 1: + layout = string("ETen_"); + break; + case 2: + layout = string("ETen26_"); + break; + case 3: + layout = string("Hsu_"); + break; + case 4: + layout = string("HanyuPinyin_"); + break; + case 5: + layout = string("IBM_"); + break; + default: + break; + } + return layout; +} + - (BOOL)handleInputText:(NSString*)inputText key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)client { NSRect textFrame = NSZeroRect; @@ -896,31 +925,7 @@ public: } } - string layout = string("Standard_");; - NSInteger keyboardLayout = [[NSUserDefaults standardUserDefaults] integerForKey:kKeyboardLayoutPreferenceKey]; - switch (keyboardLayout) { - case 0: - layout = string("Standard_"); - break; - case 1: - layout = string("ETen_"); - break; - case 2: - layout = string("ETen26_"); - break; - case 3: - layout = string("Hsu_"); - break; - case 4: - layout = string("HanyuPinyin_"); - break; - case 5: - layout = string("IBM_"); - break; - default: - break; - } - + string layout = [self currentLayout]; string customPunctuation = string("_punctuation_") + layout + string(1, (char)charCode); if (_languageModel->hasUnigramsForKey(customPunctuation)) { if (_bpmfReadingBuffer->isEmpty()) { @@ -1138,7 +1143,15 @@ public: } if (_inputMode == kPlainBopomofoModeIdentifier) { - if (_bpmfReadingBuffer->isValidKey((char)charCode)) { + // TODO: also commit punctuation. + string layout = [self currentLayout]; + string customPunctuation = string("_punctuation_") + layout + string(1, (char)charCode); + string punctuation = string("_punctuation_") + string(1, (char)charCode); + + BOOL shouldAutoSelectCandidate = _bpmfReadingBuffer->isValidKey((char)charCode) || _languageModel->hasUnigramsForKey(customPunctuation) || + _languageModel->hasUnigramsForKey(punctuation); + + if (shouldAutoSelectCandidate) { NSUInteger candidateIndex = [gCurrentCandidateController candidateIndexAtKeyLabelIndex:0]; if (candidateIndex != NSUIntegerMax) { [self candidateController:gCurrentCandidateController didSelectCandidateAtIndex:candidateIndex]; From 61f5fccc3a230c5316b1dcdf0d3aa52e43ae2380 Mon Sep 17 00:00:00 2001 From: Zonble Yang Date: Thu, 11 Nov 2021 23:02:18 +0800 Subject: [PATCH 03/18] Allows auto-commiting the first candidate when users input a punctuation in plan BPMF mode. --- Source/InputMethodController.mm | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Source/InputMethodController.mm b/Source/InputMethodController.mm index fe3f3eb1..cad6b88d 100644 --- a/Source/InputMethodController.mm +++ b/Source/InputMethodController.mm @@ -989,14 +989,14 @@ public: - (BOOL)handleCandidateEventWithInputText:(NSString *)inputText charCode:(UniChar)charCode keyCode:(NSUInteger)keyCode { - if (_inputMode == kPlainBopomofoModeIdentifier) { - if (charCode == '<') { - keyCode = kPageUpKeyCode; - } - else if (charCode == '>') { - keyCode = kPageDownKeyCode; - } - } +// if (_inputMode == kPlainBopomofoModeIdentifier) { +// if (charCode == '<') { +// keyCode = kPageUpKeyCode; +// } +// else if (charCode == '>') { +// keyCode = kPageDownKeyCode; +// } +// } BOOL cancelCandidateKey = (charCode == 27) || @@ -1143,7 +1143,6 @@ public: } if (_inputMode == kPlainBopomofoModeIdentifier) { - // TODO: also commit punctuation. string layout = [self currentLayout]; string customPunctuation = string("_punctuation_") + layout + string(1, (char)charCode); string punctuation = string("_punctuation_") + string(1, (char)charCode); From 39af38f52cd6624ad2204c4f2c4f0177e9a32c5f Mon Sep 17 00:00:00 2001 From: Zonble Yang Date: Fri, 12 Nov 2021 00:56:11 +0800 Subject: [PATCH 04/18] Updates CI settings. --- .github/workflows/continuous-integration-workflow.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration-workflow.yml b/.github/workflows/continuous-integration-workflow.yml index c8a87cdc..5c094c40 100644 --- a/.github/workflows/continuous-integration-workflow.yml +++ b/.github/workflows/continuous-integration-workflow.yml @@ -11,5 +11,10 @@ jobs: - uses: actions/checkout@v1 - name: Clean run: xcodebuild -scheme McBopomofo -configuration Release clean + - name: Clean + run: xcodebuild -scheme McBopomofoInstaller -configuration Release clean - name: Build - run: xcodebuild -scheme McBopomofo -configuration Release + run: xcodebuild -scheme McBopomofo -configuration Release build + - name: Build + run: xcodebuild -scheme McBopomofoInstaller -configuration Release build + From d2532e19f52aada5c64b70974517082f7fc71268 Mon Sep 17 00:00:00 2001 From: Zonble Yang Date: Fri, 12 Nov 2021 01:15:06 +0800 Subject: [PATCH 05/18] Allows users to use left and right key to go to another candidate page in the vertical candidates list. This fixes #61. --- Source/InputMethodController.mm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Source/InputMethodController.mm b/Source/InputMethodController.mm index cad6b88d..9dec8a06 100644 --- a/Source/InputMethodController.mm +++ b/Source/InputMethodController.mm @@ -1045,7 +1045,10 @@ public: return YES; } else { - [self beep]; + BOOL updated = [gCurrentCandidateController showPreviousPage]; + if (!updated) { + [self beep]; + } [self updateClientComposingBuffer:_currentCandidateClient]; return YES; } @@ -1060,7 +1063,10 @@ public: return YES; } else { - [self beep]; + BOOL updated = [gCurrentCandidateController showNextPage]; + if (!updated) { + [self beep]; + } [self updateClientComposingBuffer:_currentCandidateClient]; return YES; } From a9ad14785d49f1a0e5fa5f909724d51209c4835a Mon Sep 17 00:00:00 2001 From: Lukhnos Liu Date: Mon, 22 Nov 2021 20:21:49 -0800 Subject: [PATCH 06/18] Update to recommended Xcode settings --- McBopomofo.xcodeproj/project.pbxproj | 3 ++- .../xcshareddata/xcschemes/McBopomofo.xcscheme | 2 +- .../xcshareddata/xcschemes/McBopomofoInstaller.xcscheme | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/McBopomofo.xcodeproj/project.pbxproj b/McBopomofo.xcodeproj/project.pbxproj index 9187542d..66dd9c97 100644 --- a/McBopomofo.xcodeproj/project.pbxproj +++ b/McBopomofo.xcodeproj/project.pbxproj @@ -544,7 +544,7 @@ 6A0D4E9415FC0CFA00ABF4B3 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1220; + LastUpgradeCheck = 1310; TargetAttributes = { 6A0D4EA115FC0D2D00ABF4B3 = { LastSwiftMigration = 1240; @@ -837,6 +837,7 @@ "$(OTHER_CFLAGS)", "-fcxx-modules", ); + SWIFT_COMPILATION_MODE = wholemodule; }; name = Release; }; diff --git a/McBopomofo.xcodeproj/xcshareddata/xcschemes/McBopomofo.xcscheme b/McBopomofo.xcodeproj/xcshareddata/xcschemes/McBopomofo.xcscheme index 56d01ed8..3b2c3c69 100644 --- a/McBopomofo.xcodeproj/xcshareddata/xcschemes/McBopomofo.xcscheme +++ b/McBopomofo.xcodeproj/xcshareddata/xcschemes/McBopomofo.xcscheme @@ -1,6 +1,6 @@ Date: Mon, 22 Nov 2021 20:51:24 -0800 Subject: [PATCH 07/18] Fix non-existent font in .xib --- Source/zh-Hant.lproj/preferences.xib | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/zh-Hant.lproj/preferences.xib b/Source/zh-Hant.lproj/preferences.xib index e4d51139..17e6e2c9 100644 --- a/Source/zh-Hant.lproj/preferences.xib +++ b/Source/zh-Hant.lproj/preferences.xib @@ -20,7 +20,7 @@ - + @@ -223,7 +223,7 @@ - + From 99680668c7953a8a0bd7d012a6a4513f8c6765ab Mon Sep 17 00:00:00 2001 From: Lukhnos Liu Date: Mon, 22 Nov 2021 21:17:35 -0800 Subject: [PATCH 08/18] Fix IME activation issues on macOS 12 We now let the Installer to call the TextInputSources API. Since macOS 12, users are prompted to allow enabling of third-party IMEs in Preferences.app the momemnt TISRegisterInputSource or TISEnableInputSource is called. By moving the activation to the Installer, a user will clearly see that it's the Installer that wants to enable the IME. In addition, we had to make necessary changes so that on macOS 12 and later, the Installer always enable the default input source. This is due to the observation that the kTISPropertyInputSourceIsEnabled becomes unreliable on macOS 12--it may be true even if the user has removed the input mode from their active input mode list in Preferences.app. --- McBopomofo.xcodeproj/project.pbxproj | 4 ++ Source/Installer/AppDelegate.m | 83 +++++++++++++++++++++++----- Source/OVInputSourceHelper.h | 1 + Source/OVInputSourceHelper.m | 18 ++++++ 4 files changed, 93 insertions(+), 13 deletions(-) diff --git a/McBopomofo.xcodeproj/project.pbxproj b/McBopomofo.xcodeproj/project.pbxproj index 66dd9c97..64f7b808 100644 --- a/McBopomofo.xcodeproj/project.pbxproj +++ b/McBopomofo.xcodeproj/project.pbxproj @@ -33,6 +33,7 @@ 6A2E40F9253A6AA000D1AE1D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6A2E40F5253A69DA00D1AE1D /* Images.xcassets */; }; 6A38BC1515FC117A00A8A51F /* data.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6A38BBF615FC117A00A8A51F /* data.txt */; }; 6A38BC2815FC158A00A8A51F /* InputMethodKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A38BC2715FC158A00A8A51F /* InputMethodKit.framework */; }; + 6AB3620D274CA50700AC7547 /* OVInputSourceHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A0D4ECA15FC0D6400ABF4B3 /* OVInputSourceHelper.m */; }; 6ACA41CD15FC1D7500935EF6 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A0D4EA615FC0D2D00ABF4B3 /* Cocoa.framework */; }; 6ACA41F915FC1D9000935EF6 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6ACA41E915FC1D9000935EF6 /* AppDelegate.m */; }; 6ACA41FA15FC1D9000935EF6 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6ACA41EA15FC1D9000935EF6 /* InfoPlist.strings */; }; @@ -660,6 +661,7 @@ files = ( 6ACA41F915FC1D9000935EF6 /* AppDelegate.m in Sources */, 6A225A232367A1D700F685C6 /* ArchiveUtil.m in Sources */, + 6AB3620D274CA50700AC7547 /* OVInputSourceHelper.m in Sources */, 6ACA41FF15FC1D9000935EF6 /* main.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1038,6 +1040,7 @@ GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ../; INFOPLIST_FILE = "Source/Installer/Installer-Info.plist"; MACOSX_DEPLOYMENT_TARGET = 10.10; ONLY_ACTIVE_ARCH = YES; @@ -1070,6 +1073,7 @@ GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ../; INFOPLIST_FILE = "Source/Installer/Installer-Info.plist"; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_BUNDLE_IDENTIFIER = "org.openvanilla.McBopomofo.${PRODUCT_NAME:rfc1034identifier}"; diff --git a/Source/Installer/AppDelegate.m b/Source/Installer/AppDelegate.m index 435e2c37..863b4ec0 100644 --- a/Source/Installer/AppDelegate.m +++ b/Source/Installer/AppDelegate.m @@ -27,6 +27,7 @@ #import "AppDelegate.h" #import +#import "OVInputSourceHelper.h" static NSString *const kTargetBin = @"McBopomofo"; static NSString *const kTargetType = @"app"; @@ -55,7 +56,6 @@ void RunAlertPanel(NSString *title, NSString *message, NSString *buttonTitle) { @synthesize progressSheet = _progressSheet; @synthesize progressIndicator = _progressIndicator; - - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { _installingVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:(id)kCFBundleVersionKey]; @@ -130,9 +130,9 @@ void RunAlertPanel(NSString *title, NSString *message, NSString *buttonTitle) { // Schedule the install action in runloop so that the sheet gets a change to dismiss itself. dispatch_async(dispatch_get_main_queue(), ^{ if (returnCode == NSModalResponseContinue) { - [self installInputMethodWithWarning:NO]; + [self installInputMethodWithPreviousExists:YES previousVersionNotFullyDeactivatedWarning:NO]; } else { - [self installInputMethodWithWarning:YES]; + [self installInputMethodWithPreviousExists:YES previousVersionNotFullyDeactivatedWarning:YES]; } }); }]; @@ -143,7 +143,7 @@ void RunAlertPanel(NSString *title, NSString *message, NSString *buttonTitle) { } } - [self installInputMethodWithWarning:NO]; + [self installInputMethodWithPreviousExists:NO previousVersionNotFullyDeactivatedWarning:NO]; } - (void)timerTick:(NSTimer *)timer @@ -162,7 +162,7 @@ void RunAlertPanel(NSString *title, NSString *message, NSString *buttonTitle) { } -- (void)installInputMethodWithWarning:(BOOL)warning +- (void)installInputMethodWithPreviousExists:(BOOL)previousVersionExists previousVersionNotFullyDeactivatedWarning:(BOOL)warning { // If the unzipped archive does not exist, this must be a dev-mode installer. NSString *targetBundle = [_archiveUtil unzipNotarizedArchive]; @@ -177,23 +177,80 @@ void RunAlertPanel(NSString *title, NSString *message, NSString *buttonTitle) { [NSApp terminate:self]; } - NSArray *installArgs = [NSArray arrayWithObjects:@"install", nil]; - NSTask *installTask = [NSTask launchedTaskWithLaunchPath:[kTargetFullBinPartialPath stringByExpandingTildeInPath] arguments:installArgs]; - [installTask waitUntilExit]; - if ([installTask terminationStatus] != 0) { - RunAlertPanel(NSLocalizedString(@"Install Failed", nil), NSLocalizedString(@"Cannot activate the input method.", nil), NSLocalizedString(@"Cancel", nil)); - [NSApp terminate:self]; + NSBundle *imeBundle = [NSBundle bundleWithPath:[kTargetPartialPath stringByExpandingTildeInPath]]; + NSCAssert(imeBundle != nil, @"Target bundle must exists"); + NSURL *imeBundleURL = imeBundle.bundleURL; + NSString *imeIdentifier = imeBundle.bundleIdentifier; + + TISInputSourceRef inputSource = [OVInputSourceHelper inputSourceForInputSourceID:imeIdentifier]; + + // if this IME name is not found in the list of available IMEs + if (!inputSource) { + NSLog(@"Registering input source %@ at %@.", imeIdentifier, imeBundleURL.absoluteString); + // then register + BOOL status = [OVInputSourceHelper registerInputSource:imeBundleURL]; + + if (!status) { + // TODO: Localize. + NSString *message = [NSString stringWithFormat:@"Fatal error: Cannot register input source %@ at %@.", imeIdentifier, imeBundleURL.absoluteString]; + RunAlertPanel(@"Fatal Error", message, @"Abort"); + [self endAppWithDelay]; + return; + } + + inputSource = [OVInputSourceHelper inputSourceForInputSourceID:imeIdentifier]; + // if it still doesn't register successfully, bail. + if (!inputSource) { + // TODO: Localize. + NSString *message = [NSString stringWithFormat:@"Fatal error: Cannot find input source %@ after registration.", imeIdentifier]; + RunAlertPanel(@"Fatal Error", message, @"Abort"); + [self endAppWithDelay]; + return; + } + } + + BOOL isMacOS12OrAbove = NO; + if (@available(macOS 12.0, *)) { + NSLog(@"macOS 12 or later detected."); + isMacOS12OrAbove = YES; + } else { + NSLog(@"Installer runs with the pre-macOS 12 flow."); + } + + // If the IME is not enabled, enable it. Also, unconditionally enable it on macOS 12.0+, + // as the kTISPropertyInputSourceIsEnabled can still be true even if the IME is *not* + // enabled in the user's current set of IMEs (which means the IME does not show up in + // the user's input menu). + BOOL mainInputSourceEnabled = [OVInputSourceHelper inputSourceEnabled:inputSource]; + if (!mainInputSourceEnabled || isMacOS12OrAbove) { + + mainInputSourceEnabled = [OVInputSourceHelper enableInputSource:inputSource]; + if (mainInputSourceEnabled) { + NSLog(@"Input method enabled: %@", imeIdentifier); + } else { + NSLog(@"Failed to enable input method: %@", imeIdentifier); + } } if (warning) { RunAlertPanel(NSLocalizedString(@"Attention", nil), NSLocalizedString(@"McBopomofo is upgraded, but please log out or reboot for the new version to be fully functional.", nil), NSLocalizedString(@"OK", nil)); } else { - RunAlertPanel(NSLocalizedString(@"Installation Successful", nil), NSLocalizedString(@"McBopomofo is ready to use.", nil), NSLocalizedString(@"OK", nil)); + // Only prompt a warning if pre-macOS 12. The flag is not indicative of anything meaningful due to the need of user intervention in Prefernces.app on macOS 12. + if (!mainInputSourceEnabled && !isMacOS12OrAbove) { + // TODO: Localize + RunAlertPanel(@"Warning", @"Input method may not be fully enabled. Please check Preferences.app.", @"Continue"); + } else { + RunAlertPanel(NSLocalizedString(@"Installation Successful", nil), NSLocalizedString(@"McBopomofo is ready to use.", nil), NSLocalizedString(@"OK", nil)); + } } + [self endAppWithDelay]; +} + +- (void)endAppWithDelay +{ [[NSApplication sharedApplication] performSelector:@selector(terminate:) withObject:self afterDelay:0.1]; } - - (IBAction)cancelAction:(id)sender { diff --git a/Source/OVInputSourceHelper.h b/Source/OVInputSourceHelper.h index b55981ed..cc4c8919 100644 --- a/Source/OVInputSourceHelper.h +++ b/Source/OVInputSourceHelper.h @@ -41,6 +41,7 @@ + (BOOL)inputSourceEnabled:(TISInputSourceRef)inInputSource; + (BOOL)enableInputSource:(TISInputSourceRef)inInputSource; + (BOOL)enableAllInputModesForInputSourceBundleID:(NSString *)inID; ++ (BOOL)enableInputMode:(NSString *)modeID forInputSourceBundleID:(NSString *)bundleID; + (BOOL)disableInputSource:(TISInputSourceRef)inInputSource; // register (i.e. make available to Input Source tab in Language & Text Preferences) diff --git a/Source/OVInputSourceHelper.m b/Source/OVInputSourceHelper.m index d9815879..b7638a34 100644 --- a/Source/OVInputSourceHelper.m +++ b/Source/OVInputSourceHelper.m @@ -90,6 +90,24 @@ return enabled; } ++ (BOOL)enableInputMode:(NSString *)modeID forInputSourceBundleID:(NSString *)bundleID +{ + for (id source in [self allInstalledInputSources]) { + TISInputSourceRef inputSource = (__bridge TISInputSourceRef)source; + NSString *inputSoureBundleID = (__bridge NSString *)TISGetInputSourceProperty(inputSource, kTISPropertyBundleID); + NSString *inputSourceModeID = (NSString *)CFBridgingRelease(TISGetInputSourceProperty(inputSource, kTISPropertyInputModeID)); + + if ([modeID isEqual:inputSourceModeID] && [bundleID isEqual:inputSoureBundleID]) { + BOOL enabled = [self enableInputSource:inputSource]; + NSLog(@"Attempt to enable input source of mode: %@, bundle ID: %@, result: %d", modeID, bundleID, enabled); + return enabled; + } + } + + NSLog(@"Failed to find any matching input source of mode: %@, bundle ID: %@", modeID, bundleID); + return NO; +} + + (BOOL)disableInputSource:(TISInputSourceRef)inInputSource { OSStatus status = TISDisableInputSource(inInputSource); From 9e46f4f4465aac28ce6da948330955877c1430de Mon Sep 17 00:00:00 2001 From: Lukhnos Liu Date: Tue, 23 Nov 2021 13:30:13 -0800 Subject: [PATCH 09/18] Stop using IMK's showPreferences: This turns out to be unreliable on macOS 12. --- Source/InputMethodController.mm | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Source/InputMethodController.mm b/Source/InputMethodController.mm index 9dec8a06..d081ad1c 100644 --- a/Source/InputMethodController.mm +++ b/Source/InputMethodController.mm @@ -1436,11 +1436,7 @@ public: - (void)showPreferences:(id)sender { // show the preferences panel, and also make the IME app itself the focus - if ([IMKInputController instancesRespondToSelector:@selector(showPreferences:)]) { - [super showPreferences:sender]; - } else { - [(AppDelegate *)[NSApp delegate] showPreferences]; - } + [(AppDelegate *)[NSApp delegate] showPreferences]; [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; } From 2062a81b8f3dc966529bf3e70f081ac86b3e645f Mon Sep 17 00:00:00 2001 From: Lukhnos Liu Date: Tue, 23 Nov 2021 16:44:19 -0800 Subject: [PATCH 10/18] Localize new strings Also fine-tune the Chinese Conversion menu item text. --- Source/Installer/AppDelegate.m | 13 +++++-------- Source/Installer/en.lproj/Localizable.strings | 9 +++++++++ Source/Installer/zh-Hant.lproj/Localizable.strings | 9 +++++++++ Source/en.lproj/Localizable.strings | 2 +- Source/zh-Hant.lproj/Localizable.strings | 2 +- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Source/Installer/AppDelegate.m b/Source/Installer/AppDelegate.m index 863b4ec0..17485951 100644 --- a/Source/Installer/AppDelegate.m +++ b/Source/Installer/AppDelegate.m @@ -191,9 +191,8 @@ void RunAlertPanel(NSString *title, NSString *message, NSString *buttonTitle) { BOOL status = [OVInputSourceHelper registerInputSource:imeBundleURL]; if (!status) { - // TODO: Localize. - NSString *message = [NSString stringWithFormat:@"Fatal error: Cannot register input source %@ at %@.", imeIdentifier, imeBundleURL.absoluteString]; - RunAlertPanel(@"Fatal Error", message, @"Abort"); + NSString *message = [NSString stringWithFormat:NSLocalizedString(@"Cannot register input source %@ at %@.", nil), imeIdentifier, imeBundleURL.absoluteString]; + RunAlertPanel(NSLocalizedString(@"Fatal Error", nil), message, NSLocalizedString(@"Abort", nil)); [self endAppWithDelay]; return; } @@ -201,9 +200,8 @@ void RunAlertPanel(NSString *title, NSString *message, NSString *buttonTitle) { inputSource = [OVInputSourceHelper inputSourceForInputSourceID:imeIdentifier]; // if it still doesn't register successfully, bail. if (!inputSource) { - // TODO: Localize. - NSString *message = [NSString stringWithFormat:@"Fatal error: Cannot find input source %@ after registration.", imeIdentifier]; - RunAlertPanel(@"Fatal Error", message, @"Abort"); + NSString *message = [NSString stringWithFormat:NSLocalizedString(@"Cannot find input source %@ after registration.", nil), imeIdentifier]; + RunAlertPanel(NSLocalizedString(@"Fatal Error", nil), message, NSLocalizedString(@"Abort", nil)); [self endAppWithDelay]; return; } @@ -237,8 +235,7 @@ void RunAlertPanel(NSString *title, NSString *message, NSString *buttonTitle) { } else { // Only prompt a warning if pre-macOS 12. The flag is not indicative of anything meaningful due to the need of user intervention in Prefernces.app on macOS 12. if (!mainInputSourceEnabled && !isMacOS12OrAbove) { - // TODO: Localize - RunAlertPanel(@"Warning", @"Input method may not be fully enabled. Please check Preferences.app.", @"Continue"); + RunAlertPanel(NSLocalizedString(@"Warning", nil), NSLocalizedString(@"Input method may not be fully enabled. Please enable it through System Preferences > Keyboard > Input Sources.", nil), NSLocalizedString(@"Continue", nil)); } else { RunAlertPanel(NSLocalizedString(@"Installation Successful", nil), NSLocalizedString(@"McBopomofo is ready to use.", nil), NSLocalizedString(@"OK", nil)); } diff --git a/Source/Installer/en.lproj/Localizable.strings b/Source/Installer/en.lproj/Localizable.strings index 048ef949..b3f28f52 100644 --- a/Source/Installer/en.lproj/Localizable.strings +++ b/Source/Installer/en.lproj/Localizable.strings @@ -28,3 +28,12 @@ "Stopping the old version. This may take up to one minute…" = "Stopping the old version. This may take up to one minute…"; "Attention" = "Attention"; "McBopomofo is upgraded, but please log out or reboot for the new version to be fully functional." = "McBopomofo is upgraded, but please log out or reboot for the new version to be fully functional."; + +"Fatal Error" = "Fatal Error"; +"Abort" = "Abort"; +"Cannot register input source %@ at %@." = "Cannot register input source %@ at %@."; +"Cannot find input source %@ after registration." = "Cannot find input source %@ after registration."; + +"Warning" = "Warning"; +"Input method may not be fully enabled. Please enable it through System Preferences > Keyboard > Input Sources." = "Input method may not be fully enabled. Please enable it through System Preferences > Keyboard > Input Sources."; +"Continue" = "Continue"; diff --git a/Source/Installer/zh-Hant.lproj/Localizable.strings b/Source/Installer/zh-Hant.lproj/Localizable.strings index 97a971de..5a492caa 100644 --- a/Source/Installer/zh-Hant.lproj/Localizable.strings +++ b/Source/Installer/zh-Hant.lproj/Localizable.strings @@ -28,3 +28,12 @@ "Finish" = "結束"; "Attention" = "請注意"; "McBopomofo is upgraded, but please log out or reboot for the new version to be fully functional." = "McBopomofo 安裝完成,但建議您登出或重新開機,以便順利使用新版。"; + +"Fatal Error" = "安裝錯誤"; +"Abort" = "放棄安裝"; +"Cannot register input source %@ at %@." = "無法從檔案位置 %2$@ 安裝輸入法 \"%1$@\"。"; +"Cannot find input source %@ after registration." = "在註冊完輸入法 \"%@\" 仍然無法找到輸入法。"; + +"Warning" = "安裝不完整"; +"Input method may not be fully enabled. Please enable it through System Preferences > Keyboard > Input Sources." = "輸入法已經安裝好,但可能沒有完全啟用。請從「系統偏好設定」 > 「鍵盤」 > 「輸入方式」分頁加入輸入法。"; +"Continue" = "繼續"; diff --git a/Source/en.lproj/Localizable.strings b/Source/en.lproj/Localizable.strings index 0acd9b67..4fdc110c 100644 --- a/Source/en.lproj/Localizable.strings +++ b/Source/en.lproj/Localizable.strings @@ -49,4 +49,4 @@ /* No comment provided by engineer. */ "You're currently using McBopomofo %@ (%@), a new version %@ (%@) is now available. Do you want to visit McBopomofo's website to download the version?%@" = "You're currently using McBopomofo %@ (%@), a new version %@ (%@) is now available. Do you want to visit McBopomofo's website to download the version?%@"; -"Chinese Conversion" = "Chinese Conversion"; +"Chinese Conversion" = "Convert to Simplified Chinese"; diff --git a/Source/zh-Hant.lproj/Localizable.strings b/Source/zh-Hant.lproj/Localizable.strings index 4ac965ae..e49af527 100644 --- a/Source/zh-Hant.lproj/Localizable.strings +++ b/Source/zh-Hant.lproj/Localizable.strings @@ -49,4 +49,4 @@ /* No comment provided by engineer. */ "You're currently using McBopomofo %@ (%@), a new version %@ (%@) is now available. Do you want to visit McBopomofo's website to download the version?%@" = "目前使用的小麥注音版本是 %1$@ (%2$@),網路上有更新版本 %3$@ (%4$@) 可供下載。是否要前往小麥注音網站下載新版來安裝?%5$@"; -"Chinese Conversion" = "簡繁轉換"; +"Chinese Conversion" = "輸出簡體中文"; From 8239ecce4770ca1d1112daee42a4dc89bf505430 Mon Sep 17 00:00:00 2001 From: Lukhnos Liu Date: Tue, 23 Nov 2021 16:49:13 -0800 Subject: [PATCH 11/18] Update copyright years --- Source/Installer/en.lproj/InfoPlist.strings | 2 +- Source/Installer/en.lproj/License.rtf | 2 +- Source/Installer/zh-Hant.lproj/InfoPlist.strings | 2 +- Source/Installer/zh-Hant.lproj/License.rtf | 6 +++--- Source/McBopomofo-Info.plist | 2 +- Source/en.lproj/InfoPlist.strings | 2 +- Source/zh-Hant.lproj/InfoPlist.strings | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/Installer/en.lproj/InfoPlist.strings b/Source/Installer/en.lproj/InfoPlist.strings index 0dfbb121..6472f62d 100644 --- a/Source/Installer/en.lproj/InfoPlist.strings +++ b/Source/Installer/en.lproj/InfoPlist.strings @@ -1,4 +1,4 @@ /* Localized versions of Info.plist keys */ CFBundleName = "Install McBopomofo"; -NSHumanReadableCopyright = "Copyright © 2011-2020 Mengjuei Hsieh et al.\nAll Rights Reserved."; +NSHumanReadableCopyright = "Copyright © 2011-2021 Mengjuei Hsieh et al.\nAll Rights Reserved."; diff --git a/Source/Installer/en.lproj/License.rtf b/Source/Installer/en.lproj/License.rtf index c348375f..72e32461 100644 --- a/Source/Installer/en.lproj/License.rtf +++ b/Source/Installer/en.lproj/License.rtf @@ -8,7 +8,7 @@ \f0\b\fs36 \cf0 McBopomofo License Agreement \f1\b0\fs24 \ \ -Copyright \'a9 2011-2020 Mengjuei Hsieh et al.\ +Copyright \'a9 2011-2021 Mengjuei Hsieh et al.\ \ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \'93Software\'94), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\ \ diff --git a/Source/Installer/zh-Hant.lproj/InfoPlist.strings b/Source/Installer/zh-Hant.lproj/InfoPlist.strings index 1c4bd174..929742bd 100644 --- a/Source/Installer/zh-Hant.lproj/InfoPlist.strings +++ b/Source/Installer/zh-Hant.lproj/InfoPlist.strings @@ -1,5 +1,5 @@ /* Localized versions of Info.plist keys */ CFBundleName = "安裝小麥注音"; -NSHumanReadableCopyright = "Copyright © 2011-2020 Mengjuei Hsieh et al.\nAll Rights Reserved."; +NSHumanReadableCopyright = "Copyright © 2011-2021 Mengjuei Hsieh et al.\nAll Rights Reserved."; diff --git a/Source/Installer/zh-Hant.lproj/License.rtf b/Source/Installer/zh-Hant.lproj/License.rtf index 3e20eec7..24d7d652 100644 --- a/Source/Installer/zh-Hant.lproj/License.rtf +++ b/Source/Installer/zh-Hant.lproj/License.rtf @@ -9,10 +9,10 @@ \f0\b\fs36 \cf0 McBopomofo License Agreement \f1\b0\fs24 \ \ -Copyright \'a9 2011-2020 Mengjuei Hsieh et al.\ +Copyright \'a9 2011-2021 Mengjuei Hsieh et al.\ -\f2 \'b5\'db\'a7\'40\'c5\'76\'a7\'51\'a9\'d2\'a6\'b3 -\f1 \'a9 2011-2020 Mengjuei Hsieh +\f2 \cf0 \'b5\'db\'a7\'40\'c5\'76\'a7\'51\'a9\'d2\'a6\'b3 +\f1 \'a9 2011-2021 Mengjuei Hsieh \f2 \'b5\'a5\'a4\'48 \f1 \ \ diff --git a/Source/McBopomofo-Info.plist b/Source/McBopomofo-Info.plist index 6f46cf5b..3284939f 100644 --- a/Source/McBopomofo-Info.plist +++ b/Source/McBopomofo-Info.plist @@ -118,7 +118,7 @@ LSUIElement NSHumanReadableCopyright - Copyright © 2011-2020 Mengjuei Hsieh et al. + Copyright © 2011-2021 Mengjuei Hsieh et al. NSMainNibFile MainMenu NSPrincipalClass diff --git a/Source/en.lproj/InfoPlist.strings b/Source/en.lproj/InfoPlist.strings index f2c7b01f..889f7749 100644 --- a/Source/en.lproj/InfoPlist.strings +++ b/Source/en.lproj/InfoPlist.strings @@ -1,6 +1,6 @@ CFBundleName = "McBopomofo"; CFBundleDisplayName = "McBopomofo"; -NSHumanReadableCopyright = "Copyright © 2011-2020 Mengjuei Hsieh et al.\nAll Rights Reserved."; +NSHumanReadableCopyright = "Copyright © 2011-2021 Mengjuei Hsieh et al.\nAll Rights Reserved."; "org.openvanilla.inputmethod.McBopomofo.Bopomofo" = "Bopomofo"; "org.openvanilla.inputmethod.McBopomofo.PlainBopomofo" = "Plain Bopomofo"; diff --git a/Source/zh-Hant.lproj/InfoPlist.strings b/Source/zh-Hant.lproj/InfoPlist.strings index f84d1cd8..a3286784 100644 --- a/Source/zh-Hant.lproj/InfoPlist.strings +++ b/Source/zh-Hant.lproj/InfoPlist.strings @@ -1,5 +1,5 @@ CFBundleName = "小麥注音"; CFBundleDisplayName = "小麥注音"; -NSHumanReadableCopyright = "Copyright © 2011-2020 Mengjuei Hsieh et al.\nAll Rights Reserved."; +NSHumanReadableCopyright = "Copyright © 2011-2021 Mengjuei Hsieh et al.\nAll Rights Reserved."; "org.openvanilla.inputmethod.McBopomofo.Bopomofo" = "小麥注音"; "org.openvanilla.inputmethod.McBopomofo.PlainBopomofo" = "傳統注音"; From 64a3784fee1158080fe6238fc8a1918b5969f6d1 Mon Sep 17 00:00:00 2001 From: Lukhnos Liu Date: Tue, 23 Nov 2021 16:51:46 -0800 Subject: [PATCH 12/18] Bump version to 1.1 --- Source/Installer/Installer-Info.plist | 4 ++-- Source/McBopomofo-Info.plist | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Installer/Installer-Info.plist b/Source/Installer/Installer-Info.plist index 6bcc9377..9088d5a8 100644 --- a/Source/Installer/Installer-Info.plist +++ b/Source/Installer/Installer-Info.plist @@ -15,11 +15,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0 + 1.1 CFBundleSignature MBIN CFBundleVersion - 846 + 879 LSApplicationCategoryType public.app-category.utilities LSHasLocalizedDisplayName diff --git a/Source/McBopomofo-Info.plist b/Source/McBopomofo-Info.plist index 3284939f..199cc007 100644 --- a/Source/McBopomofo-Info.plist +++ b/Source/McBopomofo-Info.plist @@ -15,11 +15,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0 + 1.1 CFBundleSignature BPMF CFBundleVersion - 846 + 879 ComponentInputModeDict tsInputModeListKey From 889c9e18e8d75eaee276eb3081991b69a1c10721 Mon Sep 17 00:00:00 2001 From: Lukhnos Liu Date: Tue, 23 Nov 2021 23:09:32 -0800 Subject: [PATCH 13/18] Update README --- README.markdown | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.markdown b/README.markdown index e3da0310..69579b1a 100644 --- a/README.markdown +++ b/README.markdown @@ -8,13 +8,10 @@ 第一次安裝完,日後程式碼或詞庫有任何修改,只要重複上述流程,再次安裝小麥注音即可。 要注意的是 macOS 可能會限制同一次 login session 能 kill 同一個輸入法 process 的次數( -安裝程式透過 process killing來讓新版的輸入法生效)。如果安裝若干次後,發現程式修改的結果並 +安裝程式透過 process killing 來讓新版的輸入法生效)。如果安裝若干次後,發現程式修改的結果並 沒有出現,或甚至輸入法已無法再選用,只要登出目前帳號再重新登入即可。 ## 軟體授權 -本專案主要程式碼以及編譯後軟體採用 MIT License 釋出,使用者可自由使用、散播本軟體,惟散播本輸入法的原始碼時必須保持軟體完整原始碼、不得修改版權文字。 +本專案主要程式碼以及編譯後軟體採用 MIT License 釋出。 -## Continuous Integration - -我們使用 Travis-CI [![Build Status](https://travis-ci.org/openvanilla/McBopomofo.svg?branch=master)](https://travis-ci.org/openvanilla/McBopomofo) 作為雲端持續整合工具。 From d7e59bd8d51c81cccd3ede4a666a77c6da0d1297 Mon Sep 17 00:00:00 2001 From: Lukhnos Liu Date: Wed, 24 Nov 2021 10:04:29 -0800 Subject: [PATCH 14/18] Add LICENSE.txt --- LICENSE.txt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE.txt diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 00000000..44849223 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2011-2021 Mengjuei Hsieh et al. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 2cf6ea60ed53a2ee2f92d4aa3a277a29d24c2fa3 Mon Sep 17 00:00:00 2001 From: Lukhnos Liu Date: Wed, 24 Nov 2021 10:09:47 -0800 Subject: [PATCH 15/18] Update README --- README.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 69579b1a..3633a874 100644 --- a/README.markdown +++ b/README.markdown @@ -13,5 +13,6 @@ ## 軟體授權 -本專案主要程式碼以及編譯後軟體採用 MIT License 釋出。 +本專案採用 MIT License 釋出,使用者可自由使用、散播本軟體,惟散播時必須 +完整保留版權聲明及軟體授權([詳全文](https://github.com/openvanilla/McBopomofo/blob/master/LICENSE.txt))。 From 52745e4779dbc04614c057be4955c20e22cbfe4b Mon Sep 17 00:00:00 2001 From: Lukhnos Liu Date: Wed, 24 Nov 2021 10:12:47 -0800 Subject: [PATCH 16/18] Remove manual line wrapping in README This makes sure that Chinese paragraphs flow correctly without the extraneous space between the last character of a line and the first character of its suceeding line that is still in the same paragraph. --- README.markdown | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/README.markdown b/README.markdown index 3633a874..359a8385 100644 --- a/README.markdown +++ b/README.markdown @@ -2,17 +2,13 @@ ## 開發流程 -用 Xcode 開啟 `McBopomofo.xcodeproj`,選 "McBopomofo Installer" target,build -完之後直接執行該安裝程式,就可以安裝小麥注音。 +用 Xcode 開啟 `McBopomofo.xcodeproj`,選 "McBopomofo Installer" target,build 完之後直接執行該安裝程式,就可以安裝小麥注音。 第一次安裝完,日後程式碼或詞庫有任何修改,只要重複上述流程,再次安裝小麥注音即可。 -要注意的是 macOS 可能會限制同一次 login session 能 kill 同一個輸入法 process 的次數( -安裝程式透過 process killing 來讓新版的輸入法生效)。如果安裝若干次後,發現程式修改的結果並 -沒有出現,或甚至輸入法已無法再選用,只要登出目前帳號再重新登入即可。 +要注意的是 macOS 可能會限制同一次 login session 能 kill 同一個輸入法 process 的次數(安裝程式透過 kill input method process 來讓新版的輸入法生效)。如果安裝若干次後,發現程式修改的結果並沒有出現,或甚至輸入法已無法再選用,只要登出目前帳號再重新登入即可。 ## 軟體授權 -本專案採用 MIT License 釋出,使用者可自由使用、散播本軟體,惟散播時必須 -完整保留版權聲明及軟體授權([詳全文](https://github.com/openvanilla/McBopomofo/blob/master/LICENSE.txt))。 +本專案採用 MIT License 釋出,使用者可自由使用、散播本軟體,惟散播時必須完整保留版權聲明及軟體授權([詳全文](https://github.com/openvanilla/McBopomofo/blob/master/LICENSE.txt))。 From 22cac3ddf26d8f680afbf1f64c13d986da835c47 Mon Sep 17 00:00:00 2001 From: Lukhnos Liu Date: Wed, 24 Nov 2021 21:16:20 -0800 Subject: [PATCH 17/18] Revert "Stop using IMK's showPreferences:" This reverts commit 9e46f4f4465aac28ce6da948330955877c1430de. --- Source/InputMethodController.mm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/InputMethodController.mm b/Source/InputMethodController.mm index d081ad1c..9dec8a06 100644 --- a/Source/InputMethodController.mm +++ b/Source/InputMethodController.mm @@ -1436,7 +1436,11 @@ public: - (void)showPreferences:(id)sender { // show the preferences panel, and also make the IME app itself the focus - [(AppDelegate *)[NSApp delegate] showPreferences]; + if ([IMKInputController instancesRespondToSelector:@selector(showPreferences:)]) { + [super showPreferences:sender]; + } else { + [(AppDelegate *)[NSApp delegate] showPreferences]; + } [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; } From f1ae12c5f055a2efa648b3e39899e0e5cdb7762e Mon Sep 17 00:00:00 2001 From: Lukhnos Liu Date: Wed, 24 Nov 2021 23:22:29 -0800 Subject: [PATCH 18/18] Correctly locate a candidate panel's screen Previously only the x value was used to determine the screen to which a candidate panel should below. That was incorrect. The entire point needs to be considered. This fixes the same issue that affected OpenVanilla: https://github.com/openvanilla/openvanilla/issues/49 --- Source/CandidateUI/VTCandidateController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/CandidateUI/VTCandidateController.m b/Source/CandidateUI/VTCandidateController.m index 5605ff71..933d1018 100644 --- a/Source/CandidateUI/VTCandidateController.m +++ b/Source/CandidateUI/VTCandidateController.m @@ -98,7 +98,7 @@ for (NSScreen *screen in [NSScreen screens]) { NSRect frame = [screen visibleFrame]; - if (topLeftPoint.x >= NSMinX(frame) && topLeftPoint.x <= NSMaxX(frame)) { + if (topLeftPoint.x >= NSMinX(frame) && topLeftPoint.x <= NSMaxX(frame) && topLeftPoint.y >= NSMinY(frame) && topLeftPoint.y <= NSMaxY(frame)) { screenFrame = frame; break; }