Skip to content

Commit

Permalink
Add ==> 新增在线更新小助手
Browse files Browse the repository at this point in the history
  • Loading branch information
TKkk-iOSer committed May 4, 2018
1 parent cef4695 commit 67797eb
Show file tree
Hide file tree
Showing 39 changed files with 340 additions and 46 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Other/Products/Debug/WeChatPlugin.framework/WeChatPlugin
Binary file not shown.
8 changes: 8 additions & 0 deletions WeChatPlugin.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
520AE6F8208F632700BADE47 /* TKRemoteControlManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 520AE6F6208F632700BADE47 /* TKRemoteControlManager.m */; };
520F2009205E1DF900A36B1E /* TKWebServerManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 520F2007205E1DF900A36B1E /* TKWebServerManager.h */; };
520F200A205E1DF900A36B1E /* TKWebServerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 520F2008205E1DF900A36B1E /* TKWebServerManager.m */; };
52176DD9209809CE0035FA50 /* NSString+Action.h in Headers */ = {isa = PBXBuildFile; fileRef = 52176DD7209809CE0035FA50 /* NSString+Action.h */; };
52176DDA209809CE0035FA50 /* NSString+Action.m in Sources */ = {isa = PBXBuildFile; fileRef = 52176DD8209809CE0035FA50 /* NSString+Action.m */; };
521C49C320820662003902E7 /* TKRemoteControlWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 521C49C520820662003902E7 /* TKRemoteControlWindowController.xib */; };
521D75F92080E3670093C820 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 521D75FB2080E3670093C820 /* Localizable.strings */; };
52206B6A20836A230010C232 /* NSMenu+Action.h in Headers */ = {isa = PBXBuildFile; fileRef = 52206B6820836A230010C232 /* NSMenu+Action.h */; };
Expand Down Expand Up @@ -93,6 +95,8 @@
520AE6F6208F632700BADE47 /* TKRemoteControlManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TKRemoteControlManager.m; sourceTree = "<group>"; };
520F2007205E1DF900A36B1E /* TKWebServerManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TKWebServerManager.h; sourceTree = "<group>"; };
520F2008205E1DF900A36B1E /* TKWebServerManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TKWebServerManager.m; sourceTree = "<group>"; };
52176DD7209809CE0035FA50 /* NSString+Action.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSString+Action.h"; sourceTree = "<group>"; };
52176DD8209809CE0035FA50 /* NSString+Action.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSString+Action.m"; sourceTree = "<group>"; };
521C49C420820662003902E7 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/TKRemoteControlWindowController.xib; sourceTree = "<group>"; };
521C49C620820663003902E7 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "zh-Hans"; path = "zh-Hans.lproj/TKRemoteControlWindowController.xib"; sourceTree = "<group>"; };
521D75FA2080E3670093C820 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -212,6 +216,8 @@
52206B6920836A230010C232 /* NSMenu+Action.m */,
527D017120903C1B007155C9 /* NSMenuItem+Action.h */,
527D017220903C1B007155C9 /* NSMenuItem+Action.m */,
52176DD7209809CE0035FA50 /* NSString+Action.h */,
52176DD8209809CE0035FA50 /* NSString+Action.m */,
);
path = Category;
sourceTree = "<group>";
Expand Down Expand Up @@ -475,6 +481,7 @@
520AE6F3208F62EF00BADE47 /* TKAssistantMenuManager.h in Headers */,
526F4D831F4AAC1900E46004 /* TKAutoReplyModel.h in Headers */,
520AE6E8208E1DA300BADE47 /* TKMessageManager.h in Headers */,
52176DD9209809CE0035FA50 /* NSString+Action.h in Headers */,
52B5CF141F3B4631000D9DD9 /* TKWeChatPluginConfig.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -615,6 +622,7 @@
529CDDFF1F6E6A060056DC1A /* TKBaseModel.m in Sources */,
52DA3E0E2094790900C618BB /* TKDownloadWindowController.m in Sources */,
527E7F622018711800358D26 /* fishhook.c in Sources */,
52176DDA209809CE0035FA50 /* NSString+Action.m in Sources */,
52EA235A20862D19008E6329 /* TKHTTPManager.m in Sources */,
527D017420903C1B007155C9 /* NSMenuItem+Action.m in Sources */,
52B5CF1B1F3B4631000D9DD9 /* TKHelper.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,21 @@
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "WeChatPlugin/Sources/WindowControllers/Download/TKDownloadWindowController.m"
timestampString = "547052344.4319789"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "79"
endingLineNumber = "79"
landmarkName = "-downloadPlugin"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
20 changes: 7 additions & 13 deletions WeChatPlugin/Sources/Category/WeChat+hook.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#import "TKAutoReplyModel.h"
#import "TKVersionManager.h"
#import "TKRemoteControlManager.h"
#import "TKDownloadWindowController.h"

@implementation NSObject (WeChatHook)

Expand Down Expand Up @@ -68,18 +69,8 @@ + (void)setup {

+ (void)checkPluginVersion {
if ([[TKWeChatPluginConfig sharedConfig] forbidCheckVersion]) return;
// [[TKVersionManager shareManager] downloadPluginProgress:^(NSProgress *downloadProgress) {
//
// } completionHandler:^(NSString *filePath, NSError * _Nullable error) {
// NSString *fileName = [filePath lastPathComponent];
// NSString *realFileName = [fileName stringByDeletingPathExtension];
// NSString *cmdString = [NSString stringWithFormat:@"cd %@ && unzip -n %@ && ./%@/Other/Update.sh",cachesPath,fileName,realFileName];
// NSString *result = [TKRemoteControlManager executeShellCommand:cmdString];
// [TKRemoteControlManager executeAppleScriptCommand:@"restartWeChat"];
//
// }];
[[TKVersionManager shareManager] checkVersionFinish:^(TKVersionStatus status, NSString *message) {
if (status == TKVersionStatusNew) {
if (status != TKVersionStatusNew) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:TKLocalizedString(@"assistant.update.alret.confirm")];
Expand All @@ -89,8 +80,11 @@ + (void)checkPluginVersion {
[alert setInformativeText:message];
NSModalResponse respose = [alert runModal];
if (respose == NSAlertFirstButtonReturn) {
NSURL *url = [NSURL URLWithString:@"https://github.com/TKkk-iOSer/WeChatPlugin-MacOS"];
[[NSWorkspace sharedWorkspace] openURL:url];
TKDownloadWindowController *downloadWC = [TKDownloadWindowController downloadWindowController];

[downloadWC showWindow:downloadWC];
[downloadWC.window center];
[downloadWC.window makeKeyWindow];
} else if (respose == NSAlertSecondButtonReturn) {
[[TKWeChatPluginConfig sharedConfig] setForbidCheckVersion:YES];
}
Expand Down
16 changes: 16 additions & 0 deletions WeChatPlugin/Sources/Common/Category/NSString+Action.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// NSString+Action.h
// WeChatPlugin
//
// Created by TK on 2018/5/1.
// Copyright © 2018年 tk. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface NSString (Action)

- (CGFloat)widthWithFont:(NSFont *)font;
- (NSRect)rectWithFont:(NSFont *)font;

@end
21 changes: 21 additions & 0 deletions WeChatPlugin/Sources/Common/Category/NSString+Action.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// NSString+Action.m
// WeChatPlugin
//
// Created by TK on 2018/5/1.
// Copyright © 2018年 tk. All rights reserved.
//

#import "NSString+Action.h"

@implementation NSString (Action)

- (CGFloat)widthWithFont:(NSFont *)font {
return [self rectWithFont:font].size.width;
}

- (NSRect)rectWithFont:(NSFont *)font {
return [self boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: font}];
}

@end
12 changes: 12 additions & 0 deletions WeChatPlugin/Sources/Common/Category/NSView+Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,15 @@
- (void)addSubviews:(NSArray *)subViews;

@end

@interface NSView (Size)

@property (nonatomic) CGPoint origin;
@property (nonatomic) CGSize size;

@property (nonatomic) CGFloat x;
@property (nonatomic) CGFloat y;
@property (nonatomic) CGFloat width;
@property (nonatomic) CGFloat height;

@end
58 changes: 58 additions & 0 deletions WeChatPlugin/Sources/Common/Category/NSView+Action.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,61 @@ - (void)addSubviews:(NSArray *)subViews {
}

@end

@implementation NSView (Size)

- (CGPoint)origin {
return self.frame.origin;
}

- (void)setOrigin:(CGPoint)point {
CGRect rect = self.frame;

rect.origin = point;
self.frame = rect;
}

- (CGSize)size {
return self.frame.size;
}

- (void)setSize:(CGSize)size {
CGRect rect = self.frame;

rect.size = size;
self.frame = rect;
}

- (CGFloat)x {
return self.frame.origin.x;
}

- (void)setX:(CGFloat)x {
[self setOrigin:CGPointMake(x, self.y)];
}

- (CGFloat)y {
return self.frame.origin.y;
}

- (void)setY:(CGFloat)y {
[self setOrigin:CGPointMake(self.x, y)];
}

- (CGFloat)width {
return self.frame.size.width;
}

- (void)setWidth:(CGFloat)width {
[self setSize:CGSizeMake(width, self.height)];
}

- (CGFloat)height {
return self.frame.size.height;
}

- (void)setHeight:(CGFloat)height {
[self setSize:CGSizeMake(self.width, height)];
}

@end
1 change: 1 addition & 0 deletions WeChatPlugin/Sources/Common/TKPrefixHeader.pch
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#import "NSButton+Action.h"
#import "NSTextField+Action.h"
#import "NSMenu+Action.h"
#import "NSString+Action.h"
#import "WeChatPlugin.h"
#endif

Expand Down
21 changes: 17 additions & 4 deletions WeChatPlugin/Sources/Managers/TKAssistantMenuManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ - (void)initAssistantMenuItems {
target:self
keyEquivalent:@""
state:0];
// 关于小助手
NSMenuItem *abountPluginItem = [NSMenuItem menuItemWithTitle:TKLocalizedString(@"assistant.menu.aboutAssistant")
action:@selector(onAboutPluginControl:)
target:self
keyEquivalent:@""
state:0];

NSMenu *subMenu = [[NSMenu alloc] initWithTitle:TKLocalizedString(@"assistant.menu.title")];
[subMenu addItems:@[preventRevokeItem,
Expand All @@ -80,14 +86,15 @@ - (void)initAssistantMenuItems {
newWeChatItem,
onTopItem,
autoAuthItem,
updatePluginItem]];
updatePluginItem,
abountPluginItem]];

NSMenuItem *menuItem = [[NSMenuItem alloc] init];
[menuItem setTitle:TKLocalizedString(@"assistant.menu.title")];
[menuItem setSubmenu:subMenu];
menuItem.target = self;
[[[NSApplication sharedApplication] mainMenu] addItem:menuItem];
menuItem.enabled = NO;
// menuItem.enabled = NO;

[self addObserverWeChatConfig];
}
Expand Down Expand Up @@ -233,8 +240,10 @@ - (void)onUpdatePluginControl:(NSMenuItem *)item {
[alert setInformativeText:message];
NSModalResponse respose = [alert runModal];
if (respose == NSAlertFirstButtonReturn) {
NSURL *url = [NSURL URLWithString:@"https://github.com/TKkk-iOSer/WeChatPlugin-MacOS"];
[[NSWorkspace sharedWorkspace] openURL:url];
TKDownloadWindowController *downloadWC = [TKDownloadWindowController downloadWindowController];
[downloadWC showWindow:downloadWC];
[downloadWC.window center];
[downloadWC.window makeKeyWindow];
}
} else {
NSAlert *alert = [[NSAlert alloc] init];
Expand All @@ -245,4 +254,8 @@ - (void)onUpdatePluginControl:(NSMenuItem *)item {
}];
}

- (void)onAboutPluginControl:(NSMenuItem *)item {

}

@end
2 changes: 2 additions & 0 deletions WeChatPlugin/Sources/Managers/TKHTTPManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@
progress:(nullable void (^)(NSProgress *downloadProgress))downloadProgressBlock
completionHandler:(nullable void (^)(NSString * filePath, NSError * _Nullable error))completionHandler;

- (void)cancelDownload;

@end
11 changes: 9 additions & 2 deletions WeChatPlugin/Sources/Managers/TKHTTPManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,22 @@ - (void)downloadWithUrlString:(NSString *)urlString
self.sessionManager = [[objc_getClass("AFURLSessionManager") alloc] initWithSessionConfiguration:configuration];

self.downloadTask = [self.sessionManager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) {
downloadProgressBlock(downloadProgress);
if (downloadProgressBlock) downloadProgressBlock(downloadProgress);

} destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
NSString *path = [directory stringByAppendingPathComponent:response.suggestedFilename];
return [NSURL fileURLWithPath:path];
} completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable urlPath, NSError * _Nullable error) {
NSString *filePath = [[urlPath absoluteString] substringFromIndex:7];
completionHandler(filePath, error);
if (completionHandler) completionHandler(filePath, error);
}];
[self.downloadTask resume];
}

- (void)cancelDownload {
if (!self.downloadTask) return;
[self.downloadTask cancel];
self.downloadTask = nil;
}

@end
1 change: 1 addition & 0 deletions WeChatPlugin/Sources/Managers/TKVersionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ typedef NS_ENUM(NSUInteger, TKVersionStatus) {
+ (instancetype)shareManager;
- (void)checkVersionFinish:(void (^)(TKVersionStatus, NSString *))finish;
- (void)downloadPluginProgress:(void (^)(NSProgress *downloadProgress))downloadProgressBlock completionHandler:(void (^)(NSString *filePath, NSError * _Nullable error))completionHandler;
- (void)cancelDownload;

@end
12 changes: 5 additions & 7 deletions WeChatPlugin/Sources/Managers/TKVersionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@ - (void)downloadPluginProgress:(void (^)(NSProgress *downloadProgress))downloadP

NSString *urlString = @"https://github.com/TKkk-iOSer/WeChatPlugin-MacOS/archive/master.zip";
[[TKHTTPManager shareManager] downloadWithUrlString:urlString toDirectoryPah:cachesPath progress:^(NSProgress *downloadProgress) {
downloadProgressBlock(downloadProgress);
if (downloadProgressBlock) downloadProgressBlock(downloadProgress);
} completionHandler:^(NSString *filePath, NSError * _Nullable error) {
// NSString *fileName = [filePath lastPathComponent];
// NSString *realFileName = [fileName stringByDeletingPathExtension];
// NSString *cmdString = [NSString stringWithFormat:@"cd %@ && unzip -n %@ && ./%@/Other/Update.sh",cachesPath,fileName,realFileName];
// NSString *result = [TKRemoteControlManager executeShellCommand:cmdString];
completionHandler(filePath,error);
// [TKRemoteControlManager executeAppleScriptCommand:@"restartWeChat"];
if (completionHandler) completionHandler(filePath,error);
}];
}

- (void)cancelDownload {
[[TKHTTPManager shareManager] cancelDownload];
}
@end
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@

@interface TKDownloadWindowController : NSWindowController

+ (instancetype)downloadWindowController;

@end
Loading

0 comments on commit 67797eb

Please sign in to comment.