KMVerificationMessageViewController.m 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  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. }
  407. }
  408. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  409. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11) {
  410. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"开通会员", nil)];
  411. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  412. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  413. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
  414. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3 ||
  415. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
  416. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  417. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  418. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  419. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  420. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  421. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  422. }
  423. }
  424. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7
  425. // [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8 ||
  426. /*[KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13*/) {
  427. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"立即续费", nil)];
  428. }
  429. [self.button setTitleColor:[NSColor whiteColor]];
  430. self.bgImg.hidden = NO;
  431. self.button.hidden = NO;
  432. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  433. CGRect rect = self.button.frame;
  434. self.bgImg.frame = rect;
  435. totalWidth+=CGRectGetWidth(self.button.bounds);
  436. totalWidth+=4;
  437. }
  438. if ([KMMemberInfo shared].isLogin) {
  439. self.userButton.hidden = NO;
  440. self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  441. totalWidth += userImageWidth;
  442. totalWidth += 8;
  443. } else {
  444. self.signUpView.hidden = NO;
  445. self.signUpView.frame = CGRectMake(totalWidth, 0, signUpWidth, self.view.frame.size.height);
  446. totalWidth+=CGRectGetWidth(self.signUpView.bounds);
  447. }
  448. if (self.view.superview) {
  449. 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);
  450. } else {
  451. // if (self.button.hidden) {
  452. // self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.aiLabel.frame) + 20 ,self.view.frame.size.height);
  453. // } else {
  454. // self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.button.frame) ,self.view.frame.size.height);
  455. // }
  456. 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);
  457. }
  458. }
  459. #pragma mark - Button Actions
  460. - (IBAction)secondTrialAction:(NSButton *)sender {
  461. if ([VerificationManager manager].secondTrialEnabled) {
  462. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialGuide];
  463. [vc showWindow:nil];
  464. } else {
  465. [[KMProductCompareWC shared] setOrientation:NO];
  466. [[KMProductCompareWC shared] showWindow:nil];
  467. }
  468. }
  469. - (IBAction)buttonAction:(id)sender {
  470. // BOOL isFree = NO;
  471. //
  472. //#if VERSION_DMG
  473. // if (ActivityStatusNone == [VerificationManager manager].status) {
  474. // //弹出 试用弹窗UI优化-新用户试用路径 新UI 情况一 右上角按钮
  475. // KMPurchaseFirstTrialWindowController *firstTrialWC = [KMPurchaseFirstTrialWindowController currentFirstTrialWC];
  476. // firstTrialWC.buttonActionBlock = ^(KMPurchaseFirstTrialWindowController * _Nonnull ftWC, KMButton * _Nonnull btn, NSString * _Nonnull email, NSString * _Nonnull name) {
  477. // if (btn.tag == 10001) {
  478. // if (ActivityStatusNone == [VerificationManager manager].status ||
  479. // ActivityStatusTrialExpire == [VerificationManager manager].status) {
  480. //
  481. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_SecondTrial"}];
  482. // [[VerificationManager manager] trialForDays:7
  483. // email:email?:[VerificationManager manager].email
  484. // name:name?:[VerificationManager manager].accountName
  485. // complention:^(ActivityStatus status, NSDictionary *info, NSError *error) {
  486. // if (error ||
  487. // status != ActivityStatusTrial) {
  488. // NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  489. // defaultButton:NSLocalizedString(@"Try Again", nil)
  490. // alternateButton:nil
  491. // otherButton:nil
  492. // informativeTextWithFormat:NSLocalizedString(@"Failed to sign up for the free trial. Please make sure your internet connection is available and try again later.", nil), nil];
  493. // [alert runModal];
  494. // } else {
  495. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialSuccess];
  496. // [vc showWindow:nil];
  497. // }
  498. // }];
  499. // [ftWC close];
  500. // } else {
  501. // [ftWC close];
  502. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];
  503. // vc.callback = ^{
  504. // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  505. // };
  506. // [vc showWindow:nil];
  507. // }
  508. // } else if (btn.tag == 10002) {
  509. // NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@?utm_source=app_dmg&utm_medium=dmg_puw_free_trial", Swift_oc_Tool.Store_Link_OC]];
  510. // [[NSWorkspace sharedWorkspace] openURL:url];
  511. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_UpgradeBuyNow"}];
  512. // } else if (btn.tag == 10003) {
  513. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];//KMVerificationTypeActivate
  514. // [vc showWindow:nil];
  515. // [ftWC close];
  516. // }
  517. // };
  518. // [firstTrialWC.window center];
  519. // [firstTrialWC showWindow:nil];
  520. // } else if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  521. // ActivityStatusTrial == [VerificationManager manager].status) {
  522. // [[NSNotificationCenter defaultCenter] postNotificationName:@"KMVerificationMessagePopShowNoti" object:nil];
  523. //
  524. // if (!self.testVC) {
  525. // self.testVC = [[KMUnlockAlertViewController alloc] init];
  526. // }
  527. // [self.testVC addtrackingAreaInfo];
  528. // self.testVC.callback = ^(NSInteger index) {
  529. // if (index == 1) {
  530. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];
  531. // [vc showWindow:nil];
  532. // } else if (index == 2) {
  533. // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.mac.product_3"];
  534. // [embeddedWC showWindow:nil];
  535. // [[embeddedWC window] center];
  536. // }
  537. // };
  538. // self.testVC.mouseEventCall = ^(BOOL mouseEnter) {
  539. // if (mouseEnter) {
  540. // self.stopPopOverHide = YES;
  541. // if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  542. // ActivityStatusTrial == [VerificationManager manager].status) {
  543. // if (!self.popover.isShown) {
  544. // [self buttonAction:self.button];
  545. // }
  546. // }
  547. // } else {
  548. // self.stopPopOverHide = NO;
  549. // if (self.popover) {
  550. // [self.popover close];
  551. // }
  552. // [self.testVC removeTrackingAreaInfo];
  553. // }
  554. // };
  555. // NSPopover *popover = [[NSPopover alloc] init];
  556. // popover.delegate = self;
  557. // popover.contentViewController = self.testVC;
  558. // popover.animates = YES;
  559. // popover.behavior = NSPopoverBehaviorTransient;
  560. // [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
  561. // self.popover = popover;
  562. // } else if (ActivityStatusVerifExpire == [VerificationManager manager].status) {
  563. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateExpired];
  564. // [vc showWindow:nil];
  565. // } else if (ActivityStatusVerification == [VerificationManager manager].status) {
  566. // if ([VerificationManager manager].needUpgradeLicense) {
  567. // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.mac.product_2"];
  568. // [embeddedWC showWindow:nil];
  569. // [[embeddedWC window] center];
  570. // }
  571. // } else {
  572. // if ([VerificationManager manager].needUpgradeLicense) {
  573. // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.mac.product_2"];
  574. // [embeddedWC showWindow:nil];
  575. // [[embeddedWC window] center];
  576. // } else {
  577. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeNormal];
  578. // [vc showWindow:nil];
  579. // }
  580. // }
  581. //#else
  582. // isFree = YES;
  583. //#if VERSION_FREE
  584. // if ([IAPProductsManager defaultManager].isAvailableAllFunction) {
  585. // isFree = NO;
  586. // }
  587. // if (isFree) {
  588. // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  589. // }
  590. //#else
  591. // if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice) {
  592. // KMToolCompareWindowController *vc = [KMToolCompareWindowController toolCompareWithToolType:KMCompareWithToolTypeConvert selectNum:0];
  593. // [vc.window center];
  594. // [vc showWindow:nil];
  595. // }
  596. //#endif
  597. //
  598. //#endif
  599. if ([KMMemberInfo shared].isLogin) {
  600. [[KMProductCompareWC shared] setOrientation:YES];
  601. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
  602. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  603. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  604. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  605. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8) {
  606. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  607. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type4 ||
  608. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  609. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  610. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11 ||
  611. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13) {
  612. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_MacWindows];
  613. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
  614. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
  615. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Advanced];
  616. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3) {
  617. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  618. }
  619. [[KMProductCompareWC shared] showWindow:nil];
  620. } else {
  621. [KMLoginWindowsController.shared openWindow:^(BOOL success) {
  622. if (success) {
  623. [[KMProductCompareWC shared] setOrientation:YES];
  624. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
  625. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  626. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  627. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  628. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8) {
  629. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  630. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type4 ||
  631. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  632. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  633. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11 ||
  634. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13) {
  635. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_MacWindows];
  636. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
  637. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
  638. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Advanced];
  639. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3) {
  640. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  641. }
  642. [[KMProductCompareWC shared] showWindow:nil];
  643. }
  644. }];
  645. }
  646. }
  647. - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
  648. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
  649. NSString *temp = nil;
  650. for (NSUInteger i = 0; i <string.length; i++) {
  651. temp = [string substringWithRange:NSMakeRange(i, 1)];
  652. if ([self isPureInt:temp]) {
  653. [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  654. color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
  655. }
  656. }
  657. return attributedString;
  658. }
  659. - (BOOL)isPureInt:(NSString *)string {
  660. NSScanner *scan = [NSScanner scannerWithString:string];
  661. int value;
  662. return [scan scanInt:&value] && [scan isAtEnd];
  663. }
  664. - (IBAction)AIButtonAction:(NSButton *)sender {
  665. __block typeof(self) blockSelf = self;
  666. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit"}];
  667. // [[AIInfoManager defaultManager] fetchAIInfoWithComplention:^(NSDictionary *info, NSError *error) {
  668. //
  669. // }];
  670. // AIUserInfoController *controller = [[AIUserInfoController alloc] init];
  671. // controller.purchaseHandle = ^(AIUserInfoController * _Nonnull vc) {
  672. //#if VERSION_DMG
  673. // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.ai.product_1"];
  674. // [embeddedWC showWindow:nil];
  675. // [[embeddedWC window] center];
  676. //#else
  677. //
  678. // [[AIPurchaseWindowController currentWC] showWindow:nil];
  679. //#endif
  680. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit_BuyNow"}];
  681. // };
  682. // controller.enterLicenseHandle = ^(AIUserInfoController * _Nonnull vc) {
  683. // KMVerificationWindowController *verifyVC = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateAIInfo];
  684. // verifyVC.callback = ^{
  685. //
  686. // };
  687. // [verifyVC showWindow:nil];
  688. // };
  689. //
  690. // controller.guideHandle = ^(AIUserInfoController * _Nonnull vc) {
  691. // if (!blockSelf.guideWindowVC) {
  692. // KMFunctionGuideWindowController *guideWindowVC = [[KMFunctionGuideWindowController alloc] initWithWindowNibName:@"KMFunctionGuideWindowController"];
  693. // blockSelf.guideWindowVC = guideWindowVC;
  694. // }
  695. // ((KMFunctionGuideWindowController *)(blockSelf.guideWindowVC)).type = KMGuideInfoTypeFunctionMulti;
  696. // [blockSelf.guideWindowVC showWindow:nil];
  697. // [KMFunctionGuideWindowController setDidShowFor:KMGuideInfoTypeFunctionMultiAIGuide];
  698. // [blockSelf.guideWindowVC.window orderFront:nil];
  699. // };
  700. //
  701. // NSPopover *popover = [[NSPopover alloc] init];
  702. // popover.contentViewController = controller;
  703. // popover.animates = YES;
  704. // popover.behavior = NSPopoverBehaviorTransient;
  705. // [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
  706. [[KMFreeGetAIWC shared] showWindow:nil];
  707. }
  708. - (IBAction)userButtonAction:(NSButton *)sender {
  709. if ([KMMemberInfo shared].isLogin) {
  710. [self personalCenterAction:sender];
  711. } else {
  712. [KMLoginWindowsController.shared showWindow:nil];
  713. }
  714. }
  715. - (IBAction)personalCenterAction:(NSButton *)sender {
  716. // 用户头像点击事件
  717. self.userMenu = [[NSMenu alloc] init];
  718. KMUserInfoViewController *userInfo = [[KMUserInfoViewController alloc] init];
  719. NSMenuItem *item = [self.userMenu addItemWithTitle:@"" action:nil target:@""];
  720. item.target = self;
  721. item.representedObject = userInfo;
  722. item.view = userInfo.view;
  723. [self.userMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(-130, 30) inView:sender];
  724. }
  725. - (IBAction)signUpAction:(NSButton *)sender {
  726. [KMLoginWindowsController.shared showWindow:nil];
  727. }
  728. #pragma mark - NSNotification Methods
  729. - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
  730. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  731. [self reloadData];
  732. });
  733. }
  734. - (void)IAPResultReceived:(NSNotification *)notification {
  735. dispatch_async(dispatch_get_main_queue(), ^{
  736. [self reloadData];
  737. });
  738. }
  739. - (void)IAPPurchaseSuccess:(NSNotification *)notification {
  740. dispatch_async(dispatch_get_main_queue(), ^{
  741. [self reloadData];
  742. });
  743. }
  744. - (void)IAPRestoreFinish:(NSNotification *)notification {
  745. dispatch_async(dispatch_get_main_queue(), ^{
  746. [self reloadData];
  747. });
  748. }
  749. #pragma mark - Event
  750. - (void)mouseEntered:(NSEvent *)event {
  751. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  752. ActivityStatusTrial == [VerificationManager manager].status) {
  753. [[self class] cancelPreviousPerformRequestsWithTarget:self];
  754. if (!self.popover.isShown) {
  755. [self buttonAction:self.button];
  756. }
  757. }
  758. }
  759. - (void)mouseExited:(NSEvent *)event {
  760. [super mouseExited:event];
  761. [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
  762. }
  763. - (void)popoverDidClose:(NSNotification *)notification {
  764. self.stopPopOverHide = NO;
  765. }
  766. - (void)popoverShowNoti:(NSNotification *)noti {
  767. if (self.popover) {
  768. [self.popover close];
  769. self.stopPopOverHide = NO;
  770. }
  771. }
  772. - (void)loginSuccessNotification:(NSNotification *)noti {
  773. _userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  774. [self reloadData];
  775. }
  776. - (void)logoutSuccessNotification:(NSNotification *)noti {
  777. _userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  778. [self reloadData];
  779. }
  780. - (void)expandPersonalCenterNotification:(NSNotification *)noti {
  781. if (self.userMenu != nil) {
  782. [self personalCenterAction:_userButton];
  783. }
  784. }
  785. - (void)closeMenu:(NSNotification *)noti {
  786. if (self.userMenu != nil) {
  787. [self.userMenu cancelTracking];
  788. self.userMenu = nil;
  789. }
  790. }
  791. - (void)popOverCloseAction {
  792. if (self.stopPopOverHide == NO) {
  793. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  794. ActivityStatusTrial == [VerificationManager manager].status) {
  795. if (self.popover.isShown) {
  796. [self.popover close];
  797. self.stopPopOverHide = NO;
  798. }
  799. }
  800. }
  801. }
  802. @end