KMVerificationMessageViewController.m 35 KB

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