KMVerificationMessageViewController.m 34 KB

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