PR#1: macOS Notification when Kanji Conversation switch changes.
This commit is contained in:
parent
78f35efec1
commit
225241081c
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
@class PreferencesWindowController;
|
@class PreferencesWindowController;
|
||||||
|
|
||||||
@interface AppDelegate : NSObject <NSApplicationDelegate>
|
@interface AppDelegate : NSObject <NSApplicationDelegate, NSUserNotificationCenterDelegate>
|
||||||
{
|
{
|
||||||
@private
|
@private
|
||||||
NSURLConnection *_updateCheckConnection;
|
NSURLConnection *_updateCheckConnection;
|
||||||
|
|
|
@ -67,6 +67,7 @@ static const NSTimeInterval kTimeoutInterval = 60.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
[self checkForUpdate];
|
[self checkForUpdate];
|
||||||
|
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)checkForUpdate
|
- (void)checkForUpdate
|
||||||
|
@ -268,4 +269,8 @@ static const NSTimeInterval kTimeoutInterval = 60.0;
|
||||||
_updateNextStepURL = nil;
|
_updateNextStepURL = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification{
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -75,6 +75,9 @@
|
||||||
|
|
||||||
// if Chinese conversion is enabled
|
// if Chinese conversion is enabled
|
||||||
BOOL _chineseConversionEnabled;
|
BOOL _chineseConversionEnabled;
|
||||||
|
|
||||||
|
// if Chinese conversion status has been changed
|
||||||
|
BOOL _previousChineseConversionEnabledStatus;
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -165,6 +165,8 @@ public:
|
||||||
}
|
}
|
||||||
// the two client pointers are weak pointers (i.e. we don't retain them)
|
// the two client pointers are weak pointers (i.e. we don't retain them)
|
||||||
// therefore we don't do anything about it
|
// therefore we don't do anything about it
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"ChineseConversionStatusChanged" object:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithServer:(IMKServer *)server delegate:(id)delegate client:(id)client
|
- (id)initWithServer:(IMKServer *)server delegate:(id)delegate client:(id)client
|
||||||
|
@ -196,6 +198,10 @@ public:
|
||||||
|
|
||||||
_inputMode = kBopomofoModeIdentifier;
|
_inputMode = kBopomofoModeIdentifier;
|
||||||
_chineseConversionEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:kChineseConversionEnabledKey];
|
_chineseConversionEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:kChineseConversionEnabledKey];
|
||||||
|
_previousChineseConversionEnabledStatus = _chineseConversionEnabled;
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"ChineseConversionStatusChanged" object:nil];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleChineseConversionStatusDidChanged:) name:@"ChineseConversionStatusChanged" object:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
@ -1466,6 +1472,7 @@ public:
|
||||||
{
|
{
|
||||||
_chineseConversionEnabled = !_chineseConversionEnabled;
|
_chineseConversionEnabled = !_chineseConversionEnabled;
|
||||||
[[NSUserDefaults standardUserDefaults] setBool:_chineseConversionEnabled forKey:kChineseConversionEnabledKey];
|
[[NSUserDefaults standardUserDefaults] setBool:_chineseConversionEnabled forKey:kChineseConversionEnabledKey];
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"ChineseConversionStatusChanged" object:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)clearLearningDictionary:(id)sender
|
- (void)clearLearningDictionary:(id)sender
|
||||||
|
@ -1517,6 +1524,23 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)handleChineseConversionStatusDidChanged:(NSNotification *)notification
|
||||||
|
{
|
||||||
|
// Do not post the notification if status doesn't change.
|
||||||
|
// This is because the input method can be initiated by multiple applications, then all of them would post the notification.
|
||||||
|
if (_previousChineseConversionEnabledStatus == _chineseConversionEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSUserNotification *userNotification = [[NSUserNotification alloc] init];
|
||||||
|
userNotification.title = @"vChewing";
|
||||||
|
userNotification.informativeText = [NSString stringWithFormat:@"%@%@", NSLocalizedString(@"Chinese Conversion", @""), _chineseConversionEnabled ? @" Enabled" : @" Disabled"];
|
||||||
|
userNotification.soundName = NSUserNotificationDefaultSoundName;
|
||||||
|
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:userNotification];
|
||||||
|
|
||||||
|
_previousChineseConversionEnabledStatus = _chineseConversionEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
static void LTLoadLanguageModelFile(NSString *filenameWithoutExtension, FastLM &lm)
|
static void LTLoadLanguageModelFile(NSString *filenameWithoutExtension, FastLM &lm)
|
||||||
|
|
Loading…
Reference in New Issue