mirror of
https://github.com/Sunnyyoung/WeChatTweak-macOS.git
synced 2026-07-29 06:24:31 +08:00
Update project settings
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// AlfredManager.h
|
||||
// WeChatTweak
|
||||
//
|
||||
// Created by Sunnyyoung on 2017/9/10.
|
||||
// Copyright © 2017年 Sunnyyoung. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <objc/runtime.h>
|
||||
#import <objc/message.h>
|
||||
#import <YYModel/YYModel.h>
|
||||
#import <GCDWebServer/GCDWebServer.h>
|
||||
#import <GCDWebServer/GCDWebServerDataResponse.h>
|
||||
|
||||
@interface AlfredManager : NSObject
|
||||
|
||||
+ (instancetype)sharedInstance;
|
||||
|
||||
- (void)startListener;
|
||||
- (void)stopListener;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,102 @@
|
||||
//
|
||||
// AlfredManager.m
|
||||
// WeChatTweak
|
||||
//
|
||||
// Created by Sunnyyoung on 2017/9/10.
|
||||
// Copyright © 2017年 Sunnyyoung. All rights reserved.
|
||||
//
|
||||
|
||||
#import "AlfredManager.h"
|
||||
#import "WeChatTweakHeaders.h"
|
||||
|
||||
@interface AlfredManager()
|
||||
|
||||
@property (nonatomic, strong, nullable) GCDWebServer *server;
|
||||
|
||||
@end
|
||||
|
||||
@implementation AlfredManager
|
||||
|
||||
+ (instancetype)sharedInstance {
|
||||
static dispatch_once_t onceToken;
|
||||
static AlfredManager *shared;
|
||||
dispatch_once(&onceToken, ^{
|
||||
shared = [[AlfredManager alloc] init];
|
||||
});
|
||||
return shared;
|
||||
}
|
||||
|
||||
- (void)startListener {
|
||||
if (self.server != nil) {
|
||||
return;
|
||||
}
|
||||
self.server = [[GCDWebServer alloc] init];
|
||||
// Search contancts
|
||||
[self.server addHandlerForMethod:@"GET" path:@"/wechat/search" requestClass:[GCDWebServerRequest class] processBlock:^GCDWebServerResponse * _Nullable(__kindof GCDWebServerRequest * _Nonnull request) {
|
||||
NSString *keyword = [request.query[@"keyword"] lowercaseString] ? : @"";
|
||||
NSArray<WCContactData *> *contacts = ({
|
||||
MMServiceCenter *serviceCenter = [objc_getClass("MMServiceCenter") defaultCenter];
|
||||
ContactStorage *contactStorage = [serviceCenter getService:objc_getClass("ContactStorage")];
|
||||
GroupStorage *groupStorage = [serviceCenter getService:objc_getClass("GroupStorage")];
|
||||
NSMutableArray<WCContactData *> *array = [NSMutableArray array];
|
||||
[array addObjectsFromArray:[contactStorage GetAllFriendContacts]];
|
||||
[array addObjectsFromArray:[groupStorage GetGroupContactList:2 ContactType:0]];
|
||||
array;
|
||||
});
|
||||
NSArray<WCContactData *> *results = ({
|
||||
NSMutableArray<WCContactData *> *results = [NSMutableArray array];
|
||||
for (WCContactData *contact in contacts) {
|
||||
BOOL isOfficialAccount = (contact.m_uiCertificationFlag >> 0x3 & 0x1) == 1;
|
||||
BOOL containsNickName = [contact.m_nsNickName.lowercaseString containsString:keyword];
|
||||
BOOL containsUsername = [contact.m_nsUsrName.lowercaseString containsString:keyword];
|
||||
BOOL containsAliasName = [contact.m_nsAliasName.lowercaseString containsString:keyword];
|
||||
BOOL containsRemark = [contact.m_nsRemark.lowercaseString containsString:keyword];
|
||||
BOOL containsNickNamePinyin = [contact.m_nsFullPY.lowercaseString containsString:keyword];
|
||||
BOOL containsRemarkPinyin = [contact.m_nsRemarkPYFull.lowercaseString containsString:keyword];
|
||||
BOOL matchRemarkShortPinyin = [contact.m_nsRemarkPYShort.lowercaseString isEqualToString:keyword];
|
||||
if (!isOfficialAccount && (containsNickName || containsUsername || containsAliasName || containsRemark || containsNickNamePinyin || containsRemarkPinyin || matchRemarkShortPinyin)) {
|
||||
[results addObject:contact];
|
||||
}
|
||||
}
|
||||
results;
|
||||
});
|
||||
return [GCDWebServerDataResponse responseWithJSONObject:[results yy_modelToJSONObject]];
|
||||
}];
|
||||
// Start chat
|
||||
[self.server addHandlerForMethod:@"GET" path:@"/wechat/start" requestClass:[GCDWebServerRequest class] processBlock:^GCDWebServerResponse * _Nullable(__kindof GCDWebServerRequest * _Nonnull request) {
|
||||
WCContactData *contact = ({
|
||||
NSString *session = request.query[@"session"];
|
||||
WCContactData *contact = nil;
|
||||
if (session != nil) {
|
||||
MMServiceCenter *serviceCenter = [objc_getClass("MMServiceCenter") defaultCenter];
|
||||
if ([session rangeOfString:@"@chatroom"].location == NSNotFound) {
|
||||
ContactStorage *contactStorage = [serviceCenter getService:objc_getClass("ContactStorage")];
|
||||
contact = [contactStorage GetContact:session];
|
||||
} else {
|
||||
GroupStorage *groupStorage = [serviceCenter getService:objc_getClass("GroupStorage")];
|
||||
contact = [groupStorage GetGroupContact:session];
|
||||
}
|
||||
}
|
||||
contact;
|
||||
});
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[objc_getClass("WeChat") sharedInstance] startANewChatWithContact:contact];
|
||||
[[objc_getClass("WeChat") sharedInstance] showMainWindow];
|
||||
[[NSApplication sharedApplication] activateIgnoringOtherApps: YES];
|
||||
});
|
||||
return [GCDWebServerResponse responseWithStatusCode:200];
|
||||
}];
|
||||
[self.server startWithOptions:@{GCDWebServerOption_Port: @(48065),
|
||||
GCDWebServerOption_BindToLocalhost: @(YES)} error:nil];
|
||||
}
|
||||
|
||||
- (void)stopListener {
|
||||
if (self.server == nil) {
|
||||
return;
|
||||
}
|
||||
[self.server stop];
|
||||
[self.server removeAllHandlers];
|
||||
self.server = nil;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// WTConfigManager.h
|
||||
// WeChatTweak
|
||||
//
|
||||
// Created by Sunny Young on 21/03/2018.
|
||||
// Copyright © 2018 Sunnyyoung. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <objc/runtime.h>
|
||||
#import <objc/message.h>
|
||||
|
||||
@interface WTConfigManager : NSObject
|
||||
|
||||
@property (nonatomic, assign) BOOL compressedJSONEnabled;
|
||||
|
||||
+ (instancetype)sharedInstance;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// WTConfigManager.m
|
||||
// WeChatTweak
|
||||
//
|
||||
// Created by Sunny Young on 21/03/2018.
|
||||
// Copyright © 2018 Sunnyyoung. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WTConfigManager.h"
|
||||
|
||||
static NSString * const WeChatTweakCompressedJSONEnabledKey = @"WeChatTweakCompressedJSONEnabledKey";
|
||||
|
||||
@interface WTConfigManager()
|
||||
|
||||
@end
|
||||
|
||||
@implementation WTConfigManager
|
||||
|
||||
+ (instancetype)sharedInstance {
|
||||
static dispatch_once_t onceToken;
|
||||
static WTConfigManager *shared;
|
||||
dispatch_once(&onceToken, ^{
|
||||
shared = [[WTConfigManager alloc] init];
|
||||
});
|
||||
return shared;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
NSUserDefaults *userDefaults = NSUserDefaults.standardUserDefaults;
|
||||
if ([userDefaults objectForKey:WeChatTweakCompressedJSONEnabledKey]) {
|
||||
_compressedJSONEnabled = [userDefaults boolForKey:WeChatTweakCompressedJSONEnabledKey];
|
||||
} else {
|
||||
_compressedJSONEnabled = YES;
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - Property method
|
||||
|
||||
- (void)setCompressedJSONEnabled:(BOOL)compressedJSONEnabled {
|
||||
_compressedJSONEnabled = compressedJSONEnabled;
|
||||
[NSUserDefaults.standardUserDefaults setBool:compressedJSONEnabled forKey:WeChatTweakCompressedJSONEnabledKey];
|
||||
[NSUserDefaults.standardUserDefaults synchronize];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user