KMVerificationMessageViewController.m 27 KB

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