Skip to content

Commit 67797eb

Browse files
committed
Add ==> 新增在线更新小助手
1 parent cef4695 commit 67797eb

39 files changed

+340
-46
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

WeChatPlugin.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
520AE6F8208F632700BADE47 /* TKRemoteControlManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 520AE6F6208F632700BADE47 /* TKRemoteControlManager.m */; };
1919
520F2009205E1DF900A36B1E /* TKWebServerManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 520F2007205E1DF900A36B1E /* TKWebServerManager.h */; };
2020
520F200A205E1DF900A36B1E /* TKWebServerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 520F2008205E1DF900A36B1E /* TKWebServerManager.m */; };
21+
52176DD9209809CE0035FA50 /* NSString+Action.h in Headers */ = {isa = PBXBuildFile; fileRef = 52176DD7209809CE0035FA50 /* NSString+Action.h */; };
22+
52176DDA209809CE0035FA50 /* NSString+Action.m in Sources */ = {isa = PBXBuildFile; fileRef = 52176DD8209809CE0035FA50 /* NSString+Action.m */; };
2123
521C49C320820662003902E7 /* TKRemoteControlWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 521C49C520820662003902E7 /* TKRemoteControlWindowController.xib */; };
2224
521D75F92080E3670093C820 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 521D75FB2080E3670093C820 /* Localizable.strings */; };
2325
52206B6A20836A230010C232 /* NSMenu+Action.h in Headers */ = {isa = PBXBuildFile; fileRef = 52206B6820836A230010C232 /* NSMenu+Action.h */; };
@@ -93,6 +95,8 @@
9395
520AE6F6208F632700BADE47 /* TKRemoteControlManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TKRemoteControlManager.m; sourceTree = "<group>"; };
9496
520F2007205E1DF900A36B1E /* TKWebServerManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TKWebServerManager.h; sourceTree = "<group>"; };
9597
520F2008205E1DF900A36B1E /* TKWebServerManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TKWebServerManager.m; sourceTree = "<group>"; };
98+
52176DD7209809CE0035FA50 /* NSString+Action.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSString+Action.h"; sourceTree = "<group>"; };
99+
52176DD8209809CE0035FA50 /* NSString+Action.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSString+Action.m"; sourceTree = "<group>"; };
96100
521C49C420820662003902E7 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/TKRemoteControlWindowController.xib; sourceTree = "<group>"; };
97101
521C49C620820663003902E7 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "zh-Hans"; path = "zh-Hans.lproj/TKRemoteControlWindowController.xib"; sourceTree = "<group>"; };
98102
521D75FA2080E3670093C820 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
@@ -212,6 +216,8 @@
212216
52206B6920836A230010C232 /* NSMenu+Action.m */,
213217
527D017120903C1B007155C9 /* NSMenuItem+Action.h */,
214218
527D017220903C1B007155C9 /* NSMenuItem+Action.m */,
219+
52176DD7209809CE0035FA50 /* NSString+Action.h */,
220+
52176DD8209809CE0035FA50 /* NSString+Action.m */,
215221
);
216222
path = Category;
217223
sourceTree = "<group>";
@@ -475,6 +481,7 @@
475481
520AE6F3208F62EF00BADE47 /* TKAssistantMenuManager.h in Headers */,
476482
526F4D831F4AAC1900E46004 /* TKAutoReplyModel.h in Headers */,
477483
520AE6E8208E1DA300BADE47 /* TKMessageManager.h in Headers */,
484+
52176DD9209809CE0035FA50 /* NSString+Action.h in Headers */,
478485
52B5CF141F3B4631000D9DD9 /* TKWeChatPluginConfig.h in Headers */,
479486
);
480487
runOnlyForDeploymentPostprocessing = 0;
@@ -615,6 +622,7 @@
615622
529CDDFF1F6E6A060056DC1A /* TKBaseModel.m in Sources */,
616623
52DA3E0E2094790900C618BB /* TKDownloadWindowController.m in Sources */,
617624
527E7F622018711800358D26 /* fishhook.c in Sources */,
625+
52176DDA209809CE0035FA50 /* NSString+Action.m in Sources */,
618626
52EA235A20862D19008E6329 /* TKHTTPManager.m in Sources */,
619627
527D017420903C1B007155C9 /* NSMenuItem+Action.m in Sources */,
620628
52B5CF1B1F3B4631000D9DD9 /* TKHelper.m in Sources */,

WeChatPlugin.xcworkspace/xcuserdata/TK.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,21 @@
6767
landmarkType = "7">
6868
</BreakpointContent>
6969
</BreakpointProxy>
70+
<BreakpointProxy
71+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
72+
<BreakpointContent
73+
shouldBeEnabled = "Yes"
74+
ignoreCount = "0"
75+
continueAfterRunningActions = "No"
76+
filePath = "WeChatPlugin/Sources/WindowControllers/Download/TKDownloadWindowController.m"
77+
timestampString = "547052344.4319789"
78+
startingColumnNumber = "9223372036854775807"
79+
endingColumnNumber = "9223372036854775807"
80+
startingLineNumber = "79"
81+
endingLineNumber = "79"
82+
landmarkName = "-downloadPlugin"
83+
landmarkType = "7">
84+
</BreakpointContent>
85+
</BreakpointProxy>
7086
</Breakpoints>
7187
</Bucket>

WeChatPlugin/Sources/Category/WeChat+hook.m

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#import "TKAutoReplyModel.h"
1818
#import "TKVersionManager.h"
1919
#import "TKRemoteControlManager.h"
20+
#import "TKDownloadWindowController.h"
2021

2122
@implementation NSObject (WeChatHook)
2223

@@ -68,18 +69,8 @@ + (void)setup {
6869

6970
+ (void)checkPluginVersion {
7071
if ([[TKWeChatPluginConfig sharedConfig] forbidCheckVersion]) return;
71-
// [[TKVersionManager shareManager] downloadPluginProgress:^(NSProgress *downloadProgress) {
72-
//
73-
// } completionHandler:^(NSString *filePath, NSError * _Nullable error) {
74-
// NSString *fileName = [filePath lastPathComponent];
75-
// NSString *realFileName = [fileName stringByDeletingPathExtension];
76-
// NSString *cmdString = [NSString stringWithFormat:@"cd %@ && unzip -n %@ && ./%@/Other/Update.sh",cachesPath,fileName,realFileName];
77-
// NSString *result = [TKRemoteControlManager executeShellCommand:cmdString];
78-
// [TKRemoteControlManager executeAppleScriptCommand:@"restartWeChat"];
79-
//
80-
// }];
8172
[[TKVersionManager shareManager] checkVersionFinish:^(TKVersionStatus status, NSString *message) {
82-
if (status == TKVersionStatusNew) {
73+
if (status != TKVersionStatusNew) {
8374
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
8475
NSAlert *alert = [[NSAlert alloc] init];
8576
[alert addButtonWithTitle:TKLocalizedString(@"assistant.update.alret.confirm")];
@@ -89,8 +80,11 @@ + (void)checkPluginVersion {
8980
[alert setInformativeText:message];
9081
NSModalResponse respose = [alert runModal];
9182
if (respose == NSAlertFirstButtonReturn) {
92-
NSURL *url = [NSURL URLWithString:@"https://github.com/TKkk-iOSer/WeChatPlugin-MacOS"];
93-
[[NSWorkspace sharedWorkspace] openURL:url];
83+
TKDownloadWindowController *downloadWC = [TKDownloadWindowController downloadWindowController];
84+
85+
[downloadWC showWindow:downloadWC];
86+
[downloadWC.window center];
87+
[downloadWC.window makeKeyWindow];
9488
} else if (respose == NSAlertSecondButtonReturn) {
9589
[[TKWeChatPluginConfig sharedConfig] setForbidCheckVersion:YES];
9690
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// NSString+Action.h
3+
// WeChatPlugin
4+
//
5+
// Created by TK on 2018/5/1.
6+
// Copyright © 2018年 tk. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface NSString (Action)
12+
13+
- (CGFloat)widthWithFont:(NSFont *)font;
14+
- (NSRect)rectWithFont:(NSFont *)font;
15+
16+
@end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// NSString+Action.m
3+
// WeChatPlugin
4+
//
5+
// Created by TK on 2018/5/1.
6+
// Copyright © 2018年 tk. All rights reserved.
7+
//
8+
9+
#import "NSString+Action.h"
10+
11+
@implementation NSString (Action)
12+
13+
- (CGFloat)widthWithFont:(NSFont *)font {
14+
return [self rectWithFont:font].size.width;
15+
}
16+
17+
- (NSRect)rectWithFont:(NSFont *)font {
18+
return [self boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: font}];
19+
}
20+
21+
@end

WeChatPlugin/Sources/Common/Category/NSView+Action.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,15 @@
1313
- (void)addSubviews:(NSArray *)subViews;
1414

1515
@end
16+
17+
@interface NSView (Size)
18+
19+
@property (nonatomic) CGPoint origin;
20+
@property (nonatomic) CGSize size;
21+
22+
@property (nonatomic) CGFloat x;
23+
@property (nonatomic) CGFloat y;
24+
@property (nonatomic) CGFloat width;
25+
@property (nonatomic) CGFloat height;
26+
27+
@end

WeChatPlugin/Sources/Common/Category/NSView+Action.m

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,61 @@ - (void)addSubviews:(NSArray *)subViews {
1818
}
1919

2020
@end
21+
22+
@implementation NSView (Size)
23+
24+
- (CGPoint)origin {
25+
return self.frame.origin;
26+
}
27+
28+
- (void)setOrigin:(CGPoint)point {
29+
CGRect rect = self.frame;
30+
31+
rect.origin = point;
32+
self.frame = rect;
33+
}
34+
35+
- (CGSize)size {
36+
return self.frame.size;
37+
}
38+
39+
- (void)setSize:(CGSize)size {
40+
CGRect rect = self.frame;
41+
42+
rect.size = size;
43+
self.frame = rect;
44+
}
45+
46+
- (CGFloat)x {
47+
return self.frame.origin.x;
48+
}
49+
50+
- (void)setX:(CGFloat)x {
51+
[self setOrigin:CGPointMake(x, self.y)];
52+
}
53+
54+
- (CGFloat)y {
55+
return self.frame.origin.y;
56+
}
57+
58+
- (void)setY:(CGFloat)y {
59+
[self setOrigin:CGPointMake(self.x, y)];
60+
}
61+
62+
- (CGFloat)width {
63+
return self.frame.size.width;
64+
}
65+
66+
- (void)setWidth:(CGFloat)width {
67+
[self setSize:CGSizeMake(width, self.height)];
68+
}
69+
70+
- (CGFloat)height {
71+
return self.frame.size.height;
72+
}
73+
74+
- (void)setHeight:(CGFloat)height {
75+
[self setSize:CGSizeMake(self.width, height)];
76+
}
77+
78+
@end

WeChatPlugin/Sources/Common/TKPrefixHeader.pch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#import "NSButton+Action.h"
1818
#import "NSTextField+Action.h"
1919
#import "NSMenu+Action.h"
20+
#import "NSString+Action.h"
2021
#import "WeChatPlugin.h"
2122
#endif
2223

WeChatPlugin/Sources/Managers/TKAssistantMenuManager.m

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ - (void)initAssistantMenuItems {
7272
target:self
7373
keyEquivalent:@""
7474
state:0];
75+
// 关于小助手
76+
NSMenuItem *abountPluginItem = [NSMenuItem menuItemWithTitle:TKLocalizedString(@"assistant.menu.aboutAssistant")
77+
action:@selector(onAboutPluginControl:)
78+
target:self
79+
keyEquivalent:@""
80+
state:0];
7581

7682
NSMenu *subMenu = [[NSMenu alloc] initWithTitle:TKLocalizedString(@"assistant.menu.title")];
7783
[subMenu addItems:@[preventRevokeItem,
@@ -80,14 +86,15 @@ - (void)initAssistantMenuItems {
8086
newWeChatItem,
8187
onTopItem,
8288
autoAuthItem,
83-
updatePluginItem]];
89+
updatePluginItem,
90+
abountPluginItem]];
8491

8592
NSMenuItem *menuItem = [[NSMenuItem alloc] init];
8693
[menuItem setTitle:TKLocalizedString(@"assistant.menu.title")];
8794
[menuItem setSubmenu:subMenu];
8895
menuItem.target = self;
8996
[[[NSApplication sharedApplication] mainMenu] addItem:menuItem];
90-
menuItem.enabled = NO;
97+
// menuItem.enabled = NO;
9198

9299
[self addObserverWeChatConfig];
93100
}
@@ -233,8 +240,10 @@ - (void)onUpdatePluginControl:(NSMenuItem *)item {
233240
[alert setInformativeText:message];
234241
NSModalResponse respose = [alert runModal];
235242
if (respose == NSAlertFirstButtonReturn) {
236-
NSURL *url = [NSURL URLWithString:@"https://github.com/TKkk-iOSer/WeChatPlugin-MacOS"];
237-
[[NSWorkspace sharedWorkspace] openURL:url];
243+
TKDownloadWindowController *downloadWC = [TKDownloadWindowController downloadWindowController];
244+
[downloadWC showWindow:downloadWC];
245+
[downloadWC.window center];
246+
[downloadWC.window makeKeyWindow];
238247
}
239248
} else {
240249
NSAlert *alert = [[NSAlert alloc] init];
@@ -245,4 +254,8 @@ - (void)onUpdatePluginControl:(NSMenuItem *)item {
245254
}];
246255
}
247256

257+
- (void)onAboutPluginControl:(NSMenuItem *)item {
258+
259+
}
260+
248261
@end

WeChatPlugin/Sources/Managers/TKHTTPManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@
1717
progress:(nullable void (^)(NSProgress *downloadProgress))downloadProgressBlock
1818
completionHandler:(nullable void (^)(NSString * filePath, NSError * _Nullable error))completionHandler;
1919

20+
- (void)cancelDownload;
21+
2022
@end

WeChatPlugin/Sources/Managers/TKHTTPManager.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,22 @@ - (void)downloadWithUrlString:(NSString *)urlString
5555
self.sessionManager = [[objc_getClass("AFURLSessionManager") alloc] initWithSessionConfiguration:configuration];
5656

5757
self.downloadTask = [self.sessionManager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) {
58-
downloadProgressBlock(downloadProgress);
58+
if (downloadProgressBlock) downloadProgressBlock(downloadProgress);
59+
5960
} destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
6061
NSString *path = [directory stringByAppendingPathComponent:response.suggestedFilename];
6162
return [NSURL fileURLWithPath:path];
6263
} completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable urlPath, NSError * _Nullable error) {
6364
NSString *filePath = [[urlPath absoluteString] substringFromIndex:7];
64-
completionHandler(filePath, error);
65+
if (completionHandler) completionHandler(filePath, error);
6566
}];
6667
[self.downloadTask resume];
6768
}
6869

70+
- (void)cancelDownload {
71+
if (!self.downloadTask) return;
72+
[self.downloadTask cancel];
73+
self.downloadTask = nil;
74+
}
75+
6976
@end

WeChatPlugin/Sources/Managers/TKVersionManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ typedef NS_ENUM(NSUInteger, TKVersionStatus) {
1818
+ (instancetype)shareManager;
1919
- (void)checkVersionFinish:(void (^)(TKVersionStatus, NSString *))finish;
2020
- (void)downloadPluginProgress:(void (^)(NSProgress *downloadProgress))downloadProgressBlock completionHandler:(void (^)(NSString *filePath, NSError * _Nullable error))completionHandler;
21+
- (void)cancelDownload;
2122

2223
@end

WeChatPlugin/Sources/Managers/TKVersionManager.m

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,13 @@ - (void)downloadPluginProgress:(void (^)(NSProgress *downloadProgress))downloadP
5454

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

63+
- (void)cancelDownload {
64+
[[TKHTTPManager shareManager] cancelDownload];
65+
}
6866
@end

WeChatPlugin/Sources/WindowControllers/Download/TKDownloadWindowController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010

1111
@interface TKDownloadWindowController : NSWindowController
1212

13+
+ (instancetype)downloadWindowController;
14+
1315
@end

0 commit comments

Comments
 (0)