Fix open new WeChat and miniprogram conflict in WeChat 2.4.0;

This commit is contained in:
Jeason.L
2020-04-13 10:51:48 +08:00
parent e59b46aa33
commit 470fdda09b
4 changed files with 15 additions and 7 deletions
+9 -1
View File
@@ -16,6 +16,8 @@
#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);
@@ -281,7 +283,8 @@ static void __attribute__((constructor)) tweak(void) {
}
+ (NSArray<NSRunningApplication *> *)tweak_runningApplicationsWithBundleIdentifier:(NSString *)bundleIdentifier {
if ([bundleIdentifier isEqualToString:NSBundle.mainBundle.bundleIdentifier]) {
BOOL openNewWeChat = [NSUserDefaults.standardUserDefaults boolForKey:WeChatTweakOpenNewWeChatKey];
if (openNewWeChat && [bundleIdentifier isEqualToString:NSBundle.mainBundle.bundleIdentifier] ) {
return @[NSRunningApplication.currentApplication];
} else {
return [self tweak_runningApplicationsWithBundleIdentifier:bundleIdentifier];
@@ -298,11 +301,16 @@ 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