@@ -15,9 +15,11 @@ @implementation SquirrelApplicationDelegate {
1515
1616- (IBAction )showSwitcher : (id )sender {
1717 NSLog (@" Show Switcher" );
18- RimeSessionId session = [sender unsignedLongValue ];
19- rime_get_api ()->process_key (session, _switcherKeyEquivalent,
20- _switcherKeyModifierMask);
18+ if (_switcherKeyEquivalent) {
19+ RimeSessionId session = [sender unsignedLongValue ];
20+ rime_get_api ()->process_key (session, _switcherKeyEquivalent,
21+ _switcherKeyModifierMask);
22+ }
2123}
2224
2325- (IBAction )deploy : (id )sender {
@@ -188,7 +190,7 @@ - (void)startRimeWithFullCheck:(BOOL)fullCheck {
188190 NSLog (@" Initializing la rime..." );
189191 rime_get_api ()->initialize (NULL );
190192 // check for configuration updates
191- if (rime_get_api ()->start_maintenance ((Bool) fullCheck)) {
193+ if (rime_get_api ()->start_maintenance (fullCheck)) {
192194 // update squirrel config
193195 rime_get_api ()->deploy_config_file (" squirrel.yaml" , " config_version" );
194196 }
@@ -200,32 +202,28 @@ - (void)shutdownRime {
200202}
201203
202204- (void )loadSettings {
205+ _switcherKeyModifierMask = 0 ;
206+ _switcherKeyEquivalent = 0 ;
203207 SquirrelConfig* defaultConfig = SquirrelConfig.alloc .init ;
204208 if ([defaultConfig openWithConfigId: @" default" ]) {
205- NSString * hotKeys =
209+ NSString * hotkey =
206210 [defaultConfig getStringForOption: @" switcher/hotkeys/@0" ];
207- NSArray <NSString *>* keys = [hotKeys componentsSeparatedByString: @" +" ];
208- NSEventModifierFlags modifiers = 0 ;
209- int rime_modifiers = 0 ;
210- for (NSUInteger i = 0 ; i < keys.count - 1 ; ++i) {
211- modifiers |= parse_macos_modifiers (keys[i].UTF8String );
212- rime_modifiers |= parse_rime_modifiers (keys[i].UTF8String );
211+ if (hotkey) {
212+ NSArray <NSString *>* keys = [hotkey componentsSeparatedByString: @" +" ];
213+ for (NSUInteger i = 0 ; i < keys.count - 1 ; ++i) {
214+ _switcherKeyModifierMask |=
215+ rime_modifiers_from_name (keys[i].UTF8String );
216+ }
217+ _switcherKeyEquivalent =
218+ rime_keycode_from_name (keys.lastObject .UTF8String );
213219 }
214- int keycode = parse_keycode (keys.lastObject .UTF8String );
215- unichar keychar = keycode <= 0xFFFF ? (unichar )keycode : 0 ;
216- _menu.itemArray [0 ].keyEquivalent = [NSString stringWithCharacters: &keychar
217- length: 1 ];
218- _menu.itemArray [0 ].keyEquivalentModifierMask = modifiers;
219- _switcherKeyEquivalent = keycode;
220- _switcherKeyModifierMask = rime_modifiers;
221220 }
222221 [defaultConfig close ];
223222
224223 _config = SquirrelConfig.alloc .init ;
225224 if (!_config.openBaseConfig ) {
226225 return ;
227226 }
228-
229227 NSString * showNotificationsWhen =
230228 [_config getStringForOption: @" show_notifications_when" ];
231229 if ([@" never" caseInsensitiveCompare: showNotificationsWhen] ==
0 commit comments