KMVerificationMessageViewController.m 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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?utm_source=app_dmg&utm_medium=dmg_puw_free_trial"];
  362. if([SKInspectPublicTool currentisLanguageHans]) {
  363. url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/zh-cn/store?utm_source=app_dmg&utm_medium=dmg_puw_free_trial"];
  364. }
  365. [[NSWorkspace sharedWorkspace] openURL:url];
  366. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_UpgradeBuyNow"}];
  367. } else if (btn.tag == 10003) {
  368. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];//KMVerificationTypeActivate
  369. [vc showWindow:nil];
  370. [ftWC close];
  371. }
  372. };
  373. [firstTrialWC.window center];
  374. [firstTrialWC showWindow:nil];
  375. } else if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  376. ActivityStatusTrial == [VerificationManager manager].status) {
  377. // if ([VerificationManager manager].secondTrialEnabled) {
  378. // if (!self.checkValue) {
  379. // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  380. // }
  381. // } else {
  382. [[NSNotificationCenter defaultCenter] postNotificationName:@"KMVerificationMessagePopShowNoti" object:nil];
  383. if (!self.testVC) {
  384. self.testVC = [[KMUnlockAlertViewController alloc] init];
  385. }
  386. [self.testVC addtrackingAreaInfo];
  387. self.testVC.callback = ^(NSInteger index) {
  388. if (index == 1) {
  389. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];
  390. [vc showWindow:nil];
  391. } else if (index == 2) {
  392. NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/store"];
  393. if([SKInspectPublicTool currentisLanguageHans]) {
  394. url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/zh-cn/store"];
  395. }
  396. [[NSWorkspace sharedWorkspace] openURL:url];
  397. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"Btn_PUW_BuyNow-Expire"}];
  398. }
  399. };
  400. self.testVC.mouseEventCall = ^(BOOL mouseEnter) {
  401. if (mouseEnter) {
  402. self.stopPopOverHide = YES;
  403. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  404. ActivityStatusTrial == [VerificationManager manager].status) {
  405. if (!self.popover.isShown) {
  406. [self buttonAction:self.button];
  407. }
  408. }
  409. } else {
  410. self.stopPopOverHide = NO;
  411. if (self.popover) {
  412. [self.popover close];
  413. }
  414. [self.testVC removeTrackingAreaInfo];
  415. }
  416. };
  417. NSPopover *popover = [[NSPopover alloc] init];
  418. popover.delegate = self;
  419. popover.contentViewController = self.testVC;
  420. popover.animates = YES;
  421. popover.behavior = NSPopoverBehaviorTransient;
  422. [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
  423. self.popover = popover;
  424. // }
  425. } else if (ActivityStatusVerifExpire == [VerificationManager manager].status) {
  426. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateExpired];
  427. [vc showWindow:nil];
  428. } else if (ActivityStatusVerification == [VerificationManager manager].status) {
  429. if ([VerificationManager manager].needUpgradeLicense) {
  430. NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/store?product_code=product_2"];
  431. if([SKInspectPublicTool currentisLanguageHans]) {
  432. url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/zh-cn/store?product_code=product_2"];
  433. }
  434. [[NSWorkspace sharedWorkspace] openURL:url];
  435. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_PDFtoOffice"}];
  436. }
  437. } else {
  438. if ([VerificationManager manager].needUpgradeLicense) {
  439. NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/store?product_code=product_2"];
  440. if([SKInspectPublicTool currentisLanguageHans]) {
  441. url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/zh-cn/store?product_code=product_2"];
  442. }
  443. [[NSWorkspace sharedWorkspace] openURL:url];
  444. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_PDFtoOffice"}];
  445. } else {
  446. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeNormal];
  447. [vc showWindow:nil];
  448. }
  449. }
  450. #else
  451. isFree = YES;
  452. #if VERSION_FREE
  453. if ([IAPProductsManager defaultManager].isAvailableAllFunction) {
  454. isFree = NO;
  455. }
  456. if (isFree) {
  457. [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  458. }
  459. #else
  460. if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice) {
  461. // KMToolCompareWindowController *vc = [KMToolCompareWindowController toolCompareWithType:KMCompareWithToolType_Convert setSelectIndex:0];
  462. KMToolCompareWindowController *vc = [KMToolCompareWindowController toolCompareWithToolType:KMCompareWithToolTypeConvert selectNum:0];
  463. [vc.window center];
  464. [vc showWindow:nil];
  465. }
  466. #endif
  467. #endif
  468. }
  469. - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
  470. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
  471. NSString *temp = nil;
  472. for (NSUInteger i = 0; i <string.length; i++) {
  473. temp = [string substringWithRange:NSMakeRange(i, 1)];
  474. if ([self isPureInt:temp]) {
  475. [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  476. color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
  477. }
  478. }
  479. return attributedString;
  480. }
  481. - (BOOL)isPureInt:(NSString *)string {
  482. NSScanner *scan = [NSScanner scannerWithString:string];
  483. int value;
  484. return [scan scanInt:&value] && [scan isAtEnd];
  485. }
  486. - (IBAction)AIButtonAction:(NSButton *)sender {
  487. __block typeof(self) blockSelf = self;
  488. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit"}];
  489. [[AIInfoManager defaultManager] fetchAIInfoWithComplention:^(NSDictionary *info, NSError *error) {
  490. }];
  491. AIUserInfoController *controller = [[AIUserInfoController alloc] init];
  492. controller.purchaseHandle = ^(AIUserInfoController * _Nonnull vc) {
  493. #if VERSION_DMG
  494. NSURL *url = [NSURL URLWithString:kAIStoreServerLink];
  495. [[NSWorkspace sharedWorkspace] openURL:url];
  496. #else
  497. [[AIPurchaseWindowController currentWC] showWindow:nil];
  498. #endif
  499. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit_BuyNow"}];
  500. };
  501. controller.enterLicenseHandle = ^(AIUserInfoController * _Nonnull vc) {
  502. KMVerificationWindowController *verifyVC = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateAIInfo];
  503. verifyVC.callback = ^{
  504. };
  505. [verifyVC showWindow:nil];
  506. };
  507. controller.guideHandle = ^(AIUserInfoController * _Nonnull vc) {
  508. if (!blockSelf.guideWindowVC) {
  509. KMFunctionGuideWindowController *guideWindowVC = [[KMFunctionGuideWindowController alloc] initWithWindowNibName:@"KMFunctionGuideWindowController"];
  510. blockSelf.guideWindowVC = guideWindowVC;
  511. }
  512. ((KMFunctionGuideWindowController *)(blockSelf.guideWindowVC)).type = KMGuideInfoTypeFunctionMulti;
  513. [blockSelf.guideWindowVC showWindow:nil];
  514. [KMFunctionGuideWindowController setDidShowFor:KMGuideInfoTypeFunctionMultiAIGuide];
  515. [blockSelf.guideWindowVC.window orderFront:nil];
  516. };
  517. NSPopover *popover = [[NSPopover alloc] init];
  518. popover.contentViewController = controller;
  519. popover.animates = YES;
  520. popover.behavior = NSPopoverBehaviorTransient;
  521. [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
  522. }
  523. #pragma mark - NSNotification Methods
  524. - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
  525. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  526. [self reloadData];
  527. });
  528. }
  529. - (void)IAPResultReceived:(NSNotification *)notification {
  530. dispatch_async(dispatch_get_main_queue(), ^{
  531. [self reloadData];
  532. });
  533. }
  534. - (void)IAPPurchaseSuccess:(NSNotification *)notification {
  535. dispatch_async(dispatch_get_main_queue(), ^{
  536. [self reloadData];
  537. });
  538. }
  539. - (void)IAPRestoreFinish:(NSNotification *)notification {
  540. dispatch_async(dispatch_get_main_queue(), ^{
  541. [self reloadData];
  542. });
  543. }
  544. #pragma mark - Event
  545. - (void)mouseEntered:(NSEvent *)event {
  546. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  547. ActivityStatusTrial == [VerificationManager manager].status) {
  548. [[self class] cancelPreviousPerformRequestsWithTarget:self];
  549. if (!self.popover.isShown) {
  550. [self buttonAction:self.button];
  551. }
  552. }
  553. }
  554. - (void)mouseExited:(NSEvent *)event {
  555. [super mouseExited:event];
  556. [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
  557. }
  558. - (void)popoverDidClose:(NSNotification *)notification {
  559. self.stopPopOverHide = NO;
  560. }
  561. - (void)popoverShowNoti:(NSNotification *)noti {
  562. if (self.popover) {
  563. [self.popover close];
  564. self.stopPopOverHide = NO;
  565. }
  566. }
  567. - (void)popOverCloseAction {
  568. if (self.stopPopOverHide == NO) {
  569. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  570. ActivityStatusTrial == [VerificationManager manager].status) {
  571. if (self.popover.isShown) {
  572. [self.popover close];
  573. self.stopPopOverHide = NO;
  574. }
  575. }
  576. }
  577. }
  578. @end