KMVerificationMessageViewController.m 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  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. if (self.trackingArea) {
  113. [self.button removeTrackingArea:self.trackingArea];
  114. }
  115. self.label.stringValue = @"";
  116. if (ActivityStatusNone == [VerificationManager manager].status || isFree) {
  117. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = NO;
  118. self.label.stringValue = @"";
  119. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  120. if (isFree) {
  121. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade to Pro", nil)];
  122. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  123. [self.button setAlignment:NSTextAlignmentCenter];
  124. if ([IAPProductsManager defaultManager].isAvailableAllFunction) {
  125. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = YES;
  126. } else {
  127. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = NO;
  128. }
  129. }
  130. self.button.layer.backgroundColor = [NSColor colorWithRed:0.0/255.0 green:207.0/255.0 blue:133.0/255.0 alpha:1].CGColor;
  131. [self.button setTitleColor:[NSColor whiteColor]];
  132. } else if (ActivityStatusTrial == [VerificationManager manager].status) {
  133. NSDate *date = [NSDate date];
  134. NSDate *expireDate = [VerificationManager manager].detailInfo.expireDate;
  135. NSTimeInterval time = [expireDate timeIntervalSinceDate:date];
  136. int leftDays = ((int)time)/(3600*24);
  137. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = NO;
  138. NSString * needShowString = [NSString stringWithFormat:NSLocalizedString(@"%d days left", nil),leftDays];
  139. if (@available(macOS 10.14, *)) {
  140. self.label.attributedStringValue = [self numberConvertColor:[NSColor redColor] String:needShowString];
  141. self.label.textColor = [NSColor colorWithRed:255.0/255.0 green:94.0/255.0 blue:44.0/255.0 alpha:1];
  142. } else {
  143. self.label.stringValue = needShowString;
  144. self.label.textColor = [NSColor colorWithRed:255.0/255.0 green:94.0/255.0 blue:44.0/255.0 alpha:1];
  145. }
  146. self.label.wantsLayer = YES;
  147. self.label.layer.backgroundColor = [NSColor clearColor].CGColor;
  148. self.button.layer.backgroundColor = [NSColor colorWithRed:255.0/255.0 green:94.0/255.0 blue:44.0/255.0 alpha:1].CGColor;
  149. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  150. [self.button setTitleColor:[KMAppearance KMColor_Layout_W0]];
  151. [self.button setAlignment:NSTextAlignmentCenter];
  152. if (!self.trackingArea) {
  153. self.trackingArea = [[NSTrackingArea alloc] initWithRect:self.button.bounds options:NSTrackingMouseEnteredAndExited | NSTrackingInVisibleRect | NSTrackingActiveAlways owner:self userInfo:nil];
  154. }
  155. [self.button addTrackingArea:self.trackingArea];
  156. } else if (ActivityStatusTrialExpire == [VerificationManager manager].status) {
  157. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = NO;
  158. self.label.wantsLayer = YES;
  159. self.label.layer.backgroundColor = [NSColor clearColor].CGColor;
  160. self.label.stringValue = NSLocalizedString(@"Trial expired", nil);
  161. if (@available(macOS 10.14, *)) {
  162. self.label.textColor = [NSColor whiteColor];
  163. } else {
  164. self.label.textColor = [NSColor redColor];
  165. }
  166. self.label.stringValue = @"";
  167. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  168. [self.button setAlignment:NSTextAlignmentCenter];
  169. self.bgImg.hidden = NO;
  170. self.button.layer.backgroundColor = [NSColor clearColor].CGColor;
  171. [self.button setTitleColor:[NSColor whiteColor]];
  172. if (!self.trackingArea) {
  173. self.trackingArea = [[NSTrackingArea alloc] initWithRect:self.button.bounds options:NSTrackingMouseEnteredAndExited | NSTrackingInVisibleRect | NSTrackingActiveAlways owner:self userInfo:nil];
  174. }
  175. [self.button addTrackingArea:self.trackingArea];
  176. if ([VerificationManager manager].secondTrialEnabled) {
  177. self.label.stringValue = NSLocalizedString(@"Trial expired", nil);
  178. self.label.hidden = YES;
  179. self.secondTrialBtn.hidden = NO;
  180. self.secondTrialBtn.layer.backgroundColor = [NSColor colorWithRed:0.0/255.0 green:207.0/255.0 blue:133.0/255.0 alpha:1].CGColor;
  181. [self.secondTrialBtn setTitleColor:[NSColor whiteColor]];
  182. [self.secondTrialBtn setAlignment:NSTextAlignmentCenter];
  183. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  184. [self.button setTitleColor:[NSColor whiteColor]];
  185. self.bgImg.hidden = NO;
  186. self.button.layer.backgroundColor = [NSColor clearColor].CGColor;
  187. [self.button setAlignment:NSTextAlignmentCenter];
  188. }
  189. } else if (ActivityStatusVerifExpire == [VerificationManager manager].status) {
  190. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = NO;
  191. self.label.stringValue = @"";
  192. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  193. [self.button setTitleColor:[NSColor whiteColor]];
  194. self.bgImg.hidden = NO;
  195. self.button.layer.backgroundColor = [NSColor clearColor].CGColor;
  196. [self.button setAlignment:NSTextAlignmentCenter];
  197. } else if (ActivityStatusVerification == [VerificationManager manager].status) {
  198. if ([VerificationManager manager].needUpgradeLicense == NO) {
  199. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = YES;
  200. } else {
  201. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = NO;
  202. self.label.stringValue = @"";
  203. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"PDF to Office Pack", nil)];
  204. [self.button setTitleColor:[KMAppearance KMColor_Interactive_A0]];
  205. self.button.layer.backgroundColor = [NSColor colorWithRed:229/255. green:233/255. blue:248/255. alpha:1].CGColor;
  206. [self.button setAlignment:NSTextAlignmentCenter];
  207. }
  208. } else {
  209. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = YES;
  210. if ([VerificationManager manager].needUpgradeLicense) {
  211. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = NO;
  212. self.label.stringValue = @"";
  213. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"PDF to Office Pack", nil)];
  214. [self.button setTitleColor:[KMAppearance KMColor_Interactive_A0]];
  215. self.button.layer.backgroundColor = [NSColor colorWithRed:229/255. green:233/255. blue:248/255. alpha:1].CGColor;
  216. [self.button setAlignment:NSTextAlignmentCenter];
  217. }
  218. }
  219. #else
  220. isFree = YES;
  221. if (isFree) {
  222. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = NO;
  223. self.button.layer.backgroundColor = [NSColor clearColor].CGColor;
  224. self.label.stringValue = @"";
  225. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  226. if (isFree) {
  227. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade to Pro", nil)];
  228. [self.button setTitleColor:[NSColor whiteColor]];
  229. if ([IAPProductsManager defaultManager].isAvailableAllFunction) {
  230. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = YES;
  231. } else {
  232. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = NO;
  233. }
  234. self.bgImg.hidden = self.button.hidden;
  235. #if !VERSION_FREE
  236. self.bgImg.hidden = YES;
  237. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = NO;
  238. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"PDF to Office Pack", nil)];
  239. if ([IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice) {
  240. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = YES;
  241. }
  242. [self.button setTitleColor:[KMAppearance KMColor_Interactive_A0]];
  243. self.button.layer.backgroundColor = [NSColor colorWithRed:229/255. green:233/255. blue:248/255. alpha:1].CGColor;
  244. #endif
  245. }
  246. } else {
  247. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = YES;
  248. }
  249. #endif
  250. [self.button sizeToFit];
  251. [self.button setAlignment:NSTextAlignmentCenter];
  252. [self.secondTrialBtn sizeToFit];
  253. [self.secondTrialBtn setAlignment:NSTextAlignmentCenter];
  254. [self.label sizeToFit];
  255. if (self.label.stringValue.length == 0) {
  256. self.labelContentView.frame = CGRectZero;
  257. } else {
  258. self.labelContentView.frame = CGRectMake(0, kbottomGap, self.label.frame.size.width + self.view.frame.size.height , self.view.frame.size.height -2 *kbottomGap);
  259. if ([VerificationManager manager].secondTrialEnabled) {
  260. self.labelContentView.frame = CGRectMake(0, kbottomGap, self.button.frame.size.width + self.secondTrialBtn.frame.size.width - 16, self.view.frame.size.height -2 *kbottomGap);
  261. }
  262. self.labelContentView.wantsLayer = YES;
  263. self.labelContentView.layer.cornerRadius = 4.;
  264. [self.labelContentView.layer masksToBounds];
  265. self.labelContentView.layer.backgroundColor = [NSColor colorWithRed:255.0/255.0 green:94.0/255.0 blue:44.0/255.0 alpha:0.15].CGColor;
  266. if ([VerificationManager manager].secondTrialEnabled) {
  267. self.labelContentView.layer.backgroundColor = [NSColor clearColor].CGColor;
  268. }
  269. 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);
  270. }
  271. CGFloat totalWidth = CGRectGetMaxX(self.labelContentView.frame) + 8;
  272. // self.aiLabel.stringValue = NSLocalizedString(@"My AI Credit", nil);
  273. // [self.aiLabel sizeToFit];
  274. // CGFloat aiWidth = self.aiLabel.frame.size.width;
  275. // aiWidth += 4;
  276. // aiWidth += 16;
  277. // aiWidth += 16;
  278. // self.aiContendView.frame = CGRectMake(totalWidth, 0, aiWidth, self.view.frame.size.height);
  279. // self.aiIconImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-8, 16, 16);
  280. // CGRect ailabelRect = self.aiLabel.frame;
  281. // ailabelRect.origin.x = CGRectGetMaxX(self.aiIconImg.frame) + 4;
  282. // self.aiLabel.frame = ailabelRect;
  283. //
  284. // totalWidth += aiWidth;
  285. // totalWidth += 8;
  286. self.aiContendView.hidden = YES;
  287. if (self.button.hidden == NO) {
  288. CGFloat buttonWidth = CGRectGetMaxX(self.button.frame);
  289. NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  290. if (fabs(buttonWidth-btnRect.size.width)>50) {
  291. buttonWidth = btnRect.size.width + 10;
  292. }
  293. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  294. totalWidth += buttonWidth;
  295. totalWidth += 8;
  296. }
  297. if (!self.secondTrialBtn.hidden) {
  298. 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);
  299. }
  300. // if (self.view.superview) {
  301. // 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);
  302. // } else {
  303. // if (self.button.hidden) {
  304. // self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.aiLabel.frame) + 20 ,self.view.frame.size.height);
  305. // } else {
  306. // self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.button.frame) ,self.view.frame.size.height);
  307. // }
  308. // }
  309. if (self.frameUpdateHandle) {
  310. self.frameUpdateHandle(self.view.frame);
  311. }
  312. // CGRect rect = self.button.frame;
  313. // self.bgImg.frame = rect;
  314. totalWidth = 8;
  315. self.button.hidden = YES;
  316. self.label.hidden = YES;
  317. self.secondTrialBtn.hidden = YES;
  318. self.labelContentView.hidden = YES;
  319. self.bgImg.hidden = YES;
  320. self.aiContendView.hidden = YES;
  321. self.userButton.hidden = YES;
  322. self.signUpView.hidden = YES;
  323. self.signUpLabel.stringValue = NSLocalizedStringFromTable(@"Sign in", @"MemberCenterLocalizable", nil);
  324. [self.signUpLabel sizeToFit];
  325. CGFloat signUpWidth = self.signUpLabel.frame.size.width;
  326. signUpWidth += 4;
  327. signUpWidth += 8;
  328. signUpWidth += 8;
  329. signUpWidth += 12;
  330. self.signUpImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-6, 12, 12);
  331. CGRect signUplabelRect = self.signUpLabel.frame;
  332. signUplabelRect.origin.x = CGRectGetMaxX(self.signUpImg.frame) + 4;
  333. self.signUpLabel.frame = signUplabelRect;
  334. self.button.layer.backgroundColor = [NSColor clearColor].CGColor;
  335. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade to Pro", nil)];
  336. [self.button setTitleColor:[NSColor whiteColor]];
  337. self.aiLabel.stringValue = NSLocalizedString(@"My AI Credit", nil);
  338. [self.aiLabel sizeToFit];
  339. CGFloat aiWidth = self.aiLabel.frame.size.width;
  340. aiWidth += 4;
  341. aiWidth += 16;
  342. aiWidth += 16;
  343. self.aiIconImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-8, 16, 16);
  344. self.aiContendView.frame = CGRectMake(totalWidth, 0, aiWidth, self.view.frame.size.height);
  345. CGRect ailabelRect = self.aiLabel.frame;
  346. ailabelRect.origin.x = CGRectGetMaxX(self.aiIconImg.frame) + 4;
  347. self.aiLabel.frame = ailabelRect;
  348. // totalWidth+=aiWidth;
  349. // totalWidth+=4;
  350. CGFloat userImageWidth = 24;
  351. // self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  352. totalWidth += userImageWidth;
  353. totalWidth += 8;
  354. if ([KMMemberInfo shared].isLogin) {
  355. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  356. } else {
  357. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  358. }
  359. CGFloat buttonWidth = CGRectGetMaxX(self.button.frame);
  360. NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  361. if (fabs(buttonWidth-btnRect.size.width)>50) {
  362. buttonWidth = btnRect.size.width + 10;
  363. }
  364. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1 ||
  365. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  366. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type4 ||
  367. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  368. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  369. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8 ||
  370. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  371. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11 ||
  372. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13) {
  373. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1 ||
  374. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9) {
  375. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  376. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  377. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11) {
  378. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"开通会员", nil)];
  379. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type4 ||
  380. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5) {
  381. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"立即升级", nil)];
  382. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  383. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8 ||
  384. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13) {
  385. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"立即续费", nil)];
  386. }
  387. [self.button setTitleColor:[NSColor whiteColor]];
  388. self.bgImg.hidden = NO;
  389. self.button.hidden = NO;
  390. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  391. CGRect rect = self.button.frame;
  392. self.bgImg.frame = rect;
  393. totalWidth+=CGRectGetWidth(self.button.bounds);
  394. totalWidth+=4;
  395. }
  396. if ([KMMemberInfo shared].isLogin) {
  397. self.userButton.hidden = NO;
  398. self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  399. totalWidth += userImageWidth;
  400. totalWidth += 8;
  401. } else {
  402. self.signUpView.hidden = NO;
  403. self.signUpView.frame = CGRectMake(totalWidth, 0, signUpWidth, self.view.frame.size.height);
  404. totalWidth+=CGRectGetWidth(self.signUpView.bounds);
  405. }
  406. // if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1 || [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type2) {
  407. // self.bgImg.hidden = NO;
  408. // self.button.hidden = NO;
  409. // self.signUpView.hidden = NO;
  410. // self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  411. // CGRect rect = self.button.frame;
  412. // self.bgImg.frame = rect;
  413. // totalWidth+=CGRectGetWidth(self.button.bounds);
  414. // totalWidth+=4;
  415. // self.signUpView.frame = CGRectMake(totalWidth, 0, signUpWidth, self.view.frame.size.height);
  416. // totalWidth+=CGRectGetWidth(self.signUpView.bounds);
  417. // } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 || [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type4) {
  418. // self.signUpView.hidden = NO;
  419. // self.signUpView.frame = CGRectMake(totalWidth, 0, signUpWidth, self.view.frame.size.height);
  420. // totalWidth+=CGRectGetWidth(self.signUpView.bounds);
  421. // } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  422. // [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type6 ||
  423. // [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  424. // [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type10 ||
  425. // [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11) {
  426. // if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5) {
  427. // self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  428. // } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type6 ||
  429. // [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type10 ||
  430. // [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11) {
  431. // self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"立即续费", @"MemberCenterLocalizable", nil)];
  432. // } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7) {
  433. // self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"立即升级", @"MemberCenterLocalizable", nil)];
  434. // }
  435. // [self.button setTitleColor:[NSColor whiteColor]];
  436. // self.bgImg.hidden = NO;
  437. // self.button.hidden = NO;
  438. // self.userButton.hidden = NO;
  439. // self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  440. // CGRect rect = self.button.frame;
  441. // self.bgImg.frame = rect;
  442. // totalWidth+=CGRectGetWidth(self.button.bounds);
  443. // totalWidth+=8;
  444. //
  445. // self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  446. // totalWidth += userImageWidth;
  447. // totalWidth += 8;
  448. // } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8 ||
  449. // [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9) {
  450. // self.userButton.hidden = NO;
  451. // self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  452. // totalWidth += userImageWidth;
  453. // totalWidth += 8;
  454. // } else {
  455. // self.userButton.hidden = NO;
  456. // self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  457. // totalWidth += userImageWidth;
  458. // totalWidth += 8;
  459. // }
  460. if (self.view.superview) {
  461. 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);
  462. } else {
  463. if (self.button.hidden) {
  464. self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.aiLabel.frame) + 20 ,self.view.frame.size.height);
  465. } else {
  466. self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.button.frame) ,self.view.frame.size.height);
  467. }
  468. }
  469. }
  470. #pragma mark - Button Actions
  471. - (IBAction)secondTrialAction:(NSButton *)sender {
  472. if ([VerificationManager manager].secondTrialEnabled) {
  473. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialGuide];
  474. [vc showWindow:nil];
  475. } else {
  476. [[KMProductCompareWC shared] setOrientation:NO];
  477. [[KMProductCompareWC shared] showWindow:nil];
  478. }
  479. }
  480. - (IBAction)buttonAction:(id)sender {
  481. // BOOL isFree = NO;
  482. //
  483. //#if VERSION_DMG
  484. // if (ActivityStatusNone == [VerificationManager manager].status) {
  485. // //弹出 试用弹窗UI优化-新用户试用路径 新UI 情况一 右上角按钮
  486. // KMPurchaseFirstTrialWindowController *firstTrialWC = [KMPurchaseFirstTrialWindowController currentFirstTrialWC];
  487. // firstTrialWC.buttonActionBlock = ^(KMPurchaseFirstTrialWindowController * _Nonnull ftWC, KMButton * _Nonnull btn, NSString * _Nonnull email, NSString * _Nonnull name) {
  488. // if (btn.tag == 10001) {
  489. // if (ActivityStatusNone == [VerificationManager manager].status ||
  490. // ActivityStatusTrialExpire == [VerificationManager manager].status) {
  491. //
  492. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_SecondTrial"}];
  493. // [[VerificationManager manager] trialForDays:7
  494. // email:email?:[VerificationManager manager].email
  495. // name:name?:[VerificationManager manager].accountName
  496. // complention:^(ActivityStatus status, NSDictionary *info, NSError *error) {
  497. // if (error ||
  498. // status != ActivityStatusTrial) {
  499. // NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  500. // defaultButton:NSLocalizedString(@"Try Again", nil)
  501. // alternateButton:nil
  502. // otherButton:nil
  503. // informativeTextWithFormat:NSLocalizedString(@"Failed to sign up for the free trial. Please make sure your internet connection is available and try again later.", nil), nil];
  504. // [alert runModal];
  505. // } else {
  506. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialSuccess];
  507. // [vc showWindow:nil];
  508. // }
  509. // }];
  510. // [ftWC close];
  511. // } else {
  512. // [ftWC close];
  513. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];
  514. // vc.callback = ^{
  515. // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  516. // };
  517. // [vc showWindow:nil];
  518. // }
  519. // } else if (btn.tag == 10002) {
  520. // NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@?utm_source=app_dmg&utm_medium=dmg_puw_free_trial", Swift_oc_Tool.Store_Link_OC]];
  521. // [[NSWorkspace sharedWorkspace] openURL:url];
  522. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_UpgradeBuyNow"}];
  523. // } else if (btn.tag == 10003) {
  524. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];//KMVerificationTypeActivate
  525. // [vc showWindow:nil];
  526. // [ftWC close];
  527. // }
  528. // };
  529. // [firstTrialWC.window center];
  530. // [firstTrialWC showWindow:nil];
  531. // } else if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  532. // ActivityStatusTrial == [VerificationManager manager].status) {
  533. // [[NSNotificationCenter defaultCenter] postNotificationName:@"KMVerificationMessagePopShowNoti" object:nil];
  534. //
  535. // if (!self.testVC) {
  536. // self.testVC = [[KMUnlockAlertViewController alloc] init];
  537. // }
  538. // [self.testVC addtrackingAreaInfo];
  539. // self.testVC.callback = ^(NSInteger index) {
  540. // if (index == 1) {
  541. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];
  542. // [vc showWindow:nil];
  543. // } else if (index == 2) {
  544. // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.mac.product_3"];
  545. // [embeddedWC showWindow:nil];
  546. // [[embeddedWC window] center];
  547. // }
  548. // };
  549. // self.testVC.mouseEventCall = ^(BOOL mouseEnter) {
  550. // if (mouseEnter) {
  551. // self.stopPopOverHide = YES;
  552. // if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  553. // ActivityStatusTrial == [VerificationManager manager].status) {
  554. // if (!self.popover.isShown) {
  555. // [self buttonAction:self.button];
  556. // }
  557. // }
  558. // } else {
  559. // self.stopPopOverHide = NO;
  560. // if (self.popover) {
  561. // [self.popover close];
  562. // }
  563. // [self.testVC removeTrackingAreaInfo];
  564. // }
  565. // };
  566. // NSPopover *popover = [[NSPopover alloc] init];
  567. // popover.delegate = self;
  568. // popover.contentViewController = self.testVC;
  569. // popover.animates = YES;
  570. // popover.behavior = NSPopoverBehaviorTransient;
  571. // [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
  572. // self.popover = popover;
  573. // } else if (ActivityStatusVerifExpire == [VerificationManager manager].status) {
  574. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateExpired];
  575. // [vc showWindow:nil];
  576. // } else if (ActivityStatusVerification == [VerificationManager manager].status) {
  577. // if ([VerificationManager manager].needUpgradeLicense) {
  578. // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.mac.product_2"];
  579. // [embeddedWC showWindow:nil];
  580. // [[embeddedWC window] center];
  581. // }
  582. // } else {
  583. // if ([VerificationManager manager].needUpgradeLicense) {
  584. // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.mac.product_2"];
  585. // [embeddedWC showWindow:nil];
  586. // [[embeddedWC window] center];
  587. // } else {
  588. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeNormal];
  589. // [vc showWindow:nil];
  590. // }
  591. // }
  592. //#else
  593. // isFree = YES;
  594. //#if VERSION_FREE
  595. // if ([IAPProductsManager defaultManager].isAvailableAllFunction) {
  596. // isFree = NO;
  597. // }
  598. // if (isFree) {
  599. // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  600. // }
  601. //#else
  602. // if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice) {
  603. // KMToolCompareWindowController *vc = [KMToolCompareWindowController toolCompareWithToolType:KMCompareWithToolTypeConvert selectNum:0];
  604. // [vc.window center];
  605. // [vc showWindow:nil];
  606. // }
  607. //#endif
  608. //
  609. //#endif
  610. if ([KMMemberInfo shared].isLogin) {
  611. [[KMProductCompareWC shared] setOrientation:YES];
  612. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
  613. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  614. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  615. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  616. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8) {
  617. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  618. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type4 ||
  619. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  620. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  621. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11 ||
  622. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13) {
  623. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_MacWindows];
  624. }
  625. [[KMProductCompareWC shared] showWindow:nil];
  626. } else {
  627. [KMLoginWindowsController.shared openWindow:^(BOOL success) {
  628. if (success) {
  629. [[KMProductCompareWC shared] setOrientation:YES];
  630. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
  631. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  632. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  633. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  634. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8) {
  635. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  636. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type4 ||
  637. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  638. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  639. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11 ||
  640. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13) {
  641. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_MacWindows];
  642. }
  643. [[KMProductCompareWC shared] showWindow:nil];
  644. }
  645. }];
  646. }
  647. }
  648. - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
  649. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
  650. NSString *temp = nil;
  651. for (NSUInteger i = 0; i <string.length; i++) {
  652. temp = [string substringWithRange:NSMakeRange(i, 1)];
  653. if ([self isPureInt:temp]) {
  654. [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  655. color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
  656. }
  657. }
  658. return attributedString;
  659. }
  660. - (BOOL)isPureInt:(NSString *)string {
  661. NSScanner *scan = [NSScanner scannerWithString:string];
  662. int value;
  663. return [scan scanInt:&value] && [scan isAtEnd];
  664. }
  665. - (IBAction)AIButtonAction:(NSButton *)sender {
  666. __block typeof(self) blockSelf = self;
  667. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit"}];
  668. [[AIInfoManager defaultManager] fetchAIInfoWithComplention:^(NSDictionary *info, NSError *error) {
  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. [[AIPurchaseWindowController currentWC] showWindow:nil];
  678. #endif
  679. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit_BuyNow"}];
  680. };
  681. controller.enterLicenseHandle = ^(AIUserInfoController * _Nonnull vc) {
  682. KMVerificationWindowController *verifyVC = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateAIInfo];
  683. verifyVC.callback = ^{
  684. };
  685. [verifyVC showWindow:nil];
  686. };
  687. controller.guideHandle = ^(AIUserInfoController * _Nonnull vc) {
  688. if (!blockSelf.guideWindowVC) {
  689. KMFunctionGuideWindowController *guideWindowVC = [[KMFunctionGuideWindowController alloc] initWithWindowNibName:@"KMFunctionGuideWindowController"];
  690. blockSelf.guideWindowVC = guideWindowVC;
  691. }
  692. ((KMFunctionGuideWindowController *)(blockSelf.guideWindowVC)).type = KMGuideInfoTypeFunctionMulti;
  693. [blockSelf.guideWindowVC showWindow:nil];
  694. [KMFunctionGuideWindowController setDidShowFor:KMGuideInfoTypeFunctionMultiAIGuide];
  695. [blockSelf.guideWindowVC.window orderFront:nil];
  696. };
  697. NSPopover *popover = [[NSPopover alloc] init];
  698. popover.contentViewController = controller;
  699. popover.animates = YES;
  700. popover.behavior = NSPopoverBehaviorTransient;
  701. [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
  702. }
  703. - (IBAction)userButtonAction:(NSButton *)sender {
  704. if ([KMMemberInfo shared].isLogin) {
  705. [self personalCenterAction:sender];
  706. } else {
  707. [KMLoginWindowsController.shared showWindow:nil];
  708. }
  709. }
  710. - (IBAction)personalCenterAction:(NSButton *)sender {
  711. // 用户头像点击事件
  712. self.userMenu = [[NSMenu alloc] init];
  713. KMUserInfoViewController *userInfo = [[KMUserInfoViewController alloc] init];
  714. NSColor *color = [NSColor colorNamed:@"membercentercolor"];
  715. userInfo.view.layer.backgroundColor = color.CGColor;
  716. NSMenuItem *item = [self.userMenu addItemWithTitle:@"" action:nil target:@""];
  717. item.target = self;
  718. item.representedObject = userInfo;
  719. item.view = userInfo.view;
  720. [self.userMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(-130, 30) inView:sender];
  721. }
  722. - (IBAction)signUpAction:(NSButton *)sender {
  723. [KMLoginWindowsController.shared showWindow:nil];
  724. }
  725. #pragma mark - NSNotification Methods
  726. - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
  727. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  728. [self reloadData];
  729. });
  730. }
  731. - (void)IAPResultReceived:(NSNotification *)notification {
  732. dispatch_async(dispatch_get_main_queue(), ^{
  733. [self reloadData];
  734. });
  735. }
  736. - (void)IAPPurchaseSuccess:(NSNotification *)notification {
  737. dispatch_async(dispatch_get_main_queue(), ^{
  738. [self reloadData];
  739. });
  740. }
  741. - (void)IAPRestoreFinish:(NSNotification *)notification {
  742. dispatch_async(dispatch_get_main_queue(), ^{
  743. [self reloadData];
  744. });
  745. }
  746. #pragma mark - Event
  747. - (void)mouseEntered:(NSEvent *)event {
  748. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  749. ActivityStatusTrial == [VerificationManager manager].status) {
  750. [[self class] cancelPreviousPerformRequestsWithTarget:self];
  751. if (!self.popover.isShown) {
  752. [self buttonAction:self.button];
  753. }
  754. }
  755. }
  756. - (void)mouseExited:(NSEvent *)event {
  757. [super mouseExited:event];
  758. [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
  759. }
  760. - (void)popoverDidClose:(NSNotification *)notification {
  761. self.stopPopOverHide = NO;
  762. }
  763. - (void)popoverShowNoti:(NSNotification *)noti {
  764. if (self.popover) {
  765. [self.popover close];
  766. self.stopPopOverHide = NO;
  767. }
  768. }
  769. - (void)loginSuccessNotification:(NSNotification *)noti {
  770. _userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  771. [self reloadData];
  772. }
  773. - (void)logoutSuccessNotification:(NSNotification *)noti {
  774. _userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  775. [self reloadData];
  776. }
  777. - (void)expandPersonalCenterNotification:(NSNotification *)noti {
  778. if (self.userMenu != nil) {
  779. [self personalCenterAction:_userButton];
  780. }
  781. }
  782. - (void)closeMenu:(NSNotification *)noti {
  783. if (self.userMenu != nil) {
  784. [self.userMenu cancelTracking];
  785. self.userMenu = nil;
  786. }
  787. }
  788. - (void)popOverCloseAction {
  789. if (self.stopPopOverHide == NO) {
  790. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  791. ActivityStatusTrial == [VerificationManager manager].status) {
  792. if (self.popover.isShown) {
  793. [self.popover close];
  794. self.stopPopOverHide = NO;
  795. }
  796. }
  797. }
  798. }
  799. @end