KMVerificationMessageViewController.m 33 KB

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