From 3facc3fdee52f68dcc2b12092fee2b11a09a0b99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Tue, 25 Feb 2020 14:20:27 +0800 Subject: [PATCH] code refactor --- doric-iOS/Devkit/Classes/DoricDev.h | 33 ++++++++++ doric-iOS/Devkit/Classes/DoricDev.m | 61 +++++++++++++++++++ .../Dev => Devkit/Classes}/DoricWSClient.h | 0 .../Dev => Devkit/Classes}/DoricWSClient.m | 0 .../Devkit/Classes/QRScanViewController.h | 28 +++++++++ .../Classes}/QRScanViewController.m | 24 +++++++- doric-iOS/Devkit/Classes/ReplaceMe.m | 0 .../Example/Example.xcodeproj/project.pbxproj | 6 -- .../Example/Example/QRScanViewController.h | 10 --- doric-iOS/Example/Example/ViewController.m | 6 +- doric-iOS/Pod/Classes/DoricDriver.h | 4 -- doric-iOS/Pod/Classes/DoricDriver.m | 16 ----- 12 files changed, 147 insertions(+), 41 deletions(-) create mode 100644 doric-iOS/Devkit/Classes/DoricDev.h create mode 100644 doric-iOS/Devkit/Classes/DoricDev.m rename doric-iOS/{Pod/Classes/Dev => Devkit/Classes}/DoricWSClient.h (100%) rename doric-iOS/{Pod/Classes/Dev => Devkit/Classes}/DoricWSClient.m (100%) create mode 100644 doric-iOS/Devkit/Classes/QRScanViewController.h rename doric-iOS/{Example/Example => Devkit/Classes}/QRScanViewController.m (81%) delete mode 100644 doric-iOS/Devkit/Classes/ReplaceMe.m delete mode 100644 doric-iOS/Example/Example/QRScanViewController.h diff --git a/doric-iOS/Devkit/Classes/DoricDev.h b/doric-iOS/Devkit/Classes/DoricDev.h new file mode 100644 index 00000000..b8d1684e --- /dev/null +++ b/doric-iOS/Devkit/Classes/DoricDev.h @@ -0,0 +1,33 @@ +/* + * Copyright [2019] [Doric.Pub] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// DoricDev.h +// Doric +// +// Created by jingpeng.wang on 2020/2/25. +// + +NS_ASSUME_NONNULL_BEGIN + +@interface DoricDev : NSObject ++ (instancetype)instance; + +- (void)connectDevKit:(NSString *)url; + +- (void)disconnectDevKit; +@end + +NS_ASSUME_NONNULL_END diff --git a/doric-iOS/Devkit/Classes/DoricDev.m b/doric-iOS/Devkit/Classes/DoricDev.m new file mode 100644 index 00000000..970f9613 --- /dev/null +++ b/doric-iOS/Devkit/Classes/DoricDev.m @@ -0,0 +1,61 @@ +/* + * Copyright [2019] [Doric.Pub] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// DoricDev.m +// Doric +// +// Created by jingpeng.wang on 2020/2/25. +// + +#import "DoricDev.h" +#import "DoricWSClient.h" + +@interface DoricDev () +@property(nonatomic, strong) DoricWSClient *wsclient; +@end + +@implementation DoricDev + +- (instancetype)init { + if (self = [super init]) { + } + return self; +} + ++ (instancetype)instance { + static DoricDev *_instance; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + _instance = [[DoricDev alloc] init]; + }); + return _instance; +} + +- (void)connectDevKit:(NSString *)url { + if (self.wsclient) { + [self.wsclient close]; + } + self.wsclient = [[DoricWSClient alloc] initWithUrl:url]; +} + +- (void)disconnectDevKit { + if (self.wsclient) { + [self.wsclient close]; + self.wsclient = nil; + } +} + +@end diff --git a/doric-iOS/Pod/Classes/Dev/DoricWSClient.h b/doric-iOS/Devkit/Classes/DoricWSClient.h similarity index 100% rename from doric-iOS/Pod/Classes/Dev/DoricWSClient.h rename to doric-iOS/Devkit/Classes/DoricWSClient.h diff --git a/doric-iOS/Pod/Classes/Dev/DoricWSClient.m b/doric-iOS/Devkit/Classes/DoricWSClient.m similarity index 100% rename from doric-iOS/Pod/Classes/Dev/DoricWSClient.m rename to doric-iOS/Devkit/Classes/DoricWSClient.m diff --git a/doric-iOS/Devkit/Classes/QRScanViewController.h b/doric-iOS/Devkit/Classes/QRScanViewController.h new file mode 100644 index 00000000..f116cd1d --- /dev/null +++ b/doric-iOS/Devkit/Classes/QRScanViewController.h @@ -0,0 +1,28 @@ +/* + * Copyright [2019] [Doric.Pub] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// QRScanViewController.h +// Doric +// +// Created by jingpeng.wang on 2020/2/25. +// + + +#import +#import + +@interface QRScanViewController : UIViewController +@end diff --git a/doric-iOS/Example/Example/QRScanViewController.m b/doric-iOS/Devkit/Classes/QRScanViewController.m similarity index 81% rename from doric-iOS/Example/Example/QRScanViewController.m rename to doric-iOS/Devkit/Classes/QRScanViewController.m index 3bb87fc1..e3a406b2 100644 --- a/doric-iOS/Example/Example/QRScanViewController.m +++ b/doric-iOS/Devkit/Classes/QRScanViewController.m @@ -1,11 +1,29 @@ +/* + * Copyright [2019] [Doric.Pub] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ // -// Created by pengfei.zhou on 2019/11/21. -// Copyright (c) 2019 pengfei.zhou. All rights reserved. +// QRScanViewController.m +// Doric +// +// Created by jingpeng.wang on 2020/2/25. // #import "QRScanViewController.h" #import #import +#import @interface QRScanViewController () @property(strong, nonatomic) AVCaptureDevice *device; @@ -85,7 +103,7 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects: AVMetadataMachineReadableCodeObject *qrObject = [metadataObjects lastObject]; NSString *result = qrObject.stringValue; NSLog(@"Scan result is %@", result); - [[DoricDriver instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]]; + [[DoricDev instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]]; ShowToast([NSString stringWithFormat:@"Connected to %@", result], BOTTOM); [self.navigationController popViewControllerAnimated:NO]; } diff --git a/doric-iOS/Devkit/Classes/ReplaceMe.m b/doric-iOS/Devkit/Classes/ReplaceMe.m deleted file mode 100644 index e69de29b..00000000 diff --git a/doric-iOS/Example/Example.xcodeproj/project.pbxproj b/doric-iOS/Example/Example.xcodeproj/project.pbxproj index 3dd2b59e..8b255a4b 100644 --- a/doric-iOS/Example/Example.xcodeproj/project.pbxproj +++ b/doric-iOS/Example/Example.xcodeproj/project.pbxproj @@ -11,7 +11,6 @@ A1E221FB2DCA40D85C4D9520 /* libPods-ExampleTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4F233ACD236542275AED3DE0 /* libPods-ExampleTests.a */; }; CC537F4B9F59400BA5B4FF8F /* libPods-Example.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DEE8411A69609CC9C86063CC /* libPods-Example.a */; }; D751D4B065D8D4FA6594B5EE /* DemoVC.m in Sources */ = {isa = PBXBuildFile; fileRef = D751D19E97EF4EDD7588FEBE /* DemoVC.m */; }; - D751D4FCC0A2322211DE3D55 /* QRScanViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D751DA399F1ADB6D34563B5D /* QRScanViewController.m */; }; D751DDB012BAF476A252CD93 /* DemoLibrary.m in Sources */ = {isa = PBXBuildFile; fileRef = D751D2175D09F2C10691FB81 /* DemoLibrary.m */; }; E2334AF022E9D2060098A085 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E2334AEF22E9D2060098A085 /* AppDelegate.m */; }; E2334AF322E9D2060098A085 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E2334AF222E9D2060098A085 /* ViewController.m */; }; @@ -51,10 +50,8 @@ 8BCADA7B23CD5B64005EEF96 /* NavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NavigationController.m; sourceTree = ""; }; B93423722F2E06DC238CDD18 /* Pods-ExampleUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ExampleUITests.release.xcconfig"; path = "Pods/Target Support Files/Pods-ExampleUITests/Pods-ExampleUITests.release.xcconfig"; sourceTree = ""; }; B93D4DB00FD244178B7CE7C4 /* Pods-ExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ExampleTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-ExampleTests/Pods-ExampleTests.release.xcconfig"; sourceTree = ""; }; - D751D18AD6496F4A9BE1AB45 /* QRScanViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QRScanViewController.h; sourceTree = ""; }; D751D19E97EF4EDD7588FEBE /* DemoVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoVC.m; sourceTree = ""; }; D751D2175D09F2C10691FB81 /* DemoLibrary.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoLibrary.m; sourceTree = ""; }; - D751DA399F1ADB6D34563B5D /* QRScanViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QRScanViewController.m; sourceTree = ""; }; D751DB0CB3009E12990F661E /* DemoLibrary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoLibrary.h; sourceTree = ""; }; D751DDEC114E037231257E64 /* DemoVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoVC.h; sourceTree = ""; }; D91241144B5A3356A3C60644 /* Pods-ExampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ExampleTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ExampleTests/Pods-ExampleTests.debug.xcconfig"; sourceTree = ""; }; @@ -169,8 +166,6 @@ E2334AFD22E9D2070098A085 /* main.m */, D751D19E97EF4EDD7588FEBE /* DemoVC.m */, D751DDEC114E037231257E64 /* DemoVC.h */, - D751DA399F1ADB6D34563B5D /* QRScanViewController.m */, - D751D18AD6496F4A9BE1AB45 /* QRScanViewController.h */, D751D2175D09F2C10691FB81 /* DemoLibrary.m */, D751DB0CB3009E12990F661E /* DemoLibrary.h */, ); @@ -439,7 +434,6 @@ E2334AFE22E9D2070098A085 /* main.m in Sources */, E2334AF022E9D2060098A085 /* AppDelegate.m in Sources */, D751D4B065D8D4FA6594B5EE /* DemoVC.m in Sources */, - D751D4FCC0A2322211DE3D55 /* QRScanViewController.m in Sources */, D751DDB012BAF476A252CD93 /* DemoLibrary.m in Sources */, 8BCADA7C23CD5B65005EEF96 /* NavigationController.m in Sources */, ); diff --git a/doric-iOS/Example/Example/QRScanViewController.h b/doric-iOS/Example/Example/QRScanViewController.h deleted file mode 100644 index 05ffa4e6..00000000 --- a/doric-iOS/Example/Example/QRScanViewController.h +++ /dev/null @@ -1,10 +0,0 @@ -// -// Created by pengfei.zhou on 2019/11/21. -// Copyright (c) 2019 pengfei.zhou. All rights reserved. -// - -#import -#import - -@interface QRScanViewController : UIViewController -@end \ No newline at end of file diff --git a/doric-iOS/Example/Example/ViewController.m b/doric-iOS/Example/Example/ViewController.m index fd047ef1..f0a18b3c 100644 --- a/doric-iOS/Example/Example/ViewController.m +++ b/doric-iOS/Example/Example/ViewController.m @@ -7,9 +7,11 @@ // #import +#import +#import #import "ViewController.h" -#import "QRScanViewController.h" + #import "DemoLibrary.h" @interface ViewController () @@ -68,7 +70,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath if (indexPath.row == 0) { if (self.isSimulator) { NSString *result = @"127.0.0.1"; - [[DoricDriver instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]]; + [[DoricDev instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]]; ShowToast([NSString stringWithFormat:@"Connected to %@", result], BOTTOM); } else { [self.navigationController pushViewController:[QRScanViewController new] animated:NO]; diff --git a/doric-iOS/Pod/Classes/DoricDriver.h b/doric-iOS/Pod/Classes/DoricDriver.h index f04d72dc..6f9c7e56 100644 --- a/doric-iOS/Pod/Classes/DoricDriver.h +++ b/doric-iOS/Pod/Classes/DoricDriver.h @@ -49,10 +49,6 @@ NS_ASSUME_NONNULL_BEGIN - (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString *)method argumentsArray:(NSArray *)args; -- (void)connectDevKit:(NSString *)url; - -- (void)disconnectDevKit; - - (void)ensureSyncInMainQueue:(dispatch_block_t)block; - (NSString *)aliasWithContextId:(NSString *)contextId; diff --git a/doric-iOS/Pod/Classes/DoricDriver.m b/doric-iOS/Pod/Classes/DoricDriver.m index c8d65126..37b478f9 100644 --- a/doric-iOS/Pod/Classes/DoricDriver.m +++ b/doric-iOS/Pod/Classes/DoricDriver.m @@ -23,12 +23,10 @@ #import "DoricDriver.h" #import "DoricJSEngine.h" #import "DoricConstant.h" -#import "DoricWSClient.h" #import "DoricContextManager.h" @interface DoricDriver () @property(nonatomic, strong) DoricJSEngine *jsExecutor; -@property(nonatomic, strong) DoricWSClient *wsclient; @end @implementation DoricDriver @@ -178,20 +176,6 @@ - (DoricAsyncResult *)destroyContext:(NSString *)contextId { return ret; } -- (void)connectDevKit:(NSString *)url { - if (self.wsclient) { - [self.wsclient close]; - } - self.wsclient = [[DoricWSClient alloc] initWithUrl:url]; -} - -- (void)disconnectDevKit { - if (self.wsclient) { - [self.wsclient close]; - self.wsclient = nil; - } -} - - (void)ensureSyncInMainQueue:(dispatch_block_t)block { if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(dispatch_get_main_queue())) == 0) { block();