Skip to content

Commit

Permalink
#451 #455 Refactor Alfred module
Browse files Browse the repository at this point in the history
1. Remove Alfred workflow Python dependency
2. Remove Alfred JSON compressing
  • Loading branch information
sunnyyoung committed Mar 21, 2022
1 parent 82e7f6e commit f6482b1
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 240 deletions.
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ GEM
specs:
CFPropertyList (3.0.5)
rexml
activesupport (6.1.4.4)
activesupport (6.1.5)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
Expand All @@ -16,10 +16,10 @@ GEM
json (>= 1.5.1)
atomos (0.1.3)
claide (1.1.0)
cocoapods (1.11.2)
cocoapods (1.11.3)
addressable (~> 2.8)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.11.2)
cocoapods-core (= 1.11.3)
cocoapods-deintegrate (>= 1.0.3, < 2.0)
cocoapods-downloader (>= 1.4.0, < 2.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
Expand All @@ -34,7 +34,7 @@ GEM
nap (~> 1.0)
ruby-macho (>= 1.0, < 3.0)
xcodeproj (>= 1.21.0, < 2.0)
cocoapods-core (1.11.2)
cocoapods-core (1.11.3)
activesupport (>= 5.0, < 7)
addressable (~> 2.8)
algoliasearch (~> 1.0)
Expand Down Expand Up @@ -63,7 +63,7 @@ GEM
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
httpclient (2.8.3)
i18n (1.9.1)
i18n (1.10.0)
concurrent-ruby (~> 1.0)
json (2.6.1)
minitest (5.15.0)
Expand Down
1 change: 0 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ inhibit_all_warnings!
target 'WeChatTweak' do
pod 'JRSwizzle'
pod 'GCDWebServer'
pod 'YYModel'
end

post_install do |installer|
Expand Down
8 changes: 2 additions & 6 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@ PODS:
- GCDWebServer/Core (= 3.5.4)
- GCDWebServer/Core (3.5.4)
- JRSwizzle (1.0)
- YYModel (1.0.4)

DEPENDENCIES:
- GCDWebServer
- JRSwizzle
- YYModel

SPEC REPOS:
trunk:
- GCDWebServer
- JRSwizzle
- YYModel

SPEC CHECKSUMS:
GCDWebServer: 2c156a56c8226e2d5c0c3f208a3621ccffbe3ce4
JRSwizzle: dd5ead5d913a0f29e7f558200165849f006bb1e3
YYModel: 2a7fdd96aaa4b86a824e26d0c517de8928c04b30

PODFILE CHECKSUM: cae308b81d1bbf94a739799a5bf2524cf9bec366
PODFILE CHECKSUM: 63b2e533dfa408b1a24337678cd9025cc987011f

COCOAPODS: 1.11.2
COCOAPODS: 1.11.3
Binary file modified WeChat.alfredworkflow
Binary file not shown.
16 changes: 6 additions & 10 deletions WeChatTweak.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
7D54A05C20E74D9400CB5306 /* TweakPreferencesController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7D54A05E20E74D9400CB5306 /* TweakPreferencesController.xib */; };
7D54A06A20E74FE500CB5306 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 7D54A06C20E74FE500CB5306 /* Localizable.strings */; };
7D64150827A9469900A8A398 /* ContextMenu.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D64150627A9469900A8A398 /* ContextMenu.m */; };
7D64150A27A9481C00A8A398 /* ContactData.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D64150927A9481C00A8A398 /* ContactData.m */; };
7D64150C27A94B9600A8A398 /* Directory.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D64150B27A94B9600A8A398 /* Directory.m */; };
7D64150E27A94BEA00A8A398 /* MultipleInstances.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D64150D27A94BEA00A8A398 /* MultipleInstances.m */; };
7D64151027A94DE200A8A398 /* PreferencesWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D64150F27A94DE200A8A398 /* PreferencesWindow.m */; };
Expand All @@ -40,15 +39,14 @@
7D54A07120E7535F00CB5306 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
7D54A07220E7536300CB5306 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/Localizable.strings"; sourceTree = "<group>"; };
7D64150627A9469900A8A398 /* ContextMenu.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ContextMenu.m; sourceTree = "<group>"; };
7D64150927A9481C00A8A398 /* ContactData.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ContactData.m; sourceTree = "<group>"; };
7D64150B27A94B9600A8A398 /* Directory.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Directory.m; sourceTree = "<group>"; };
7D64150D27A94BEA00A8A398 /* MultipleInstances.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MultipleInstances.m; sourceTree = "<group>"; };
7D64150F27A94DE200A8A398 /* PreferencesWindow.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PreferencesWindow.m; sourceTree = "<group>"; };
7D64B96727853C2100A07164 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/TweakPreferencesController.strings; sourceTree = "<group>"; };
7D64B96827853C2800A07164 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/TweakPreferencesController.strings"; sourceTree = "<group>"; };
7D64B96927853C2B00A07164 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/TweakPreferencesController.strings"; sourceTree = "<group>"; };
7D9049F31F82A415004E6370 /* fishhook.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = fishhook.c; sourceTree = "<group>"; };
7D9049F41F82A415004E6370 /* fishhook.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = fishhook.h; sourceTree = "<group>"; };
7DAE1DD727E828960009C01E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/TweakPreferencesController.strings; sourceTree = "<group>"; };
7DAE1DD927E828A50009C01E /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/TweakPreferencesController.strings"; sourceTree = "<group>"; };
7DAE1DDB27E828B00009C01E /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/TweakPreferencesController.strings"; sourceTree = "<group>"; };
7DF842271F40583F00D42D79 /* WeChatTweak.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = WeChatTweak.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7DF8422A1F40583F00D42D79 /* WeChatTweak.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WeChatTweak.h; sourceTree = "<group>"; };
7DF8422B1F40583F00D42D79 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -149,7 +147,6 @@
7D64150D27A94BEA00A8A398 /* MultipleInstances.m */,
7D64150F27A94DE200A8A398 /* PreferencesWindow.m */,
7D64150627A9469900A8A398 /* ContextMenu.m */,
7D64150927A9481C00A8A398 /* ContactData.m */,
7D14E5A21F6447DB00D75132 /* Alfred.h */,
7D14E5A31F6447DB00D75132 /* Alfred.m */,
7D5AAF3720DF4BB300860EEE /* Vendor */,
Expand Down Expand Up @@ -314,7 +311,6 @@
7D64150827A9469900A8A398 /* ContextMenu.m in Sources */,
7D2194CC264701950068F4CC /* AntiRevoke.m in Sources */,
7DF842341F4058AB00D42D79 /* WeChatTweak.m in Sources */,
7D64150A27A9481C00A8A398 /* ContactData.m in Sources */,
7D9049F51F82A41A004E6370 /* fishhook.c in Sources */,
7D64151027A94DE200A8A398 /* PreferencesWindow.m in Sources */,
7D64150E27A94BEA00A8A398 /* MultipleInstances.m in Sources */,
Expand All @@ -330,9 +326,9 @@
isa = PBXVariantGroup;
children = (
7D54A05F20E74E4600CB5306 /* Base */,
7D64B96727853C2100A07164 /* en */,
7D64B96827853C2800A07164 /* zh-Hans */,
7D64B96927853C2B00A07164 /* zh-Hant */,
7DAE1DD727E828960009C01E /* en */,
7DAE1DD927E828A50009C01E /* zh-Hans */,
7DAE1DDB27E828B00009C01E /* zh-Hant */,
);
name = TweakPreferencesController.xib;
sourceTree = "<group>";
Expand Down
2 changes: 1 addition & 1 deletion WeChatTweak/Alfred.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2017年 Sunnyyoung. All rights reserved.
//

#import <YYModel/YYModel.h>
#import <objc/runtime.h>
#import <GCDWebServer/GCDWebServer.h>
#import <GCDWebServer/GCDWebServerDataResponse.h>

Expand Down
65 changes: 39 additions & 26 deletions WeChatTweak/Alfred.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ @interface AlfredManager()

@implementation AlfredManager

static int port = 48065;

+ (void)load {
[AlfredManager.sharedInstance startListener];
}
Expand All @@ -37,17 +35,19 @@ - (void)startListener {
return;
}
self.server = [[GCDWebServer alloc] init];
// Search contancts
// Search contacts
[self.server addHandlerForMethod:@"GET" path:@"/wechat/search" requestClass:[GCDWebServerRequest class] processBlock:^GCDWebServerResponse * _Nullable(__kindof GCDWebServerRequest * _Nonnull request) {
NSString *path = ({
NSString *path = nil;
if ([objc_getClass("PathUtility") respondsToSelector:@selector(GetCurUserDocumentPath)]) {
path = [objc_getClass("PathUtility") GetCurUserDocumentPath];
} else {
path = nil;
}
path;
});
NSString *keyword = [request.query[@"keyword"] lowercaseString] ? : @"";

NSString *hostname = request.headers[@"Host"];
NSString *url1 = [NSString stringWithFormat:@"127.0.0.1:%d", port];
NSString *url2 = [NSString stringWithFormat:@"localhost:%d", port];
if(!([hostname isEqualToString:url1] | [hostname isEqualToString:url2])){
return [GCDWebServerResponse responseWithStatusCode:404];
}

NSArray<WCContactData *> *contacts = ({
MMServiceCenter *serviceCenter = [objc_getClass("MMServiceCenter") defaultCenter];
ContactStorage *contactStorage = [serviceCenter getService:objc_getClass("ContactStorage")];
Expand All @@ -57,9 +57,10 @@ - (void)startListener {
[array addObjectsFromArray:[groupStorage GetGroupContactList:2 ContactType:0]];
array;
});
NSArray<WCContactData *> *results = ({
NSMutableArray<WCContactData *> *results = [NSMutableArray array];
NSArray<NSDictionary<NSString *, id> *> *items = ({
NSMutableArray<NSDictionary<NSString *, id> *> *items = NSMutableArray.array;
for (WCContactData *contact in contacts) {
NSString *avatar = [NSString stringWithFormat:@"%@/Avatar/%@.jpg", path, [contact.m_nsUsrName md5String]];
BOOL isOfficialAccount = (contact.m_uiCertificationFlag >> 0x3 & 0x1) == 1;
BOOL containsNickName = [contact.m_nsNickName.lowercaseString containsString:keyword];
BOOL containsUsername = [contact.m_nsUsrName.lowercaseString containsString:keyword];
Expand All @@ -69,23 +70,33 @@ - (void)startListener {
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];
[items addObject:@{
@"icon": @{
@"path": [NSFileManager.defaultManager fileExistsAtPath:avatar] ? avatar : NSNull.null
},
@"title": ({
id value = nil;
if (contact.m_nsRemark.length) {
value = contact.m_nsRemark;
} else if (contact.m_nsNickName.length) {
value = contact.m_nsNickName;
} else {
value = NSNull.null;
}
value;
}),
@"subtitle": contact.m_nsNickName.length ? contact.m_nsNickName : NSNull.null,
@"arg": contact.m_nsUsrName.length ? contact.m_nsUsrName : NSNull.null,
@"valid": @(contact.m_nsUsrName.length > 0)
}];
}
}
results;
items;
});
return [GCDWebServerDataResponse responseWithJSONObject:[results yy_modelToJSONObject]];
return [GCDWebServerDataResponse responseWithJSONObject:@{@"items": items}];
}];
// Start chat
// Start session
[self.server addHandlerForMethod:@"GET" path:@"/wechat/start" requestClass:[GCDWebServerRequest class] processBlock:^GCDWebServerResponse * _Nullable(__kindof GCDWebServerRequest * _Nonnull request) {

NSString *hostname = request.headers[@"Host"];
NSString *url1 = [NSString stringWithFormat:@"127.0.0.1:%d", port];
NSString *url2 = [NSString stringWithFormat:@"localhost:%d", port];
if(!([hostname isEqualToString:url1] | [hostname isEqualToString:url2])){
return [GCDWebServerResponse responseWithStatusCode:404];
}

WCContactData *contact = ({
NSString *session = request.query[@"session"];
WCContactData *contact = nil;
Expand All @@ -108,8 +119,10 @@ - (void)startListener {
});
return [GCDWebServerResponse responseWithStatusCode:200];
}];
[self.server startWithOptions:@{GCDWebServerOption_Port: [NSNumber numberWithInt:port],
GCDWebServerOption_BindToLocalhost: @(YES)} error:nil];
[self.server startWithOptions:@{
GCDWebServerOption_Port: @(48065),
GCDWebServerOption_BindToLocalhost: @(YES)
} error:nil];
}

- (void)stopListener {
Expand Down
48 changes: 0 additions & 48 deletions WeChatTweak/ContactData.m

This file was deleted.

Loading

0 comments on commit f6482b1

Please sign in to comment.