KMVerificationMessageViewController.m 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505
  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. #import "KMMessageModel.h"
  14. #import "KMMessageItemView.h"
  15. #import "KMOCLanguage.h"
  16. #if !VERSION_DMG
  17. #import <StoreKit/StoreKit.h>
  18. #endif
  19. #define kbottomGap 0
  20. @interface KMVerificationMessageViewController ()<
  21. NSPopoverDelegate>
  22. @property (nonatomic, assign) IBOutlet NSTextField *label;
  23. @property (nonatomic, assign) IBOutlet NSButton *button;
  24. @property (nonatomic, assign) IBOutlet NSButton *secondTrialBtn;
  25. @property (assign) IBOutlet NSView *labelContentView;
  26. @property (assign) IBOutlet NSImageView *bgImg;
  27. @property (assign) IBOutlet NSView *aiContendView;
  28. @property (assign) IBOutlet NSImageView *aiIconImg;
  29. @property (assign) IBOutlet NSTextField *aiLabel;
  30. @property (weak) IBOutlet NSButton *userButton;
  31. @property (assign) IBOutlet NSView *signUpView;
  32. @property (assign) IBOutlet NSImageView *signUpImg;
  33. @property (assign) IBOutlet NSTextField *signUpLabel;
  34. @property (strong) IBOutlet NSImageView *signUpBGImage;
  35. @property (weak) IBOutlet NSButton *officeButton;
  36. @property (assign) IBOutlet NSImageView *officeImg;
  37. @property (strong) IBOutlet NSBox *betaFeedBackBox;
  38. @property (strong) IBOutlet NSTextField *betaFeedBackLabel;
  39. @property (strong) IBOutlet NSImageView *betaFeedBackBGImg;
  40. @property (strong) IBOutlet NSLayoutConstraint *betaFeedBackRightConst;
  41. @property (strong) IBOutlet NSBox *feedbackBox;
  42. @property (strong) IBOutlet NSTextField *feedbackLabel;
  43. @property (nonatomic, retain) NSTrackingArea *trackingArea;
  44. @property (nonatomic, retain) NSPopover *popover;
  45. @property (nonatomic, assign) BOOL isPopoverShow;
  46. @property (nonatomic, assign) BOOL checkValue;
  47. @property (nonatomic, assign) BOOL stopPopOverHide;
  48. @property (nonatomic, retain) KMUnlockAlertViewController *testVC;
  49. @property (nonatomic, retain) NSMenu *userMenu;
  50. // 远程按钮 最大宽度限制 100
  51. @property (nonatomic, assign) CGFloat remoteButtonMaxWidth;
  52. @property (nonatomic, strong) NSMutableArray *datas;
  53. @property (nonatomic, strong) KMMessageDiscountItemView *userGiftView;
  54. @property (nonatomic, strong) KMMessageDiscountItemView *discountItemView;
  55. @end
  56. @implementation KMVerificationMessageViewController
  57. #pragma mark Init Methods
  58. - (instancetype)init {
  59. if (self = [super initWithNibName:@"KMVerificationMessageViewController" bundle:nil]) {
  60. self.remoteButtonMaxWidth = 200;
  61. #if VERSION_DMG
  62. [[NSNotificationCenter defaultCenter] addObserver:self
  63. selector:@selector(deviceActivateStatusChangeNotification:)
  64. name:kDeviceActivateStatusChangeNotification
  65. object:nil];
  66. [[NSNotificationCenter defaultCenter] addObserver:self
  67. selector:@selector(deviceActivateStatusChangeNotification:)
  68. name:KMIAPSubscriptionLoadedNotification
  69. object:nil];
  70. #else
  71. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPProductLoaded:) name:KMIAPProductLoadedNotification object:nil];
  72. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPResultReceived:) name:KMIAPSubscriptionLoadedNotification object:nil];
  73. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPPurchaseSuccess:) name:KMIAPProductPurchasedNotification object:nil];
  74. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPRestoreFinish:) name:KMIAPProductRestoreFinishedNotification object:nil];
  75. #endif
  76. [[NSNotificationCenter defaultCenter] addObserver:self
  77. selector:@selector(languageChangedNotification:)
  78. name:@"APPLanguageChangedNotificationName"
  79. object:nil];
  80. [[NSNotificationCenter defaultCenter] addObserver:self
  81. selector:@selector(uiThemeChangedNotification:)
  82. name:@"APPAppearanceChangedNotificationName"
  83. object:nil];
  84. _datas = [NSMutableArray arrayWithCapacity:4];
  85. }
  86. return self;
  87. }
  88. - (void)dealloc {
  89. [[NSNotificationCenter defaultCenter] removeObserver:self];
  90. if (self.trackingArea) {
  91. [self.button removeTrackingArea:self.trackingArea];
  92. }
  93. }
  94. #pragma mark Setter Methods
  95. - (void)loadView {
  96. [super loadView];
  97. // Do view setup here.
  98. self.button.wantsLayer = YES;
  99. self.button.layer.masksToBounds = YES;
  100. self.button.layer.cornerRadius = 4.0;
  101. self.button.font = [NSFont SFProTextSemiboldFont:11];
  102. self.button.layer.backgroundColor = [NSColor colorWithDeviceRed:121.0/255.0 green:196.0/255.0 blue:66.0/255.0 alpha:1.0].CGColor;
  103. [self.button setAlignment:NSTextAlignmentCenter];
  104. self.userButton.font = [NSFont SFProTextSemiboldFont:11];
  105. self.secondTrialBtn.wantsLayer = YES;
  106. self.secondTrialBtn.layer.masksToBounds = YES;
  107. self.secondTrialBtn.layer.cornerRadius = 4.0;
  108. self.secondTrialBtn.font = [NSFont SFProTextSemiboldFont:11];
  109. self.secondTrialBtn.layer.backgroundColor = [NSColor colorWithDeviceRed:121.0/255.0 green:196.0/255.0 blue:66.0/255.0 alpha:1.0].CGColor;
  110. [self.secondTrialBtn setAlignment:NSTextAlignmentCenter];
  111. NSString *tTips = KMLocalizedString(@"Upgrade to Pro", nil);
  112. #if VERSION_DMG
  113. tTips = @"";
  114. #else
  115. tTips = [NSString stringWithFormat:@"%@", KMLocalizedString(@"Subscribe to All Access Pack to enjoy more expanded features.", nil)];
  116. #endif
  117. self.button.toolTip = tTips;
  118. self.button.title = [NSString stringWithFormat:@" %@ ",KMLocalizedString(@"Upgrade", nil)];
  119. [self.button setTitleColor:[NSColor whiteColor]];
  120. [self.button setAlignment:NSTextAlignmentCenter];
  121. self.secondTrialBtn.toolTip = tTips;
  122. self.secondTrialBtn.title = [NSString stringWithFormat:@" %@ ",KMLocalizedString(@"Free Trial", nil)];
  123. [self.secondTrialBtn setTitleColor:[NSColor whiteColor]];
  124. [self.secondTrialBtn setAlignment:NSTextAlignmentCenter];
  125. self.secondTrialBtn.hidden = YES;
  126. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = NO;
  127. self.bgImg.wantsLayer = YES;
  128. self.bgImg.image = [NSImage imageNamed:@"Upgarde_bg_icon"];
  129. self.bgImg.layer.masksToBounds = YES;
  130. self.bgImg.layer.cornerRadius = 4.;
  131. self.bgImg.hidden = YES;
  132. self.aiLabel.font = [NSFont SFProTextSemiboldFont:11];
  133. self.aiLabel.textColor = [NSColor whiteColor];
  134. self.signUpView.wantsLayer = true;
  135. self.signUpView.layer.cornerRadius = 4;
  136. self.userGiftView = [[KMMessageDiscountItemView alloc] init];
  137. self.userGiftView.gradientColors = @[[NSColor colorWithRed:248/255.0 green:150/255.0 blue:90/255.0 alpha:1.0],
  138. [NSColor colorWithRed:253/255.0 green:113/255.0 blue:113/255.0 alpha:1.0]];
  139. self.userGiftView.radius = 4;
  140. self.userGiftView.titleLabel.font = [NSFont SFProTextBoldFont:11];
  141. self.userGiftView.titleLabel.textColor = NSColor.whiteColor;
  142. self.userGiftView.hidden = true;
  143. self.userGiftView.leftImageView.image = [NSImage imageNamed:@"NewUserGift"];
  144. self.userGiftView.kTarget = self;
  145. self.userGiftView.kAction = @selector(userGiftAction:);
  146. _discountItemView = [[KMMessageDiscountItemView alloc] init];
  147. _discountItemView.gradientColors = @[[NSColor colorWithRed:248/255.0 green:150/255.0 blue:90/255.0 alpha:1.0],
  148. [NSColor colorWithRed:253/255.0 green:113/255.0 blue:113/255.0 alpha:1.0]];
  149. _discountItemView.radius = 4;
  150. _discountItemView.titleLabel.font = [NSFont SFProTextBoldFont:11];
  151. _discountItemView.titleLabel.textColor = NSColor.whiteColor;
  152. _discountItemView.hidden = true;
  153. _discountItemView.leftImageView.image = [NSImage imageNamed:@"KMImageNameCancelSubscribeDiscount"];
  154. _discountItemView.kTarget = self;
  155. _discountItemView.kAction = @selector(discountAction:);
  156. self.betaFeedBackBox.hidden = true;
  157. self.feedbackBox.hidden = true;
  158. #if VERSION_BETA
  159. self.betaFeedBackBox.hidden = false;
  160. self.betaFeedBackBox.borderWidth = 0;
  161. // self.betaFeedBackBox.clipsToBounds = true;
  162. self.betaFeedBackBox.fillColor = NSColor.clearColor;
  163. self.betaFeedBackBox.borderColor = NSColor.clearColor;
  164. self.betaFeedBackBGImg.wantsLayer = true;
  165. self.betaFeedBackBGImg.layer.cornerRadius = 4;
  166. self.betaFeedBackBGImg.layer.masksToBounds = true;
  167. self.betaFeedBackLabel.stringValue = KMLocalizedString(@"Feedback to Win Gifts", nil);
  168. self.betaFeedBackLabel.textColor = NSColor.whiteColor;
  169. self.feedbackBox.cornerRadius = 4;
  170. self.feedbackBox.borderWidth = 0;
  171. self.feedbackBox.fillColor = [NSColor colorWithRed:7/255. green:115/255. blue:237/255. alpha:1];
  172. #endif
  173. [self reloadData];
  174. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popoverShowNoti:) name:@"KMVerificationMessagePopShowNoti" object:nil];
  175. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccessNotification:) name:@"MemberCenterLoginSuccess" object:nil];
  176. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logoutSuccessNotification:) name:@"MemberCenterLogoutSuccess" object:nil];
  177. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(expandPersonalCenterNotification:) name:@"ExpandPersonalCenter" object:nil];
  178. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeMenu:) name:@"CloseMenuNotification" object:nil];
  179. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(memberInfoChangeNotification:) name:KMMemberInfoChangeNotification object:nil];
  180. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(betaUpdateNotification:) name:@"kBetaFeedbackHaveFeedbackChange" object:nil];
  181. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(subscriptionLoadedNotification:) name:KMIAPSubscriptionLoadedNotification object:nil];
  182. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(trailCancelStateDidChange:) name:@"KMTrailCancelStateDidChangeNotificationName" object:nil];
  183. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(advertisementDidLoaded:) name:@"KMAdvertisementDidLoadedNotification" object:nil];
  184. }
  185. // MARK: - Private Methods
  186. - (NSString *)_getAppStoreFreeVersionBuyNowTitle {
  187. return [NSString stringWithFormat:@" %@ ",KMLocalizedString(@"Purchase without Login", nil)];
  188. }
  189. - (NSString *)_getDiscountTitle {
  190. #if VERSION_DMG
  191. if ([KMLocalizedString(@"USD", @"") isEqualToString:@"USD"]) {
  192. return [NSString stringWithFormat:KMLocalizedString(@"%@ Coupons", @""), @"$60"];
  193. } else {
  194. return [NSString stringWithFormat:KMLocalizedString(@"%@ Coupons", @""), @"¥360"];
  195. }
  196. #else
  197. BOOL showCNY = false;
  198. #if VERSION_FREE
  199. NSString *localeId = [IAPProductsManager defaultManager].allAccessPackPermanent_lite.product.priceLocale.localeIdentifier;
  200. if ([localeId containsString:@"zh_CN"] || [localeId containsString:@"zh_TW"] || [localeId containsString:@"zh-TW"]) {
  201. showCNY = true;
  202. }
  203. #endif
  204. if ([[KMCheckInManager default] trailCancel] || [[KMCheckInManager default] advancedYearSubscribeTrailCancelForLocal]) {
  205. if (showCNY == false) {
  206. // if ([KMLocalizedString(@"USD", "") isEqualToString:@"USD"]) {
  207. return [NSString stringWithFormat:KMLocalizedString(@"%@ Coupons", @""), @"USD 60"];
  208. } else {
  209. return [NSString stringWithFormat:KMLocalizedString(@"%@ Coupons", @""), @"¥360"];
  210. }
  211. } else {
  212. if ([[KMMemberInfo shared] isFreeAccount]) {
  213. if (showCNY == false) {
  214. // if ([KMLocalizedString(@"USD", "") isEqualToString:@"USD"]) {
  215. return [NSString stringWithFormat:KMLocalizedString(@"%@ Coupons", @""), @"USD 30"];
  216. } else {
  217. return [NSString stringWithFormat:KMLocalizedString(@"%@ Coupons", @""), @"¥180"];
  218. }
  219. } else {
  220. return @"";
  221. }
  222. }
  223. #endif
  224. }
  225. - (CGFloat)_calTextWidth:(NSString *)textString font:(NSFont *)font {
  226. NSMutableDictionary *attri = [NSMutableDictionary dictionary];
  227. if (font != nil) {
  228. [attri setObject:font forKey:NSFontAttributeName];
  229. }
  230. NSRect rect = [textString boundingRectWithSize:CGSizeMake(MAXFLOAT, 30) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attri];
  231. return rect.size.width;
  232. }
  233. // 是否定向跳转比较表
  234. - (BOOL)_isNowGotoPurcahseTable {
  235. #if VERSION_FREE
  236. #if VERSION_DMG
  237. return false;
  238. #else
  239. // AppStore 免费版 有特定需求
  240. // 无本机权益 true,否则 false
  241. return IAPProductsManager.defaultManager.isAvailableAllFunction == false;
  242. #endif
  243. #else
  244. return false;
  245. #endif
  246. }
  247. - (CGFloat)_dealDiscountViewWithMessageType:(KMMessageType)messageType {
  248. KMMessageModel *newUserGiftModel = nil;
  249. KMMessageModel *discountModel = nil;
  250. for (KMMessageModel *model in self.datas) {
  251. if (model.type == KMMessageTypeNewUserGift) {
  252. newUserGiftModel = model;
  253. }
  254. if (model.type == KMMessageTypeDiscount) {
  255. discountModel = model;
  256. }
  257. }
  258. CGFloat discountWidth = 0;
  259. if (newUserGiftModel != nil && newUserGiftModel.show) {
  260. if (self.userGiftView.superview == nil) {
  261. [self.view addSubview:self.userGiftView positioned:NSWindowAbove relativeTo:self.button];
  262. }
  263. [self.userGiftView mas_remakeConstraints:^(MASConstraintMaker *make) {
  264. if (messageType == KMMessageTypeFreeTrail || messageType == KMMessageTypePurchaseWithoutLogin) {
  265. make.trailing.equalTo(self.button.mas_leading).mas_offset(-4);;
  266. } else {
  267. make.trailing.equalTo(self.button);
  268. }
  269. make.top.mas_equalTo(0);
  270. make.width.mas_equalTo(newUserGiftModel.viewWidth);
  271. make.height.equalTo(self.view);
  272. }];
  273. discountWidth = newUserGiftModel.viewWidth + 4;
  274. self.userGiftView.hidden = false;
  275. self.userGiftView.titleLabel.stringValue = newUserGiftModel.titleText;
  276. } else if (discountModel != nil && discountModel.show) {
  277. if (self.discountItemView.superview == nil) {
  278. [self.view addSubview:self.discountItemView positioned:NSWindowAbove relativeTo:self.button];
  279. }
  280. [self.discountItemView mas_remakeConstraints:^(MASConstraintMaker *make) {
  281. if (messageType == KMMessageTypeFreeTrail || messageType == KMMessageTypePurchaseWithoutLogin) {
  282. make.trailing.equalTo(self.button.mas_leading).mas_offset(-4);
  283. } else {
  284. make.trailing.equalTo(self.button);
  285. }
  286. make.top.mas_equalTo(0);
  287. make.width.mas_equalTo(discountModel.viewWidth);
  288. make.height.equalTo(self.view);
  289. }];
  290. discountWidth = discountModel.viewWidth + 4;
  291. self.discountItemView.hidden = false;
  292. _discountItemView.titleLabel.stringValue = discountModel.titleText;
  293. }
  294. return discountWidth;
  295. }
  296. - (KMMessageModel *)_createDiscountModelWithType:(KMMessageType)type {
  297. NSString *titleText = @"";
  298. if (type == KMMessageTypeNewUserGift) {
  299. titleText = KMLocalizedString(@"Welcome Gifts", @"");
  300. } else if (type == KMMessageTypeDiscount) {
  301. titleText = [self _getDiscountTitle];
  302. }
  303. NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
  304. CGFloat width = [self _calTextWidth:calTitleText font:nil];
  305. KMMessageModel *model = [[KMMessageModel alloc] init];
  306. model.type = type;
  307. model.show = true;
  308. model.titleText = titleText;
  309. model.viewWidth = width + 10;
  310. return model;
  311. }
  312. - (void)_trackButtonEvent {
  313. if (self.button.tag == KMMessageTypePurchaseWithoutLogin) {
  314. #if VERSION_FREE
  315. #if VERSION_DMG
  316. #else
  317. #endif
  318. #endif
  319. } else if (self.button.tag == KMMessageTypeFreeTrail) {
  320. }
  321. }
  322. - (CGFloat)dealSignUpView {
  323. self.signUpLabel.stringValue = KMLocalizedString(@"Unlock Benefits", nil);
  324. self.signUpLabel.font = [NSFont SFProTextRegularFont:13];
  325. [self.signUpLabel sizeToFit];
  326. CGFloat signUpWidth = self.signUpLabel.frame.size.width;
  327. signUpWidth += 4;
  328. signUpWidth += 8;
  329. signUpWidth += 8;
  330. // signUpWidth += 12;
  331. self.signUpImg.frame = CGRectMake(8, CGRectGetHeight(self.signUpView.frame)/2.-6, 12, 12);
  332. CGRect signUplabelRect = self.signUpLabel.frame;
  333. // signUplabelRect.origin.x = CGRectGetMaxX(self.signUpImg.frame) + 4;
  334. signUplabelRect.origin.x = 8;
  335. signUplabelRect.origin.y = 4;
  336. self.signUpLabel.frame = signUplabelRect;
  337. [self.signUpLabel setAutoresizingMask:NSViewMinYMargin | NSViewMaxYMargin];
  338. return signUpWidth;
  339. }
  340. - (void)reloadData {
  341. [self.datas removeAllObjects];
  342. // [self.userGiftView removeFromSuperview];
  343. self.userGiftView.hidden = true;
  344. self.discountItemView.hidden = true;
  345. self.label.textColor = [NSColor blackColor];
  346. self.label.hidden = NO;
  347. self.secondTrialBtn.hidden = YES;
  348. CGFloat totalWidth = 8;
  349. self.button.hidden = NO;
  350. self.officeButton.hidden = NO;
  351. self.bgImg.hidden = NO;
  352. self.officeImg.hidden = NO;
  353. self.label.hidden = YES;
  354. self.secondTrialBtn.hidden = YES;
  355. self.labelContentView.hidden = YES;
  356. self.aiContendView.hidden = YES;
  357. self.userButton.hidden = YES;
  358. self.signUpView.hidden = YES;
  359. CGFloat signUpWidth = [self dealSignUpView];
  360. self.button.layer.backgroundColor = [NSColor clearColor].CGColor;
  361. self.button.title = [NSString stringWithFormat:@" %@ ",KMLocalizedString(@"Upgrade to Pro", nil)];
  362. [self.button setTitleColor:[NSColor whiteColor]];
  363. self.button.tag = KMMessageTypeNone;
  364. self.officeButton.layer.backgroundColor = [NSColor clearColor].CGColor;
  365. self.officeButton.title = [NSString stringWithFormat:@" %@ ",KMLocalizedString(@"PDF to Office", nil)];
  366. [self.officeButton setTitleColor:[NSColor whiteColor]];
  367. self.aiLabel.stringValue = NSLocalizedStringFromTable(@"Free Use 1-Year AI Tools", @"MemberCenterLocalizable", nil);
  368. [self.aiLabel sizeToFit];
  369. CGFloat aiWidth = self.aiLabel.frame.size.width;
  370. aiWidth += 4;
  371. aiWidth += 16;
  372. aiWidth += 16;
  373. self.aiIconImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-8, 16, 16);
  374. self.aiContendView.frame = CGRectMake(totalWidth, 0, aiWidth, self.view.frame.size.height);
  375. CGRect ailabelRect = self.aiLabel.frame;
  376. ailabelRect.origin.x = CGRectGetMaxX(self.aiIconImg.frame) + 4;
  377. self.aiLabel.frame = ailabelRect;
  378. // totalWidth+=aiWidth;
  379. // totalWidth+=4;
  380. // self.aiContendView.hidden = NO;
  381. CGFloat userImageWidth = 24;
  382. if ([KMMemberInfo shared].isLogin) {
  383. self.userButton.image = [NSImage imageNamed:@"member_avatar"];
  384. } else {
  385. self.userButton.image = [NSImage imageNamed:@"member_avatar"];
  386. }
  387. CGFloat buttonWidth = CGRectGetMaxX(self.button.frame);
  388. NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  389. // if (fabs(buttonWidth-btnRect.size.width)>50) {
  390. buttonWidth = btnRect.size.width + 10;
  391. // buttonWidth += 10;
  392. // }
  393. CGFloat officeWidth = CGRectGetMaxX(self.officeButton.frame);
  394. NSRect officeRect = [self.officeButton.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.officeButton.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  395. if (fabs(officeWidth-officeRect.size.width)>50) {
  396. officeWidth = officeRect.size.width + 10;
  397. }
  398. #if VERSION_BETA
  399. self.betaFeedBackLabel.stringValue = KMLocalizedString(@"Feedback to Win Gifts", nil);
  400. #endif
  401. #if VERSION_DMG
  402. self.button.hidden = YES;
  403. self.officeButton.hidden = YES;
  404. self.bgImg.hidden = YES;
  405. self.officeImg.hidden = YES;
  406. if ([[KMMemberInfo shared].isHaveAIDiscount isEqualToString:@"1"]) {
  407. self.aiContendView.hidden = NO;
  408. totalWidth+=aiWidth;
  409. totalWidth+=4;
  410. }
  411. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  412. KMMessageType messageType = KMMessageTypeNone;
  413. if (type == KMUserScenarioTypeDmg_type1 ||
  414. type == KMUserScenarioTypeDmg_type2 ||
  415. type == KMUserScenarioTypeDmg_type3 ||
  416. type == KMUserScenarioTypeDmg_type5 ||
  417. type == KMUserScenarioTypeDmg_type6 ||
  418. type == KMUserScenarioTypeDmg_type7 ||
  419. type == KMUserScenarioTypeDmg_type28 ||
  420. type == KMUserScenarioTypeDmg_type29 ||
  421. type == KMUserScenarioTypeDmg_type30 ||
  422. type == KMUserScenarioTypeDmg_type43 ||
  423. type == KMUserScenarioTypeDmg_type44 ||
  424. type == KMUserScenarioTypeDmg_type45) {
  425. self.button.title = [NSString stringWithFormat:@" %@ ",KMLocalizedString(@"Upgrade", nil)];
  426. messageType = KMMessageTypeUpgrade;
  427. } else if (type == KMUserScenarioTypeDmg_type4 ) {
  428. self.button.title = [NSString stringWithFormat:@" %@ ",KMLocalizedString(@"Free Trial", nil)];
  429. messageType = KMMessageTypeFreeTrail;
  430. self.button.tag = KMMessageTypeFreeTrail;
  431. } else if (type == KMUserScenarioTypeDmg_type11 ||
  432. type == KMUserScenarioTypeDmg_type19 ||
  433. type == KMUserScenarioTypeDmg_type22 ||
  434. type == KMUserScenarioTypeDmg_type34 ||
  435. type == KMUserScenarioTypeDmg_type37 ) {
  436. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now", @"MemberCenterLocalizable", nil)];
  437. messageType = KMMessageTypeBuyNow;
  438. } else if (type == KMUserScenarioTypeDmg_type18 ||
  439. type == KMUserScenarioTypeDmg_type33 ||
  440. type == KMUserScenarioTypeDmg_type48) {
  441. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now", @"MemberCenterLocalizable", nil)];
  442. messageType = KMMessageTypeRenew;
  443. }
  444. if (type == KMUserScenarioTypeDmg_type2 ||
  445. type == KMUserScenarioTypeDmg_type19 ||
  446. type == KMUserScenarioTypeDmg_type20 ||
  447. type == KMUserScenarioTypeDmg_type21 ||
  448. type == KMUserScenarioTypeDmg_type22 ||
  449. type == KMUserScenarioTypeDmg_type30 ||
  450. type == KMUserScenarioTypeDmg_type31 ||
  451. type == KMUserScenarioTypeDmg_type32 ||
  452. type == KMUserScenarioTypeDmg_type33) {
  453. [self.officeButton setTitleColor:[NSColor whiteColor]];
  454. self.officeButton.hidden = NO;
  455. self.officeImg.hidden = NO;
  456. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  457. CGRect officeRect = self.officeButton.frame;
  458. self.officeImg.frame = officeRect;
  459. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  460. totalWidth+=4;
  461. }
  462. if (type == KMUserScenarioTypeDmg_type1 ||
  463. type == KMUserScenarioTypeDmg_type2 ||
  464. type == KMUserScenarioTypeDmg_type3 ||
  465. type == KMUserScenarioTypeDmg_type4 ||
  466. type == KMUserScenarioTypeDmg_type5 ||
  467. type == KMUserScenarioTypeDmg_type6 ||
  468. type == KMUserScenarioTypeDmg_type7 ||
  469. type == KMUserScenarioTypeDmg_type11 ||
  470. type == KMUserScenarioTypeDmg_type18 ||
  471. type == KMUserScenarioTypeDmg_type19 ||
  472. type == KMUserScenarioTypeDmg_type22 ||
  473. type == KMUserScenarioTypeDmg_type28 ||
  474. type == KMUserScenarioTypeDmg_type29 ||
  475. type == KMUserScenarioTypeDmg_type30 ||
  476. type == KMUserScenarioTypeDmg_type33 ||
  477. type == KMUserScenarioTypeDmg_type34 ||
  478. type == KMUserScenarioTypeDmg_type37 ||
  479. type == KMUserScenarioTypeDmg_type43 ||
  480. type == KMUserScenarioTypeDmg_type44 ||
  481. type == KMUserScenarioTypeDmg_type45 ||
  482. type == KMUserScenarioTypeDmg_type48 ||
  483. type == KMUserScenarioTypeDmg_type13) {
  484. [self.button setTitleColor:[NSColor whiteColor]];
  485. KMAdvertisementItem *advertiseItem = KMAdvertisementManager.manager.info.topRightInfoContent;
  486. if (advertiseItem != nil && advertiseItem.content.firstObject != nil) {
  487. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  488. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  489. self.button.title = [NSString stringWithFormat:@" %@ ",KMLocalizedString(name, nil)];
  490. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  491. __weak typeof(self)weakSelf = self;
  492. NSImage * img = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  493. if (image != nil) {
  494. weakSelf.bgImg.image = image;
  495. }
  496. }];
  497. } else {
  498. #if !VERSION_BETA
  499. KMMemberInfo *member = [KMMemberInfo shared];
  500. KMNewUserGiftManager *man = [KMNewUserGiftManager default];
  501. if ([man needShow] && [member isLogin] == false && member.isMemberAllFunction == false) { // 未登陆的新用户
  502. NSString *titleText = KMLocalizedString(@"Welcome Gifts", @"");
  503. NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
  504. if (messageType != KMMessageTypeFreeTrail) {
  505. self.button.stringValue = calTitleText;
  506. }
  507. [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeNewUserGift]];
  508. } else {
  509. if ([man needShow] && [member isFreeAccount]) {
  510. NSString *titleText = [self _getDiscountTitle];
  511. NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
  512. if (messageType != KMMessageTypeFreeTrail) {
  513. self.button.stringValue = calTitleText;
  514. }
  515. [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
  516. } else if (([member isMemberAllFunction] == false || type == KMUserScenarioTypeDmg_type13) && [[KMCheckInManager default] trailCancel]) {
  517. NSString *titleText = [self _getDiscountTitle];
  518. NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
  519. if (messageType != KMMessageTypeFreeTrail) {
  520. self.button.stringValue = calTitleText;
  521. }
  522. [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
  523. }
  524. }
  525. CGFloat discountWidth = [self _dealDiscountViewWithMessageType:messageType];
  526. totalWidth += discountWidth;
  527. #endif
  528. }
  529. #if VERSION_BETA
  530. #else
  531. if (type != KMUserScenarioTypeDmg_type13 || self.datas.count > 0) {
  532. buttonWidth = CGRectGetWidth(self.button.frame);
  533. NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  534. buttonWidth = btnRect.size.width + 10;
  535. self.bgImg.hidden = NO;
  536. self.button.hidden = NO;
  537. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  538. CGRect rect = self.button.frame;
  539. self.bgImg.frame = rect;
  540. totalWidth+=CGRectGetWidth(self.button.bounds);
  541. totalWidth+=4;
  542. }
  543. #endif
  544. }
  545. #else
  546. if ([[KMMemberInfo shared].isHaveAIDiscount isEqualToString:@"1"]) {
  547. #if VERSION_FREE
  548. if(IAPProductsManager.defaultManager.aiAllAccessPack12month_lite.isTrialPeriod == false) {
  549. self.aiContendView.hidden = NO;
  550. totalWidth+=aiWidth;
  551. totalWidth+=4;
  552. }
  553. #else
  554. if(IAPProductsManager.defaultManager.aiAllAccessPack12month_pro.isTrialPeriod == false) {
  555. self.aiContendView.hidden = NO;
  556. totalWidth+=aiWidth;
  557. totalWidth+=4;
  558. }
  559. #endif
  560. }
  561. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  562. BOOL buttonHiddenFlag = false;
  563. KMMessageType messageType = KMMessageTypeNone;
  564. if (type == KMUserScenarioTypeLite_type1 ||
  565. type == KMUserScenarioTypeLite_type3 ||
  566. type == KMUserScenarioTypeLite_type5 ||
  567. type == KMUserScenarioTypeLite_type7 ||
  568. type == KMUserScenarioTypeLite_type9 ||
  569. type == KMUserScenarioTypeLite_type11 ||
  570. type == KMUserScenarioTypePro_type1 ||
  571. type == KMUserScenarioTypePro_type3 ||
  572. type == KMUserScenarioTypePro_type4 || type == KMUserScenarioTypeLite_type8) {
  573. if (type == KMUserScenarioTypeLite_type1) { //免费用户
  574. #if !VERSION_DMG
  575. if(KMMemberInfo.shared.isLogin == NO) {
  576. #if VERSION_FREE
  577. if (IAPProductsManager.defaultManager.isAvailableAllFunction) {
  578. if (IAPProductsManager.defaultManager.isAvailableAdvancedPDFToOffice) {
  579. BOOL advanceFreeTrailing = [IAPReceiptTool isFreeTrailingWithModel:[IAPProductsManager defaultManager].receiptModel withProductId:[IAPProductsManager defaultManager].fourDevicesAllAccessPackNew12months_lite.product.productIdentifier];
  580. if (advanceFreeTrailing && [[KMCheckInManager default] advancedYearSubscribeTrailCancelForLocal]) {
  581. [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
  582. } else {
  583. self.button.title = @"";
  584. buttonHiddenFlag = true;
  585. }
  586. } else {
  587. self.button.title = [NSString stringWithFormat:@" %@ ",KMLocalizedString(@"Upgrade", nil)];
  588. messageType = KMMessageTypeUpgrade;
  589. }
  590. } else {
  591. self.button.title = [self _getAppStoreFreeVersionBuyNowTitle];
  592. if ([[KMNewUserGiftManager default] needShow]) {
  593. [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeNewUserGift]];
  594. } else if ([[KMCheckInManager default] advancedYearSubscribeTrailCancelForLocal]) {
  595. [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
  596. }
  597. messageType = KMMessageTypePurchaseWithoutLogin;
  598. self.button.tag = KMMessageTypePurchaseWithoutLogin;
  599. }
  600. #else
  601. self.button.title = [NSString stringWithFormat:@" %@ ",KMLocalizedString(@"Upgrade", nil)];
  602. messageType = KMMessageTypeUpgrade;
  603. #endif
  604. } else {
  605. if(IAPProductsManager.defaultManager.fourDevicesAllAccessPackNew12months_lite.isTrialPeriod == YES) { //是否有试用
  606. self.button.title = [NSString stringWithFormat:@" %@ ",KMLocalizedString(@"Buy Now", nil)];
  607. messageType = KMMessageTypeBuyNow;
  608. } else {
  609. self.button.title = [NSString stringWithFormat:@" %@ ",KMLocalizedString(@"Free Trial", nil)];
  610. messageType = KMMessageTypeFreeTrail;
  611. self.button.tag = KMMessageTypeFreeTrail;
  612. }
  613. KMMemberInfo *member = [KMMemberInfo shared];
  614. KMNewUserGiftManager *man = [KMNewUserGiftManager default];
  615. if ([man needShow] && [member isFreeAccount]) {
  616. NSString *titleText = [self _getDiscountTitle];
  617. NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
  618. if (messageType != KMMessageTypeFreeTrail) {
  619. self.button.stringValue = calTitleText;
  620. }
  621. [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
  622. } else if (man.progressState != KMProgressStateNone && member.isMemberAllFunction == false && [[KMCheckInManager default] trailCancel]) {
  623. NSString *titleText = [self _getDiscountTitle];
  624. NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
  625. if (messageType != KMMessageTypeFreeTrail) {
  626. self.button.stringValue = calTitleText;
  627. }
  628. [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
  629. }
  630. }
  631. #else
  632. #endif
  633. } else if (type == KMUserScenarioTypeLite_type3 ) {
  634. self.button.title = [NSString stringWithFormat:@" %@ ",KMLocalizedString(@"Buy Now", nil)];
  635. messageType = KMMessageTypeBuyNow;
  636. } else if (type == KMUserScenarioTypeLite_type5) {
  637. self.button.title = [NSString stringWithFormat:@" %@ ",KMLocalizedString(@"Upgrade", nil)];
  638. messageType = KMMessageTypeUpgrade;
  639. } else if (type == KMUserScenarioTypeLite_type7) {
  640. self.button.title = [NSString stringWithFormat:@" %@ ",KMLocalizedString(@"Renew now", nil)];
  641. messageType = KMMessageTypeRenew;
  642. } else if (type == KMUserScenarioTypeLite_type8) {
  643. KMMemberInfo *member = [KMMemberInfo shared];
  644. KMNewUserGiftManager *man = [KMNewUserGiftManager default];
  645. if (man.progressState != KMProgressStateNone && [[KMCheckInManager default] trailCancel]) {
  646. NSString *titleText = [self _getDiscountTitle];
  647. NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
  648. if (messageType != KMMessageTypeFreeTrail) {
  649. self.button.stringValue = calTitleText;
  650. }
  651. [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
  652. }
  653. if (self.datas.count > 1) {
  654. } else {
  655. self.button.title = @"";
  656. buttonHiddenFlag = true;
  657. }
  658. } else if (type == KMUserScenarioTypeLite_type9) {
  659. if([KMMemberInfo shared].vip_status == 2) {
  660. self.button.title = [NSString stringWithFormat:@" %@ ",KMLocalizedString(@"Renew now", nil)];
  661. messageType = KMMessageTypeRenew;
  662. } else if ([KMMemberInfo shared].vip_status == 4) {
  663. self.button.title = [NSString stringWithFormat:@" %@ ",KMLocalizedString(@"Buy Now", nil)];
  664. messageType = KMMessageTypeBuyNow;
  665. } else {
  666. self.button.title = [NSString stringWithFormat:@" %@ ",KMLocalizedString(@"Upgrade", nil)];
  667. messageType = KMMessageTypeUpgrade;
  668. }
  669. } else if (type == KMUserScenarioTypeLite_type11) {
  670. self.button.title = [NSString stringWithFormat:@" %@ ",KMLocalizedString(@"Upgrade", nil)];
  671. messageType = KMMessageTypeUpgrade;
  672. } else if (type == KMUserScenarioTypePro_type3) {
  673. if([KMMemberInfo shared].vip_status == 2) {
  674. self.button.title = [NSString stringWithFormat:@" %@ ",KMLocalizedString(@"Renew now", nil)];
  675. messageType = KMMessageTypeRenew;
  676. } else {
  677. self.button.title = [NSString stringWithFormat:@" %@ ",KMLocalizedString(@"Upgrade", nil)];
  678. messageType = KMMessageTypeUpgrade;
  679. }
  680. }
  681. #if !VERSION_FREE
  682. BOOL isNoSupportMemberUpgrade = YES;
  683. if ([KMMemberInfo shared].vip_status == 1) { //订阅+永久
  684. isNoSupportMemberUpgrade = NO;
  685. }
  686. if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice && isNoSupportMemberUpgrade) {
  687. [self.officeButton setTitleColor:[NSColor whiteColor]];
  688. self.officeButton.hidden = NO;
  689. self.officeImg.hidden = NO;
  690. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  691. CGRect officeRect = self.officeButton.frame;
  692. self.officeImg.frame = officeRect;
  693. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  694. totalWidth+=4;
  695. } else {
  696. self.officeButton.hidden = YES;
  697. self.officeImg.hidden = YES;
  698. }
  699. #else
  700. self.officeButton.hidden = YES;
  701. self.officeImg.hidden = YES;
  702. #endif
  703. KMAdvertisementItem *advertiseItem = KMAdvertisementManager.manager.info.topRightInfoContent;
  704. if (advertiseItem != nil && advertiseItem.content.firstObject != nil) {
  705. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  706. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  707. self.button.title = [NSString stringWithFormat:@" %@ ",KMLocalizedString(name, nil)];
  708. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  709. __weak typeof(self)weakSelf = self;
  710. NSImage * img = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  711. if (image != nil) {
  712. weakSelf.bgImg.image = image;
  713. }
  714. }];
  715. } else {
  716. CGFloat discountWidth = [self _dealDiscountViewWithMessageType:messageType];
  717. totalWidth += discountWidth;
  718. }
  719. [self.button setTitleColor:[NSColor whiteColor]];
  720. self.bgImg.hidden = NO;
  721. self.button.hidden = NO;
  722. BOOL isOldSubscribed = NO;
  723. #if VERSION_FREE
  724. #if !VERSION_DMG
  725. isOldSubscribed = (IAPProductsManager.defaultManager.allAccessPack6months_lite.isSubscribed == YES || IAPProductsManager.defaultManager.allAccessPack12months_lite.isSubscribed == YES);
  726. #endif
  727. #endif
  728. // 单平台高级版永久 未登录时 也不显示升级(因为点了也得先登录),但是登录后的卡片里是有升级按钮的,可以升级成全平台高级版年订阅
  729. //原来是订阅的,不需要升级,因为目前不支持订阅升级订阅这种场景
  730. if(type == KMUserScenarioTypeLite_type9 ||
  731. type == KMUserScenarioTypeLite_type10 ||
  732. type == KMUserScenarioTypeLite_type11) {
  733. if([KMMemberInfo shared].isLogin == NO) { //未登录
  734. self.button.hidden = YES;
  735. self.bgImg.hidden = YES;
  736. } else {
  737. if(isOldSubscribed) { //老版本付费功能是订阅包
  738. self.button.hidden = YES;
  739. self.bgImg.hidden = YES;
  740. } else {
  741. if((KMMemberInfo.shared.vip_status == 1) && [KMMemberInfo.shared.vip_paymentModel isEqualToString:@"1"]) { //会员订阅中
  742. self.button.hidden = YES;
  743. self.bgImg.hidden = YES;
  744. }
  745. }
  746. }
  747. }
  748. #if VERSION_FREE
  749. #if !VERSION_DMG
  750. if (buttonHiddenFlag) {
  751. self.bgImg.hidden = YES;
  752. self.button.hidden = YES;
  753. }
  754. #endif
  755. #endif
  756. buttonWidth = CGRectGetWidth(self.button.frame);
  757. NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  758. // if (fabs(buttonWidth-btnRect.size.width)>50) {
  759. buttonWidth = btnRect.size.width + 10;
  760. // buttonWidth += 10;
  761. // }
  762. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  763. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  764. buttonWidth += 10;
  765. buttonWidth = MIN(buttonWidth, self.remoteButtonMaxWidth);
  766. }
  767. }
  768. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  769. CGRect rect = self.button.frame;
  770. self.bgImg.frame = rect;
  771. totalWidth+=CGRectGetWidth(self.button.bounds);
  772. totalWidth+=4;
  773. } else if (type == KMUserScenarioTypeLite_type12 ||
  774. type == KMUserScenarioTypeLite_type13 ||
  775. type == KMUserScenarioTypeLite_type2 ||
  776. type == KMUserScenarioTypeLite_type4 ||
  777. type == KMUserScenarioTypeLite_type6 ||
  778. type == KMUserScenarioTypeLite_type8 ||
  779. type == KMUserScenarioTypePro_type2 ||
  780. type == KMUserScenarioTypePro_type5) {
  781. self.button.hidden = YES;
  782. self.bgImg.hidden = YES;
  783. #if !VERSION_FREE
  784. BOOL isNoSupportMemberUpgrade = YES;
  785. if ([KMMemberInfo shared].vip_status == 1) { //订阅+永久
  786. isNoSupportMemberUpgrade = NO;
  787. }
  788. if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice && isNoSupportMemberUpgrade) {
  789. [self.officeButton setTitleColor:[NSColor whiteColor]];
  790. self.officeButton.hidden = NO;
  791. self.officeImg.hidden = NO;
  792. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  793. CGRect officeRect = self.officeButton.frame;
  794. self.officeImg.frame = officeRect;
  795. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  796. totalWidth+=4;
  797. } else {
  798. self.officeButton.hidden = YES;
  799. self.officeImg.hidden = YES;
  800. }
  801. #else
  802. self.officeButton.hidden = YES;
  803. self.officeImg.hidden = YES;
  804. #endif
  805. }
  806. #endif
  807. #if VERSION_BETA
  808. self.officeButton.hidden = YES;
  809. self.officeImg.hidden = YES;
  810. self.button.hidden = YES;
  811. self.bgImg.hidden = YES;
  812. self.aiContendView.hidden = YES;
  813. self.userGiftView.hidden = YES;
  814. self.signUpView.wantsLayer = YES;
  815. self.signUpView.layer.cornerRadius = 4;
  816. self.signUpView.layer.masksToBounds = YES;
  817. self.signUpView.layer.borderWidth = 1;
  818. self.signUpView.layer.borderColor = [ComponentLibrary.shared getComponentColorFromKey:@"comp-button/default-colorBorder-nor"].CGColor;
  819. self.signUpView.layer.backgroundColor = [ComponentLibrary.shared getComponentColorFromKey:@"comp-button/default-colorFill-nor"].CGColor;
  820. self.signUpLabel.textColor = [ComponentLibrary.shared getComponentColorFromKey:@"comp-button/default-colorText-nor"];
  821. self.signUpBGImage.hidden = YES;
  822. self.signUpImg.hidden = true;
  823. totalWidth = 10;
  824. totalWidth += self.betaFeedBackLabel.fittingSize.width;
  825. totalWidth += 44;
  826. if ([KMMemberInfo shared].isLogin) {
  827. self.betaFeedBackRightConst.constant = userImageWidth + 8;
  828. } else {
  829. self.betaFeedBackRightConst.constant = signUpWidth + 8;
  830. }
  831. if([KMNBetaFeedbackManager defalutManager].isHaveFeedback) {
  832. [self.betaFeedBackBox setHidden:YES];
  833. self.feedbackBox.hidden = NO;
  834. } else {
  835. [self.betaFeedBackBox setHidden:NO];
  836. self.feedbackBox.hidden = YES;
  837. }
  838. self.feedbackLabel.stringValue = KMLocalizedString(@"Feedback", nil);
  839. self.feedbackLabel.textColor = NSColor.whiteColor;
  840. #endif
  841. if ([KMMemberInfo shared].isLogin) {
  842. self.userButton.hidden = NO;
  843. self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  844. totalWidth += userImageWidth;
  845. totalWidth += 8;
  846. } else {
  847. self.signUpView.hidden = NO;
  848. self.signUpView.frame = CGRectMake(totalWidth, 4, signUpWidth, 24);
  849. totalWidth+=CGRectGetWidth(self.signUpView.bounds);
  850. }
  851. 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);
  852. if (self.frameUpdateHandle) {
  853. self.frameUpdateHandle(self.view.frame);
  854. }
  855. }
  856. #pragma mark - Button Actions
  857. - (IBAction)betaFeedbackAction:(NSButton *)sender {
  858. if ([KMMemberInfo shared].isLogin) {
  859. #if VERSION_BETA
  860. KMNBetaFeedbackWindowController *feedbackWindowController = [KMNBetaFeedbackWindowController shared] ;
  861. [feedbackWindowController showWindow:nil];
  862. __block __typeof(self) blockSelf = self;
  863. feedbackWindowController.submitActionCallback = ^(BOOL) {
  864. KMNBetaFeedbackSuccessWindowController *successWindowController = [[KMNBetaFeedbackSuccessWindowController alloc] initWithWindowNibName:@"KMNBetaFeedbackSuccessWindowController"];
  865. [successWindowController own_beginSheetModalFor:blockSelf.view.window completionHandler:^(NSString * _Nullable) {
  866. }];
  867. };
  868. #endif
  869. } else {
  870. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  871. if (success) {
  872. }
  873. }];
  874. }
  875. }
  876. - (IBAction)feedbackClicked:(NSButton *)sender {
  877. if ([KMMemberInfo shared].isLogin) {
  878. #if VERSION_BETA
  879. KMUserFeekbackWindowController.shared.typeString = KMLocalizedString(@"Feedback", nil);
  880. [KMUserFeekbackWindowController.shared showWindow:nil];
  881. #endif
  882. } else {
  883. }
  884. }
  885. - (IBAction)secondTrialAction:(NSButton *)sender {
  886. if ([VerificationManager manager].secondTrialEnabled) {
  887. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialGuide];
  888. [vc showWindow:nil];
  889. } else {
  890. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeNone];
  891. }
  892. }
  893. - (IBAction)buttonAction:(id)sender {
  894. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  895. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  896. #if VERSION_FREE
  897. #if VERSION_DMG
  898. #else
  899. #endif
  900. #endif
  901. if ([KMMemberInfo shared].isLogin) {
  902. if ([[KMMemberInfo shared].vip_levels isEqualToString:@"1"]) {
  903. [[KMProductCompareWC shared] setOrientation:YES];
  904. #if VERSION_FREE
  905. #if VERSION_DMG
  906. // DMG
  907. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  908. #else
  909. // AppStore 免费版本
  910. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  911. #endif
  912. #else
  913. // AppStore 付费版
  914. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  915. #endif
  916. [[KMProductCompareWC shared] showWindow:nil];
  917. } else {
  918. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeNone];
  919. }
  920. } else {
  921. if ([self _isNowGotoPurcahseTable]) {
  922. KMProductCompareWC *winC = [KMProductCompareWC shared];
  923. // 定向跳转
  924. winC.orientation = true;
  925. // App Store 免费版 基础比较表
  926. winC.orientationType = KMCompareTableTypeLite_Base;
  927. [winC showWindow:nil];
  928. } else {
  929. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  930. if (success) {
  931. if ([[KMMemberInfo shared].vip_levels isEqualToString:@"1"]) {
  932. [[KMProductCompareWC shared] setOrientation:YES];
  933. #if VERSION_FREE
  934. #if VERSION_DMG
  935. // DMG
  936. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  937. #else
  938. // AppStore 免费版本
  939. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  940. #endif
  941. #else
  942. // AppStore 付费版
  943. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  944. #endif
  945. [[KMProductCompareWC shared] showWindow:nil];
  946. } else {
  947. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeNone];
  948. }
  949. }
  950. }];
  951. }
  952. }
  953. } else {
  954. [self _trackButtonEvent];
  955. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  956. if (type == KMUserScenarioTypeDmg_type4) {
  957. if ([KMMemberInfo shared].isLogin) {
  958. [[KMProductCompareWC shared] setOrientation:YES];
  959. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  960. // [[KMProductCompareWC shared] showWindow:nil];
  961. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeFreeTrail];
  962. } else {
  963. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  964. if (success) {
  965. [[KMProductCompareWC shared] setOrientation:YES];
  966. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  967. // [[KMProductCompareWC shared] showWindow:nil];
  968. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeFreeTrail];
  969. }
  970. }];
  971. }
  972. } else {
  973. if ([self _isNowGotoPurcahseTable] &&
  974. ![KMMemberInfo shared].isLogin) { //本机(Apple ID)无权益,且未未登录时,直接跳购买
  975. [self _doNowGotoPurcahseTable];
  976. } else {
  977. if ([[KMMemberInfo shared] isLogin] && self.button.tag == KMMessageTypeFreeTrail) { // 免费试用
  978. [[KMProductCompareWC shared] setOrientation:YES];
  979. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  980. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeFreeTrail];
  981. } else {
  982. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeInvalid];
  983. }
  984. }
  985. }
  986. }
  987. } else {
  988. [self _trackButtonEvent];
  989. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  990. if (type == KMUserScenarioTypeDmg_type4) {
  991. if ([KMMemberInfo shared].isLogin) {
  992. [[KMProductCompareWC shared] setOrientation:YES];
  993. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  994. // [[KMProductCompareWC shared] showWindow:nil];
  995. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeFreeTrail];
  996. } else {
  997. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  998. if (success) {
  999. [[KMProductCompareWC shared] setOrientation:YES];
  1000. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  1001. // [[KMProductCompareWC shared] showWindow:nil];
  1002. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeFreeTrail];
  1003. }
  1004. }];
  1005. }
  1006. } else {
  1007. if ([self _isNowGotoPurcahseTable] && ![KMMemberInfo shared].isLogin) { //本机(Apple ID)无权益,且未未登录时,直接跳购买
  1008. [self _doNowGotoPurcahseTable];
  1009. } else {
  1010. if ([[KMMemberInfo shared] isLogin] && self.button.tag == KMMessageTypeFreeTrail) { // 免费试用
  1011. [[KMProductCompareWC shared] setOrientation:YES];
  1012. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  1013. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeFreeTrail];
  1014. } else {
  1015. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeInvalid];
  1016. }
  1017. }
  1018. }
  1019. }
  1020. }
  1021. - (void)_doNowGotoPurcahseTable {
  1022. KMProductCompareWC *winC = [KMProductCompareWC shared];
  1023. // 定向跳转
  1024. winC.orientation = true;
  1025. // App Store 免费版 基础比较表
  1026. winC.orientationType = KMCompareTableTypeLite_Base;
  1027. if ([[KMMemberInfo shared] isLogin] && self.button.tag == KMMessageTypeFreeTrail) { // 免费试用
  1028. [winC openWindowWithDiscountType:KMDiscountTypeFreeTrail];
  1029. } else if (self.userGiftView.isHidden == false) { // 新手礼
  1030. KMMessageModel *model = nil;
  1031. for (KMMessageModel *m in self.datas) {
  1032. if (m.type == KMMessageTypeNewUserGift) {
  1033. model = m;
  1034. break;
  1035. }
  1036. }
  1037. if (model != nil) { // 检查数据
  1038. if ([[KMNewUserGiftManager default] needShow]) { // 检查条件
  1039. [winC openWindowWithDiscountType:KMDiscountTypeNewUserGift];
  1040. } else {
  1041. [winC showWindow:nil];
  1042. }
  1043. } else {
  1044. [winC showWindow:nil];
  1045. }
  1046. } else if (self.discountItemView.isHidden == false) { // 优惠卷 (新手礼 & 试用退订)
  1047. KMMessageModel *model = nil;
  1048. for (KMMessageModel *m in self.datas) {
  1049. if (m.type == KMMessageTypeDiscount) {
  1050. model = m;
  1051. }
  1052. }
  1053. if (model != nil) { // 检查数据
  1054. if ([[KMCheckInManager default] trailCancel] || [[KMCheckInManager default] advancedYearSubscribeTrailCancelForLocal]) { // 检查条件
  1055. [winC openWindowWithDiscountType:KMDiscountTypeAdvancedYearSubscribeTrialingCancel];
  1056. } else if ([[KMNewUserGiftManager default] needShow]) { // 检查条件
  1057. [winC openWindowWithDiscountType:KMDiscountTypeNewUserGift];
  1058. } else {
  1059. [winC showWindow:nil];
  1060. }
  1061. } else {
  1062. [winC showWindow:nil];
  1063. }
  1064. } else {
  1065. [winC showWindow:nil];
  1066. }
  1067. }
  1068. - (IBAction)officeButtonAction:(id)sender {
  1069. #if VERSION_FREE
  1070. #if VERSION_DMG
  1071. DMGEmbeddedOldWC *embeddedWC = [DMGEmbeddedOldWC currentFirstTrialWC:@"com.brother.pdfreaderpro.mac.product_2"];
  1072. [embeddedWC showWindow:nil];
  1073. [embeddedWC.window center];
  1074. #endif
  1075. #else
  1076. if ([KMMemberInfo shared].isLogin) {
  1077. [[KMMemberInfo shared] productCompareShow];
  1078. } else {
  1079. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  1080. if (success) {
  1081. [[KMMemberInfo shared] productCompareShow];
  1082. }
  1083. }];
  1084. }
  1085. #endif
  1086. }
  1087. - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
  1088. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
  1089. NSString *temp = nil;
  1090. for (NSUInteger i = 0; i <string.length; i++) {
  1091. temp = [string substringWithRange:NSMakeRange(i, 1)];
  1092. if ([self isPureInt:temp]) {
  1093. [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  1094. color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
  1095. }
  1096. }
  1097. return attributedString;
  1098. }
  1099. - (BOOL)isPureInt:(NSString *)string {
  1100. NSScanner *scan = [NSScanner scannerWithString:string];
  1101. int value;
  1102. return [scan scanInt:&value] && [scan isAtEnd];
  1103. }
  1104. - (IBAction)AIButtonAction:(NSButton *)sender {
  1105. if ([[[KMMemberInfo shared] validFlag] isEqualToString:@"5"]) {
  1106. [[KMMemberPromptWC shared] showWindow:sender];
  1107. [KMMemberPromptWC shared].tipType = KMMemberTipTypeSignouting;
  1108. } else {
  1109. #if VERSION_FREE
  1110. #if VERSION_DMG
  1111. KMPurchaseEmbeddedWindowController *winC = [KMPurchaseEmbeddedWindowController currentCode:KMAISubscriptionYearTrailCodeKey_DMG];
  1112. [winC showWindow:nil];
  1113. [winC.window center];
  1114. #else
  1115. [[KMFreeGetAIWC shared] showWindow:nil];
  1116. #endif
  1117. #else
  1118. [[KMFreeGetAIWC shared] showWindow:nil];
  1119. #endif
  1120. }
  1121. }
  1122. - (IBAction)userButtonAction:(NSButton *)sender {
  1123. if ([KMMemberInfo shared].isLogin) {
  1124. [self personalCenterAction:sender];
  1125. } else {
  1126. [KMLoginWindowsController.shared showWindow:nil];
  1127. }
  1128. }
  1129. - (BOOL)isConnectionAvailable {
  1130. BOOL isExistenceNetwork = YES;
  1131. Reachability *reach = [Reachability reachabilityWithHostname:@"www.apple.com"];
  1132. switch ([reach currentReachabilityStatus]) {
  1133. case NotReachable:
  1134. isExistenceNetwork = NO;
  1135. //NSLog(@"notReachable");
  1136. break;
  1137. case ReachableViaWiFi:
  1138. isExistenceNetwork = YES;
  1139. //NSLog(@"WIFI");
  1140. break;
  1141. case ReachableViaWWAN:
  1142. isExistenceNetwork = YES;
  1143. //NSLog(@"3G");
  1144. break;
  1145. }
  1146. if (NotReachable == [[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
  1147. return NO;
  1148. }
  1149. return YES;
  1150. }
  1151. - (IBAction)personalCenterAction:(NSButton *)sender {
  1152. if (![self isConnectionAvailable]) {
  1153. NSAlert *alert = [NSAlert alertWithMessageText:KMLocalizedString(@"Connection Error", nil)
  1154. defaultButton:KMLocalizedString(@"OK", nil)
  1155. alternateButton:nil
  1156. otherButton:nil
  1157. informativeTextWithFormat:KMLocalizedString(@"Please make sure your internet connection is available.", nil), nil];
  1158. [alert runModal];
  1159. return;
  1160. }
  1161. // 用户头像点击事件
  1162. self.userMenu = [[NSMenu alloc] init];
  1163. // KMUserInfoViewController *userInfo = [[KMUserInfoViewController alloc] init];
  1164. KMBetaUserInfoController *userInfo = [[KMBetaUserInfoController alloc] init];
  1165. NSMenuItem *item = [self.userMenu addItemWithTitle:@"" action:nil target:@""];
  1166. item.target = self;
  1167. item.representedObject = userInfo;
  1168. item.view = userInfo.view;
  1169. [self.userMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(-130, 30) inView:sender];
  1170. }
  1171. - (IBAction)signUpAction:(NSButton *)sender {
  1172. #if VERSION_FREE
  1173. #if VERSION_DMG
  1174. #else
  1175. #endif
  1176. #endif
  1177. [KMLoginWindowsController.shared showWindow:nil];
  1178. }
  1179. - (void)userGiftAction:(id)sender {
  1180. [[KMNewUserGiftWindowController shared] openWindow];
  1181. }
  1182. - (void)discountAction:(id)sender {
  1183. #if VERSION_FREE
  1184. if ([[KMCheckInManager default] trailCancel] || [[KMCheckInManager default] advancedYearSubscribeTrailCancelForLocal]) {
  1185. [[KMProductCompareWC shared] setOrientation:true];
  1186. #if VERSION_DMG
  1187. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  1188. #else
  1189. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  1190. #endif
  1191. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeAdvancedYearSubscribeTrialingCancel];
  1192. } else {
  1193. [[KMProductCompareWC shared] setOrientation:true];
  1194. #if VERSION_DMG
  1195. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  1196. #else
  1197. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  1198. #endif
  1199. [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeNewUserGift];
  1200. }
  1201. #endif
  1202. }
  1203. #pragma mark - NSNotification Methods
  1204. - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
  1205. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1206. [self reloadData];
  1207. });
  1208. }
  1209. - (void)IAPProductLoaded:(NSNotification *)notification {
  1210. dispatch_async(dispatch_get_main_queue(), ^{
  1211. [self reloadData];
  1212. });
  1213. }
  1214. - (void)IAPResultReceived:(NSNotification *)notification {
  1215. dispatch_async(dispatch_get_main_queue(), ^{
  1216. [self reloadData];
  1217. });
  1218. }
  1219. - (void)IAPPurchaseSuccess:(NSNotification *)notification {
  1220. dispatch_async(dispatch_get_main_queue(), ^{
  1221. [self reloadData];
  1222. #if VERSION_FREE
  1223. #if VERSION_DMG
  1224. #else
  1225. [[KMProductCompareWC shared] closeAction];
  1226. #endif
  1227. #endif
  1228. });
  1229. }
  1230. - (void)IAPRestoreFinish:(NSNotification *)notification {
  1231. dispatch_async(dispatch_get_main_queue(), ^{
  1232. [self reloadData];
  1233. });
  1234. }
  1235. - (void)trailCancelStateDidChange:(NSNotification *)noti {
  1236. dispatch_async(dispatch_get_main_queue(), ^{
  1237. [self reloadData];
  1238. });
  1239. }
  1240. - (void)advertisementDidLoaded:(NSNotification *)noti {
  1241. dispatch_async(dispatch_get_main_queue(), ^{
  1242. [self reloadData];
  1243. });
  1244. }
  1245. - (void)languageChangedNotification:(NSNotification*)notification {
  1246. [self reloadData];
  1247. }
  1248. - (void)uiThemeChangedNotification:(NSNotification*)notification {
  1249. [self reloadData];
  1250. }
  1251. #pragma mark - Event
  1252. - (void)mouseEntered:(NSEvent *)event {
  1253. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  1254. ActivityStatusTrial == [VerificationManager manager].status) {
  1255. [[self class] cancelPreviousPerformRequestsWithTarget:self];
  1256. if (!self.popover.isShown) {
  1257. [self buttonAction:self.button];
  1258. }
  1259. }
  1260. }
  1261. - (void)mouseExited:(NSEvent *)event {
  1262. [super mouseExited:event];
  1263. [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
  1264. }
  1265. - (void)popoverDidClose:(NSNotification *)notification {
  1266. self.stopPopOverHide = NO;
  1267. }
  1268. - (void)popoverShowNoti:(NSNotification *)noti {
  1269. if (self.popover) {
  1270. [self.popover close];
  1271. self.stopPopOverHide = NO;
  1272. }
  1273. }
  1274. - (void)loginSuccessNotification:(NSNotification *)noti {
  1275. dispatch_async(dispatch_get_main_queue(), ^{
  1276. self.userButton.image = [NSImage imageNamed:@"member_avatar"];
  1277. [self reloadData];
  1278. });
  1279. }
  1280. - (void)logoutSuccessNotification:(NSNotification *)noti {
  1281. dispatch_async(dispatch_get_main_queue(), ^{
  1282. self.userButton.image = [NSImage imageNamed:@"member_avatar"];
  1283. [self reloadData];
  1284. #if VERSION_BETA
  1285. if(!KMMemberInfo.shared.isLogin) {
  1286. [[KMNBetaFeedbackManager defalutManager] resetHaveFeedback];
  1287. }
  1288. #endif
  1289. });
  1290. }
  1291. - (void)betaUpdateNotification:(NSNotification *)noti {
  1292. #if VERSION_BETA
  1293. [self reloadData];
  1294. #endif
  1295. }
  1296. - (void)expandPersonalCenterNotification:(NSNotification *)noti {
  1297. if (self.userMenu != nil) {
  1298. [self personalCenterAction:_userButton];
  1299. }
  1300. }
  1301. - (void)closeMenu:(NSNotification *)noti {
  1302. if (self.userMenu != nil) {
  1303. [self.userMenu cancelTracking];
  1304. self.userMenu = nil;
  1305. }
  1306. }
  1307. - (void)subscriptionLoadedNotification:(NSNotification *)noti {
  1308. dispatch_async(dispatch_get_main_queue(), ^{
  1309. [self reloadData];
  1310. });
  1311. }
  1312. - (void)memberInfoChangeNotification:(NSNotification *)noti {
  1313. dispatch_async(dispatch_get_main_queue(), ^{
  1314. [self reloadData];
  1315. });
  1316. }
  1317. - (void)popOverCloseAction {
  1318. if (self.stopPopOverHide == NO) {
  1319. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  1320. ActivityStatusTrial == [VerificationManager manager].status) {
  1321. if (self.popover.isShown) {
  1322. [self.popover close];
  1323. self.stopPopOverHide = NO;
  1324. }
  1325. }
  1326. }
  1327. }
  1328. @end