Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
yanmao committed Apr 29, 2020
1 parent 102514f commit b5c3ac1
Show file tree
Hide file tree
Showing 28 changed files with 49 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// YMUtility.h
// YMDeviceHelper.h
// WeChatExtension
//
// Created by WeChatExtension on 2019/1/12.
Expand All @@ -8,11 +8,11 @@

#import <Foundation/Foundation.h>

#define LargerOrEqualVersion(version) [YMUtility isLargerOrEqualVersion:version]
#define LargerOrEqualLongVersion(version) [YMUtility isLargeOrEqualLongVersion:version]
#define LargerOrEqualVersion(version) [YMDeviceHelper isLargerOrEqualVersion:version]
#define LargerOrEqualLongVersion(version) [YMDeviceHelper isLargeOrEqualLongVersion:version]
NS_ASSUME_NONNULL_BEGIN

@interface YMUtility : NSObject
@interface YMDeviceHelper : NSObject
+ (BOOL)isLargerOrEqualVersion:(NSString *)version;
+ (BOOL)isLargeOrEqualLongVersion:(NSString *)version;
@end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//
// YMUtility.m
// YMDeviceHelper.m
// WeChatExtension
//
// Created by WeChatExtension on 2019/1/12.
// Copyright © 2019 WeChatExtension. All rights reserved.
//

#import "YMUtility.h"
#import "YMDeviceHelper.h"

@implementation YMUtility
@implementation YMDeviceHelper

+ (BOOL)isLargerOrEqualVersion:(NSString *)version
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// YMMessageTool.h
// YMMessageHelper.h
// WeChatExtension
//
// Created by MustangYM on 2019/1/22.
Expand All @@ -9,17 +9,9 @@
#import <Foundation/Foundation.h>
#import "WeChatPlugin.h"

@interface YMMessageTool : NSObject
/**
将AddMsg转换成MessageData
*/
@interface YMMessageHelper : NSObject
+ (MessageData *)getMessageData:(AddMsg *)addMsg;

/**
通过AddMsg获取会话Data
*/
+ (WCContactData *)getContactData:(AddMsg *)addMsg;

+ (void)parseMiniProgramMsg:(AddMsg *)addMsg;
+ (void)addLocalWarningMsg:(NSString *)msg fromUsr:(NSString *)fromUsr;
@end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//
// YMMessageTool.m
// YMMessageHelper.m
// WeChatExtension
//
// Created by MustangYM on 2019/1/22.
// Copyright © 2019 MustangYM. All rights reserved.
//

#import "YMMessageTool.h"
#import "YMMessageHelper.h"
#import <objc/runtime.h>
#import "XMLReader.h"

@implementation YMMessageTool
@implementation YMMessageHelper
+ (MessageData *)getMessageData:(AddMsg *)addMsg
{
if (!addMsg) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// YMHelper.h
// YMSwizzledHelper.h
// WeChatExtension
//
// Created by WeChatExtension on 2017/4/19.
Expand All @@ -9,7 +9,7 @@
#import <Foundation/Foundation.h>
#import <objc/runtime.h>

@interface YMHelper : NSObject
@interface YMSwizzledHelper : NSObject

/**
替换对象方法
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//
// YMHelper.m
// YMSwizzledHelper.m
// WeChatExtension
//
// Created by WeChatExtension on 2017/4/19.
// Copyright © 2017年 WeChatExtension. All rights reserved.
//

#import "YMHelper.h"
#import "YMSwizzledHelper.h"

@implementation YMHelper
@implementation YMSwizzledHelper

/**
替换对象方法
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
//

#import "TKAssistantMenuManager.h"
#import "TKRemoteControlManager.h"
#import "YMRemoteControlManager.h"
#import "TKAutoReplyWindowController.h"
#import "TKRemoteControlWindowController.h"
#import "TKVersionManager.h"
#import "YMVersionManager.h"
#import "NSMenuItem+Action.h"
#import "TKDownloadWindowController.h"
#import "TKAboutWindowController.h"
Expand Down Expand Up @@ -171,7 +171,7 @@ - (void)initAssistantMenuItems
state:0];

NSString *versionStr = YMLanguage(@"当前版本", @"Version");
NSMenuItem *currentVersionItem = [NSMenuItem menuItemWithTitle:[NSString stringWithFormat:@"%@%@",versionStr,[TKVersionManager shareManager].currentVersion]
NSMenuItem *currentVersionItem = [NSMenuItem menuItemWithTitle:[NSString stringWithFormat:@"%@%@",versionStr,[YMVersionManager shareManager].currentVersion]
action:@selector(onCurrentVersion:)
target:self
keyEquivalent:@""
Expand Down Expand Up @@ -442,7 +442,7 @@ - (void)onNewWechatInstance:(NSMenuItem *)item

if ([TKWeChatPluginConfig sharedConfig].isAllowMoreOpenBaby) {
[TKWeChatPluginConfig sharedConfig].launchFromNew = YES;
[TKRemoteControlManager executeShellCommand:@"open -n /Applications/WeChat.app"];
[YMRemoteControlManager executeShellCommand:@"open -n /Applications/WeChat.app"];
} else {
NSAlert *alert = [NSAlert alertWithMessageText:YMLanguage(@"警告", @"WARNING")
defaultButton:YMLanguage(@"取消", @"cancel") alternateButton:YMLanguage(@"确定重启",@"restart")
Expand Down Expand Up @@ -516,7 +516,7 @@ - (void)onWechatOnTopControl:(NSMenuItem *)item
- (void)onUpdatePluginControl:(NSMenuItem *)item
{
[[TKWeChatPluginConfig sharedConfig] setForbidCheckVersion:NO];
[[TKVersionManager shareManager] checkVersionFinish:^(TKVersionStatus status, NSString *message) {
[[YMVersionManager shareManager] checkVersionFinish:^(TKVersionStatus status, NSString *message) {
if (status == TKVersionStatusNew) {
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:YMLocalizedString(@"assistant.update.alret.confirm")];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// TKRemoteControlManager.h
// YMRemoteControlManager.h
// WeChatExtension
//
// Created by WeChatExtension on 2018/4/24.
Expand All @@ -8,7 +8,7 @@

#import <Foundation/Foundation.h>

@interface TKRemoteControlManager : NSObject
@interface YMRemoteControlManager : NSObject

+ (void)executeRemoteControlCommandWithVoiceMsg:(NSString *)msg;
+ (void)executeRemoteControlCommandWithMsg:(NSString *)msg;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//
// TKRemoteControlManager.m
// YMRemoteControlManager.m
// WeChatExtension
//
// Created by WeChatExtension on 2018/4/24.
// Copyright © 2018年 WeChatExtension. All rights reserved.
//

#import "TKRemoteControlManager.h"
#import "YMRemoteControlManager.h"
#import "TKWeChatPluginConfig.h"
#import "TKRemoteControlModel.h"
#import "YMMessageManager.h"
Expand All @@ -19,7 +19,7 @@ typedef NS_ENUM(NSUInteger, MessageDataType) {
// 执行 AppleScript
static NSString * const kRemoteControlAppleScript = @"osascript /Applications/WeChat.app/Contents/MacOS/WeChatExtension.framework/Resources/TKRemoteControlScript.scpt";

@implementation TKRemoteControlManager
@implementation YMRemoteControlManager

+ (void)executeRemoteControlCommandWithVoiceMsg:(NSString *)msg
{
Expand Down Expand Up @@ -127,7 +127,7 @@ + (void)executePluginCommand:(NSString *)cmd
NSString *callBack = @"";
TKWeChatPluginConfig *config = [TKWeChatPluginConfig sharedConfig];
if ([cmd isEqualToString:@"getDirectiveList"]) {
callBack = [TKRemoteControlManager remoteControlCommandsString];
callBack = [YMRemoteControlManager remoteControlCommandsString];
} else if ([cmd isEqualToString:@"AutoReplySwitch"]) {
NSString *status = config.autoReplyEnable ? YMLocalizedString(@"Assistant.Directive.SwitchOff") : YMLocalizedString(@"Assistant.Directive.SwitchOn");
callBack = [NSString stringWithFormat:@"%@-%@",YMLocalizedString(@"Assistant.Directive.AutoReplySwitch"),status];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import "TKVersionManager.h"
#import "TKWeChatPluginConfig.h"
#import "TKHTTPManager.h"
#import "YMHTTPManager.h"
#import "TKRemoteControlManager.h"
#import "TKCacheManager.h"

Expand Down Expand Up @@ -67,7 +67,7 @@ - (void)downloadPluginProgress:(void (^)(NSProgress *downloadProgress))downloadP
[fileManager removeItemAtPath:pluginZipPath error:nil];

NSString *urlString = @"https://github.com/MustangYM/WeChatExtension-ForMac/raw/master/WeChatExtension/Rely/Plugin/WeChatExtension.zip";
[[TKHTTPManager shareManager] downloadWithUrlString:urlString toDirectoryPah:cachesPath progress:^(NSProgress *downloadProgress) {
[[YMHTTPManager shareManager] downloadWithUrlString:urlString toDirectoryPah:cachesPath progress:^(NSProgress *downloadProgress) {
if (downloadProgressBlock) {
downloadProgressBlock(downloadProgress);
}
Expand All @@ -80,6 +80,6 @@ - (void)downloadPluginProgress:(void (^)(NSProgress *downloadProgress))downloadP

- (void)cancelDownload
{
[[TKHTTPManager shareManager] cancelDownload];
[[YMHTTPManager shareManager] cancelDownload];
}
@end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// TKWebServerManager.h
// YMWebServerManager.h
// WeChatExtension
//
// Created by WeChatExtension on 2018/3/18.
Expand All @@ -8,7 +8,7 @@

#import <Foundation/Foundation.h>

@interface TKWebServerManager : NSObject
@interface YMWebServerManager : NSObject

+ (instancetype)shareManager;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
//
// TKWebServerManager.m
// YMWebServerManager.m
// WeChatExtension
//
// Created by WeChatExtension on 2018/3/18.
// Copyright © 2018年 WeChatExtension. All rights reserved.
//

#import "TKWebServerManager.h"
#import "YMWebServerManager.h"
#import "WeChatPlugin.h"
#import <GCDWebServer.h>
#import <GCDWebServerDataResponse.h>
#import <GCDWebServerURLEncodedFormRequest.h>
#import "YMMessageManager.h"
#import "TKCacheManager.h"
#import "YMCacheManager.h"

@interface TKWebServerManager ()
@interface YMWebServerManager ()

@property (nonatomic, strong) GCDWebServer *webServer;
@property (nonatomic, strong) MMContactSearchLogic *searchLogic;

@end

@implementation TKWebServerManager
@implementation YMWebServerManager

static int port=52700;

+ (instancetype)shareManager
{
static TKWebServerManager *manager = nil;
static YMWebServerManager *manager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
manager = [[TKWebServerManager alloc] init];
manager = [[YMWebServerManager alloc] init];
});
return manager;
}
Expand Down Expand Up @@ -185,7 +185,7 @@ - (void)addHandleForSearchUserChatLog

NSString *wechatId = [toUserContact getContactDisplayUsrName];
NSString *title = [weakSelf getUserNameWithContactData:toUserContact showOriginName:YES];
NSString *imgPath = [[TKCacheManager shareManager] cacheAvatarWithContact:toUserContact];
NSString *imgPath = [[YMCacheManager shareManager] cacheAvatarWithContact:toUserContact];
NSDictionary *toUserContactDict = @{@"title": [NSString stringWithFormat:@"To: %@", title],
@"subTitle": chatLogList.count > 0 ? YMLocalizedString(@"assistant.search.chatlog") : @"",
@"icon": imgPath ?: @"",
Expand Down Expand Up @@ -331,7 +331,7 @@ - (NSDictionary *)dictFromGroupSearchResult:(MMComplexGroupContactSearchResult *
if (subTitleArray.count > 0) {
subTitle = [NSString stringWithFormat:@"%@%@",YMLocalizedString(@"assistant.search.member"),[subTitleArray componentsJoinedByString:@", "]];
}
NSString *imgPath = [[TKCacheManager shareManager] cacheAvatarWithContact:groupContact];
NSString *imgPath = [[YMCacheManager shareManager] cacheAvatarWithContact:groupContact];
NSString *wechatId = [groupContact getContactDisplayUsrName];

return @{@"title": [NSString stringWithFormat:@"%@%@", YMLocalizedString(@"assistant.search.group"), groupContact.getGroupDisplayName],
Expand Down Expand Up @@ -393,7 +393,7 @@ - (NSDictionary *)dictFromContactSearchResult:(MMComplexContactSearchResult *)re
}

NSString *subTitle =[self matchWithContactResult:result];
NSString *imgPath = [[TKCacheManager shareManager] cacheAvatarWithContact:contact];
NSString *imgPath = [[YMCacheManager shareManager] cacheAvatarWithContact:contact];

NSString *wechatId = [contact getContactDisplayUsrName];
return @{@"title": title,
Expand All @@ -416,7 +416,7 @@ - (NSDictionary *)dictFromSessionInfo:(MMSessionInfo *)sessionInfo

NSString *title = [self getUserNameWithContactData:contact showOriginName:YES];
NSString *msgContent = [[YMMessageManager shareManager] getMessageContentWithData:msgData];
NSString *imgPath = [[TKCacheManager shareManager] cacheAvatarWithContact:contact];
NSString *imgPath = [[YMCacheManager shareManager] cacheAvatarWithContact:contact];

NSString *wechatId = [contact getContactDisplayUsrName];
return @{@"title": title,
Expand Down Expand Up @@ -482,10 +482,10 @@ - (NSDictionary *)dictFromMessageData:(MessageData *)msgData
[imgMgr downloadImageWithMessage:msgData];
}
} else if (msgData.isCustomEmojiMsg || msgData.isEmojiAppMsg) {
if ([[TKCacheManager shareManager] fileExistsWithName:msgData.m_nsEmoticonMD5]) {
url = [[TKCacheManager shareManager] filePathWithName:msgData.m_nsEmoticonMD5];
if ([[YMCacheManager shareManager] fileExistsWithName:msgData.m_nsEmoticonMD5]) {
url = [[YMCacheManager shareManager] filePathWithName:msgData.m_nsEmoticonMD5];
} else {
url = [[TKCacheManager shareManager] cacheEmotionMessage:msgData];
url = [[YMCacheManager shareManager] cacheEmotionMessage:msgData];
}
// }

Expand Down Expand Up @@ -513,9 +513,9 @@ - (NSDictionary *)dictFromMessageData:(MessageData *)msgData
if ([msgContact isGroupChat]) {
GroupStorage *contactStorage = [[objc_getClass("MMServiceCenter") defaultCenter] getService:objc_getClass("GroupStorage")];
WCContactData *fromContact = [contactStorage GetGroupMemberContact:[msgData getChatRoomUsrName]];
imgPath = [[TKCacheManager shareManager] cacheAvatarWithContact:fromContact];
imgPath = [[YMCacheManager shareManager] cacheAvatarWithContact:fromContact];
} else {
imgPath = [[TKCacheManager shareManager] cacheAvatarWithContact:msgContact];
imgPath = [[YMCacheManager shareManager] cacheAvatarWithContact:msgContact];
}

if (!msgContact.isGroupChat) {
Expand Down

0 comments on commit b5c3ac1

Please sign in to comment.