mirror of
https://github.com/Sunnyyoung/WeChatTweak-macOS.git
synced 2026-07-29 06:24:31 +08:00
Fixed potential crash on exit
This commit is contained in:
@@ -46,7 +46,7 @@ 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("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("CUtility") jr_swizzleClassMethod:NSSelectorFromString(@"HasWechatInstance") withClassMethod:@selector(tweak_HasWechatInstance) 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];
|
||||
}
|
||||
|
||||
- (NSApplicationTerminateReply)tweak_applicationShouldTerminate:(NSApplication *)sender {
|
||||
- (void)tweak_sendLogoutCGIWithCompletion:(id)completion {
|
||||
BOOL enabledAutoAuth = [[NSUserDefaults standardUserDefaults] boolForKey:WeChatTweakPreferenceAutoAuthKey];
|
||||
if (enabledAutoAuth) {
|
||||
return NSTerminateNow;
|
||||
} else {
|
||||
return [self tweak_applicationShouldTerminate:sender];
|
||||
WeChat *wechat = [objc_getClass("WeChat") sharedInstance];
|
||||
if (enabledAutoAuth && wechat.isAppTerminating) {
|
||||
return;
|
||||
}
|
||||
[self tweak_sendLogoutCGIWithCompletion:completion];
|
||||
}
|
||||
|
||||
#pragma mark - Preferences Window
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
|
||||
@interface WeChat : NSObject
|
||||
|
||||
@property(nonatomic) BOOL isAppTerminating;
|
||||
|
||||
+ (instancetype)sharedInstance;
|
||||
- (void)lock:(id)block;
|
||||
- (void)showMainWindow;
|
||||
@@ -92,6 +94,12 @@
|
||||
|
||||
@end
|
||||
|
||||
@interface LogoutCGI: NSObject
|
||||
|
||||
- (void)sendLogoutCGIWithCompletion:(id)arg1;
|
||||
|
||||
@end
|
||||
|
||||
@protocol MASPreferencesViewController <NSObject>
|
||||
|
||||
@property(readonly, nonatomic) NSString *toolbarItemLabel;
|
||||
@@ -104,7 +112,7 @@
|
||||
|
||||
@end
|
||||
|
||||
@interface MASPreferencesWindowController : NSWindowController
|
||||
@interface MASPreferencesWindowController: NSWindowController
|
||||
|
||||
- (id)initWithViewControllers:(NSArray *)arg1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user