Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…-ForMac

# Conflicts:
#	WeChatExtension/WeChatExtension.xcodeproj/project.pbxproj
#	WeChatExtension/WeChatExtension/Sources/Hook/NSObject+ThemeHook.m
#	WeChatExtension/WeChatExtension/Sources/Hook/WeChat+hook.m
  • Loading branch information
yanmao committed Apr 29, 2020
2 parents a8b324f + 0095384 commit dd140b3
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 42 deletions.
7 changes: 7 additions & 0 deletions WeChatExtension/WeChatExtension.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
08294044245812FB0056E0C6 /* pin.png in Resources */ = {isa = PBXBuildFile; fileRef = 08294043245812FA0056E0C6 /* pin.png */; };
1828B9AA23BA319E008EC8E9 /* TKAboutWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1828B9A923BA319E008EC8E9 /* TKAboutWindowController.xib */; };
1853B3C422C6133C00A5C4FA /* YMIMContactsManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 1853B3C222C6133C00A5C4FA /* YMIMContactsManager.h */; };
1853B3C522C6133C00A5C4FA /* YMIMContactsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 1853B3C322C6133C00A5C4FA /* YMIMContactsManager.m */; };
Expand Down Expand Up @@ -169,6 +170,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
08294043245812FA0056E0C6 /* pin.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = pin.png; sourceTree = "<group>"; };
1802C087239826CB0061823C /* en-GB */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "en-GB"; path = "en-GB.lproj/TKRemoteControlWindowController.strings"; sourceTree = "<group>"; };
1802C088239826CB0061823C /* en-GB */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "en-GB"; path = "en-GB.lproj/Info.plist"; sourceTree = "<group>"; };
1802C089239826CB0061823C /* en-GB */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "en-GB"; path = "en-GB.lproj/Localizable.strings"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -383,6 +385,7 @@
isa = PBXGroup;
children = (
18ECDCF42405194800090014 /* aliPayCode.png */,
08294043245812FA0056E0C6 /* pin.png */,
18B606DD23979FC6000A41DC /* order_avatar.png */,
96B578B62360A92500F3F66C /* Info.plist */,
18A7A12D2272ACE300361A98 /* main.mm */,
Expand Down Expand Up @@ -637,6 +640,9 @@
18D4C34A24236180006A20E2 /* NSObject+ThemeHook.m */,
18B37AB7245536ED00037B58 /* NSObject+Safe.h */,
18B37AB8245536ED00037B58 /* NSObject+Safe.m */,
188A65EB2272ACBA0096663E /* YMMessageTool.h */,
188A65EA2272ACBA0096663E /* YMMessageTool.m */,

);
path = Hook;
sourceTree = "<group>";
Expand Down Expand Up @@ -909,6 +915,7 @@
1828B9AA23BA319E008EC8E9 /* TKAboutWindowController.xib in Resources */,
18ECDCF52405194800090014 /* aliPayCode.png in Resources */,
188A65FB2272ACBA0096663E /* TKAutoReplyWindowController.xib in Resources */,
08294044245812FB0056E0C6 /* pin.png in Resources */,
3632293F22A6ADB300F62EAB /* LockPlist.plist in Resources */,
18B606DE23979FC6000A41DC /* order_avatar.png in Resources */,
);
Expand Down
Binary file not shown.
27 changes: 25 additions & 2 deletions WeChatExtension/WeChatExtension/Sources/Common/YMPrefixHeader.pch
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,30 @@
#define kDarkBacgroundColor kRGBColor(24, 34, 45, 1.0)
#define kLightDarkBacgroundColor kRGBColor(54, 54, 54, 1.0)
#define kPinkBacgroundColor kRGBColor(229,173,177,1.0)
#define kBlackBackgroundColor kRGBColor(31, 31, 31, 1)

#define kDefaultTextColor kRGBColor(47, 47, 50, 0.7)
#define kDarkModeTextColor kRGBColor(177, 195, 213, 1.0)
#define kBlackModeTextColor kRGBColor(192,192,192, 0.8)
#define kPinkModeTextColor kDefaultTextColor

#define kDefaultIgnoredBackgroundColor kRGBColor(128,128,128, 1)
#define kDarkModeIgnoredBackgroundColor kBG3
#define kBlackModeIgnoredBackgroundColor kBG3
#define kPinkModeIgnoredBackgroundColor kDefaultIgnoredBackgroundColor

#define kDefaultIgnoredTextColor kRGBColor(25, 185, 77, 1.0)
#define kDarkModeIgnoredTextColor kRGBColor(25, 185, 77, 1.0)
#define kBlackModeIgnoredTextColor kRGBColor(192,192,192, 0.5)
#define kPinkModeIgnoredTextColor kDefaultIgnoredTextColor


#define kMainBackgroundColor ((NSColor *)TKWeChatPluginConfig.sharedConfig.mainBackgroundColor)
#define kMainTextColor ((NSColor *)TKWeChatPluginConfig.sharedConfig.mainTextColor)
#define kMainIgnoredBackgroundColor ((NSColor *)TKWeChatPluginConfig.sharedConfig.mainIgnoredBackgroundColor)
#define kMainIgnoredTextColor ((NSColor *)TKWeChatPluginConfig.sharedConfig.mainIgnoredTextColor)
#define kMainSeperatorColor ((NSColor *)TKWeChatPluginConfig.sharedConfig.mainSeperatorColor)
#define kMainDividerColor ((NSColor *)TKWeChatPluginConfig.sharedConfig.mainDividerColor)
#define kMainScrollerColor ((NSColor *)TKWeChatPluginConfig.sharedConfig.mainScrollerColor)

#define kMainBackgroundColor [TKWeChatPluginConfig sharedConfig].darkMode ? kDarkBacgroundColor : kPinkBacgroundColor
#define kMainTextColor [TKWeChatPluginConfig sharedConfig].darkMode ? kRGBColor(177, 195, 213, 1.0) : kRGBColor(47, 47, 50, 0.7)
#endif /* YMPrefixHeader_pch */
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ typedef NS_ENUM(NSInteger, PluginLanguageType) {
@property (nonatomic, copy) NSString *currentUserName; /**< 当前用户的id */
@property (nonatomic) BOOL isAllowMoreOpenBaby; /**< 子WeChat多开 */
@property (nonatomic) BOOL darkMode; /**< 黑暗模式 */
@property (nonatomic) BOOL blackMode; /**< 深邃模式 */
@property (nonatomic) BOOL pinkMode; /**< 少女模式 */
@property (nonatomic) BOOL groupMultiColorMode; /**< 群成员彩色 */
@property (nonatomic) BOOL isThemeLoaded; /**< 是否有使用过皮肤 */
Expand All @@ -64,5 +65,15 @@ typedef NS_ENUM(NSInteger, PluginLanguageType) {
- (NSMutableArray *)getMonitorQuitMembers;
- (NSString *)languageSetting:(NSString *)chinese english:(NSString *)english;

- (BOOL)usingTheme;
- (BOOL)usingDarkTheme;

- (id)mainBackgroundColor;
- (id)mainTextColor;
- (id)mainIgnoredBackgroundColor;
- (id)mainIgnoredTextColor;
- (id)mainSeperatorColor;
- (id)mainScrollerColor;
- (id)mainDividerColor;
@end

Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ @implementation TKWeChatPluginConfig
@dynamic currentUserName;
@dynamic isAllowMoreOpenBaby;
@dynamic darkMode;
@dynamic blackMode;
@dynamic pinkMode;
@dynamic groupMultiColorMode;
@dynamic isThemeLoaded;
Expand Down Expand Up @@ -339,4 +340,51 @@ - (NSString *)languageSetting:(NSString *)chinese english:(NSString *)english
return english;
}

- (BOOL)usingTheme {
return self.darkMode || self.blackMode || self.pinkMode;
}

- (BOOL)usingDarkTheme {
return self.darkMode || self.blackMode;
}

- (id)mainTextColor {
if (![self usingTheme]) {
return kDefaultTextColor;
}
return self.darkMode ? kDarkModeTextColor : (self.blackMode ? kBlackModeTextColor : kPinkModeTextColor);
}

- (id)mainBackgroundColor {
if (![self usingTheme]) {
return NSColor.clearColor;
}
return self.darkMode ? kDarkBacgroundColor : (self.blackMode ? kBlackBackgroundColor : kPinkBacgroundColor);
}

- (id)mainIgnoredTextColor {
if (![self usingTheme]) {
return kDefaultIgnoredTextColor;
}
return self.darkMode ? kDarkModeIgnoredTextColor : (self.blackMode ? kBlackModeIgnoredTextColor : kPinkModeIgnoredTextColor);
}

- (id)mainIgnoredBackgroundColor {
if (![self usingTheme]) {
return kDefaultIgnoredBackgroundColor;
}
return self.darkMode ? kDarkModeIgnoredBackgroundColor : (self.blackMode ? kBlackModeIgnoredBackgroundColor : kPinkModeIgnoredBackgroundColor);
}

- (id)mainSeperatorColor {
return self.darkMode ? kRGBColor(147, 148, 248, 0.2) : (self.blackMode ? kRGBColor(128,128,128, 0.5) : kRGBColor(147, 148, 248, 0.2));
}

- (id)mainScrollerColor {
return self.darkMode ? kRGBColor(33, 48, 64, 1.0) : (self.blackMode ? kRGBColor(128,128,128, 0.5) : NSColor.clearColor);
}

- (id)mainDividerColor {
return self.darkMode ? kRGBColor(71, 69, 112, 0.5) : (self.blackMode ? kRGBColor(128,128,128, 0.7) : kRGBColor(71, 69, 112, 0.5));
}
@end
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ - (void)hook_setSessionInfo:(MMSessionInfo *)sessionInfo

NSMutableArray *selectSessions = [[TKWeChatPluginConfig sharedConfig] selectSessions];

if ([TKWeChatPluginConfig sharedConfig].darkMode) {
NSColor *changeColor = [TKWeChatPluginConfig sharedConfig].darkMode ? kRGBColor(255, 255, 255, 1.0) : [NSColor blackColor];
if ([TKWeChatPluginConfig sharedConfig].usingDarkTheme) {
NSColor *changeColor = kRGBColor(255, 255, 255, 1.0);
if (isIgnore) {
changeColor = kRGBColor(25, 185, 77, 1.0);
changeColor = kMainIgnoredTextColor;//kRGBColor(25, 185, 77, 1.0);
} else if ([selectSessions containsObject:sessionInfo]) {
changeColor = [NSColor redColor];
}
Expand All @@ -85,6 +85,32 @@ - (void)hook_setSessionInfo:(MMSessionInfo *)sessionInfo
NSFont *attributesFont = [attributes valueForKey:@"NSFont"];
NSMutableAttributedString *returnValue = [[NSMutableAttributedString alloc] initWithString:str.string attributes:@{NSForegroundColorAttributeName :changeColor, NSFontAttributeName : attributesFont}];
cellView.nickName.attributedStringValue = returnValue;

// MARK: - Add pined image in dark mode
NSBundle *bundle = [NSBundle bundleWithIdentifier:@"MustangYM.WeChatExtension"];
NSString *imgPath= [bundle pathForImageResource:@"pin.png"];

NSImage *pined = [[NSImage alloc] initWithContentsOfFile:imgPath];
NSImageView *pinedView = [[NSImageView alloc] initWithFrame:NSMakeRect(0, 0, 20, 20)];
[pinedView setImage:pined];

pinedView.tag = 9999999;
[cellView.stickyBackgroundView addSubview:pinedView];
pinedView.translatesAutoresizingMaskIntoConstraints = NO;
NSMutableArray<NSLayoutConstraint*> *contraints = [NSMutableArray array];
if (@available(macOS 10.11, *)) {
[contraints addObject:[pinedView.topAnchor constraintEqualToAnchor:cellView.stickyBackgroundView.topAnchor constant:0]];

[contraints addObject:[pinedView.widthAnchor constraintEqualToConstant:10]];

[contraints addObject:[pinedView.heightAnchor constraintEqualToConstant:10]];

[contraints addObject:[pinedView.leadingAnchor constraintEqualToAnchor:cellView.stickyBackgroundView.leadingAnchor constant:0]];
[cellView.stickyBackgroundView addConstraints:contraints];
} else {
// Fallback on earlier versions
}

});
} else {
if (isIgnore) {
Expand Down
83 changes: 55 additions & 28 deletions WeChatExtension/WeChatExtension/Sources/Hook/NSObject+ThemeHook.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ + (void)hookTheme
[[TKWeChatPluginConfig sharedConfig] setGroupMultiColorMode:YES];
}

if ([TKWeChatPluginConfig sharedConfig].darkMode || [TKWeChatPluginConfig sharedConfig].pinkMode) {
if (TKWeChatPluginConfig.sharedConfig.usingTheme) {
hookMethod(objc_getClass("MMTextField"), @selector(setTextColor:), [self class], @selector(hook_setTextColor:));
hookMethod([NSTextField class], @selector(setAttributedStringValue:), [self class], @selector(hook_textFieldSetAttributedStringValue:));
hookMethod(objc_getClass("MMTextView"), NSSelectorFromString(@"shouldDisableSetFrameOrigin"), [self class], @selector(hook_shouldDisableSetFrameOrigin));
Expand Down Expand Up @@ -58,13 +58,17 @@ + (void)hookTheme
hookMethod(objc_getClass("MMCTTextView"), @selector(setAttributedString:), [self class], @selector(hook_textFieldSetTextColor:));
hookMethod(objc_getClass("MMSessionPickerListRowView"), @selector(drawRect:), [self class], @selector(hook_pickerListDrawRect:));
hookMethod(objc_getClass("MMChatDetailMemberRowView"), @selector(avatarImageView), [self class], @selector(hook_chatDetailAvatarImageView));
hookMethod(objc_getClass("MMAppReferContainerView"), NSSelectorFromString(@"normalColor"), [self class], @selector(hook_referNormalColor));
hookMethod(objc_getClass("MMAppReferContainerView"), NSSelectorFromString(@"highlightColor"), [self class], @selector(hook_referHighlightColor));
hookMethod(objc_getClass("MMReferTextAttachmentView"), NSSelectorFromString(@"setBgView:"), [self class], @selector(hook_referSetBgView:));

}

}

- (NSImageView *)hook_chatDetailAvatarImageView
{
if ([TKWeChatPluginConfig sharedConfig].darkMode) {
if ([TKWeChatPluginConfig sharedConfig].usingDarkTheme) {
@try {
MMChatDetailMemberRowView *row = (MMChatDetailMemberRowView *)self;
NSTextFieldCell *cell = [row.nameField valueForKey:@"cell"];
Expand All @@ -83,7 +87,7 @@ - (void)hook_pickerListDrawRect:(CGRect)arg1
{
[self hook_pickerListDrawRect:arg1];

if ([TKWeChatPluginConfig sharedConfig].darkMode) {
if ([TKWeChatPluginConfig sharedConfig].usingDarkTheme) {
@try {
MMSessionPickerListRowView *row = (MMSessionPickerListRowView *)self;
NSTextFieldCell *cell = [row.sessionNameField valueForKey:@"cell"];
Expand All @@ -99,7 +103,8 @@ - (void)hook_pickerListDrawRect:(CGRect)arg1

- (void)hook_textFieldSetTextColor:(NSAttributedString *)arg1
{
if ([TKWeChatPluginConfig sharedConfig].darkMode) {
// history trigger by button in chat dialog
if ([TKWeChatPluginConfig sharedConfig].usingDarkTheme) {
NSView *view = (NSView *)self;
if ([view.superview isKindOfClass:objc_getClass("MMChatTextMessageCellView")] && arg1.string.length > 0) {
arg1 = [[NSMutableAttributedString alloc] initWithString:arg1.string attributes:@{NSForegroundColorAttributeName : kMainTextColor, NSFontAttributeName : [NSFont systemFontOfSize:14]}];
Expand All @@ -114,7 +119,7 @@ - (void)hook_textFieldSetAttributedStringValue:(NSAttributedString *)attributedS
NSTextField *field = (NSTextField *)self;
NSMutableAttributedString *a = [attributedString mutableCopy];

if ([TKWeChatPluginConfig sharedConfig].darkMode || [TKWeChatPluginConfig sharedConfig].pinkMode) {
if (TKWeChatPluginConfig.sharedConfig.usingTheme) {
NSView *sv = field.superview;

Class tcClass = NSClassFromString(@"MMFavoritesListTextCell");
Expand Down Expand Up @@ -144,7 +149,8 @@ - (BOOL)hook_shouldDisableSetFrameOrigin
{
NSTextView *view = (NSTextView *)self;

if (view.superview != nil && [view.superview isKindOfClass:NSClassFromString(@"MMChatLogEventView")]) {
// Search chat history window
if (view.superview != nil && ([view.superview isKindOfClass:NSClassFromString(@"MMChatLogEventView")] || [view.superview isKindOfClass:NSClassFromString(@"MMView")])) {
NSRange area = NSMakeRange(0, [view.textStorage length]);
[view.textStorage removeAttribute:NSForegroundColorAttributeName range:area];
[view.textStorage addAttributes:@{
Expand All @@ -164,8 +170,8 @@ - (void)hook_updateGroupChatNickName

if (originalText.length > 0) {
NSColor *radomColor = nil;
if ([TKWeChatPluginConfig sharedConfig].darkMode && [TKWeChatPluginConfig sharedConfig].groupMultiColorMode) {
radomColor = [[YMThemeManager shareInstance] randomColor:originalText.string.md5String];
if ([TKWeChatPluginConfig sharedConfig].usingDarkTheme && [TKWeChatPluginConfig sharedConfig].groupMultiColorMode) {
radomColor = [[YMThemeMgr shareInstance] randomColor:originalText.string.md5String];
} else {
radomColor = kMainTextColor;
}
Expand Down Expand Up @@ -209,7 +215,7 @@ - (void)hook_setMessageText:(id)arg1
NSAlert *alert = (NSAlert *)self;
[[YMThemeManager shareInstance] changeTheme:alert.window.contentView];

if ([TKWeChatPluginConfig sharedConfig].darkMode) {
if ([TKWeChatPluginConfig sharedConfig].usingDarkTheme) {
for (NSView *sub in alert.window.contentView.subviews) {
if ([sub isKindOfClass:NSTextField.class]) {
NSTextFieldCell *cell = [sub valueForKey:@"cell"];
Expand All @@ -227,7 +233,7 @@ - (void)hook_setMessageText:(id)arg1

- (void)hook_setSeperator:(NSView *)arg1
{
[[YMThemeManager shareInstance] changeTheme:arg1 color:kRGBColor(147, 148, 248, 0.2)];
[[YMThemeMgr shareInstance] changeTheme:arg1 color:kMainSeperatorColor];
[self hook_setSeperator:arg1];
}

Expand All @@ -254,12 +260,30 @@ - (void)hook_sessionPickerWindowDidLoad

- (void)hook_setPreferredDividerColor:(NSColor *)arg1
{
[self hook_setPreferredDividerColor:kRGBColor(71, 69, 112, 0.5)];
[self hook_setPreferredDividerColor:kMainDividerColor];
}

- (void)hook_composeSetTextColor:(NSColor *)color
{
[self hook_composeSetTextColor:[NSColor whiteColor]];
// 联系人介绍 What's up
[self hook_composeSetTextColor:kMainTextColor];
}

- (NSColor *)hook_referNormalColor
{
return kRGBColor(160, 180, 200, 1);
}

- (NSColor *)hook_referHighlightColor
{
return NSColor.lightGrayColor;
}

- (void) hook_referSetBgView: (NSView *) view
{
[self hook_referSetBgView:view];

view.layer.backgroundColor = kRGBColor(160, 180, 200, 1).CGColor;
}

- (void)hook_memberListViewDidLoad
Expand Down Expand Up @@ -334,29 +358,32 @@ - (void)hook_updateNickName
NSMutableAttributedString *returnValue = [[NSMutableAttributedString alloc] initWithString:str.string attributes:@{NSForegroundColorAttributeName :kRGBColor(255, 255, 255, 1.0), NSFontAttributeName : attributesFont}];
cell.nickName.attributedStringValue = returnValue;

if ([TKWeChatPluginConfig sharedConfig].darkMode) {
[[YMThemeManager shareInstance] changeTheme:cell color:kRGBColor(33, 48, 64, 1.0)];
if ([TKWeChatPluginConfig sharedConfig].usingDarkTheme) {
// MARK: - 点击对框列表之后,无法显示该对话框处于选择状态,故注释掉
// [[YMThemeMgr shareInstance] changeTheme:cell.containerView color:kRGBColor(56, 70, 92, 1.0)];
cell.muteIndicator.normalColor = [NSColor redColor];
}
}

- (void)hook_mouseDown:(id)arg1
{
[self hook_mouseDown:arg1];
MMChatsTableCellView *cell = (MMChatsTableCellView *)self;

if ([TKWeChatPluginConfig sharedConfig].usingDarkTheme) {

NSColor *highColor = nil;
if (cell.selected) {
highColor = kRGBColor(147, 148, 248, 0.5);
} else {
[TKWeChatPluginConfig sharedConfig].darkMode ? highColor = kRGBColor(33, 48, 64, 1.0) : [NSColor clearColor];
}
cell.layer.backgroundColor = highColor.CGColor;
[cell setNeedsDisplay:YES];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
cell.layer.backgroundColor = [TKWeChatPluginConfig sharedConfig].darkMode ? kRGBColor(33, 48, 64, 1.0).CGColor : [NSColor clearColor].CGColor;
MMChatsTableCellView *cell = (MMChatsTableCellView *)self;

NSColor *original = [NSColor colorWithCGColor:cell.layer.backgroundColor];
cell.layer.backgroundColor = (TKWeChatPluginConfig.sharedConfig.blackMode ? kRGBColor(128,128,128, 0.5) : kRGBColor(147, 148, 248, 0.5)).CGColor;
[cell setNeedsDisplay:YES];
});
// MARK: - 点击对框列表之后,恢复之前状态
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
cell.layer.backgroundColor = original.CGColor;
[cell setNeedsDisplay:YES];
});
}


}

- (void)hook_setAttributedStringValue:(NSAttributedString *)arg1
Expand Down Expand Up @@ -437,14 +464,14 @@ - (void)hook_ComposeInputViewControllerViewDidLoad
MMComposeInputViewController *controller = (MMComposeInputViewController *)self;
[[YMThemeManager shareInstance] changeTheme:controller.view];

if ([TKWeChatPluginConfig sharedConfig].darkMode) {
if ([TKWeChatPluginConfig sharedConfig].usingDarkTheme) {
for (NSView *sub in controller.view.subviews) {
if ([sub isKindOfClass:objc_getClass("SVGButton")]) {
NSButton *button = (NSButton *)sub;
NSImage *tempImage = button.image;
button.image = button.alternateImage;
button.alternateImage = tempImage;
button.alphaValue = 0.5;
button.alphaValue = TKWeChatPluginConfig.sharedConfig.darkMode ? 0.5 : 0.7;
}
}
}
Expand Down
Loading

0 comments on commit dd140b3

Please sign in to comment.