diff --git a/README-Chinese.md b/README-Chinese.md index 50e0691..2fb33b7 100644 --- a/README-Chinese.md +++ b/README-Chinese.md @@ -17,6 +17,7 @@ - 客户端无限多开 - 右键 Dock Icon 登录新的微信账号 - 命令行执行:`open -n /Applications/WeChat.app` +- 阻止退出登录(重新打开应用无需手机认证) ## 使用 diff --git a/README.md b/README.md index e672732..bb18e3f 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ A dynamic library tweak for WeChat macOS. - Multiple WeChat Instance - Right click on the Dock icon to login another WeChat account - Run command: `open -n /Applications/WeChat.app` +- Prevent logout (Auto login without authority) ## Usage diff --git a/WeChatTweak.dylib b/WeChatTweak.dylib index 4ab4827..0927196 100755 Binary files a/WeChatTweak.dylib and b/WeChatTweak.dylib differ diff --git a/WeChatTweak.m b/WeChatTweak.m index bcc67fc..81f996a 100755 --- a/WeChatTweak.m +++ b/WeChatTweak.m @@ -9,14 +9,16 @@ #pragma mark - Constructor static void __attribute__((constructor)) tweak(void) { - [objc_getClass("MessageService") jr_swizzleMethod:NSSelectorFromString(@"onRevokeMsg:") withMethod:@selector(tweak_OnRevokeMsg:) error:nil]; + [objc_getClass("MessageService") jr_swizzleMethod:NSSelectorFromString(@"onRevokeMsg:") withMethod:@selector(tweak_onRevokeMsg:) error:nil]; [objc_getClass("CUtility") jr_swizzleClassMethod:NSSelectorFromString(@"HasWechatInstance") withClassMethod:@selector(tweak_HasWechatInstance) error:nil]; - class_addMethod(objc_getClass("AppDelegate"), @selector(applicationDockMenu:), method_getImplementation(class_getInstanceMethod(objc_getClass("AppDelegate"), @selector(applicationDockMenu:))), "@:@"); + 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("AppDelegate") jr_swizzleMethod:NSSelectorFromString(@"applicationShouldTerminate:") withMethod:@selector(tweak_applicationShouldTerminate:) error:nil]; } #pragma mark - No Revoke Message -- (void)tweak_OnRevokeMsg:(NSString *)message { +- (void)tweak_onRevokeMsg:(NSString *)message { NSRange begin = [message rangeOfString:@""]; NSRange subRange = NSMakeRange(begin.location + begin.length,end.location - begin.location - begin.length); @@ -34,7 +36,7 @@ static void __attribute__((constructor)) tweak(void) { return NO; } -- (NSMenu *)applicationDockMenu:(NSApplication *)sender { +- (NSMenu *)tweak_applicationDockMenu:(NSApplication *)sender { NSMenu *menu = [[objc_getClass("NSMenu") alloc] init]; NSMenuItem *menuItem = [[objc_getClass("NSMenuItem") alloc] initWithTitle:@"登录新的微信账号" action:@selector(openNewWeChatInstace:) keyEquivalent:@""]; [menu insertItem:menuItem atIndex:0]; @@ -49,4 +51,22 @@ static void __attribute__((constructor)) tweak(void) { [task launch]; } +#pragma mark - No Logout + +- (void)tweak_applicationDidFinishLaunching:(NSNotification *)notification { + [self tweak_applicationDidFinishLaunching:notification]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wobjc-method-access" + id serviceCenter = [objc_getClass("MMServiceCenter") defaultCenter]; + id accountService = [serviceCenter getService:objc_getClass("AccountService")]; + if ([accountService canAutoAuth]) { + [accountService AutoAuth]; + } +#pragma clang diagnostic pop +} + +- (NSApplicationTerminateReply)tweak_applicationShouldTerminate:(NSApplication *)sender { + return NSTerminateNow; +} + @end