Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
yanmao committed Apr 29, 2020
1 parent b5c3ac1 commit a8b324f
Show file tree
Hide file tree
Showing 24 changed files with 244 additions and 201 deletions.
172 changes: 85 additions & 87 deletions WeChatExtension/WeChatExtension.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
#import "NSDate+Action.h"
#import "NSWindowController+Action.h"
#import "WeChatPlugin.h"
#import "YMUtility.h"
#import "YMDeviceHelper.h"

#import "TKWeChatPluginConfig.h"
#import "YMHelper.h"
#import "YMSwizzledHelper.h"
#endif

#define kRGBColor(r,g,b,a) [NSColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface YMDeviceHelper : NSObject
+ (BOOL)isLargerOrEqualVersion:(NSString *)version;
+ (BOOL)isLargeOrEqualLongVersion:(NSString *)version;
+ (NSString *)deviceFingerprint;
@end

NS_ASSUME_NONNULL_END
12 changes: 12 additions & 0 deletions WeChatExtension/WeChatExtension/Sources/Helper/YMDeviceHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,16 @@ + (BOOL)isLargeOrEqualLongVersion:(NSString *)version
return YES;
}
}

+ (NSString *)deviceFingerprint
{
CFUUIDRef uuidRef = CFUUIDCreate(NULL);
CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef);
CFRelease(uuidRef);

NSString *uuidValue = (__bridge_transfer NSString *)uuidStringRef;
uuidValue = [uuidValue lowercaseString];
uuidValue = [uuidValue stringByReplacingOccurrencesOfString:@"-" withString:@""];
return uuidValue;
}
@end
68 changes: 34 additions & 34 deletions WeChatExtension/WeChatExtension/Sources/Hook/NSObject+ThemeHook.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#import <dlfcn.h>
#import <QuartzCore/QuartzCore.h>
#import <AppKit/AppKit.h>
#import "YMThemeMgr.h"
#import "YMThemeManager.h"

@interface NSCellAuxiliary : NSObject

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

if ([TKWeChatPluginConfig sharedConfig].darkMode) {
for (NSView *sub in alert.window.contentView.subviews) {
Expand All @@ -227,7 +227,7 @@ - (void)hook_setMessageText:(id)arg1

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

Expand All @@ -240,15 +240,15 @@ - (void)hook_globalChatManagerWindowDidLoad
{
[self hook_globalChatManagerWindowDidLoad];
NSViewController *viewController = (NSViewController *)self;
[[YMThemeMgr shareInstance] changeTheme:viewController.view];
[[YMThemeManager shareInstance] changeTheme:viewController.view];
}

- (void)hook_sessionPickerWindowDidLoad
{
[self hook_sessionPickerWindowDidLoad];
MMSessionPickerWindow *window = (MMSessionPickerWindow *)self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[[YMThemeMgr shareInstance] changeTheme:window.window.contentView];
[[YMThemeManager shareInstance] changeTheme:window.window.contentView];
});
}

Expand All @@ -270,7 +270,7 @@ - (void)hook_memberListViewDidLoad
for (NSView *effect in sub.subviews) {
if ([effect isKindOfClass:NSVisualEffectView.class]) {
for (NSView *effectSub in effect.subviews) {
[[YMThemeMgr shareInstance] changeTheme:effectSub];
[[YMThemeManager shareInstance] changeTheme:effectSub];
}
break;
}
Expand All @@ -283,15 +283,15 @@ - (void)hook_preferencesWindowDidLoad
[self hook_preferencesWindowDidLoad];
MMPreferencesWindowController *window = (MMPreferencesWindowController *)self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[[YMThemeMgr shareInstance] changeTheme:window.window.contentView];
[[YMThemeManager shareInstance] changeTheme:window.window.contentView];
});
}

- (void)hook_fileListViewDidLoad
{
[self hook_fileListViewDidLoad];
MMFileListViewController *fileListVC = (MMFileListViewController *)self;
[[YMThemeMgr shareInstance] changeTheme:fileListVC.view];
[[YMThemeManager shareInstance] changeTheme:fileListVC.view];
}

- (void)hook_windowDidLoad
Expand All @@ -303,13 +303,13 @@ - (void)hook_windowDidLoad
}

NSWindowController *window = (NSWindowController *)self;
[[YMThemeMgr shareInstance] changeTheme:window.window.contentView];
[[YMThemeManager shareInstance] changeTheme:window.window.contentView];

if ([self isKindOfClass:objc_getClass("MMGlobalChatManagerWindowController")]) {
MMGlobalChatManagerWindowController *window = (MMGlobalChatManagerWindowController *)self;
for (NSView *sub in window.window.contentView.subviews) {
if (![sub isKindOfClass:objc_getClass("MMCustomSearchField")]) {
[[YMThemeMgr shareInstance] changeTheme:sub];
[[YMThemeManager shareInstance] changeTheme:sub];
}
}
}
Expand All @@ -320,7 +320,7 @@ - (void)hook_showWindow:(nullable id)sender
{
[self hook_showWindow:sender];
NSWindowController *window = (NSWindowController *)self;
[[YMThemeMgr shareInstance] changeTheme:window.window.contentView];
[[YMThemeManager shareInstance] changeTheme:window.window.contentView];
}

- (void)hook_updateNickName
Expand All @@ -335,7 +335,7 @@ - (void)hook_updateNickName
cell.nickName.attributedStringValue = returnValue;

if ([TKWeChatPluginConfig sharedConfig].darkMode) {
[[YMThemeMgr shareInstance] changeTheme:cell color:kRGBColor(33, 48, 64, 1.0)];
[[YMThemeManager shareInstance] changeTheme:cell color:kRGBColor(33, 48, 64, 1.0)];
cell.muteIndicator.normalColor = [NSColor redColor];
}
}
Expand Down Expand Up @@ -406,7 +406,7 @@ - (void)hook_loginWaitingViewDidLoad

if ([self.className isEqualToString:@"MMLoginWaitingConfirmViewController"]) {
MMLoginWaitingConfirmViewController *loginWaitVC = (MMLoginWaitingConfirmViewController *)self;
[[YMThemeMgr shareInstance] changeTheme:loginWaitVC.view];
[[YMThemeManager shareInstance] changeTheme:loginWaitVC.view];
}
}

Expand All @@ -422,7 +422,7 @@ - (void)hook_setTextColor:(NSColor *)arg1
- (instancetype)hook_scrollViewInitWithFrame:(NSRect)frameRect
{
NSScrollView *view = (NSScrollView *)self;
[[YMThemeMgr shareInstance] changeTheme:view.contentView];
[[YMThemeManager shareInstance] changeTheme:view.contentView];
return [self hook_scrollViewInitWithFrame:frameRect];
}

Expand All @@ -435,7 +435,7 @@ - (void)hook_ComposeInputViewControllerViewDidLoad
{
[self hook_ComposeInputViewControllerViewDidLoad];
MMComposeInputViewController *controller = (MMComposeInputViewController *)self;
[[YMThemeMgr shareInstance] changeTheme:controller.view];
[[YMThemeManager shareInstance] changeTheme:controller.view];

if ([TKWeChatPluginConfig sharedConfig].darkMode) {
for (NSView *sub in controller.view.subviews) {
Expand Down Expand Up @@ -516,32 +516,32 @@ - (void)hook_addSubView:(NSView *)view
}

if ([view isKindOfClass:[objc_getClass("NewNoteContentView") class]]) {
[[YMThemeMgr shareInstance] changeTheme:view];
[[YMThemeManager shareInstance] changeTheme:view];
}

#pragma mark - view
if ([view isKindOfClass:[objc_getClass("MMSessionPickerListGroupRowView") class]]) {
for (NSView *sub in view.subviews) {
if (![sub isKindOfClass:[NSTextField class]]) {
[[YMThemeMgr shareInstance] changeTheme:sub];
[[YMThemeManager shareInstance] changeTheme:sub];
}
}
}

if ([view isKindOfClass:[objc_getClass("MMOutlineButton") class]]) {
[[YMThemeMgr shareInstance] changeTheme:view];
[[YMThemeManager shareInstance] changeTheme:view];
}

if ([view isKindOfClass:[objc_getClass("JNWClipView") class]]) {
[[YMThemeMgr shareInstance] changeTheme:view];
[[YMThemeManager shareInstance] changeTheme:view];
}

if ([view isKindOfClass:[objc_getClass("_NSBrowserFlippedClipView") class]]) {
[[YMThemeMgr shareInstance] changeTheme:view];
[[YMThemeManager shareInstance] changeTheme:view];
}

if ([view isKindOfClass:[objc_getClass("NSClipView") class]]) {
[[YMThemeMgr shareInstance] changeTheme:view];
[[YMThemeManager shareInstance] changeTheme:view];
}


Expand All @@ -563,39 +563,39 @@ - (void)hook_addSubView:(NSView *)view
}

if ([view isKindOfClass:[objc_getClass("SwipeDeleteView") class]]) {
[[YMThemeMgr shareInstance] changeTheme:view];
[[YMThemeManager shareInstance] changeTheme:view];
}


if ([view isKindOfClass:[objc_getClass("MMFavoritesListMediaCell") class]]) {
for (NSView *sub in view.subviews) {
[[YMThemeMgr shareInstance] changeTheme:sub];
[[YMThemeManager shareInstance] changeTheme:sub];
}
}


if ([view isKindOfClass:[objc_getClass("MMFavoritesListTextCell") class]]) {
for (NSView *sub in view.subviews) {
[[YMThemeMgr shareInstance] changeTheme:sub];
[[YMThemeManager shareInstance] changeTheme:sub];
}
}

if ([view isKindOfClass:[objc_getClass("MMFavoritesListNoteCell") class]]) {
for (NSView *sub in view.subviews) {
[[YMThemeMgr shareInstance] changeTheme:sub];
[[YMThemeManager shareInstance] changeTheme:sub];
}
}

//公众号
if ([view isKindOfClass:[objc_getClass("MMDragEventView") class]]) {
dispatch_async(dispatch_get_main_queue(), ^{
if (![view.superview isKindOfClass:objc_getClass("MMQLPreviewView")]) {
[[YMThemeMgr shareInstance] changeTheme:view];
[[YMThemeManager shareInstance] changeTheme:view];
for (NSView *effect in view.subviews) {
if ([effect isKindOfClass:NSVisualEffectView.class]) {
for (NSView *effectSub in effect.subviews) {
if (![effectSub isKindOfClass:NSTextField.class]) {
[[YMThemeMgr shareInstance] changeTheme:effectSub];
[[YMThemeManager shareInstance] changeTheme:effectSub];
break;
}
}
Expand All @@ -610,26 +610,26 @@ - (void)hook_addSubView:(NSView *)view
[msgViewController.messageTableView setBackgroundColor:kMainBackgroundColor];
[[msgViewController.messageTableView enclosingScrollView] setDrawsBackground:NO];
if (![view isKindOfClass:objc_getClass("NSTextField")]) {
[[YMThemeMgr shareInstance] changeTheme:view];
[[YMThemeManager shareInstance] changeTheme:view];
}
}

if ([controller isKindOfClass:[objc_getClass("MMFavoriteDetailViewContoller") class]]) {
[[YMThemeMgr shareInstance] changeTheme:view];
[[YMThemeManager shareInstance] changeTheme:view];
}

if ([controller isKindOfClass:[objc_getClass("MMComposeInputViewController") class]]) {
[[YMThemeMgr shareInstance] changeTheme:view];
[[YMThemeManager shareInstance] changeTheme:view];
}

if ([controller isKindOfClass:[objc_getClass("MMMainViewController") class]]) {
if (![view isKindOfClass:objc_getClass("_NSImageViewSimpleImageView")]) {
[[YMThemeMgr shareInstance] changeTheme:view];
[[YMThemeManager shareInstance] changeTheme:view];
}
}

if ([controller isKindOfClass:[objc_getClass("MMContactsDetailViewController") class]]) {
[[YMThemeMgr shareInstance] changeTheme:view];
[[YMThemeManager shareInstance] changeTheme:view];
}
}

Expand Down Expand Up @@ -660,7 +660,7 @@ - (void)hook_themeViewDidLoad
}

NSViewController *viewController = (NSViewController *)self;
[[YMThemeMgr shareInstance] changeTheme:viewController.view];
[[YMThemeManager shareInstance] changeTheme:viewController.view];
}

@end
Loading

0 comments on commit a8b324f

Please sign in to comment.