From 3685d28592faffcea84851df30bee52010b1e757 Mon Sep 17 00:00:00 2001 From: Sunny Young Date: Fri, 28 Apr 2023 17:41:24 +0800 Subject: [PATCH] Add custom mask color support --- WeChatTweak/AntiRevoke.m | 6 +- .../Base.lproj/TweakPreferencesController.xib | 131 +++++++++++++----- .../Controller/TweakPreferencesController.m | 11 +- .../Supporting Files/WeChatTweakHeaders.h | 8 -- WeChatTweak/WeChatTweak.h | 9 ++ WeChatTweak/WeChatTweak.m | 18 +++ 6 files changed, 132 insertions(+), 51 deletions(-) diff --git a/WeChatTweak/AntiRevoke.m b/WeChatTweak/AntiRevoke.m index 7a126a9..95cb98c 100644 --- a/WeChatTweak/AntiRevoke.m +++ b/WeChatTweak/AntiRevoke.m @@ -83,8 +83,8 @@ static void __attribute__((constructor)) tweak(void) { // Dispatch notification dispatch_async(dispatch_get_main_queue(), ^{ // Deliver notification - RevokeNotificationType notificationType = [[NSUserDefaults standardUserDefaults] integerForKey:WeChatTweakPreferenceRevokeNotificationTypeKey]; - if (notificationType == RevokeNotificationTypeReceiveAll || (notificationType == RevokeNotificationTypeInherited && isChatStatusNotifyOpen)) { + WeChatTweakNotificationType notificationType = WeChatTweak.notificationType; + if (notificationType == WeChatTweakNotificationTypeReceiveAll || (notificationType == WeChatTweakNotificationTypeInherited && isChatStatusNotifyOpen)) { [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:userNotification]; } }); @@ -119,7 +119,7 @@ static void __attribute__((constructor)) tweak(void) { *stop = YES; view.hidden = !recalled; }]; - ((MMMessageCellView *)self).layer.backgroundColor = recalled ? [NSColor.systemYellowColor colorWithAlphaComponent:0.3].CGColor : nil; + ((MMMessageCellView *)self).layer.backgroundColor = recalled ? WeChatTweak.maskColor.CGColor : nil; } - (void)tweak_layout { diff --git a/WeChatTweak/Controller/Base.lproj/TweakPreferencesController.xib b/WeChatTweak/Controller/Base.lproj/TweakPreferencesController.xib index 284cc5b..9ab82dc 100644 --- a/WeChatTweak/Controller/Base.lproj/TweakPreferencesController.xib +++ b/WeChatTweak/Controller/Base.lproj/TweakPreferencesController.xib @@ -8,6 +8,7 @@ + @@ -15,49 +16,103 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + - + diff --git a/WeChatTweak/Controller/TweakPreferencesController.m b/WeChatTweak/Controller/TweakPreferencesController.m index 6ab7a3a..69c6d8d 100644 --- a/WeChatTweak/Controller/TweakPreferencesController.m +++ b/WeChatTweak/Controller/TweakPreferencesController.m @@ -12,6 +12,7 @@ @interface TweakPreferencesController () @property (weak) IBOutlet NSPopUpButton *notificationTypeButton; +@property (weak) IBOutlet NSColorWell *maskColorWell; @end @@ -19,6 +20,7 @@ - (void)viewDidLoad { [super viewDidLoad]; + [NSColorPanel.sharedColorPanel setShowsAlpha:YES]; } - (void)viewWillAppear { @@ -27,13 +29,18 @@ } - (void)reloadData { - [self.notificationTypeButton selectItemAtIndex:[NSUserDefaults.standardUserDefaults integerForKey:WeChatTweakPreferenceRevokeNotificationTypeKey]]; + self.maskColorWell.color = WeChatTweak.maskColor; + [self.notificationTypeButton selectItemAtIndex:WeChatTweak.notificationType]; } #pragma mark - Event method - (IBAction)switchNotificationTypeAction:(NSPopUpButton *)sender { - [NSUserDefaults.standardUserDefaults setInteger:sender.indexOfSelectedItem forKey:WeChatTweakPreferenceRevokeNotificationTypeKey]; + WeChatTweak.notificationType = sender.indexOfSelectedItem; +} + +- (IBAction)changeMaskColorAction:(NSColorWell *)sender { + WeChatTweak.maskColor = sender.color; } #pragma mark - MASPreferencesViewController diff --git a/WeChatTweak/Supporting Files/WeChatTweakHeaders.h b/WeChatTweak/Supporting Files/WeChatTweakHeaders.h index e16e22e..649346a 100644 --- a/WeChatTweak/Supporting Files/WeChatTweakHeaders.h +++ b/WeChatTweak/Supporting Files/WeChatTweakHeaders.h @@ -11,12 +11,6 @@ #import #import -typedef NS_ENUM(NSUInteger, RevokeNotificationType) { - RevokeNotificationTypeInherited = 0, - RevokeNotificationTypeReceiveAll, - RevokeNotificationTypeDisable, -}; - typedef NS_ENUM(unsigned int, MessageDataType) { MessageDataTypeText = 1, MessageDataTypeImage = 3, @@ -27,8 +21,6 @@ typedef NS_ENUM(unsigned int, MessageDataType) { MessageDataTypePrompt = 10000 }; -static NSString * const WeChatTweakPreferenceRevokeNotificationTypeKey = @"WeChatTweakPreferenceRevokeNotificationTypeKey"; - @interface NSString (MD5) - (NSString *)md5String; diff --git a/WeChatTweak/WeChatTweak.h b/WeChatTweak/WeChatTweak.h index 843f5ee..1b14086 100644 --- a/WeChatTweak/WeChatTweak.h +++ b/WeChatTweak/WeChatTweak.h @@ -11,6 +11,15 @@ FOUNDATION_EXPORT double WeChatTweakVersionNumber; FOUNDATION_EXPORT const unsigned char WeChatTweakVersionString[]; +typedef NS_ENUM(NSUInteger, WeChatTweakNotificationType) { + WeChatTweakNotificationTypeInherited = 0, + WeChatTweakNotificationTypeReceiveAll, + WeChatTweakNotificationTypeDisable +}; + @interface WeChatTweak : NSObject +@property (class, assign) WeChatTweakNotificationType notificationType; +@property (class, nonnull) NSColor *maskColor; + @end diff --git a/WeChatTweak/WeChatTweak.m b/WeChatTweak/WeChatTweak.m index c3b826f..2dd2ce8 100755 --- a/WeChatTweak/WeChatTweak.m +++ b/WeChatTweak/WeChatTweak.m @@ -10,4 +10,22 @@ @implementation WeChatTweak ++ (WeChatTweakNotificationType)notificationType { + return [NSUserDefaults.standardUserDefaults integerForKey:@"WeChatTweakPreferenceRevokeNotificationTypeKey"]; +} + ++ (void)setNotificationType:(WeChatTweakNotificationType)notificationType { + [NSUserDefaults.standardUserDefaults setInteger:notificationType forKey:@"WeChatTweakPreferenceRevokeNotificationTypeKey"]; +} + ++ (NSColor *)maskColor { + NSData *data = [NSUserDefaults.standardUserDefaults objectForKey:@"WeChatTweakMaskColor"]; + return data ? [NSUnarchiver unarchiveObjectWithData:data] : [NSColor.systemYellowColor colorWithAlphaComponent:0.3]; +} + ++ (void)setMaskColor:(NSColor *)maskColor { + NSData *data = [NSArchiver archivedDataWithRootObject:maskColor]; + [NSUserDefaults.standardUserDefaults setObject:data forKey:@"WeChatTweakMaskColor"]; +} + @end