Fix multiple instaces issue

#230 #237 #240 #246 etc
This commit is contained in:
Sunnyyoung 2021-05-08 13:49:18 +08:00
parent 1f2fd3cd9f
commit 948018196b

View File

@ -16,8 +16,6 @@
#import "WTConfigManager.h"
#import "RecallCacheManager.h"
static NSString * const WeChatTweakOpenNewWeChatKey = @"WeChatTweakOpenNewWeChatKey";
// Global Function
static NSString *(*original_NSHomeDirectory)(void);
static NSArray<NSString *> *(*original_NSSearchPathForDirectoriesInDomains)(NSSearchPathDirectory directory, NSSearchPathDomainMask domainMask, BOOL expandTilde);
@ -401,8 +399,7 @@ static void __attribute__((constructor)) tweak(void) {
}
+ (NSArray<NSRunningApplication *> *)tweak_runningApplicationsWithBundleIdentifier:(NSString *)bundleIdentifier {
BOOL openNewWeChat = [NSUserDefaults.standardUserDefaults boolForKey:WeChatTweakOpenNewWeChatKey];
if (openNewWeChat && [bundleIdentifier isEqualToString:NSBundle.mainBundle.bundleIdentifier] ) {
if ([bundleIdentifier isEqualToString:NSBundle.mainBundle.bundleIdentifier] ) {
return @[NSRunningApplication.currentApplication];
} else {
return [self tweak_runningApplicationsWithBundleIdentifier:bundleIdentifier];
@ -419,16 +416,12 @@ static void __attribute__((constructor)) tweak(void) {
}
- (void)openNewWeChatInstace:(id)sender {
[NSUserDefaults.standardUserDefaults setBool:YES forKey:WeChatTweakOpenNewWeChatKey];
[NSUserDefaults.standardUserDefaults synchronize];
NSString *applicationPath = NSBundle.mainBundle.bundlePath;
NSTask *task = [[NSTask alloc] init];
task.launchPath = @"/usr/bin/open";
task.arguments = @[@"-n", applicationPath];
[task launch];
[task waitUntilExit];
[NSUserDefaults.standardUserDefaults removeObjectForKey:WeChatTweakOpenNewWeChatKey];
[NSUserDefaults.standardUserDefaults synchronize];
}
#pragma mark - Auto Auth