KMVerificationMessageViewController.m 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. //
  2. // KMVerificationMessageViewController.m
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by 王帅 on 2018/5/9.
  6. //
  7. #import "KMVerificationMessageViewController.h"
  8. #import <PDF_Reader_Pro-Swift.h>
  9. #import "VerificationManager.h"
  10. #import "AIInfoManager.h"
  11. #import "KMVerificationWindowController.h"
  12. #import "KMPurchaseCompareWindowController.h"
  13. #import "KMUnlockAlertViewController.h"
  14. #define kbottomGap 0
  15. @interface KMVerificationMessageViewController ()<
  16. NSPopoverDelegate>
  17. @property (strong) IBOutlet NSView *contendView;
  18. @property (strong) IBOutlet NSButton *freeTrialButton;
  19. @property (strong) IBOutlet NSButton *upgradButton;
  20. @property (nonatomic, strong) NSTrackingArea *trackingArea;
  21. @property (nonatomic, strong) NSPopover *popover;
  22. @property (nonatomic, assign) BOOL isPopoverShow;
  23. @property (nonatomic, assign) BOOL checkValue;
  24. @property (nonatomic, assign) BOOL stopPopOverHide;
  25. @property (nonatomic, strong) KMUnlockAlertViewController *testVC;
  26. @property (nonatomic, strong) KMTrialGuideWindowController *trialGuideWC;
  27. @property (nonatomic, strong) FreeTrialApplyWindowController *freeTrialApplyWC;
  28. @end
  29. @implementation KMVerificationMessageViewController
  30. #pragma mark Init Methods
  31. - (instancetype)init {
  32. if (self = [super initWithNibName:@"KMVerificationMessageViewController" bundle:nil]) {
  33. #if VERSION_DMG
  34. [[NSNotificationCenter defaultCenter] addObserver:self
  35. selector:@selector(deviceActivateStatusChangeNotification:)
  36. name:kDeviceActivateStatusChangeNotification
  37. object:nil];
  38. #else
  39. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPResultReceived:) name:KMIAPSubscriptionLoadedNotification object:nil];
  40. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPPurchaseSuccess:) name:KMIAPProductPurchasedNotification object:nil];
  41. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPRestoreFinish:) name:KMIAPProductRestoreFinishedNotification object:nil];
  42. #endif
  43. }
  44. return self;
  45. }
  46. - (void)dealloc {
  47. [[NSNotificationCenter defaultCenter] removeObserver:self];
  48. // if (self.trackingArea) {
  49. // [self.upgradButton removeTrackingArea:self.trackingArea];
  50. // }
  51. }
  52. #pragma mark Setter Methods
  53. - (void)loadView {
  54. [super loadView];
  55. // Do view setup here.
  56. self.freeTrialButton.wantsLayer = YES;
  57. self.freeTrialButton.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  58. [self.freeTrialButton setTitleColor:[NSColor whiteColor]];
  59. [self.freeTrialButton setAlignment:NSTextAlignmentCenter];
  60. self.upgradButton.wantsLayer = YES;
  61. self.upgradButton.layer.masksToBounds = YES;
  62. self.upgradButton.layer.cornerRadius = 4.0;
  63. self.upgradButton.font = [NSFont SFProTextSemiboldFont:11];
  64. self.upgradButton.layer.backgroundColor = [NSColor colorWithDeviceRed:121.0/255.0 green:196.0/255.0 blue:66.0/255.0 alpha:1.0].CGColor;
  65. [self.upgradButton setAlignment:NSTextAlignmentCenter];
  66. self.freeTrialButton.wantsLayer = YES;
  67. self.freeTrialButton.layer.masksToBounds = YES;
  68. self.freeTrialButton.layer.cornerRadius = 4.0;
  69. self.freeTrialButton.font = [NSFont SFProTextSemiboldFont:11];
  70. NSString *tTips = NSLocalizedString(@"Upgrade to Pro", nil);
  71. #if VERSION_DMG
  72. tTips = [NSString stringWithFormat:@"%@\n%@", NSLocalizedString(@"Upgrade to Permanent License with one time purchase", nil), NSLocalizedString(@"Complete the purchase in your web browser to get a license", nil)];
  73. #else
  74. tTips = [NSString stringWithFormat:@"%@\n%@", NSLocalizedString(@"Subscribe to All Access Pack to enjoy more expanded features.", nil), NSLocalizedString(@"Choose your favorite payment and enjoy flexible upgrades.", nil)];
  75. #endif
  76. self.upgradButton.toolTip = tTips;
  77. self.upgradButton.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  78. [self.upgradButton setTitleColor:[NSColor whiteColor]];
  79. [self.upgradButton setAlignment:NSTextAlignmentCenter];
  80. [self reloadData];
  81. }
  82. - (void)reloadData {
  83. /*
  84. 未试用:申请试用 + 解锁完整版
  85. 试用中:试用剩余天数 + 解锁完整版
  86. 试用过期:解锁完整版
  87. 已激活:隐藏
  88. */
  89. #if VERSION_DMG
  90. if (self.trackingArea) {
  91. [self.upgradButton removeTrackingArea:self.trackingArea];
  92. }
  93. self.freeTrialButton.hidden = self.upgradButton.hidden = YES;
  94. if (ActivityStatusNone == [VerificationManager manager].status) {
  95. self.freeTrialButton.hidden = self.upgradButton.hidden = NO;
  96. self.freeTrialButton.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  97. self.freeTrialButton.layer.backgroundColor = [NSColor colorWithRed:0.0/255.0 green:207.0/255.0 blue:133.0/255.0 alpha:1].CGColor;
  98. [self.freeTrialButton setTitleColor:[NSColor whiteColor]];
  99. self.upgradButton.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  100. [self.upgradButton setAlignment:NSTextAlignmentCenter];
  101. [self.upgradButton setTitleColor:[NSColor whiteColor]];
  102. } else if (ActivityStatusTrial == [VerificationManager manager].status) {
  103. self.freeTrialButton.hidden = self.upgradButton.hidden = NO;
  104. NSDate *date = [NSDate date];
  105. NSDate *expireDate = [VerificationManager manager].detailInfo.expireDate;
  106. NSTimeInterval time = [expireDate timeIntervalSinceDate:date];
  107. int leftDays = ((int)time)/(3600*24);
  108. NSString *needShowString = [NSString stringWithFormat:NSLocalizedString(@"%d days left", nil),leftDays];
  109. self.freeTrialButton.title = needShowString;
  110. [self.freeTrialButton setTitleColor:[NSColor redColor]];
  111. self.freeTrialButton.layer.backgroundColor = [NSColor clearColor].CGColor;
  112. self.upgradButton.layer.backgroundColor = [NSColor colorWithRed:255.0/255.0 green:94.0/255.0 blue:44.0/255.0 alpha:1].CGColor;
  113. self.upgradButton.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  114. [self.upgradButton setTitleColor:[NSColor whiteColor]];
  115. [self.upgradButton setAlignment:NSTextAlignmentCenter];
  116. // if (!self.trackingArea) {
  117. // self.trackingArea = [[NSTrackingArea alloc] initWithRect:self.upgradButton.bounds options:NSTrackingMouseEnteredAndExited | NSTrackingInVisibleRect | NSTrackingActiveAlways owner:self userInfo:nil];
  118. // }
  119. // [self.upgradButton addTrackingArea:self.trackingArea];
  120. } else if (ActivityStatusTrialExpire == [VerificationManager manager].status) {
  121. self.upgradButton.hidden = NO;
  122. self.upgradButton.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  123. [self.upgradButton setAlignment:NSTextAlignmentCenter];
  124. self.upgradButton.layer.backgroundColor = [NSColor clearColor].CGColor;
  125. [self.upgradButton setTitleColor:[NSColor whiteColor]];
  126. // if (!self.trackingArea) {
  127. // self.trackingArea = [[NSTrackingArea alloc] initWithRect:self.upgradButton.bounds options:NSTrackingMouseEnteredAndExited | NSTrackingInVisibleRect | NSTrackingActiveAlways owner:self userInfo:nil];
  128. // }
  129. // [self.upgradButton addTrackingArea:self.trackingArea];
  130. } else if (ActivityStatusVerifExpire == [VerificationManager manager].status) {
  131. self.upgradButton.hidden = NO;
  132. self.upgradButton.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  133. [self.upgradButton setTitleColor:[NSColor whiteColor]];
  134. self.upgradButton.layer.backgroundColor = [NSColor clearColor].CGColor;
  135. [self.upgradButton setAlignment:NSTextAlignmentCenter];
  136. } else if (ActivityStatusVerification == [VerificationManager manager].status) {
  137. } else {
  138. }
  139. #else
  140. #endif
  141. [self.freeTrialButton sizeToFit];
  142. [self.freeTrialButton setAlignment:NSTextAlignmentCenter];
  143. [self.upgradButton sizeToFit];
  144. [self.upgradButton setAlignment:NSTextAlignmentCenter];
  145. CGFloat totalWidth = 8;
  146. if (self.freeTrialButton.hidden == NO) {
  147. CGFloat buttonWidth = self.freeTrialButton.frame.size.width;
  148. buttonWidth += 10;
  149. self.freeTrialButton.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  150. totalWidth += buttonWidth;
  151. totalWidth += 8;
  152. }
  153. if (self.upgradButton.hidden == NO) {
  154. NSRect btnRect = [self.upgradButton.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.upgradButton.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  155. CGFloat buttonWidth = btnRect.size.width + 40;
  156. self.upgradButton.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  157. totalWidth += buttonWidth;
  158. totalWidth += 8;
  159. }
  160. if (self.view.superview) {
  161. self.view.frame = CGRectMake(MAX(0, CGRectGetWidth(self.view.superview.frame)-totalWidth - 8), (CGRectGetHeight(self.view.superview.frame)-CGRectGetHeight(self.view.frame))/2., totalWidth, self.view.frame.size.height);
  162. } else {
  163. if (self.upgradButton.hidden) {
  164. self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.freeTrialButton.frame) + 20 ,self.view.frame.size.height);
  165. } else {
  166. self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.upgradButton.frame) ,self.view.frame.size.height);
  167. }
  168. }
  169. self.contendView.wantsLayer = true;
  170. self.contendView.layer.backgroundColor = NSColor.clearColor.CGColor;
  171. if (self.frameUpdateHandle) {
  172. self.frameUpdateHandle(self.view.frame);
  173. }
  174. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popoverShowNoti:) name:@"KMVerificationMessagePopShowNoti" object:nil];
  175. }
  176. #pragma mark - Button Actions
  177. - (IBAction)freeTrialButtonAction:(NSButton *)sender {
  178. if (ActivityStatusNone != [VerificationManager manager].status) {
  179. return;
  180. }
  181. __weak typeof(self) weakSelf = self;
  182. if (!self.trialGuideWC) {
  183. self.trialGuideWC = [KMTrialGuideWindowController currentWC];
  184. }
  185. self.trialGuideWC.noEmailBlock = ^{
  186. [weakSelf.trialGuideWC close];
  187. [weakSelf showFreeTrialApplyWC];
  188. };
  189. self.trialGuideWC.shouldMinSizeAnimate = true;
  190. [self.trialGuideWC.window center];
  191. CGRect originalRect = self.trialGuideWC.window.frame;
  192. originalRect.size.width = 888;
  193. originalRect.size.height = 520;
  194. originalRect.origin.x = ([NSScreen mainScreen].frame.size.width - originalRect.size.width)/2.0;
  195. originalRect.origin.y = ([NSScreen mainScreen].frame.size.height - originalRect.size.height)/2.0;
  196. self.trialGuideWC.originalFrame = originalRect;
  197. CGRect rect = [self.view convertRect:self.upgradButton.frame toView:self.view.window.contentView];
  198. rect.origin.x = CGRectGetMaxX(self.view.window.frame) - self.upgradButton.frame.size.width - self.freeTrialButton.frame.size.width/2.0 - 15;
  199. rect.origin.y = CGRectGetMaxY(self.view.window.frame) - self.upgradButton.frame.size.height - 5;
  200. rect.size.width = 0;
  201. rect.size.height = 0;
  202. self.trialGuideWC.startFrame = rect;
  203. [self.trialGuideWC.window setFrame:rect display:YES];
  204. [self.trialGuideWC showWindow:nil];
  205. [self.trialGuideWC animateScaling];
  206. }
  207. - (void)showFreeTrialApplyWC {
  208. if (self.freeTrialApplyWC != nil) {
  209. self.freeTrialApplyWC = nil;
  210. }
  211. if (self.freeTrialApplyWC == nil) {
  212. self.freeTrialApplyWC = [[FreeTrialApplyWindowController alloc] init];
  213. }
  214. [self.freeTrialApplyWC.window center];
  215. [self.freeTrialApplyWC showWindow:nil];
  216. }
  217. - (IBAction)upgradeButtonAction:(id)sender {
  218. BOOL isFree = NO;
  219. __weak typeof(self) weakSelf = self;
  220. #if VERSION_DMG
  221. if (ActivityStatusNone == [VerificationManager manager].status ||
  222. ActivityStatusTrialExpire == [VerificationManager manager].status) {
  223. // [[NSNotificationCenter defaultCenter] postNotificationName:@"KMVerificationMessagePopShowNoti" object:nil];
  224. //
  225. // if (!self.testVC) {
  226. // self.testVC = [[KMUnlockAlertViewController alloc] init];
  227. // if (ActivityStatusNone == [VerificationManager manager].status) {
  228. // //弹出 试用弹窗UI优化-新用户试用路径 新UI 情况一 右上角按钮
  229. // KMPurchaseFirstTrialWindowController *firstTrialWC = [KMPurchaseFirstTrialWindowController currentFirstTrialWC];
  230. // firstTrialWC.buttonActionBlock = ^(KMPurchaseFirstTrialWindowController * _Nonnull ftWC, KMButton * _Nonnull btn, NSString * _Nonnull email, NSString * _Nonnull name) {
  231. // if (btn.tag == 10001) {
  232. // if (ActivityStatusNone == [VerificationManager manager].status ||
  233. // ActivityStatusTrialExpire == [VerificationManager manager].status) {
  234. //
  235. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_SecondTrial"}];
  236. // [[VerificationManager manager] trialForDays:7
  237. // email:email?:[VerificationManager manager].email
  238. // name:name?:[VerificationManager manager].accountName
  239. // complention:^(ActivityStatus status, NSDictionary *info, NSError *error) {
  240. // if (error ||
  241. // status != ActivityStatusTrial) {
  242. // NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  243. // defaultButton:NSLocalizedString(@"Try Again", nil)
  244. // alternateButton:nil
  245. // otherButton:nil
  246. // informativeTextWithFormat:NSLocalizedString(@"Failed to sign up for the free trial. Please make sure your internet connection is available and try again later.", nil), nil];
  247. // [alert runModal];
  248. // } else {
  249. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialSuccess];
  250. // [vc showWindow:nil];
  251. // }
  252. // }];
  253. // [ftWC close];
  254. // } else {
  255. // [ftWC close];
  256. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];
  257. // vc.callback = ^{
  258. // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  259. // };
  260. // [vc showWindow:nil];
  261. // }
  262. // } else if (btn.tag == 10002) {
  263. // NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/store/pdftecheditor?utm_source=app_dmg&utm_medium=dmg_puw_free_trial"];
  264. // [[NSWorkspace sharedWorkspace] openURL:url];
  265. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_UpgradeBuyNow"}];
  266. // } else if (btn.tag == 10003) {
  267. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];//KMVerificationTypeActivate
  268. // [vc showWindow:nil];
  269. // [ftWC close];
  270. // }
  271. // };
  272. // [firstTrialWC.window center];
  273. // [firstTrialWC showWindow:nil];
  274. // } else if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  275. // ActivityStatusTrial == [VerificationManager manager].status) {
  276. //// if ([VerificationManager manager].secondTrialEnabled) {
  277. //// if (!self.checkValue) {
  278. //// [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  279. //// }
  280. //// } else {
  281. // [[NSNotificationCenter defaultCenter] postNotificationName:@"KMVerificationMessagePopShowNoti" object:nil];
  282. //
  283. // if (!self.testVC) {
  284. // self.testVC = [[KMUnlockAlertViewController alloc] init];
  285. // }
  286. // [self.testVC addtrackingAreaInfo];
  287. // self.testVC.callback = ^(NSInteger index) {
  288. // if (index == 1) {
  289. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];
  290. // [vc showWindow:nil];
  291. // } else if (index == 2) {
  292. // NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/store/pdftecheditor"];
  293. //
  294. // [[NSWorkspace sharedWorkspace] openURL:url];
  295. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"Btn_PUW_BuyNow-Expire"}];
  296. //// KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.mac.product_3"];
  297. //// [embeddedWC showWindow:nil];
  298. //// [[embeddedWC window] center];
  299. // }
  300. // };
  301. // self.testVC.mouseEventCall = ^(BOOL mouseEnter) {
  302. // if (mouseEnter) {
  303. // self.stopPopOverHide = YES;
  304. // if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  305. // ActivityStatusTrial == [VerificationManager manager].status) {
  306. // if (!self.popover.isShown) {
  307. // [self buttonAction:self.button];
  308. // }
  309. // }
  310. // } else {
  311. // self.stopPopOverHide = NO;
  312. // if (self.popover) {
  313. // [self.popover close];
  314. // }
  315. // [self.testVC removeTrackingAreaInfo];
  316. // }
  317. // };
  318. // NSPopover *popover = [[NSPopover alloc] init];
  319. // popover.delegate = self;
  320. // popover.contentViewController = self.testVC;
  321. // popover.animates = YES;
  322. // popover.behavior = NSPopoverBehaviorTransient;
  323. // [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
  324. // self.popover = popover;
  325. // }
  326. // [self.testVC addtrackingAreaInfo];
  327. // self.testVC.callback = ^(NSInteger index) {
  328. // if (index == 1) {
  329. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];
  330. // [vc showWindow:nil];
  331. // } else if (index == 2) {
  332. // NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/store/pdftecheditor"];
  333. //
  334. // [[NSWorkspace sharedWorkspace] openURL:url];
  335. // }
  336. // };
  337. // self.testVC.mouseEventCall = ^(BOOL mouseEnter) {
  338. // if (mouseEnter) {
  339. // weakSelf.stopPopOverHide = YES;
  340. // if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  341. // ActivityStatusTrial == [VerificationManager manager].status) {
  342. // if (!weakSelf.popover.isShown) {
  343. // [weakSelf upgradeButtonAction:weakSelf.upgradButton];
  344. // }
  345. // }
  346. // } else {
  347. // weakSelf.stopPopOverHide = NO;
  348. // if (weakSelf.popover) {
  349. // [weakSelf.popover close];
  350. // }
  351. // [weakSelf.testVC removeTrackingAreaInfo];
  352. // }
  353. // };
  354. // NSPopover *popover = [[NSPopover alloc] init];
  355. // popover.delegate = self;
  356. // popover.contentViewController = self.testVC;
  357. // popover.animates = YES;
  358. // popover.behavior = NSPopoverBehaviorTransient;
  359. // [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
  360. // self.popover = popover;
  361. if (IAPProductsManager.defaultManager.isAvailableAllFunction == NO) {
  362. [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  363. }
  364. } else if (ActivityStatusTrial == [VerificationManager manager].status) {
  365. [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  366. } else if (ActivityStatusVerifExpire == [VerificationManager manager].status) {
  367. if (IAPProductsManager.defaultManager.isAvailableAllFunction == NO) {
  368. [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  369. }
  370. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateExpired];
  371. // [vc showWindow:nil];
  372. } else if (ActivityStatusVerification == [VerificationManager manager].status) {
  373. if ([VerificationManager manager].needUpgradeLicense) {
  374. NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/store/pdftecheditor?product_code=product_2"];
  375. [[NSWorkspace sharedWorkspace] openURL:url];
  376. }
  377. } else {
  378. if ([VerificationManager manager].needUpgradeLicense) {
  379. NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/store/pdftecheditor?product_code=product_2"];
  380. [[NSWorkspace sharedWorkspace] openURL:url];
  381. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_PDFtoOffice"}];
  382. } else {
  383. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeNormal];
  384. [vc showWindow:nil];
  385. }
  386. }
  387. #else
  388. isFree = YES;
  389. #if VERSION_FREE
  390. if ([IAPProductsManager defaultManager].isAvailableAllFunction) {
  391. isFree = NO;
  392. }
  393. if (isFree) {
  394. [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  395. }
  396. #else
  397. if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice) {
  398. // KMToolCompareWindowController *vc = [KMToolCompareWindowController toolCompareWithType:KMCompareWithToolType_Convert setSelectIndex:0];
  399. KMToolCompareWindowController *vc = [KMToolCompareWindowController toolCompareWithToolType:KMCompareWithToolTypeConvert selectNum:0];
  400. [vc.window center];
  401. [vc showWindow:nil];
  402. }
  403. #endif
  404. #endif
  405. }
  406. #pragma mark - Private Method
  407. - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
  408. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
  409. NSString *temp = nil;
  410. for (NSUInteger i = 0; i <string.length; i++) {
  411. temp = [string substringWithRange:NSMakeRange(i, 1)];
  412. if ([self isPureInt:temp]) {
  413. [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  414. color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
  415. }
  416. }
  417. return attributedString;
  418. }
  419. - (BOOL)isPureInt:(NSString *)string {
  420. NSScanner *scan = [NSScanner scannerWithString:string];
  421. int value;
  422. return [scan scanInt:&value] && [scan isAtEnd];
  423. }
  424. - (IBAction)AIButtonAction:(NSButton *)sender {
  425. __block typeof(self) blockSelf = self;
  426. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit"}];
  427. [[AIInfoManager defaultManager] fetchAIInfoWithComplention:^(NSDictionary *info, NSError *error) {
  428. }];
  429. AIUserInfoController *controller = [[AIUserInfoController alloc] init];
  430. controller.purchaseHandle = ^(AIUserInfoController * _Nonnull vc) {
  431. #if VERSION_DMG
  432. // NSURL *url = [NSURL URLWithString:Swift_oc_Tool.AIProduct_Link_OC];
  433. // [[NSWorkspace sharedWorkspace] openURL:url];
  434. // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.ai.product_1"];
  435. // [embeddedWC showWindow:nil];
  436. // [[embeddedWC window] center];
  437. #else
  438. [[AIPurchaseWindowController currentWC] showWindow:nil];
  439. #endif
  440. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit_BuyNow"}];
  441. };
  442. controller.enterLicenseHandle = ^(AIUserInfoController * _Nonnull vc) {
  443. KMVerificationWindowController *verifyVC = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateAIInfo];
  444. verifyVC.callback = ^{
  445. };
  446. [verifyVC showWindow:nil];
  447. };
  448. controller.guideHandle = ^(AIUserInfoController * _Nonnull vc) {
  449. // if (!blockSelf.guideWindowVC) {
  450. // KMFunctionGuideWindowController *guideWindowVC = [[KMFunctionGuideWindowController alloc] initWithWindowNibName:@"KMFunctionGuideWindowController"];
  451. // blockSelf.guideWindowVC = guideWindowVC;
  452. // }
  453. // ((KMFunctionGuideWindowController *)(blockSelf.guideWindowVC)).type = KMGuideInfoTypeFunctionMulti;
  454. // [blockSelf.guideWindowVC showWindow:nil];
  455. // [KMFunctionGuideWindowController setDidShowFor:KMGuideInfoTypeFunctionMultiAIGuide];
  456. // [blockSelf.guideWindowVC.window orderFront:nil];
  457. };
  458. NSPopover *popover = [[NSPopover alloc] init];
  459. popover.contentViewController = controller;
  460. popover.animates = YES;
  461. popover.behavior = NSPopoverBehaviorTransient;
  462. [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
  463. }
  464. #pragma mark - NSNotification Methods
  465. - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
  466. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  467. [self reloadData];
  468. });
  469. }
  470. - (void)IAPResultReceived:(NSNotification *)notification {
  471. dispatch_async(dispatch_get_main_queue(), ^{
  472. [self reloadData];
  473. });
  474. }
  475. - (void)IAPPurchaseSuccess:(NSNotification *)notification {
  476. dispatch_async(dispatch_get_main_queue(), ^{
  477. [self reloadData];
  478. });
  479. }
  480. - (void)IAPRestoreFinish:(NSNotification *)notification {
  481. dispatch_async(dispatch_get_main_queue(), ^{
  482. [self reloadData];
  483. });
  484. }
  485. #pragma mark -Popover
  486. - (void)popoverDidClose:(NSNotification *)notification {
  487. self.stopPopOverHide = NO;
  488. }
  489. - (void)popoverShowNoti:(NSNotification *)noti {
  490. if (self.popover) {
  491. [self.popover close];
  492. self.stopPopOverHide = NO;
  493. }
  494. }
  495. - (void)popOverCloseAction {
  496. if (self.stopPopOverHide == NO) {
  497. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  498. ActivityStatusTrial == [VerificationManager manager].status) {
  499. if (self.popover.isShown) {
  500. [self.popover close];
  501. self.stopPopOverHide = NO;
  502. }
  503. }
  504. }
  505. }
  506. #pragma mark - Event
  507. - (void)mouseEntered:(NSEvent *)event {
  508. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  509. ActivityStatusTrial == [VerificationManager manager].status) {
  510. [[self class] cancelPreviousPerformRequestsWithTarget:self];
  511. if (!self.popover.isShown) {
  512. [self upgradeButtonAction:self.upgradButton];
  513. }
  514. }
  515. }
  516. - (void)mouseExited:(NSEvent *)event {
  517. [super mouseExited:event];
  518. [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
  519. }
  520. @end