Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into UI
Browse files Browse the repository at this point in the history
  • Loading branch information
groverlynn committed Mar 8, 2024
2 parents 8faa534 + baeb420 commit 96c3ed2
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 136 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
BasedOnStyle: Chromium
SortIncludes: false
SortIncludes: false
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ $(RIME_DEPS):
$(MAKE) -C librime deps

librime: $(RIME_DEPS)
$(MAKE) -C librime install
$(MAKE) -C librime release install
$(MAKE) copy-rime-binaries

copy-rime-binaries:
Expand Down
20 changes: 0 additions & 20 deletions Squirrel.entitlements

This file was deleted.

8 changes: 4 additions & 4 deletions Squirrel.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
A4FC48CB0F6530EF0069BE81 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = A4FC48C90F6530EF0069BE81 /* Localizable.strings */; };
D26434552706A15100857391 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D26434542706A15100857391 /* QuartzCore.framework */; };
E93074B70A5C264700470842 /* InputMethodKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E93074B60A5C264700470842 /* InputMethodKit.framework */; };
F45E005F2B8CA81C00179B75 /* UserNotifications.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F45E005E2B8CA81C00179B75 /* UserNotifications.framework */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -232,7 +233,6 @@
44F84AD614E94C490005D70B /* SquirrelPanel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SquirrelPanel.m; sourceTree = "<group>"; };
44FA4D891685997300116C1F /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
44FA4D8E16859B2900116C1F /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/Localizable.strings"; sourceTree = "<group>"; };
5BCE17192B81D03D008C8D9E /* Squirrel.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Squirrel.entitlements; sourceTree = "<group>"; };
77AA67DC2588916300A592E2 /* HKVariants.ocd2 */ = {isa = PBXFileReference; lastKnownFileType = file; path = HKVariants.ocd2; sourceTree = "<group>"; };
77AA67DD2588916300A592E2 /* t2s.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = t2s.json; sourceTree = "<group>"; };
77AA67DE2588916300A592E2 /* t2tw.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = t2tw.json; sourceTree = "<group>"; };
Expand Down Expand Up @@ -279,6 +279,7 @@
A4FC48CA0F6530EF0069BE81 /* en */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
D26434542706A15100857391 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
E93074B60A5C264700470842 /* InputMethodKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = InputMethodKit.framework; path = /System/Library/Frameworks/InputMethodKit.framework; sourceTree = "<absolute>"; };
F45E005E2B8CA81C00179B75 /* UserNotifications.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotifications.framework; path = System/Library/Frameworks/UserNotifications.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -288,6 +289,7 @@
files = (
D26434552706A15100857391 /* QuartzCore.framework in Frameworks */,
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */,
F45E005F2B8CA81C00179B75 /* UserNotifications.framework in Frameworks */,
E93074B70A5C264700470842 /* InputMethodKit.framework in Frameworks */,
A4B8E1B30F645B870094E08B /* Carbon.framework in Frameworks */,
447765C925C30E97002415AF /* Sparkle.framework in Frameworks */,
Expand Down Expand Up @@ -349,7 +351,6 @@
29B97314FDCFA39411CA2CEA /* Squirrel */ = {
isa = PBXGroup;
children = (
5BCE17192B81D03D008C8D9E /* Squirrel.entitlements */,
442C648F1F7A40180027EFBE /* bin */,
44DA7A4214DD598900C1ED3B /* SharedSupport */,
080E96DDFE201D6D7F000001 /* Sources */,
Expand Down Expand Up @@ -381,6 +382,7 @@
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
isa = PBXGroup;
children = (
F45E005E2B8CA81C00179B75 /* UserNotifications.framework */,
D26434542706A15100857391 /* QuartzCore.framework */,
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */,
1058C7A2FEA54F0111CA2CBB /* Other Frameworks */,
Expand Down Expand Up @@ -605,7 +607,6 @@
buildSettings = {
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_ENTITLEMENTS = Squirrel.entitlements;
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
Expand Down Expand Up @@ -656,7 +657,6 @@
buildSettings = {
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_ENTITLEMENTS = Squirrel.entitlements;
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 0.16.2u;
Expand Down
99 changes: 42 additions & 57 deletions SquirrelApplicationDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,54 +32,43 @@ - (IBAction)openWiki:(id)sender {
}

void show_notification(const char* msg_text) {
if (@available(macOS 10.14, *)) {
UNUserNotificationCenter* center =
UNUserNotificationCenter.currentNotificationCenter;
[center
requestAuthorizationWithOptions:UNAuthorizationOptionAlert |
UNAuthorizationOptionProvisional
completionHandler:^(BOOL granted,
NSError* _Nullable error) {
if (error) {
NSLog(@"User notification authorization error: %@",
error.debugDescription);
}
}];
[center getNotificationSettingsWithCompletionHandler:^(
UNNotificationSettings* _Nonnull settings) {
if ((settings.authorizationStatus == UNAuthorizationStatusAuthorized ||
settings.authorizationStatus == UNAuthorizationStatusProvisional) &&
(settings.alertSetting == UNNotificationSettingEnabled)) {
UNMutableNotificationContent* content =
[[UNMutableNotificationContent alloc] init];
content.title = NSLocalizedString(@"Squirrel", nil);
content.subtitle = NSLocalizedString(@(msg_text), nil);
if (@available(macOS 12.0, *)) {
content.interruptionLevel = UNNotificationInterruptionLevelActive;
}
UNNotificationRequest* request =
[UNNotificationRequest requestWithIdentifier:@"SquirrelNotification"
content:content
trigger:nil];
[center addNotificationRequest:request
withCompletionHandler:^(NSError* _Nullable error) {
if (error) {
NSLog(@"User notification request error: %@",
error.debugDescription);
}
}];
UNUserNotificationCenter* center =
UNUserNotificationCenter.currentNotificationCenter;
[center
requestAuthorizationWithOptions:UNAuthorizationOptionAlert |
UNAuthorizationOptionProvisional
completionHandler:^(BOOL granted,
NSError* _Nullable error) {
if (error) {
NSLog(@"User notification authorization error: %@",
error.debugDescription);
}
}];
[center getNotificationSettingsWithCompletionHandler:^(
UNNotificationSettings* _Nonnull settings) {
if ((settings.authorizationStatus == UNAuthorizationStatusAuthorized ||
settings.authorizationStatus == UNAuthorizationStatusProvisional) &&
(settings.alertSetting == UNNotificationSettingEnabled)) {
UNMutableNotificationContent* content =
[[UNMutableNotificationContent alloc] init];
content.title = NSLocalizedString(@"Squirrel", nil);
content.subtitle = NSLocalizedString(@(msg_text), nil);
if (@available(macOS 12.0, *)) {
content.interruptionLevel = UNNotificationInterruptionLevelActive;
}
}];
} else {
NSUserNotification* notification = [[NSUserNotification alloc] init];
notification.title = NSLocalizedString(@"Squirrel", nil);
notification.subtitle = NSLocalizedString(@(msg_text), nil);

NSUserNotificationCenter* notificationCenter =
NSUserNotificationCenter.defaultUserNotificationCenter;
[notificationCenter removeAllDeliveredNotifications];
[notificationCenter deliverNotification:notification];
}
UNNotificationRequest* request =
[UNNotificationRequest requestWithIdentifier:@"SquirrelNotification"
content:content
trigger:nil];
[center addNotificationRequest:request
withCompletionHandler:^(NSError* _Nullable error) {
if (error) {
NSLog(@"User notification request error: %@",
error.debugDescription);
}
}];
}
}];
}

static void show_status(const char* msg_text_long, const char* msg_text_short) {
Expand Down Expand Up @@ -150,13 +139,13 @@ static void notification_handler(void* context_object,
}

- (void)setupRime {
NSString* userDataDir = (@"~/Library/Rime").stringByStandardizingPath;
NSString* userDataDir = @"~/Library/Rime".stringByExpandingTildeInPath;
NSFileManager* fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:userDataDir]) {
if (![fileManager createDirectoryAtPath:userDataDir
withIntermediateDirectories:YES
attributes:nil
error:NULL]) {
error:nil]) {
NSLog(@"Error creating user data directory: %@", userDataDir);
}
}
Expand All @@ -168,8 +157,8 @@ - (void)setupRime {
squirrel_traits.user_data_dir = userDataDir.UTF8String;
squirrel_traits.distribution_code_name = "Squirrel";
squirrel_traits.distribution_name = "鼠鬚管";
squirrel_traits.distribution_version =
[[NSBundle mainBundle].infoDictionary[@"CFBundleVersion"] UTF8String];
squirrel_traits.distribution_version = [[[NSBundle mainBundle]
objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey] UTF8String];
squirrel_traits.app_name = "rime.squirrel";
rime_get_api()->setup(&squirrel_traits);
}
Expand Down Expand Up @@ -295,9 +284,7 @@ - (BOOL)problematicLaunchDetected {
NSData* record = [NSKeyedArchiver archivedDataWithRootObject:now
requiringSecureCoding:NO
error:nil];
NSFileHandle* fileHandle = [NSFileHandle fileHandleForWritingToURL:logfile
error:nil];
[fileHandle writeData:record];
[record writeToURL:logfile atomically:NO];
return detected;
}

Expand Down Expand Up @@ -350,9 +337,7 @@ - (void)awakeFromNib {
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSDistributedNotificationCenter defaultCenter] removeObserver:self];
if (_panel) {
[_panel hide];
}
[_panel hide];
}

@end // SquirrelApplicationDelegate
Expand Down
8 changes: 4 additions & 4 deletions SquirrelConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,22 @@ - (BOOL)hasSection:(NSString*)section {
return NO;
}

- (BOOL)setBool:(bool)value forOption:(NSString*)option {
- (BOOL)setOption:(NSString*)option withBool:(bool)value {
return (BOOL)(rime_get_api()->config_set_bool(&_config, option.UTF8String,
value));
}

- (BOOL)setInt:(int)value forOption:(NSString*)option {
- (BOOL)setOption:(NSString*)option withInt:(int)value {
return (
BOOL)(rime_get_api()->config_set_int(&_config, option.UTF8String, value));
}

- (BOOL)setDouble:(double)value forOption:(NSString*)option {
- (BOOL)setOption:(NSString*)option withDouble:(double)value {
return (BOOL)(rime_get_api()->config_set_double(&_config, option.UTF8String,
value));
}

- (BOOL)setString:(NSString*)value forOption:(NSString*)option {
- (BOOL)setOption:(NSString*)option withString:(NSString*)value {
return (BOOL)(rime_get_api()->config_set_string(&_config, option.UTF8String,
value.UTF8String));
}
Expand Down
Loading

0 comments on commit 96c3ed2

Please sign in to comment.