Skip to content

Commit

Permalink
use separate textviews
Browse files Browse the repository at this point in the history
  • Loading branch information
groverlynn committed May 15, 2024
1 parent 4460598 commit 2ef0d00
Show file tree
Hide file tree
Showing 14 changed files with 1,755 additions and 1,683 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions Squirrel.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@
CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES;
CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES;
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_TIDY_BUGPRONE_REDUNDANT_BRANCH_CONDITION = YES;
Expand Down Expand Up @@ -701,6 +702,7 @@
CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES;
CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES;
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_TIDY_BUGPRONE_REDUNDANT_BRANCH_CONDITION = YES;
Expand Down
5 changes: 2 additions & 3 deletions SquirrelApplicationDelegate.hh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import <Cocoa/Cocoa.h>
#import "rime_api.h"

@class SquirrelConfig;
@class SquirrelPanel;
Expand All @@ -8,14 +9,12 @@
// outlet of NSApp's instance
@interface SquirrelApplicationDelegate : NSObject <NSApplicationDelegate>

typedef NS_ENUM(NSUInteger, SquirrelNotificationPolicy) {
typedef NS_CLOSED_ENUM(NSUInteger, SquirrelNotificationPolicy) {
kShowNotificationsNever = 0,
kShowNotificationsWhenAppropriate = 1,
kShowNotificationsAlways = 2
};

typedef uintptr_t RimeSessionId;

@property(nonatomic, weak, nullable) IBOutlet NSMenu* menu;
@property(nonatomic, weak, nullable) IBOutlet SquirrelPanel* panel;
@property(nonatomic, weak, nullable) IBOutlet id updater;
Expand Down
53 changes: 28 additions & 25 deletions SquirrelApplicationDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#import "SquirrelConfig.hh"
#import "SquirrelPanel.hh"
#import "macos_keycode.hh"
#import "rime_api.h"
#import <UserNotifications/UserNotifications.h>

static NSString* const kRimeWikiURL = @"https://github.com/rime/home/wiki";
Expand All @@ -15,7 +14,7 @@ @implementation SquirrelApplicationDelegate {

- (IBAction)showSwitcher:(id)sender {
NSLog(@"Show Switcher");
if (_switcherKeyEquivalent) {
if (_switcherKeyEquivalent != 0) {
RimeSessionId session = [sender unsignedLongValue];
rime_get_api()->process_key(session, _switcherKeyEquivalent,
_switcherKeyModifierMask);
Expand Down Expand Up @@ -46,13 +45,20 @@ - (IBAction)openWiki:(id)sender {
}

- (IBAction)openLogFolder:(id)sender {
NSURL* logFile = [NSFileManager.defaultManager.temporaryDirectory
NSURL* infoLog = [NSFileManager.defaultManager.temporaryDirectory
URLByAppendingPathComponent:@"rime.squirrel.INFO"
isDirectory:NO];
[NSWorkspace.sharedWorkspace activateFileViewerSelectingURLs:@[ logFile ]];
NSURL* warningLog = [NSFileManager.defaultManager.temporaryDirectory
URLByAppendingPathComponent:@"rime.squirrel.WARNING"
isDirectory:NO];
NSURL* errorLog = [NSFileManager.defaultManager.temporaryDirectory
URLByAppendingPathComponent:@"rime.squirrel.ERROR"
isDirectory:NO];
[NSWorkspace.sharedWorkspace
activateFileViewerSelectingURLs:@[ infoLog, warningLog, errorLog ]];
}

void show_notification(const char* msg_text) {
extern void show_notification(const char* msg_text) {
if (@available(macOS 10.14, *)) {
UNUserNotificationCenter* center =
UNUserNotificationCenter.currentNotificationCenter;
Expand All @@ -61,7 +67,7 @@ void show_notification(const char* msg_text) {
UNAuthorizationOptionProvisional
completionHandler:^(BOOL granted,
NSError* _Nullable error) {
if (error) {
if (error != nil) {
NSLog(@"User notification authorization error: %@",
error.debugDescription);
}
Expand All @@ -84,7 +90,7 @@ void show_notification(const char* msg_text) {
content:content
trigger:nil]
withCompletionHandler:^(NSError* _Nullable error) {
if (error) {
if (error != nil) {
NSLog(@"User notification request error: %@",
error.debugDescription);
}
Expand All @@ -104,9 +110,9 @@ void show_notification(const char* msg_text) {
}

static void show_status(const char* msg_text_long, const char* msg_text_short) {
NSString* msgLong = msg_text_long ? @(msg_text_long) : nil;
NSString* msgLong = msg_text_long != NULL ? @(msg_text_long) : nil;
NSString* msgShort =
msg_text_short
msg_text_short != NULL
? @(msg_text_short)
: [msgLong substringWithRange:
[msgLong rangeOfComposedCharacterSequenceAtIndex:0]];
Expand All @@ -118,37 +124,34 @@ static void notification_handler(void* context_object,
RimeSessionId session_id,
const char* message_type,
const char* message_value) {
if (!strcmp(message_type, "deploy")) {
if (!strcmp(message_value, "start")) {
if (strcmp(message_type, "deploy") == 0) {
if (strcmp(message_value, "start") == 0) {
show_notification("deploy_start");
} else if (!strcmp(message_value, "success")) {
} else if (strcmp(message_value, "success") == 0) {
show_notification("deploy_success");
} else if (!strcmp(message_value, "failure")) {
} else if (strcmp(message_value, "failure") == 0) {
show_notification("deploy_failure");
}
return;
}
SquirrelApplicationDelegate* app_delegate = (__bridge id)context_object;
// schema change
if (!strcmp(message_type, "schema") &&
if (strcmp(message_type, "schema") == 0 &&
app_delegate.showNotifications != kShowNotificationsNever) {
const char* schema_name = strchr(message_value, '/');
if (schema_name) {
if (schema_name != NULL) {
++schema_name;
show_status(schema_name, schema_name);
}
return;
}
// option change
if (!strcmp(message_type, "option") && app_delegate) {
if (strcmp(message_type, "option") == 0 && app_delegate) {
Bool state = message_value[0] != '!';
const char* option_name = message_value + !state;
BOOL updateScriptVariant = [app_delegate.panel.optionSwitcher
updateCurrentScriptVariant:@(message_value)];
BOOL updateStyleOptions = NO;
BOOL updateScriptVariant = NO;
if ([app_delegate.panel.optionSwitcher
updateCurrentScriptVariant:@(message_value)]) {
updateScriptVariant = YES;
}
if ([app_delegate.panel.optionSwitcher updateGroupState:@(message_value)
ofOption:@(option_name)]) {
updateStyleOptions = YES;
Expand All @@ -167,7 +170,7 @@ static void notification_handler(void* context_object,
RimeStringSlice state_label_short =
rime_get_api()->get_state_label_abbreviated(session_id, option_name,
state, True);
if (state_label_long.str || state_label_short.str) {
if (state_label_long.str != NULL || state_label_short.str != NULL) {
const char* short_message =
state_label_short.length < strlen(state_label_short.str)
? NULL
Expand Down Expand Up @@ -227,7 +230,7 @@ - (void)loadSettings {
if ([defaultConfig openWithConfigId:@"default"]) {
NSString* hotkey =
[defaultConfig getStringForOption:@"switcher/hotkeys/@0"];
if (hotkey) {
if (hotkey != nil) {
NSArray<NSString*>* keys = [hotkey componentsSeparatedByString:@"+"];
for (NSUInteger i = 0; i < keys.count - 1; ++i) {
_switcherKeyModifierMask |=
Expand Down Expand Up @@ -304,7 +307,7 @@ - (BOOL)problematicLaunchDetected {
NSData* archive = [NSData dataWithContentsOfURL:logfile
options:NSDataReadingUncached
error:nil];
if (archive) {
if (archive != nil) {
NSDate* previousLaunch =
[NSKeyedUnarchiver unarchivedObjectOfClass:NSDate.class
fromData:archive
Expand Down Expand Up @@ -348,7 +351,7 @@ - (void)inputSourceChanged:(NSNotification*)aNotification {
CFStringRef inputSource = (CFStringRef)TISGetInputSourceProperty(
TISCopyCurrentKeyboardInputSource(), kTISPropertyInputSourceID);
CFStringRef bundleId = CFBundleGetIdentifier(CFBundleGetMainBundle());
if (!CFStringHasPrefix(inputSource, bundleId)) {
if (CFStringHasPrefix(inputSource, bundleId) == kCFCompareEqualTo) {
_isCurrentInputMethod = NO;
}
}
Expand Down
5 changes: 2 additions & 3 deletions SquirrelConfig.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#import <Cocoa/Cocoa.h>

typedef uintptr_t RimeSessionId;
#import <rime_api.h>

__attribute__((objc_direct_members))
@interface SquirrelOptionSwitcher : NSObject
Expand Down Expand Up @@ -101,7 +100,7 @@ typedef NSDictionary<NSString*, NSNumber*> SquirrelAppOptions;
- (NSUInteger)getListSizeForOption:(NSString* _Nonnull)option;
- (NSArray<NSString*>* _Nullable)getListForOption:(NSString* _Nonnull)option;

- (SquirrelOptionSwitcher* _Nullable)getOptionSwitcher;
- (SquirrelOptionSwitcher* _Nonnull)getOptionSwitcher;
- (SquirrelAppOptions* _Nonnull)getAppOptions:(NSString* _Nonnull)appName;

@end // SquirrelConfig
Loading

0 comments on commit 2ef0d00

Please sign in to comment.