33#import " SquirrelConfig.hh"
44#import " SquirrelPanel.hh"
55#import " macos_keycode.hh"
6- #import " rime_api.h"
76#import < UserNotifications/UserNotifications.h>
87
98static NSString * const kRimeWikiURL = @" https://github.com/rime/home/wiki" ;
@@ -15,7 +14,7 @@ @implementation SquirrelApplicationDelegate {
1514
1615- (IBAction )showSwitcher : (id )sender {
1716 NSLog (@" Show Switcher" );
18- if (_switcherKeyEquivalent) {
17+ if (_switcherKeyEquivalent != 0 ) {
1918 RimeSessionId session = [sender unsignedLongValue ];
2019 rime_get_api ()->process_key (session, _switcherKeyEquivalent,
2120 _switcherKeyModifierMask);
@@ -45,14 +44,14 @@ - (IBAction)openWiki:(id)sender {
4544 [NSWorkspace .sharedWorkspace openURL: [NSURL URLWithString: kRimeWikiURL ]];
4645}
4746
48- void show_notification (const char * msg_text) {
47+ extern void show_notification (const char * msg_text) {
4948 UNUserNotificationCenter * center =
5049 UNUserNotificationCenter .currentNotificationCenter ;
5150 [center requestAuthorizationWithOptions: UNAuthorizationOptionAlert |
5251 UNAuthorizationOptionProvisional
5352 completionHandler: ^(BOOL granted,
5453 NSError * _Nullable error) {
55- if (error) {
54+ if (error != nil ) {
5655 NSLog (@" User notification authorization error: %@ " ,
5756 error.debugDescription);
5857 }
@@ -63,7 +62,7 @@ void show_notification(const char* msg_text) {
6362 settings.authorizationStatus == UNAuthorizationStatusProvisional ) &&
6463 (settings.alertSetting == UNNotificationSettingEnabled )) {
6564 UNMutableNotificationContent * content =
66- [[ UNMutableNotificationContent alloc ] init ] ;
65+ UNMutableNotificationContent . alloc . init ;
6766 content.title = NSLocalizedString(@" Squirrel" , nil );
6867 content.subtitle = NSLocalizedString(@(msg_text), nil );
6968 if (@available (macOS 12.0 , *)) {
@@ -75,7 +74,7 @@ void show_notification(const char* msg_text) {
7574 trigger: nil ];
7675 [center addNotificationRequest: request
7776 withCompletionHandler: ^(NSError * _Nullable error) {
78- if (error) {
77+ if (error != nil ) {
7978 NSLog (@" User notification request error: %@ " ,
8079 error.debugDescription);
8180 }
@@ -85,9 +84,9 @@ void show_notification(const char* msg_text) {
8584}
8685
8786static void show_status (const char * msg_text_long, const char * msg_text_short) {
88- NSString * msgLong = msg_text_long ? @(msg_text_long) : nil ;
87+ NSString * msgLong = msg_text_long != NULL ? @(msg_text_long) : nil ;
8988 NSString * msgShort =
90- msg_text_short
89+ msg_text_short != NULL
9190 ? @(msg_text_short)
9291 : [msgLong substringWithRange:
9392 [msgLong rangeOfComposedCharacterSequenceAtIndex: 0 ]];
@@ -99,37 +98,34 @@ static void notification_handler(void* context_object,
9998 RimeSessionId session_id,
10099 const char * message_type,
101100 const char * message_value) {
102- if (! strcmp (message_type, " deploy" )) {
103- if (! strcmp (message_value, " start" )) {
101+ if (strcmp (message_type, " deploy" ) == 0 ) {
102+ if (strcmp (message_value, " start" ) == 0 ) {
104103 show_notification (" deploy_start" );
105- } else if (! strcmp (message_value, " success" )) {
104+ } else if (strcmp (message_value, " success" ) == 0 ) {
106105 show_notification (" deploy_success" );
107- } else if (! strcmp (message_value, " failure" )) {
106+ } else if (strcmp (message_value, " failure" ) == 0 ) {
108107 show_notification (" deploy_failure" );
109108 }
110109 return ;
111110 }
112111 SquirrelApplicationDelegate* app_delegate = (__bridge id )context_object;
113112 // schema change
114- if (! strcmp (message_type, " schema" ) &&
113+ if (strcmp (message_type, " schema" ) == 0 &&
115114 app_delegate.showNotifications != kShowNotificationsNever ) {
116115 const char * schema_name = strchr (message_value, ' /' );
117- if (schema_name) {
116+ if (schema_name != NULL ) {
118117 ++schema_name;
119118 show_status (schema_name, schema_name);
120119 }
121120 return ;
122121 }
123122 // option change
124- if (! strcmp (message_type, " option" ) && app_delegate) {
123+ if (strcmp (message_type, " option" ) == 0 && app_delegate) {
125124 Bool state = message_value[0 ] != ' !' ;
126125 const char * option_name = message_value + !state;
126+ BOOL updateScriptVariant = [app_delegate.panel.optionSwitcher
127+ updateCurrentScriptVariant: @(message_value)];
127128 BOOL updateStyleOptions = NO ;
128- BOOL updateScriptVariant = NO ;
129- if ([app_delegate.panel.optionSwitcher
130- updateCurrentScriptVariant: @(message_value)]) {
131- updateScriptVariant = YES ;
132- }
133129 if ([app_delegate.panel.optionSwitcher updateGroupState: @(message_value)
134130 ofOption: @(option_name)]) {
135131 updateStyleOptions = YES ;
@@ -148,7 +144,7 @@ static void notification_handler(void* context_object,
148144 RimeStringSlice state_label_short =
149145 rime_get_api ()->get_state_label_abbreviated (session_id, option_name,
150146 state, True);
151- if (state_label_long.str || state_label_short.str ) {
147+ if (state_label_long.str != NULL || state_label_short.str != NULL ) {
152148 const char * short_message =
153149 state_label_short.length < strlen (state_label_short.str )
154150 ? NULL
@@ -208,7 +204,7 @@ - (void)loadSettings {
208204 if ([defaultConfig openWithConfigId: @" default" ]) {
209205 NSString * hotkey =
210206 [defaultConfig getStringForOption: @" switcher/hotkeys/@0" ];
211- if (hotkey) {
207+ if (hotkey != nil ) {
212208 NSArray <NSString *>* keys = [hotkey componentsSeparatedByString: @" +" ];
213209 for (NSUInteger i = 0 ; i < keys.count - 1 ; ++i) {
214210 _switcherKeyModifierMask |=
@@ -285,7 +281,7 @@ - (BOOL)problematicLaunchDetected {
285281 NSData * archive = [NSData dataWithContentsOfURL: logfile
286282 options: NSDataReadingUncached
287283 error: nil ];
288- if (archive) {
284+ if (archive != nil ) {
289285 NSDate * previousLaunch =
290286 [NSKeyedUnarchiver unarchivedObjectOfClass: NSDate .class
291287 fromData:archive
@@ -294,8 +290,7 @@ - (BOOL)problematicLaunchDetected {
294290 detected = YES ;
295291 }
296292 }
297- NSDate * now = [NSDate date ];
298- NSData * record = [NSKeyedArchiver archivedDataWithRootObject: now
293+ NSData * record = [NSKeyedArchiver archivedDataWithRootObject: NSDate .date
299294 requiringSecureCoding: NO
300295 error: nil ];
301296 [record writeToURL: logfile atomically: NO ];
@@ -328,7 +323,7 @@ - (void)inputSourceChanged:(NSNotification*)aNotification {
328323 CFStringRef inputSource = (CFStringRef)TISGetInputSourceProperty (
329324 TISCopyCurrentKeyboardInputSource (), kTISPropertyInputSourceID );
330325 CFStringRef bundleId = CFBundleGetIdentifier (CFBundleGetMainBundle ());
331- if (! CFStringHasPrefix (inputSource, bundleId)) {
326+ if (CFStringHasPrefix (inputSource, bundleId) == kCFCompareEqualTo ) {
332327 _isCurrentInputMethod = NO ;
333328 }
334329}
@@ -337,8 +332,7 @@ - (void)inputSourceChanged:(NSNotification*)aNotification {
337332// any menuItems without an action will be disabled when displayed in the Text
338333// Input Menu.
339334- (void )awakeFromNib {
340- NSNotificationCenter * center =
341- [NSWorkspace sharedWorkspace ].notificationCenter ;
335+ NSNotificationCenter * center = NSWorkspace .sharedWorkspace .notificationCenter ;
342336 [center addObserver: self
343337 selector: @selector (workspaceWillPowerOff: )
344338 name: NSWorkspaceWillPowerOffNotification
@@ -365,8 +359,8 @@ - (void)awakeFromNib {
365359}
366360
367361- (void )dealloc {
368- [[ NSNotificationCenter defaultCenter ] removeObserver: self ];
369- [[ NSDistributedNotificationCenter defaultCenter ] removeObserver: self ];
362+ [NSNotificationCenter . defaultCenter removeObserver: self ];
363+ [NSDistributedNotificationCenter . defaultCenter removeObserver: self ];
370364 [_panel hide ];
371365}
372366
0 commit comments