Fixed potential crash on exit

This commit is contained in:
Sunnyyoung 2017-12-10 17:20:10 +08:00
parent 701b8a3ad0
commit b41fb3910d
4 changed files with 20 additions and 12 deletions

View File

@ -3,7 +3,7 @@
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>BuildMachineOSBuild</key> <key>BuildMachineOSBuild</key>
<string>17A365</string> <string>17C88</string>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>
<string>en</string> <string>en</string>
<key>CFBundleExecutable</key> <key>CFBundleExecutable</key>
@ -27,17 +27,17 @@
<key>DTCompiler</key> <key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string> <string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key> <key>DTPlatformBuild</key>
<string>9A235</string> <string>9C40b</string>
<key>DTPlatformVersion</key> <key>DTPlatformVersion</key>
<string>GM</string> <string>GM</string>
<key>DTSDKBuild</key> <key>DTSDKBuild</key>
<string>17A360</string> <string>17C76</string>
<key>DTSDKName</key> <key>DTSDKName</key>
<string>macosx10.13</string> <string>macosx10.13</string>
<key>DTXcode</key> <key>DTXcode</key>
<string>0900</string> <string>0920</string>
<key>DTXcodeBuild</key> <key>DTXcodeBuild</key>
<string>9A235</string> <string>9C40b</string>
<key>NSHumanReadableCopyright</key> <key>NSHumanReadableCopyright</key>
<string>Copyright © 2017年 Sunnyyoung. All rights reserved.</string> <string>Copyright © 2017年 Sunnyyoung. All rights reserved.</string>
</dict> </dict>

View File

@ -46,7 +46,7 @@ static void __attribute__((constructor)) tweak(void) {
// Method Swizzling // Method Swizzling
class_addMethod(objc_getClass("AppDelegate"), @selector(applicationDockMenu:), method_getImplementation(class_getInstanceMethod(objc_getClass("AppDelegate"), @selector(tweak_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(@"applicationDidFinishLaunching:") withMethod:@selector(tweak_applicationDidFinishLaunching:) error:nil];
[objc_getClass("AppDelegate") jr_swizzleMethod:NSSelectorFromString(@"applicationShouldTerminate:") withMethod:@selector(tweak_applicationShouldTerminate:) error:nil]; [objc_getClass("LogoutCGI") jr_swizzleMethod:NSSelectorFromString(@"sendLogoutCGIWithCompletion:") withMethod:@selector(tweak_sendLogoutCGIWithCompletion:) error:nil];
[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]; [objc_getClass("CUtility") jr_swizzleClassMethod:NSSelectorFromString(@"HasWechatInstance") withClassMethod:@selector(tweak_HasWechatInstance) error:nil];
[objc_getClass("MASPreferencesWindowController") jr_swizzleMethod:NSSelectorFromString(@"initWithViewControllers:") withMethod:@selector(tweak_initWithViewControllers:) error:nil]; [objc_getClass("MASPreferencesWindowController") jr_swizzleMethod:NSSelectorFromString(@"initWithViewControllers:") withMethod:@selector(tweak_initWithViewControllers:) error:nil];
@ -153,13 +153,13 @@ static void __attribute__((constructor)) tweak(void) {
[[AlfredManager sharedInstance] startListener]; [[AlfredManager sharedInstance] startListener];
} }
- (NSApplicationTerminateReply)tweak_applicationShouldTerminate:(NSApplication *)sender { - (void)tweak_sendLogoutCGIWithCompletion:(id)completion {
BOOL enabledAutoAuth = [[NSUserDefaults standardUserDefaults] boolForKey:WeChatTweakPreferenceAutoAuthKey]; BOOL enabledAutoAuth = [[NSUserDefaults standardUserDefaults] boolForKey:WeChatTweakPreferenceAutoAuthKey];
if (enabledAutoAuth) { WeChat *wechat = [objc_getClass("WeChat") sharedInstance];
return NSTerminateNow; if (enabledAutoAuth && wechat.isAppTerminating) {
} else { return;
return [self tweak_applicationShouldTerminate:sender];
} }
[self tweak_sendLogoutCGIWithCompletion:completion];
} }
#pragma mark - Preferences Window #pragma mark - Preferences Window

View File

@ -11,6 +11,8 @@
@interface WeChat : NSObject @interface WeChat : NSObject
@property(nonatomic) BOOL isAppTerminating;
+ (instancetype)sharedInstance; + (instancetype)sharedInstance;
- (void)lock:(id)block; - (void)lock:(id)block;
- (void)showMainWindow; - (void)showMainWindow;
@ -92,6 +94,12 @@
@end @end
@interface LogoutCGI: NSObject
- (void)sendLogoutCGIWithCompletion:(id)arg1;
@end
@protocol MASPreferencesViewController <NSObject> @protocol MASPreferencesViewController <NSObject>
@property(readonly, nonatomic) NSString *toolbarItemLabel; @property(readonly, nonatomic) NSString *toolbarItemLabel;
@ -104,7 +112,7 @@
@end @end
@interface MASPreferencesWindowController : NSWindowController @interface MASPreferencesWindowController: NSWindowController
- (id)initWithViewControllers:(NSArray *)arg1; - (id)initWithViewControllers:(NSArray *)arg1;