KMVerificationMessageViewController.m 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  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 "KMUnlockAlertViewController.h"
  13. #define kbottomGap 0
  14. @interface KMVerificationMessageViewController ()<
  15. NSPopoverDelegate>
  16. @property (nonatomic, assign) IBOutlet NSTextField *label;
  17. @property (nonatomic, assign) IBOutlet NSButton *button;
  18. @property (nonatomic, assign) IBOutlet NSButton *secondTrialBtn;
  19. @property (assign) IBOutlet NSView *labelContentView;
  20. @property (assign) IBOutlet NSImageView *bgImg;
  21. @property (assign) IBOutlet NSView *aiContendView;
  22. @property (assign) IBOutlet NSImageView *aiIconImg;
  23. @property (assign) IBOutlet NSTextField *aiLabel;
  24. @property (weak) IBOutlet NSButton *userButton;
  25. @property (assign) IBOutlet NSView *signUpView;
  26. @property (assign) IBOutlet NSImageView *signUpImg;
  27. @property (assign) IBOutlet NSTextField *signUpLabel;
  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) NSMenu *userMenu;
  35. @end
  36. @implementation KMVerificationMessageViewController
  37. #pragma mark Init Methods
  38. - (instancetype)init {
  39. if (self = [super initWithNibName:@"KMVerificationMessageViewController" bundle:nil]) {
  40. #if VERSION_DMG
  41. [[NSNotificationCenter defaultCenter] addObserver:self
  42. selector:@selector(deviceActivateStatusChangeNotification:)
  43. name:kDeviceActivateStatusChangeNotification
  44. object:nil];
  45. #else
  46. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPResultReceived:) name:KMIAPSubscriptionLoadedNotification object:nil];
  47. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPPurchaseSuccess:) name:KMIAPProductPurchasedNotification object:nil];
  48. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPRestoreFinish:) name:KMIAPProductRestoreFinishedNotification object:nil];
  49. #endif
  50. }
  51. return self;
  52. }
  53. - (void)dealloc {
  54. [[NSNotificationCenter defaultCenter] removeObserver:self];
  55. if (self.trackingArea) {
  56. [self.button removeTrackingArea:self.trackingArea];
  57. }
  58. }
  59. #pragma mark Setter Methods
  60. - (void)loadView {
  61. [super loadView];
  62. // Do view setup here.
  63. self.button.wantsLayer = YES;
  64. self.button.layer.masksToBounds = YES;
  65. self.button.layer.cornerRadius = 4.0;
  66. self.button.font = [NSFont SFProTextSemiboldFont:11];
  67. self.button.layer.backgroundColor = [NSColor colorWithDeviceRed:121.0/255.0 green:196.0/255.0 blue:66.0/255.0 alpha:1.0].CGColor;
  68. [self.button setAlignment:NSTextAlignmentCenter];
  69. self.secondTrialBtn.wantsLayer = YES;
  70. self.secondTrialBtn.layer.masksToBounds = YES;
  71. self.secondTrialBtn.layer.cornerRadius = 4.0;
  72. self.secondTrialBtn.font = [NSFont SFProTextSemiboldFont:11];
  73. self.secondTrialBtn.layer.backgroundColor = [NSColor colorWithDeviceRed:121.0/255.0 green:196.0/255.0 blue:66.0/255.0 alpha:1.0].CGColor;
  74. [self.secondTrialBtn setAlignment:NSTextAlignmentCenter];
  75. NSString *tTips = NSLocalizedString(@"Upgrade to Pro", nil);
  76. #if VERSION_DMG
  77. tTips = [NSString stringWithFormat:@"%@\n%@", NSLocalizedString(@"Upgrade to Permanent License with one time purchase", nil), NSLocalizedString(@"Complete the purchase in your web browser to get a license", nil)];
  78. #else
  79. tTips = [NSString stringWithFormat:@"%@\n%@", NSLocalizedString(@"Subscribe to All Access Pack to enjoy more expanded features.", nil), NSLocalizedString(@"Choose your favorite payment and enjoy flexible upgrades.", nil)];
  80. #endif
  81. self.button.toolTip = tTips;
  82. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  83. [self.button setTitleColor:[NSColor whiteColor]];
  84. [self.button setAlignment:NSTextAlignmentCenter];
  85. self.secondTrialBtn.toolTip = tTips;
  86. self.secondTrialBtn.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  87. [self.secondTrialBtn setTitleColor:[NSColor whiteColor]];
  88. [self.secondTrialBtn setAlignment:NSTextAlignmentCenter];
  89. self.secondTrialBtn.hidden = YES;
  90. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = YES;
  91. self.bgImg.wantsLayer = YES;
  92. self.bgImg.image = [NSImage imageNamed:@"Upgarde_bg_icon"];
  93. self.bgImg.layer.masksToBounds = YES;
  94. self.bgImg.layer.cornerRadius = 4.;
  95. self.bgImg.hidden = YES;
  96. self.aiLabel.font = [NSFont SFProTextSemiboldFont:11];
  97. self.aiLabel.textColor = [NSColor whiteColor];
  98. [self reloadData];
  99. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popoverShowNoti:) name:@"KMVerificationMessagePopShowNoti" object:nil];
  100. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccessNotification:) name:@"MemberCenterLoginSuccess" object:nil];
  101. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logoutSuccessNotification:) name:@"MemberCenterLogoutSuccess" object:nil];
  102. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(expandPersonalCenterNotification:) name:@"ExpandPersonalCenter" object:nil];
  103. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeMenu:) name:@"CloseMenuNotification" object:nil];
  104. }
  105. - (void)reloadData {
  106. self.label.textColor = [NSColor blackColor];
  107. self.label.hidden = NO;
  108. BOOL isFree = NO;
  109. self.secondTrialBtn.hidden = YES;
  110. self.bgImg.hidden = YES;
  111. //#if VERSION_DMG
  112. //
  113. // if (self.trackingArea) {
  114. // [self.button removeTrackingArea:self.trackingArea];
  115. // }
  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. //
  149. //
  150. // self.label.wantsLayer = YES;
  151. // self.label.layer.backgroundColor = [NSColor clearColor].CGColor;
  152. // self.button.layer.backgroundColor = [NSColor colorWithRed:255.0/255.0 green:94.0/255.0 blue:44.0/255.0 alpha:1].CGColor;
  153. // self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  154. // [self.button setTitleColor:[KMAppearance KMColor_Layout_W0]];
  155. // [self.button setAlignment:NSTextAlignmentCenter];
  156. //
  157. // if (!self.trackingArea) {
  158. // self.trackingArea = [[NSTrackingArea alloc] initWithRect:self.button.bounds options:NSTrackingMouseEnteredAndExited | NSTrackingInVisibleRect | NSTrackingActiveAlways owner:self userInfo:nil];
  159. // }
  160. // [self.button addTrackingArea:self.trackingArea];
  161. // } else if (ActivityStatusTrialExpire == [VerificationManager manager].status) {
  162. // self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = NO;
  163. //
  164. // self.label.wantsLayer = YES;
  165. // self.label.layer.backgroundColor = [NSColor clearColor].CGColor;
  166. // self.label.stringValue = NSLocalizedString(@"Trial expired", nil);
  167. // if (@available(macOS 10.14, *)) {
  168. // self.label.textColor = [NSColor whiteColor];
  169. // } else {
  170. // self.label.textColor = [NSColor redColor];
  171. // }
  172. // self.label.stringValue = @"";
  173. //
  174. // self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  175. // [self.button setAlignment:NSTextAlignmentCenter];
  176. // self.bgImg.hidden = NO;
  177. // self.button.layer.backgroundColor = [NSColor clearColor].CGColor;
  178. // [self.button setTitleColor:[NSColor whiteColor]];
  179. //
  180. // if (!self.trackingArea) {
  181. // self.trackingArea = [[NSTrackingArea alloc] initWithRect:self.button.bounds options:NSTrackingMouseEnteredAndExited | NSTrackingInVisibleRect | NSTrackingActiveAlways owner:self userInfo:nil];
  182. // }
  183. // [self.button addTrackingArea:self.trackingArea];
  184. //
  185. // if ([VerificationManager manager].secondTrialEnabled) {
  186. //
  187. // self.label.stringValue = NSLocalizedString(@"Trial expired", nil);
  188. // self.label.hidden = YES;
  189. // self.secondTrialBtn.hidden = NO;
  190. // self.secondTrialBtn.layer.backgroundColor = [NSColor colorWithRed:0.0/255.0 green:207.0/255.0 blue:133.0/255.0 alpha:1].CGColor;
  191. // [self.secondTrialBtn setTitleColor:[NSColor whiteColor]];
  192. // [self.secondTrialBtn setAlignment:NSTextAlignmentCenter];
  193. //
  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. // }
  200. // } else if (ActivityStatusVerifExpire == [VerificationManager manager].status) {
  201. // self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = NO;
  202. // self.label.stringValue = @"";
  203. // self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  204. // [self.button setTitleColor:[NSColor whiteColor]];
  205. // self.bgImg.hidden = NO;
  206. // self.button.layer.backgroundColor = [NSColor clearColor].CGColor;
  207. // [self.button setAlignment:NSTextAlignmentCenter];
  208. // } else if (ActivityStatusVerification == [VerificationManager manager].status) {
  209. // if ([VerificationManager manager].needUpgradeLicense == NO) {
  210. // self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = YES;
  211. // } else {
  212. // self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = NO;
  213. // self.label.stringValue = @"";
  214. // self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"PDF to Office Pack", nil)];
  215. // [self.button setTitleColor:[KMAppearance KMColor_Interactive_A0]];
  216. // self.button.layer.backgroundColor = [NSColor colorWithRed:229/255. green:233/255. blue:248/255. alpha:1].CGColor;
  217. // [self.button setAlignment:NSTextAlignmentCenter];
  218. // }
  219. // } else {
  220. // self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = YES;
  221. // if ([VerificationManager manager].needUpgradeLicense) {
  222. // self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = NO;
  223. // self.label.stringValue = @"";
  224. //
  225. // self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"PDF to Office Pack", nil)];
  226. // [self.button setTitleColor:[KMAppearance KMColor_Interactive_A0]];
  227. // self.button.layer.backgroundColor = [NSColor colorWithRed:229/255. green:233/255. blue:248/255. alpha:1].CGColor;
  228. // [self.button setAlignment:NSTextAlignmentCenter];
  229. // }
  230. // }
  231. //#else
  232. // isFree = YES;
  233. // if (isFree) {
  234. // self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = NO;
  235. // self.button.layer.backgroundColor = [NSColor clearColor].CGColor;
  236. // self.label.stringValue = @"";
  237. // self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  238. // if (isFree) {
  239. // self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade to Pro", nil)];
  240. // [self.button setTitleColor:[NSColor whiteColor]];
  241. // if ([IAPProductsManager defaultManager].isAvailableAllFunction) {
  242. // self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = YES;
  243. // } else {
  244. // self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = NO;
  245. // }
  246. // self.bgImg.hidden = self.button.hidden;
  247. //#if !VERSION_FREE
  248. // self.bgImg.hidden = YES;
  249. // self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = NO;
  250. // self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"PDF to Office Pack", nil)];
  251. // if ([IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice) {
  252. // self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = YES;
  253. // }
  254. // [self.button setTitleColor:[KMAppearance KMColor_Interactive_A0]];
  255. // self.button.layer.backgroundColor = [NSColor colorWithRed:229/255. green:233/255. blue:248/255. alpha:1].CGColor;
  256. //#endif
  257. // }
  258. // } else {
  259. // self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = YES;
  260. // }
  261. //
  262. //#endif
  263. //
  264. // [self.button sizeToFit];
  265. // [self.button setAlignment:NSTextAlignmentCenter];
  266. // [self.secondTrialBtn sizeToFit];
  267. // [self.secondTrialBtn setAlignment:NSTextAlignmentCenter];
  268. //
  269. // [self.label sizeToFit];
  270. // if (self.label.stringValue.length == 0) {
  271. // self.labelContentView.frame = CGRectZero;
  272. // } else {
  273. // self.labelContentView.frame = CGRectMake(0, kbottomGap, self.label.frame.size.width + self.view.frame.size.height , self.view.frame.size.height -2 *kbottomGap);
  274. //
  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. //
  282. // self.labelContentView.layer.backgroundColor = [NSColor colorWithRed:255.0/255.0 green:94.0/255.0 blue:44.0/255.0 alpha:0.15].CGColor;
  283. // if ([VerificationManager manager].secondTrialEnabled) {
  284. // self.labelContentView.layer.backgroundColor = [NSColor clearColor].CGColor;
  285. // }
  286. // 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);
  287. // }
  288. //
  289. // CGFloat totalWidth = CGRectGetMaxX(self.labelContentView.frame) + 8;
  290. //
  291. //// self.aiLabel.stringValue = NSLocalizedString(@"My AI Credit", nil);
  292. //// [self.aiLabel sizeToFit];
  293. //// CGFloat aiWidth = self.aiLabel.frame.size.width;
  294. //// aiWidth += 4;
  295. //// aiWidth += 16;
  296. //// aiWidth += 16;
  297. //// self.aiContendView.frame = CGRectMake(totalWidth, 0, aiWidth, self.view.frame.size.height);
  298. //// self.aiIconImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-8, 16, 16);
  299. //// CGRect ailabelRect = self.aiLabel.frame;
  300. //// ailabelRect.origin.x = CGRectGetMaxX(self.aiIconImg.frame) + 4;
  301. //// self.aiLabel.frame = ailabelRect;
  302. ////
  303. //// totalWidth += aiWidth;
  304. //// totalWidth += 8;
  305. // self.aiContendView.hidden = YES;
  306. //
  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. //
  318. // if (!self.secondTrialBtn.hidden) {
  319. // 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);
  320. // }
  321. //// if (self.view.superview) {
  322. //// 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);
  323. //// } else {
  324. //// if (self.button.hidden) {
  325. //// self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.aiLabel.frame) + 20 ,self.view.frame.size.height);
  326. //// } else {
  327. //// self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.button.frame) ,self.view.frame.size.height);
  328. // }
  329. // }
  330. if (self.frameUpdateHandle) {
  331. self.frameUpdateHandle(self.view.frame);
  332. }
  333. // CGRect rect = self.button.frame;
  334. // self.bgImg.frame = rect;
  335. CGFloat totalWidth = 8;
  336. self.button.hidden = YES;
  337. self.label.hidden = YES;
  338. self.secondTrialBtn.hidden = YES;
  339. self.labelContentView.hidden = YES;
  340. self.bgImg.hidden = YES;
  341. self.aiContendView.hidden = YES;
  342. self.userButton.hidden = YES;
  343. self.signUpView.hidden = YES;
  344. self.signUpLabel.stringValue = NSLocalizedStringFromTable(@"Sign in", @"MemberCenterLocalizable", nil);
  345. [self.signUpLabel sizeToFit];
  346. CGFloat signUpWidth = self.signUpLabel.frame.size.width;
  347. signUpWidth += 4;
  348. signUpWidth += 8;
  349. signUpWidth += 8;
  350. signUpWidth += 12;
  351. self.signUpImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-6, 12, 12);
  352. CGRect signUplabelRect = self.signUpLabel.frame;
  353. signUplabelRect.origin.x = CGRectGetMaxX(self.signUpImg.frame) + 4;
  354. self.signUpLabel.frame = signUplabelRect;
  355. self.button.layer.backgroundColor = [NSColor clearColor].CGColor;
  356. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade to Pro", nil)];
  357. [self.button setTitleColor:[NSColor whiteColor]];
  358. self.aiLabel.stringValue = NSLocalizedStringFromTable(@"Free to receive 1 year of AI", @"MemberCenterLocalizable", nil);
  359. [self.aiLabel sizeToFit];
  360. CGFloat aiWidth = self.aiLabel.frame.size.width;
  361. aiWidth += 4;
  362. aiWidth += 16;
  363. aiWidth += 16;
  364. self.aiIconImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-8, 16, 16);
  365. self.aiContendView.frame = CGRectMake(totalWidth, 0, aiWidth, self.view.frame.size.height);
  366. CGRect ailabelRect = self.aiLabel.frame;
  367. ailabelRect.origin.x = CGRectGetMaxX(self.aiIconImg.frame) + 4;
  368. self.aiLabel.frame = ailabelRect;
  369. // totalWidth+=aiWidth;
  370. // totalWidth+=4;
  371. // self.aiContendView.hidden = NO;
  372. CGFloat userImageWidth = 24;
  373. if ([KMMemberInfo shared].isLogin) {
  374. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  375. } else {
  376. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  377. }
  378. CGFloat buttonWidth = CGRectGetMaxX(self.button.frame);
  379. NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  380. if (fabs(buttonWidth-btnRect.size.width)>50) {
  381. buttonWidth = btnRect.size.width + 10;
  382. }
  383. if ([[KMMemberInfo shared].isHaveAIDiscount isEqualToString:@"1"]) {
  384. self.aiContendView.hidden = NO;
  385. totalWidth+=aiWidth;
  386. totalWidth+=4;
  387. }
  388. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1 ||
  389. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  390. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  391. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  392. // [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8 ||
  393. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  394. // [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13 ||
  395. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11 ||
  396. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
  397. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3 ||
  398. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
  399. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
  400. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  401. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  402. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  403. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  404. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  405. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  406. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  407. __weak typeof(self)weakSelf = self;
  408. weakSelf.bgImg.image = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  409. weakSelf.bgImg.image = image;
  410. }];
  411. }
  412. }
  413. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  414. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11) {
  415. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"开通会员", nil)];
  416. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  417. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  418. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
  419. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3 ||
  420. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
  421. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  422. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  423. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  424. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  425. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  426. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  427. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  428. __weak typeof(self)weakSelf = self;
  429. weakSelf.bgImg.image = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  430. weakSelf.bgImg.image = image;
  431. }];
  432. }
  433. }
  434. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7
  435. // [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8 ||
  436. /*[KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13*/) {
  437. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"立即续费", nil)];
  438. }
  439. [self.button setTitleColor:[NSColor whiteColor]];
  440. self.bgImg.hidden = NO;
  441. self.button.hidden = NO;
  442. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  443. CGRect rect = self.button.frame;
  444. self.bgImg.frame = rect;
  445. totalWidth+=CGRectGetWidth(self.button.bounds);
  446. totalWidth+=4;
  447. }
  448. if ([KMMemberInfo shared].isLogin) {
  449. self.userButton.hidden = NO;
  450. self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  451. totalWidth += userImageWidth;
  452. totalWidth += 8;
  453. } else {
  454. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  455. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  456. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  457. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  458. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  459. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  460. __weak typeof(self)weakSelf = self;
  461. weakSelf.bgImg.image = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  462. weakSelf.bgImg.image = image;
  463. }];
  464. }
  465. }
  466. self.signUpView.hidden = NO;
  467. self.signUpView.frame = CGRectMake(totalWidth, 0, signUpWidth, self.view.frame.size.height);
  468. totalWidth+=CGRectGetWidth(self.signUpView.bounds);
  469. }
  470. if (self.view.superview) {
  471. 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);
  472. } else {
  473. // if (self.button.hidden) {
  474. // self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.aiLabel.frame) + 20 ,self.view.frame.size.height);
  475. // } else {
  476. // self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.button.frame) ,self.view.frame.size.height);
  477. // }
  478. 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);
  479. }
  480. }
  481. #pragma mark - Button Actions
  482. - (IBAction)secondTrialAction:(NSButton *)sender {
  483. if ([VerificationManager manager].secondTrialEnabled) {
  484. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialGuide];
  485. [vc showWindow:nil];
  486. } else {
  487. [[KMProductCompareWC shared] setOrientation:NO];
  488. [[KMProductCompareWC shared] showWindow:nil];
  489. }
  490. }
  491. - (IBAction)buttonAction:(id)sender {
  492. // BOOL isFree = NO;
  493. //
  494. //#if VERSION_DMG
  495. // if (ActivityStatusNone == [VerificationManager manager].status) {
  496. // //弹出 试用弹窗UI优化-新用户试用路径 新UI 情况一 右上角按钮
  497. // KMPurchaseFirstTrialWindowController *firstTrialWC = [KMPurchaseFirstTrialWindowController currentFirstTrialWC];
  498. // firstTrialWC.buttonActionBlock = ^(KMPurchaseFirstTrialWindowController * _Nonnull ftWC, KMButton * _Nonnull btn, NSString * _Nonnull email, NSString * _Nonnull name) {
  499. // if (btn.tag == 10001) {
  500. // if (ActivityStatusNone == [VerificationManager manager].status ||
  501. // ActivityStatusTrialExpire == [VerificationManager manager].status) {
  502. //
  503. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_SecondTrial"}];
  504. // [[VerificationManager manager] trialForDays:7
  505. // email:email?:[VerificationManager manager].email
  506. // name:name?:[VerificationManager manager].accountName
  507. // complention:^(ActivityStatus status, NSDictionary *info, NSError *error) {
  508. // if (error ||
  509. // status != ActivityStatusTrial) {
  510. // NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  511. // defaultButton:NSLocalizedString(@"Try Again", nil)
  512. // alternateButton:nil
  513. // otherButton:nil
  514. // informativeTextWithFormat:NSLocalizedString(@"Failed to sign up for the free trial. Please make sure your internet connection is available and try again later.", nil), nil];
  515. // [alert runModal];
  516. // } else {
  517. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialSuccess];
  518. // [vc showWindow:nil];
  519. // }
  520. // }];
  521. // [ftWC close];
  522. // } else {
  523. // [ftWC close];
  524. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];
  525. // vc.callback = ^{
  526. // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  527. // };
  528. // [vc showWindow:nil];
  529. // }
  530. // } else if (btn.tag == 10002) {
  531. // NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@?utm_source=app_dmg&utm_medium=dmg_puw_free_trial", Swift_oc_Tool.Store_Link_OC]];
  532. // [[NSWorkspace sharedWorkspace] openURL:url];
  533. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_UpgradeBuyNow"}];
  534. // } else if (btn.tag == 10003) {
  535. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];//KMVerificationTypeActivate
  536. // [vc showWindow:nil];
  537. // [ftWC close];
  538. // }
  539. // };
  540. // [firstTrialWC.window center];
  541. // [firstTrialWC showWindow:nil];
  542. // } else if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  543. // ActivityStatusTrial == [VerificationManager manager].status) {
  544. // [[NSNotificationCenter defaultCenter] postNotificationName:@"KMVerificationMessagePopShowNoti" object:nil];
  545. //
  546. // if (!self.testVC) {
  547. // self.testVC = [[KMUnlockAlertViewController alloc] init];
  548. // }
  549. // [self.testVC addtrackingAreaInfo];
  550. // self.testVC.callback = ^(NSInteger index) {
  551. // if (index == 1) {
  552. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];
  553. // [vc showWindow:nil];
  554. // } else if (index == 2) {
  555. // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.mac.product_3"];
  556. // [embeddedWC showWindow:nil];
  557. // [[embeddedWC window] center];
  558. // }
  559. // };
  560. // self.testVC.mouseEventCall = ^(BOOL mouseEnter) {
  561. // if (mouseEnter) {
  562. // self.stopPopOverHide = YES;
  563. // if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  564. // ActivityStatusTrial == [VerificationManager manager].status) {
  565. // if (!self.popover.isShown) {
  566. // [self buttonAction:self.button];
  567. // }
  568. // }
  569. // } else {
  570. // self.stopPopOverHide = NO;
  571. // if (self.popover) {
  572. // [self.popover close];
  573. // }
  574. // [self.testVC removeTrackingAreaInfo];
  575. // }
  576. // };
  577. // NSPopover *popover = [[NSPopover alloc] init];
  578. // popover.delegate = self;
  579. // popover.contentViewController = self.testVC;
  580. // popover.animates = YES;
  581. // popover.behavior = NSPopoverBehaviorTransient;
  582. // [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
  583. // self.popover = popover;
  584. // } else if (ActivityStatusVerifExpire == [VerificationManager manager].status) {
  585. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateExpired];
  586. // [vc showWindow:nil];
  587. // } else if (ActivityStatusVerification == [VerificationManager manager].status) {
  588. // if ([VerificationManager manager].needUpgradeLicense) {
  589. // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.mac.product_2"];
  590. // [embeddedWC showWindow:nil];
  591. // [[embeddedWC window] center];
  592. // }
  593. // } else {
  594. // if ([VerificationManager manager].needUpgradeLicense) {
  595. // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.mac.product_2"];
  596. // [embeddedWC showWindow:nil];
  597. // [[embeddedWC window] center];
  598. // } else {
  599. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeNormal];
  600. // [vc showWindow:nil];
  601. // }
  602. // }
  603. //#else
  604. // isFree = YES;
  605. //#if VERSION_FREE
  606. // if ([IAPProductsManager defaultManager].isAvailableAllFunction) {
  607. // isFree = NO;
  608. // }
  609. // if (isFree) {
  610. // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  611. // }
  612. //#else
  613. // if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice) {
  614. // KMToolCompareWindowController *vc = [KMToolCompareWindowController toolCompareWithToolType:KMCompareWithToolTypeConvert selectNum:0];
  615. // [vc.window center];
  616. // [vc showWindow:nil];
  617. // }
  618. //#endif
  619. //
  620. //#endif
  621. if ([KMMemberInfo shared].isLogin) {
  622. [[KMProductCompareWC shared] setOrientation:YES];
  623. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
  624. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  625. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  626. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  627. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8) {
  628. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  629. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type4 ||
  630. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  631. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  632. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11 ||
  633. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13) {
  634. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_MacWindows];
  635. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
  636. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
  637. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Advanced];
  638. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3) {
  639. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  640. }
  641. [[KMProductCompareWC shared] showWindow:nil];
  642. } else {
  643. [KMLoginWindowsController.shared openWindow:^(BOOL success) {
  644. if (success) {
  645. [[KMProductCompareWC shared] setOrientation:YES];
  646. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
  647. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  648. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  649. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  650. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8) {
  651. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  652. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type4 ||
  653. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  654. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  655. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11 ||
  656. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13) {
  657. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_MacWindows];
  658. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
  659. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
  660. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Advanced];
  661. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3) {
  662. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  663. }
  664. [[KMProductCompareWC shared] showWindow:nil];
  665. }
  666. }];
  667. }
  668. }
  669. - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
  670. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
  671. NSString *temp = nil;
  672. for (NSUInteger i = 0; i <string.length; i++) {
  673. temp = [string substringWithRange:NSMakeRange(i, 1)];
  674. if ([self isPureInt:temp]) {
  675. [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  676. color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
  677. }
  678. }
  679. return attributedString;
  680. }
  681. - (BOOL)isPureInt:(NSString *)string {
  682. NSScanner *scan = [NSScanner scannerWithString:string];
  683. int value;
  684. return [scan scanInt:&value] && [scan isAtEnd];
  685. }
  686. - (IBAction)AIButtonAction:(NSButton *)sender {
  687. __block typeof(self) blockSelf = self;
  688. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit"}];
  689. // [[AIInfoManager defaultManager] fetchAIInfoWithComplention:^(NSDictionary *info, NSError *error) {
  690. //
  691. // }];
  692. // AIUserInfoController *controller = [[AIUserInfoController alloc] init];
  693. // controller.purchaseHandle = ^(AIUserInfoController * _Nonnull vc) {
  694. //#if VERSION_DMG
  695. // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.ai.product_1"];
  696. // [embeddedWC showWindow:nil];
  697. // [[embeddedWC window] center];
  698. //#else
  699. //
  700. // [[AIPurchaseWindowController currentWC] showWindow:nil];
  701. //#endif
  702. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit_BuyNow"}];
  703. // };
  704. // controller.enterLicenseHandle = ^(AIUserInfoController * _Nonnull vc) {
  705. // KMVerificationWindowController *verifyVC = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateAIInfo];
  706. // verifyVC.callback = ^{
  707. //
  708. // };
  709. // [verifyVC showWindow:nil];
  710. // };
  711. //
  712. // controller.guideHandle = ^(AIUserInfoController * _Nonnull vc) {
  713. // if (!blockSelf.guideWindowVC) {
  714. // KMFunctionGuideWindowController *guideWindowVC = [[KMFunctionGuideWindowController alloc] initWithWindowNibName:@"KMFunctionGuideWindowController"];
  715. // blockSelf.guideWindowVC = guideWindowVC;
  716. // }
  717. // ((KMFunctionGuideWindowController *)(blockSelf.guideWindowVC)).type = KMGuideInfoTypeFunctionMulti;
  718. // [blockSelf.guideWindowVC showWindow:nil];
  719. // [KMFunctionGuideWindowController setDidShowFor:KMGuideInfoTypeFunctionMultiAIGuide];
  720. // [blockSelf.guideWindowVC.window orderFront:nil];
  721. // };
  722. //
  723. // NSPopover *popover = [[NSPopover alloc] init];
  724. // popover.contentViewController = controller;
  725. // popover.animates = YES;
  726. // popover.behavior = NSPopoverBehaviorTransient;
  727. // [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
  728. [[KMFreeGetAIWC shared] showWindow:nil];
  729. }
  730. - (IBAction)userButtonAction:(NSButton *)sender {
  731. if ([KMMemberInfo shared].isLogin) {
  732. [self personalCenterAction:sender];
  733. } else {
  734. [KMLoginWindowsController.shared showWindow:nil];
  735. }
  736. }
  737. - (IBAction)personalCenterAction:(NSButton *)sender {
  738. // 用户头像点击事件
  739. self.userMenu = [[NSMenu alloc] init];
  740. KMUserInfoViewController *userInfo = [[KMUserInfoViewController alloc] init];
  741. NSMenuItem *item = [self.userMenu addItemWithTitle:@"" action:nil target:@""];
  742. item.target = self;
  743. item.representedObject = userInfo;
  744. item.view = userInfo.view;
  745. [self.userMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(-130, 30) inView:sender];
  746. }
  747. - (IBAction)signUpAction:(NSButton *)sender {
  748. [KMLoginWindowsController.shared showWindow:nil];
  749. }
  750. #pragma mark - NSNotification Methods
  751. - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
  752. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  753. [self reloadData];
  754. });
  755. }
  756. - (void)IAPResultReceived:(NSNotification *)notification {
  757. dispatch_async(dispatch_get_main_queue(), ^{
  758. [self reloadData];
  759. });
  760. }
  761. - (void)IAPPurchaseSuccess:(NSNotification *)notification {
  762. dispatch_async(dispatch_get_main_queue(), ^{
  763. [self reloadData];
  764. });
  765. }
  766. - (void)IAPRestoreFinish:(NSNotification *)notification {
  767. dispatch_async(dispatch_get_main_queue(), ^{
  768. [self reloadData];
  769. });
  770. }
  771. #pragma mark - Event
  772. - (void)mouseEntered:(NSEvent *)event {
  773. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  774. ActivityStatusTrial == [VerificationManager manager].status) {
  775. [[self class] cancelPreviousPerformRequestsWithTarget:self];
  776. if (!self.popover.isShown) {
  777. [self buttonAction:self.button];
  778. }
  779. }
  780. }
  781. - (void)mouseExited:(NSEvent *)event {
  782. [super mouseExited:event];
  783. [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
  784. }
  785. - (void)popoverDidClose:(NSNotification *)notification {
  786. self.stopPopOverHide = NO;
  787. }
  788. - (void)popoverShowNoti:(NSNotification *)noti {
  789. if (self.popover) {
  790. [self.popover close];
  791. self.stopPopOverHide = NO;
  792. }
  793. }
  794. - (void)loginSuccessNotification:(NSNotification *)noti {
  795. _userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  796. [self reloadData];
  797. }
  798. - (void)logoutSuccessNotification:(NSNotification *)noti {
  799. _userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  800. [self reloadData];
  801. }
  802. - (void)expandPersonalCenterNotification:(NSNotification *)noti {
  803. if (self.userMenu != nil) {
  804. [self personalCenterAction:_userButton];
  805. }
  806. }
  807. - (void)closeMenu:(NSNotification *)noti {
  808. if (self.userMenu != nil) {
  809. [self.userMenu cancelTracking];
  810. self.userMenu = nil;
  811. }
  812. }
  813. - (void)popOverCloseAction {
  814. if (self.stopPopOverHide == NO) {
  815. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  816. ActivityStatusTrial == [VerificationManager manager].status) {
  817. if (self.popover.isShown) {
  818. [self.popover close];
  819. self.stopPopOverHide = NO;
  820. }
  821. }
  822. }
  823. }
  824. @end