From d1893b6a370e4be177340b0343a133f0f67ba4ce Mon Sep 17 00:00:00 2001 From: Lukhnos Liu Date: Tue, 11 Sep 2012 21:38:59 -0700 Subject: [PATCH] Correctly enable all input modes when upgrading. --- McBopomofo.xcodeproj/project.pbxproj | 2 +- Source/AppDelegate.m | 2 +- Source/Installer/AppDelegate.m | 21 +++++++++++++-------- Source/OVInputSourceHelper.h | 1 + Source/OVInputSourceHelper.m | 22 +++++++++++++++++++++- Source/main.m | 11 +++++++++++ 6 files changed, 48 insertions(+), 11 deletions(-) diff --git a/McBopomofo.xcodeproj/project.pbxproj b/McBopomofo.xcodeproj/project.pbxproj index 9e052130..eef9406e 100644 --- a/McBopomofo.xcodeproj/project.pbxproj +++ b/McBopomofo.xcodeproj/project.pbxproj @@ -616,7 +616,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "FROM=\"$BUILT_PRODUCTS_DIR/$FULL_PRODUCT_NAME\"\nPREVIOUS=\"$HOME/Library/Input Methods/$FULL_PRODUCT_NAME\"\nTO=\"$HOME/Library/Input Methods/\"\nEXE=\"$HOME/Library/Input Methods/$EXECUTABLE_FOLDER_PATH/$EXECUTABLE_NAME\"\n\nif [ $CONFIGURATION = \"Debug\" ]\nthen\n echo Stopping $PRODUCT_NAME\n killall \"$PRODUCT_NAME\"\n\n echo Removing the installed version at $PREVIOUS\n rm -rf \"$PREVIOUS\"\n\n echo Copying built product from $FROM to $TO\n cp -R \"$FROM\" \"$TO\"\n\n echo Invoking $EXE to activate $PRODUCT_NAME\n \"$EXE\" install\n\n echo Restarting SystemUIServer to reflect icon changes\n killall SystemUIServer\nfi\n"; + shellScript = "FROM=\"$BUILT_PRODUCTS_DIR/$FULL_PRODUCT_NAME\"\nPREVIOUS=\"$HOME/Library/Input Methods/$FULL_PRODUCT_NAME\"\nTO=\"$HOME/Library/Input Methods/\"\nEXE=\"$HOME/Library/Input Methods/$EXECUTABLE_FOLDER_PATH/$EXECUTABLE_NAME\"\n\nif [ $CONFIGURATION = \"Debug\" ]\nthen\n echo Stopping $PRODUCT_NAME\n killall \"$PRODUCT_NAME\"\n\n echo Removing the installed version at $PREVIOUS\n rm -rf \"$PREVIOUS\"\n\n echo Restarting SystemUIServer to ensure full removal of the old copy\n killall SystemUIServer\n\n echo Copying built product from $FROM to $TO\n cp -R \"$FROM\" \"$TO\"\n\n echo Invoking $EXE to activate $PRODUCT_NAME\n \"$EXE\" install\nfi\n"; }; /* End PBXShellScriptBuildPhase section */ diff --git a/Source/AppDelegate.m b/Source/AppDelegate.m index b5a1e252..76d54225 100644 --- a/Source/AppDelegate.m +++ b/Source/AppDelegate.m @@ -112,7 +112,7 @@ static const NSTimeInterval kNextCheckInterval = 86400.0; - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { -NSLog(@"error"); + NSLog(@"error"); } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data diff --git a/Source/Installer/AppDelegate.m b/Source/Installer/AppDelegate.m index 51dded67..a39d473b 100644 --- a/Source/Installer/AppDelegate.m +++ b/Source/Installer/AppDelegate.m @@ -85,6 +85,12 @@ static NSString *const kTargetFullBinPartialPath = @"~/Library/Input Methods/McB [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:sourceDir destination:trashDir files:[NSArray arrayWithObject:kTargetBundle] tag:&tag]; (void)tag; + // alno need to restart SystemUIServer to ensure that the icon is fully cleaned up + if (_currentVersion && [_currentVersion compare:@"0.9.4"] != NSOrderedDescending) { + NSTask *restartSystemUIServerTask = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/killall" arguments:[NSArray arrayWithObjects: @"-9", @"SystemUIServer", nil]]; + [restartSystemUIServerTask waitUntilExit]; + } + NSTask *killTask = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/killall" arguments:[NSArray arrayWithObjects: @"-9", kTargetBin, nil]]; [killTask waitUntilExit]; } @@ -95,20 +101,19 @@ static NSString *const kTargetFullBinPartialPath = @"~/Library/Input Methods/McB NSRunAlertPanel(NSLocalizedString(@"Install Failed", nil), NSLocalizedString(@"Cannot copy the file to the destination.", nil), NSLocalizedString(@"Cancel", nil), nil, nil); [NSApp terminate:self]; } - - NSTask *installTask = [NSTask launchedTaskWithLaunchPath:[kTargetFullBinPartialPath stringByExpandingTildeInPath] arguments:[NSArray arrayWithObjects:@"install", nil]]; + + NSArray *installArgs = [NSArray arrayWithObjects:@"install", nil]; + if (_currentVersion && [_currentVersion compare:@"0.9.4"] != NSOrderedDescending) { + installArgs = [installArgs arrayByAddingObject:@"--all"]; + } + + NSTask *installTask = [NSTask launchedTaskWithLaunchPath:[kTargetFullBinPartialPath stringByExpandingTildeInPath] arguments:installArgs]; [installTask waitUntilExit]; if ([installTask terminationStatus] != 0) { NSRunAlertPanel(NSLocalizedString(@"Install Failed", nil), NSLocalizedString(@"Cannot activate the input method.", nil), NSLocalizedString(@"Cancel", nil), nil, nil); [NSApp terminate:self]; } - // alno need to restart SystemUIServer to reflect icon changes if the replaced version <= 0.9.4 - if (_currentVersion && [_currentVersion compare:@"0.9.4"] != NSOrderedDescending) { - NSTask *restartSystemUIServerTask = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/killall" arguments:[NSArray arrayWithObjects: @"-9", @"SystemUIServer", nil]]; - [restartSystemUIServerTask waitUntilExit]; - } - NSRunAlertPanel(NSLocalizedString(@"Installation Successful", nil), NSLocalizedString(@"McBopomofo is ready to use.", nil), NSLocalizedString(@"OK", nil), nil, nil); [NSApp terminate:self]; } diff --git a/Source/OVInputSourceHelper.h b/Source/OVInputSourceHelper.h index b92e7eea..b55981ed 100644 --- a/Source/OVInputSourceHelper.h +++ b/Source/OVInputSourceHelper.h @@ -40,6 +40,7 @@ // enable/disable an input source (along with all its input modes) + (BOOL)inputSourceEnabled:(TISInputSourceRef)inInputSource; + (BOOL)enableInputSource:(TISInputSourceRef)inInputSource; ++ (BOOL)enableAllInputModesForInputSourceBundleID:(NSString *)inID; + (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 3f0e429f..33ffe703 100644 --- a/Source/OVInputSourceHelper.m +++ b/Source/OVInputSourceHelper.m @@ -36,7 +36,6 @@ + (TISInputSourceRef)inputSourceForProperty:(CFStringRef)inPropertyKey stringValue:(NSString *)inValue { - CFTypeID stringID = CFStringGetTypeID(); for (id source in [self allInstalledInputSources]) { @@ -70,6 +69,27 @@ return status == noErr; } ++ (BOOL)enableAllInputModesForInputSourceBundleID:(NSString *)inID +{ + BOOL enabled = NO; + + for (id source in [self allInstalledInputSources]) { + TISInputSourceRef inputSource = (TISInputSourceRef)source; + NSString *bundleID = (NSString *)TISGetInputSourceProperty(inputSource, kTISPropertyBundleID); + NSString *mode = (NSString *)TISGetInputSourceProperty(inputSource, kTISPropertyInputModeID); + if (mode && [bundleID isEqualToString:inID]) { + BOOL modeEnabled = [self enableInputSource:inputSource]; + if (!modeEnabled) { + return NO; + } + + enabled = YES; + } + } + + return enabled; +} + + (BOOL)disableInputSource:(TISInputSourceRef)inInputSource { OSStatus status = TISDisableInputSource(inInputSource); diff --git a/Source/main.m b/Source/main.m index ad95b226..1f2b96f6 100644 --- a/Source/main.m +++ b/Source/main.m @@ -94,6 +94,17 @@ int main(int argc, char *argv[]) } } + if (argc > 2 && !strcmp(argv[2], "--all")) { + BOOL enabled = [OVInputSourceHelper enableAllInputModesForInputSourceBundleID:bundleID]; + if (enabled) { + NSLog(@"All input sources enabled for %@", bundleID); + } + else { + NSLog(@"Failed to enable all input sources for %@", bundleID); + return -1; + } + } + return 0; }