mirror of
https://github.com/Sunnyyoung/WeChatTweak-macOS.git
synced 2026-07-28 22:14:33 +08:00
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// AutoAuth.h
|
||||
// WeChatTweak
|
||||
//
|
||||
// Created by Sunny Young on 2021/5/8.
|
||||
// Copyright © 2021 Sunnyyoung. All rights reserved.
|
||||
//
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
#import <objc/runtime.h>
|
||||
#import <objc/message.h>
|
||||
#import <JRSwizzle/JRSwizzle.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface NSObject (AutoAuth)
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// AutoAuth.m
|
||||
// WeChatTweak
|
||||
//
|
||||
// Created by Sunny Young on 2021/5/8.
|
||||
// Copyright © 2021 Sunnyyoung. All rights reserved.
|
||||
//
|
||||
|
||||
#import "AutoAuth.h"
|
||||
#import "WeChatTweakHeaders.h"
|
||||
#import "WTConfigManager.h"
|
||||
|
||||
@implementation NSObject(AutoAuth)
|
||||
|
||||
static void __attribute__((constructor)) tweak(void) {
|
||||
[objc_getClass("MMLoginOneClickViewController") jr_swizzleMethod:NSSelectorFromString(@"onLoginButtonClicked:") withMethod:@selector(tweak_onLoginButtonClicked:) error:nil];
|
||||
[objc_getClass("MMMainViewController") jr_swizzleMethod:NSSelectorFromString(@"viewDidLoad") withMethod:@selector(tweak_viewDidLoad) error:nil];
|
||||
[objc_getClass("LogoutCGI") jr_swizzleMethod:NSSelectorFromString(@"FFVCRecvDataAddDataToMsgChatMgrRecvZZ:") withMethod:@selector(tweak_FFVCRecvDataAddDataToMsgChatMgrRecvZZ:) error:nil];
|
||||
[objc_getClass("AccountService") jr_swizzleMethod:NSSelectorFromString(@"FFAddSvrMsgImgVCZZ") withMethod:@selector(tweak_FFAddSvrMsgImgVCZZ) error:nil];
|
||||
}
|
||||
|
||||
- (void)tweak_onLoginButtonClicked:(id)sender {
|
||||
AccountService *accountService = [[objc_getClass("MMServiceCenter") defaultCenter] getService:objc_getClass("AccountService")];
|
||||
BOOL enabledAutoAuth = [NSUserDefaults.standardUserDefaults boolForKey:WeChatTweakPreferenceAutoAuthKey];
|
||||
BOOL canAutoAuth = accountService.canAutoAuth;
|
||||
if (enabledAutoAuth && canAutoAuth) {
|
||||
[accountService AutoAuth];
|
||||
} else {
|
||||
[self tweak_onLoginButtonClicked:sender];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)tweak_viewDidLoad {
|
||||
[self tweak_viewDidLoad];
|
||||
if ([NSUserDefaults.standardUserDefaults boolForKey:WeChatTweakPreferenceAutoAuthKey]) {
|
||||
MMSessionMgr *mgr = [[objc_getClass("MMServiceCenter") defaultCenter] getService:objc_getClass("MMSessionMgr")];
|
||||
[mgr loadSessionData];
|
||||
[mgr loadBrandSessionData];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)tweak_FFVCRecvDataAddDataToMsgChatMgrRecvZZ:(id)arg {
|
||||
if (![NSUserDefaults.standardUserDefaults boolForKey:WeChatTweakPreferenceAutoAuthKey]) {
|
||||
[self tweak_FFVCRecvDataAddDataToMsgChatMgrRecvZZ:arg];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)tweak_FFAddSvrMsgImgVCZZ {
|
||||
if ([NSUserDefaults.standardUserDefaults boolForKey:WeChatTweakPreferenceAutoAuthKey]) {
|
||||
return;
|
||||
} else {
|
||||
[self tweak_FFAddSvrMsgImgVCZZ];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -8,15 +8,6 @@
|
||||
|
||||
#import "WeChatTweakHeaders.h"
|
||||
|
||||
typedef NS_ENUM(NSUInteger, RevokeNotificationType) {
|
||||
RevokeNotificationTypeFollow = 0,
|
||||
RevokeNotificationTypeReceiveAll,
|
||||
RevokeNotificationTypeDisable,
|
||||
};
|
||||
|
||||
static NSString * const WeChatTweakPreferenceAutoAuthKey = @"WeChatTweakPreferenceAutoAuthKey";
|
||||
static NSString * const WeChatTweakPreferenceRevokeNotificationTypeKey = @"WeChatTweakPreferenceRevokeNotificationTypeKey";
|
||||
|
||||
@interface TweakPreferencesController : NSViewController
|
||||
|
||||
@end
|
||||
|
||||
@@ -11,6 +11,12 @@
|
||||
#import <objc/runtime.h>
|
||||
#import <objc/message.h>
|
||||
|
||||
typedef NS_ENUM(NSUInteger, RevokeNotificationType) {
|
||||
RevokeNotificationTypeFollow = 0,
|
||||
RevokeNotificationTypeReceiveAll,
|
||||
RevokeNotificationTypeDisable,
|
||||
};
|
||||
|
||||
typedef NS_ENUM(unsigned int, MessageDataType) {
|
||||
MessageDataTypeText = 1,
|
||||
MessageDataTypeImage = 3,
|
||||
@@ -21,6 +27,9 @@ typedef NS_ENUM(unsigned int, MessageDataType) {
|
||||
MessageDataTypePrompt = 10000
|
||||
};
|
||||
|
||||
static NSString * const WeChatTweakPreferenceAutoAuthKey = @"WeChatTweakPreferenceAutoAuthKey";
|
||||
static NSString * const WeChatTweakPreferenceRevokeNotificationTypeKey = @"WeChatTweakPreferenceRevokeNotificationTypeKey";
|
||||
|
||||
@interface NSString (MD5)
|
||||
|
||||
- (NSString *)md5String;
|
||||
@@ -29,8 +38,6 @@ typedef NS_ENUM(unsigned int, MessageDataType) {
|
||||
|
||||
@interface WeChat : NSObject
|
||||
|
||||
@property(nonatomic) BOOL isAppTerminating;
|
||||
|
||||
+ (instancetype)sharedInstance;
|
||||
- (void)lock:(id)block;
|
||||
- (void)showMainWindow;
|
||||
@@ -112,13 +119,6 @@ typedef NS_ENUM(unsigned int, MessageDataType) {
|
||||
|
||||
- (BOOL)canAutoAuth;
|
||||
- (void)AutoAuth;
|
||||
- (void)onAuthOKOfUser:(id)arg1 withSessionKey:(id)arg2 withServerId:(id)arg3 autoAuthKey:(id)arg4 isAutoAuth:(BOOL)arg5;
|
||||
|
||||
@end
|
||||
|
||||
@interface LogoutCGI: NSObject
|
||||
|
||||
- (void)sendLogoutCGIWithCompletion:(id)arg1;
|
||||
|
||||
@end
|
||||
|
||||
@@ -128,6 +128,13 @@ typedef NS_ENUM(unsigned int, MessageDataType) {
|
||||
|
||||
@end
|
||||
|
||||
@interface MMSessionMgr: NSObject
|
||||
|
||||
- (void)loadSessionData;
|
||||
- (void)loadBrandSessionData;
|
||||
|
||||
@end
|
||||
|
||||
@protocol MASPreferencesViewController <NSObject>
|
||||
|
||||
@property(readonly, nonatomic) NSString *toolbarItemLabel;
|
||||
|
||||
@@ -53,11 +53,6 @@ static void __attribute__((constructor)) tweak(void) {
|
||||
// Method Swizzling
|
||||
class_addMethod(objc_getClass("AppDelegate"), @selector(applicationDockMenu:), method_getImplementation(class_getInstanceMethod(objc_getClass("AppDelegate"), @selector(tweak_applicationDockMenu:))), "@:@");
|
||||
[objc_getClass("AppDelegate") jr_swizzleMethod:NSSelectorFromString(@"applicationDidFinishLaunching:") withMethod:@selector(tweak_applicationDidFinishLaunching:) error:nil];
|
||||
[objc_getClass("LogoutCGI") jr_swizzleMethod:NSSelectorFromString(@"sendLogoutCGIWithCompletion:") withMethod:@selector(tweak_sendLogoutCGIWithCompletion:) error:nil];
|
||||
[objc_getClass("LogoutCGI") jr_swizzleMethod:NSSelectorFromString(@"FFVCRecvDataAddDataToMsgChatMgrRecvZZ:") withMethod:@selector(tweak_sendLogoutCGIWithCompletion:) error:nil];
|
||||
[objc_getClass("AccountService") jr_swizzleMethod:NSSelectorFromString(@"onAuthOKOfUser:withSessionKey:withServerId:autoAuthKey:isAutoAuth:") withMethod:@selector(tweak_onAuthOKOfUser:withSessionKey:withServerId:autoAuthKey:isAutoAuth:) error:nil];
|
||||
[objc_getClass("AccountService") jr_swizzleMethod:NSSelectorFromString(@"ManualLogout") withMethod:@selector(tweak_ManualLogout) error:nil];
|
||||
[objc_getClass("AccountService") jr_swizzleMethod:NSSelectorFromString(@"FFAddSvrMsgImgVCZZ") withMethod:@selector(tweak_ManualLogout) error:nil];
|
||||
[objc_getClass("MessageService") jr_swizzleMethod:NSSelectorFromString(@"onRevokeMsg:") withMethod:@selector(tweak_onRevokeMsg:) error:nil];
|
||||
[objc_getClass("MessageService") jr_swizzleMethod:NSSelectorFromString(@"FFToNameFavChatZZ:") withMethod:@selector(tweak_onRevokeMsg:) error:nil];
|
||||
[objc_getClass("MessageService") jr_swizzleMethod:NSSelectorFromString(@"FFToNameFavChatZZ:sessionMsgList:") withMethod:@selector(tweak_onRevokeMsg:sessionMessageList:) error:nil];
|
||||
@@ -435,42 +430,11 @@ static void __attribute__((constructor)) tweak(void) {
|
||||
[task waitUntilExit];
|
||||
}
|
||||
|
||||
#pragma mark - Auto Auth
|
||||
#pragma mark - Alfred
|
||||
|
||||
- (void)tweak_applicationDidFinishLaunching:(NSNotification *)notification {
|
||||
[AlfredManager.sharedInstance startListener];
|
||||
[self tweak_applicationDidFinishLaunching:notification];
|
||||
NSString *bundleIdentifier = NSBundle.mainBundle.bundleIdentifier;
|
||||
NSArray *instances = [NSRunningApplication tweak_runningApplicationsWithBundleIdentifier:bundleIdentifier];
|
||||
// Detect multiple instance conflict
|
||||
BOOL hasInstance = instances.count == 1;
|
||||
BOOL enabledAutoAuth = [[NSUserDefaults standardUserDefaults] boolForKey:WeChatTweakPreferenceAutoAuthKey];
|
||||
if (hasInstance && enabledAutoAuth) {
|
||||
AccountService *accountService = [[objc_getClass("MMServiceCenter") defaultCenter] getService:objc_getClass("AccountService")];
|
||||
if ([accountService canAutoAuth]) {
|
||||
[accountService AutoAuth];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)tweak_onAuthOKOfUser:(id)arg1 withSessionKey:(id)arg2 withServerId:(id)arg3 autoAuthKey:(id)arg4 isAutoAuth:(BOOL)arg5 {
|
||||
[[AlfredManager sharedInstance] startListener];
|
||||
[self tweak_onAuthOKOfUser:arg1 withSessionKey:arg2 withServerId:arg3 autoAuthKey:arg4 isAutoAuth:arg5];
|
||||
}
|
||||
|
||||
- (void)tweak_sendLogoutCGIWithCompletion:(id)completion {
|
||||
BOOL enabledAutoAuth = [[NSUserDefaults standardUserDefaults] boolForKey:WeChatTweakPreferenceAutoAuthKey];
|
||||
WeChat *wechat = [objc_getClass("WeChat") sharedInstance];
|
||||
if (enabledAutoAuth && wechat.isAppTerminating) {
|
||||
return;
|
||||
}
|
||||
[self tweak_sendLogoutCGIWithCompletion:completion];
|
||||
}
|
||||
|
||||
- (void)tweak_ManualLogout {
|
||||
BOOL enabledAutoAuth = [[NSUserDefaults standardUserDefaults] boolForKey:WeChatTweakPreferenceAutoAuthKey];
|
||||
if (!enabledAutoAuth) {
|
||||
[self tweak_ManualLogout];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Preferences Window
|
||||
|
||||
Reference in New Issue
Block a user