KMVerificationMessageViewController.m 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  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. // PDF Reader Pro Lite
  315. // 未登录 - 无订阅 - 无AI
  316. // 未登录 - 有订阅高级版+有AI序列码
  317. // 已登录(未试用过的免费用户+未订阅AI) - 无订阅+无AI旧剩余点数
  318. // 已登录(试用到期且未付费用户+未订阅AI) - 无旧订阅+有AI旧剩余点数
  319. // 已登录(新的买断会员+有订阅AI) - 无旧订阅+无AI旧剩余点数
  320. // 已登录(自动订阅中 + 订阅AI) - 无旧订阅+有AI旧剩余点数
  321. // 已登录(订阅中但取消续订用户) - 无旧订阅+无AI旧剩余点数
  322. // 已登录(订阅过期用户) - 无旧订阅+无AI旧剩余点数
  323. // 已登录(试用过期用户) - 无旧订阅+无AI旧剩余点数
  324. // PDF Reader Pro
  325. // 未登录 - 标准版+无AI
  326. // 未登录 - 高级版(有购买转档包)+有AI序列码
  327. // 已登录(未试用过的免费用户+未订阅AI) - 标准版+无AI旧剩余点数
  328. // 已登录(新的买断会员+有订阅AI) - 高级版(有升级转档包)+无AI旧剩余点数
  329. // 已登录(全平台高级版年订阅自动订阅中 + 订阅AI) - 无旧订阅+有AI旧剩余点数
  330. // 已登录(全平台标准版年订阅订阅中但取消续订用户) - 标准版+无AI旧剩余点数
  331. // 已登录(订阅过期用户) - 高级版+无AI旧剩余点数
  332. // PDF Reader Pro DMG
  333. // 未登录 - 无激活+无AI序列码
  334. // 未登录 - 有激活标准版+有AI序列码
  335. // 未登录 - 有激活高级版+无AI序列码
  336. // 已登录(未试用过的免费用户+未订阅AI) - 无激活+无AI序列码
  337. // 已登录(新的买断会员+有订阅AI) - 无激活+无AI序列码
  338. // 已登录(自动订阅中 + 订阅AI) - 无激活+有AI序列码
  339. // 已登录(订阅中但取消续订用户) - 无激活+无AI
  340. // 已登录(订阅过期用户) - 无激活+无AI
  341. totalWidth = 8;
  342. self.button.hidden = YES;
  343. self.label.hidden = YES;
  344. self.secondTrialBtn.hidden = YES;
  345. self.labelContentView.hidden = YES;
  346. self.bgImg.hidden = YES;
  347. self.aiContendView.hidden = YES;
  348. self.userButton.hidden = YES;
  349. self.signUpView.hidden = YES;
  350. self.signUpLabel.stringValue = NSLocalizedStringFromTable(@"Sign Up", @"MemberCenterLocalizable", nil);
  351. [self.signUpLabel sizeToFit];
  352. CGFloat signUpWidth = self.signUpLabel.frame.size.width;
  353. signUpWidth += 4;
  354. signUpWidth += 8;
  355. signUpWidth += 8;
  356. signUpWidth += 12;
  357. self.signUpImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-6, 12, 12);
  358. CGRect signUplabelRect = self.signUpLabel.frame;
  359. signUplabelRect.origin.x = CGRectGetMaxX(self.signUpImg.frame) + 4;
  360. self.signUpLabel.frame = signUplabelRect;
  361. self.button.layer.backgroundColor = [NSColor clearColor].CGColor;
  362. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade to Pro", nil)];
  363. [self.button setTitleColor:[NSColor whiteColor]];
  364. self.aiLabel.stringValue = NSLocalizedString(@"My AI Credit", nil);
  365. [self.aiLabel sizeToFit];
  366. CGFloat aiWidth = self.aiLabel.frame.size.width;
  367. aiWidth += 4;
  368. aiWidth += 16;
  369. aiWidth += 16;
  370. self.aiIconImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-8, 16, 16);
  371. self.aiContendView.frame = CGRectMake(totalWidth, 0, aiWidth, self.view.frame.size.height);
  372. CGRect ailabelRect = self.aiLabel.frame;
  373. ailabelRect.origin.x = CGRectGetMaxX(self.aiIconImg.frame) + 4;
  374. self.aiLabel.frame = ailabelRect;
  375. // totalWidth+=aiWidth;
  376. // totalWidth+=4;
  377. CGFloat userImageWidth = 24;
  378. // self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  379. totalWidth += userImageWidth;
  380. totalWidth += 8;
  381. if ([KMMemberInfo shared].isLogin) {
  382. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  383. } else {
  384. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  385. }
  386. CGFloat buttonWidth = CGRectGetMaxX(self.button.frame);
  387. NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  388. if (fabs(buttonWidth-btnRect.size.width)>50) {
  389. buttonWidth = btnRect.size.width + 10;
  390. }
  391. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1 ||
  392. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  393. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type4 ||
  394. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  395. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  396. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8 ||
  397. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  398. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11 ||
  399. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13) {
  400. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1 ||
  401. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9) {
  402. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  403. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  404. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11) {
  405. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"开通会员", nil)];
  406. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type4 ||
  407. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5) {
  408. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"立即升级", nil)];
  409. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  410. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8 ||
  411. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13) {
  412. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"立即续费", nil)];
  413. }
  414. self.bgImg.hidden = NO;
  415. self.button.hidden = NO;
  416. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  417. self.bgImg.frame = rect;
  418. totalWidth+=CGRectGetWidth(self.button.bounds);
  419. totalWidth+=4;
  420. }
  421. if ([KMMemberInfo shared].isLogin) {
  422. self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  423. totalWidth += userImageWidth;
  424. totalWidth += 8;
  425. } else {
  426. self.signUpView.hidden = NO;
  427. self.signUpView.frame = CGRectMake(totalWidth, 0, signUpWidth, self.view.frame.size.height);
  428. totalWidth+=CGRectGetWidth(self.signUpView.bounds);
  429. }
  430. // if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1 || [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type2) {
  431. // self.bgImg.hidden = NO;
  432. // self.button.hidden = NO;
  433. // self.signUpView.hidden = NO;
  434. // self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  435. // CGRect rect = self.button.frame;
  436. // self.bgImg.frame = rect;
  437. // totalWidth+=CGRectGetWidth(self.button.bounds);
  438. // totalWidth+=4;
  439. // self.signUpView.frame = CGRectMake(totalWidth, 0, signUpWidth, self.view.frame.size.height);
  440. // totalWidth+=CGRectGetWidth(self.signUpView.bounds);
  441. // } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 || [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type4) {
  442. // self.signUpView.hidden = NO;
  443. // self.signUpView.frame = CGRectMake(totalWidth, 0, signUpWidth, self.view.frame.size.height);
  444. // totalWidth+=CGRectGetWidth(self.signUpView.bounds);
  445. // } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  446. // [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type6 ||
  447. // [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  448. // [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type10 ||
  449. // [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11) {
  450. // if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5) {
  451. // self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  452. // } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type6 ||
  453. // [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type10 ||
  454. // [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11) {
  455. // self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"立即续费", @"MemberCenterLocalizable", nil)];
  456. // } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7) {
  457. // self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"立即升级", @"MemberCenterLocalizable", nil)];
  458. // }
  459. // [self.button setTitleColor:[NSColor whiteColor]];
  460. // self.bgImg.hidden = NO;
  461. // self.button.hidden = NO;
  462. // self.userButton.hidden = NO;
  463. // self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  464. // CGRect rect = self.button.frame;
  465. // self.bgImg.frame = rect;
  466. // totalWidth+=CGRectGetWidth(self.button.bounds);
  467. // totalWidth+=8;
  468. //
  469. // self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  470. // totalWidth += userImageWidth;
  471. // totalWidth += 8;
  472. // } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8 ||
  473. // [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9) {
  474. // self.userButton.hidden = NO;
  475. // self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  476. // totalWidth += userImageWidth;
  477. // totalWidth += 8;
  478. // } else {
  479. // self.userButton.hidden = NO;
  480. // self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  481. // totalWidth += userImageWidth;
  482. // totalWidth += 8;
  483. // }
  484. if (self.view.superview) {
  485. 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);
  486. } else {
  487. if (self.button.hidden) {
  488. self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.aiLabel.frame) + 20 ,self.view.frame.size.height);
  489. } else {
  490. self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.button.frame) ,self.view.frame.size.height);
  491. }
  492. }
  493. }
  494. #pragma mark - Button Actions
  495. - (IBAction)secondTrialAction:(NSButton *)sender {
  496. if ([VerificationManager manager].secondTrialEnabled) {
  497. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialGuide];
  498. [vc showWindow:nil];
  499. } else {
  500. [[KMProductCompareWC shared] setOrientation:NO];
  501. [[KMProductCompareWC shared] showWindow:nil];
  502. }
  503. }
  504. - (IBAction)buttonAction:(id)sender {
  505. // BOOL isFree = NO;
  506. //
  507. //#if VERSION_DMG
  508. // if (ActivityStatusNone == [VerificationManager manager].status) {
  509. // //弹出 试用弹窗UI优化-新用户试用路径 新UI 情况一 右上角按钮
  510. // KMPurchaseFirstTrialWindowController *firstTrialWC = [KMPurchaseFirstTrialWindowController currentFirstTrialWC];
  511. // firstTrialWC.buttonActionBlock = ^(KMPurchaseFirstTrialWindowController * _Nonnull ftWC, KMButton * _Nonnull btn, NSString * _Nonnull email, NSString * _Nonnull name) {
  512. // if (btn.tag == 10001) {
  513. // if (ActivityStatusNone == [VerificationManager manager].status ||
  514. // ActivityStatusTrialExpire == [VerificationManager manager].status) {
  515. //
  516. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_SecondTrial"}];
  517. // [[VerificationManager manager] trialForDays:7
  518. // email:email?:[VerificationManager manager].email
  519. // name:name?:[VerificationManager manager].accountName
  520. // complention:^(ActivityStatus status, NSDictionary *info, NSError *error) {
  521. // if (error ||
  522. // status != ActivityStatusTrial) {
  523. // NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
  524. // defaultButton:NSLocalizedString(@"Try Again", nil)
  525. // alternateButton:nil
  526. // otherButton:nil
  527. // informativeTextWithFormat:NSLocalizedString(@"Failed to sign up for the free trial. Please make sure your internet connection is available and try again later.", nil), nil];
  528. // [alert runModal];
  529. // } else {
  530. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialSuccess];
  531. // [vc showWindow:nil];
  532. // }
  533. // }];
  534. // [ftWC close];
  535. // } else {
  536. // [ftWC close];
  537. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];
  538. // vc.callback = ^{
  539. // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  540. // };
  541. // [vc showWindow:nil];
  542. // }
  543. // } else if (btn.tag == 10002) {
  544. // NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@?utm_source=app_dmg&utm_medium=dmg_puw_free_trial", Swift_oc_Tool.Store_Link_OC]];
  545. // [[NSWorkspace sharedWorkspace] openURL:url];
  546. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_UpgradeBuyNow"}];
  547. // } else if (btn.tag == 10003) {
  548. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];//KMVerificationTypeActivate
  549. // [vc showWindow:nil];
  550. // [ftWC close];
  551. // }
  552. // };
  553. // [firstTrialWC.window center];
  554. // [firstTrialWC showWindow:nil];
  555. // } else if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  556. // ActivityStatusTrial == [VerificationManager manager].status) {
  557. // [[NSNotificationCenter defaultCenter] postNotificationName:@"KMVerificationMessagePopShowNoti" object:nil];
  558. //
  559. // if (!self.testVC) {
  560. // self.testVC = [[KMUnlockAlertViewController alloc] init];
  561. // }
  562. // [self.testVC addtrackingAreaInfo];
  563. // self.testVC.callback = ^(NSInteger index) {
  564. // if (index == 1) {
  565. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];
  566. // [vc showWindow:nil];
  567. // } else if (index == 2) {
  568. // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.mac.product_3"];
  569. // [embeddedWC showWindow:nil];
  570. // [[embeddedWC window] center];
  571. // }
  572. // };
  573. // self.testVC.mouseEventCall = ^(BOOL mouseEnter) {
  574. // if (mouseEnter) {
  575. // self.stopPopOverHide = YES;
  576. // if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  577. // ActivityStatusTrial == [VerificationManager manager].status) {
  578. // if (!self.popover.isShown) {
  579. // [self buttonAction:self.button];
  580. // }
  581. // }
  582. // } else {
  583. // self.stopPopOverHide = NO;
  584. // if (self.popover) {
  585. // [self.popover close];
  586. // }
  587. // [self.testVC removeTrackingAreaInfo];
  588. // }
  589. // };
  590. // NSPopover *popover = [[NSPopover alloc] init];
  591. // popover.delegate = self;
  592. // popover.contentViewController = self.testVC;
  593. // popover.animates = YES;
  594. // popover.behavior = NSPopoverBehaviorTransient;
  595. // [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
  596. // self.popover = popover;
  597. // } else if (ActivityStatusVerifExpire == [VerificationManager manager].status) {
  598. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateExpired];
  599. // [vc showWindow:nil];
  600. // } else if (ActivityStatusVerification == [VerificationManager manager].status) {
  601. // if ([VerificationManager manager].needUpgradeLicense) {
  602. // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.mac.product_2"];
  603. // [embeddedWC showWindow:nil];
  604. // [[embeddedWC window] center];
  605. // }
  606. // } else {
  607. // if ([VerificationManager manager].needUpgradeLicense) {
  608. // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.mac.product_2"];
  609. // [embeddedWC showWindow:nil];
  610. // [[embeddedWC window] center];
  611. // } else {
  612. // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeNormal];
  613. // [vc showWindow:nil];
  614. // }
  615. // }
  616. //#else
  617. // isFree = YES;
  618. //#if VERSION_FREE
  619. // if ([IAPProductsManager defaultManager].isAvailableAllFunction) {
  620. // isFree = NO;
  621. // }
  622. // if (isFree) {
  623. // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  624. // }
  625. //#else
  626. // if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice) {
  627. // KMToolCompareWindowController *vc = [KMToolCompareWindowController toolCompareWithToolType:KMCompareWithToolTypeConvert selectNum:0];
  628. // [vc.window center];
  629. // [vc showWindow:nil];
  630. // }
  631. //#endif
  632. //
  633. //#endif
  634. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1 ||
  635. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type2 ||
  636. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  637. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type4) {
  638. if ([KMMemberInfo shared].isLogin) {
  639. [[KMProductCompareWC shared] setOrientation:YES];
  640. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  641. [[KMProductCompareWC shared] showWindow:nil];
  642. } else {
  643. [KMLoginWindowsController.shared openWindow:^(BOOL success) {
  644. if (success) {
  645. [[KMProductCompareWC shared] setOrientation:YES];
  646. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  647. [[KMProductCompareWC shared] showWindow:nil];
  648. }
  649. }];
  650. }
  651. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5) {
  652. [[KMProductCompareWC shared] setOrientation:NO];
  653. [[KMProductCompareWC shared] showWindow:nil];
  654. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type6 ||
  655. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type10 ||
  656. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11) {
  657. [[KMProductCompareWC shared] setOrientation:YES];
  658. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  659. [[KMProductCompareWC shared] showWindow:nil];
  660. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7) {
  661. [[KMProductCompareWC shared] setOrientation:YES];
  662. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_MacWindows];
  663. [[KMProductCompareWC shared] showWindow:nil];
  664. }
  665. }
  666. - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
  667. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
  668. NSString *temp = nil;
  669. for (NSUInteger i = 0; i <string.length; i++) {
  670. temp = [string substringWithRange:NSMakeRange(i, 1)];
  671. if ([self isPureInt:temp]) {
  672. [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  673. color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
  674. }
  675. }
  676. return attributedString;
  677. }
  678. - (BOOL)isPureInt:(NSString *)string {
  679. NSScanner *scan = [NSScanner scannerWithString:string];
  680. int value;
  681. return [scan scanInt:&value] && [scan isAtEnd];
  682. }
  683. - (IBAction)AIButtonAction:(NSButton *)sender {
  684. __block typeof(self) blockSelf = self;
  685. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit"}];
  686. [[AIInfoManager defaultManager] fetchAIInfoWithComplention:^(NSDictionary *info, NSError *error) {
  687. }];
  688. AIUserInfoController *controller = [[AIUserInfoController alloc] init];
  689. controller.purchaseHandle = ^(AIUserInfoController * _Nonnull vc) {
  690. #if VERSION_DMG
  691. KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.ai.product_1"];
  692. [embeddedWC showWindow:nil];
  693. [[embeddedWC window] center];
  694. #else
  695. [[AIPurchaseWindowController currentWC] showWindow:nil];
  696. #endif
  697. [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit_BuyNow"}];
  698. };
  699. controller.enterLicenseHandle = ^(AIUserInfoController * _Nonnull vc) {
  700. KMVerificationWindowController *verifyVC = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateAIInfo];
  701. verifyVC.callback = ^{
  702. };
  703. [verifyVC showWindow:nil];
  704. };
  705. controller.guideHandle = ^(AIUserInfoController * _Nonnull vc) {
  706. if (!blockSelf.guideWindowVC) {
  707. KMFunctionGuideWindowController *guideWindowVC = [[KMFunctionGuideWindowController alloc] initWithWindowNibName:@"KMFunctionGuideWindowController"];
  708. blockSelf.guideWindowVC = guideWindowVC;
  709. }
  710. ((KMFunctionGuideWindowController *)(blockSelf.guideWindowVC)).type = KMGuideInfoTypeFunctionMulti;
  711. [blockSelf.guideWindowVC showWindow:nil];
  712. [KMFunctionGuideWindowController setDidShowFor:KMGuideInfoTypeFunctionMultiAIGuide];
  713. [blockSelf.guideWindowVC.window orderFront:nil];
  714. };
  715. NSPopover *popover = [[NSPopover alloc] init];
  716. popover.contentViewController = controller;
  717. popover.animates = YES;
  718. popover.behavior = NSPopoverBehaviorTransient;
  719. [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
  720. }
  721. - (IBAction)userButtonAction:(NSButton *)sender {
  722. if ([KMMemberInfo shared].isLogin) {
  723. [self personalCenterAction:sender];
  724. } else {
  725. [KMLoginWindowsController.shared showWindow:nil];
  726. }
  727. }
  728. - (IBAction)personalCenterAction:(NSButton *)sender {
  729. // 用户头像点击事件
  730. self.userMenu = [[NSMenu alloc] init];
  731. KMUserInfoViewController *userInfo = [[KMUserInfoViewController alloc] init];
  732. userInfo.view.layer.backgroundColor = [NSColor whiteColor].CGColor;
  733. NSMenuItem *item = [self.userMenu addItemWithTitle:@"" action:nil target:@""];
  734. item.target = self;
  735. item.representedObject = userInfo;
  736. item.view = userInfo.view;
  737. [self.userMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(-130, 30) inView:sender];
  738. }
  739. - (IBAction)signUpAction:(NSButton *)sender {
  740. [KMLoginWindowsController.shared showWindow:nil];
  741. }
  742. #pragma mark - NSNotification Methods
  743. - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
  744. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  745. [self reloadData];
  746. });
  747. }
  748. - (void)IAPResultReceived:(NSNotification *)notification {
  749. dispatch_async(dispatch_get_main_queue(), ^{
  750. [self reloadData];
  751. });
  752. }
  753. - (void)IAPPurchaseSuccess:(NSNotification *)notification {
  754. dispatch_async(dispatch_get_main_queue(), ^{
  755. [self reloadData];
  756. });
  757. }
  758. - (void)IAPRestoreFinish:(NSNotification *)notification {
  759. dispatch_async(dispatch_get_main_queue(), ^{
  760. [self reloadData];
  761. });
  762. }
  763. #pragma mark - Event
  764. - (void)mouseEntered:(NSEvent *)event {
  765. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  766. ActivityStatusTrial == [VerificationManager manager].status) {
  767. [[self class] cancelPreviousPerformRequestsWithTarget:self];
  768. if (!self.popover.isShown) {
  769. [self buttonAction:self.button];
  770. }
  771. }
  772. }
  773. - (void)mouseExited:(NSEvent *)event {
  774. [super mouseExited:event];
  775. [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
  776. }
  777. - (void)popoverDidClose:(NSNotification *)notification {
  778. self.stopPopOverHide = NO;
  779. }
  780. - (void)popoverShowNoti:(NSNotification *)noti {
  781. if (self.popover) {
  782. [self.popover close];
  783. self.stopPopOverHide = NO;
  784. }
  785. }
  786. - (void)loginSuccessNotification:(NSNotification *)noti {
  787. _userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  788. [self reloadData];
  789. }
  790. - (void)logoutSuccessNotification:(NSNotification *)noti {
  791. _userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  792. [self reloadData];
  793. }
  794. - (void)expandPersonalCenterNotification:(NSNotification *)noti {
  795. if (self.userMenu != nil) {
  796. [self personalCenterAction:_userButton];
  797. }
  798. }
  799. - (void)closeMenu:(NSNotification *)noti {
  800. if (self.userMenu != nil) {
  801. [self.userMenu cancelTracking];
  802. self.userMenu = nil;
  803. }
  804. }
  805. - (void)popOverCloseAction {
  806. if (self.stopPopOverHide == NO) {
  807. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  808. ActivityStatusTrial == [VerificationManager manager].status) {
  809. if (self.popover.isShown) {
  810. [self.popover close];
  811. self.stopPopOverHide = NO;
  812. }
  813. }
  814. }
  815. }
  816. @end