KMVerificationMessageViewController.m 31 KB

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