KMRecommondPopWindow.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. //
  2. // KMRecommondPopWindow.m
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2023/07/12.
  6. //
  7. #import "KMRecommondPopWindow.h"
  8. #import "PDF_Reader_Pro-Swift.h"
  9. @interface KMRecommondPopWindow ()<
  10. NSWindowDelegate>
  11. @property (assign) IBOutlet NSView *contendView;
  12. @property (assign) IBOutlet NSImageView *infoImg;
  13. @property (assign) IBOutlet NSTextField *titleLbl;
  14. @property (assign) IBOutlet NSTextField *subTitleLbl;
  15. @property (assign) IBOutlet NSTextField *expireDateLbl;
  16. @property (assign) IBOutlet NSButton *buyBtn;
  17. @property (nonatomic, strong) KMAdvertisementItemInfo *info;
  18. @end
  19. @implementation KMRecommondPopWindow
  20. - (void)dealloc {
  21. [[NSNotificationCenter defaultCenter] removeObserver:self];
  22. }
  23. + (KMRecommondPopWindow *)defaultWindow {
  24. static KMRecommondPopWindow *singleton = nil;
  25. static dispatch_once_t pred;
  26. dispatch_once(&pred, ^{
  27. singleton = [[KMRecommondPopWindow alloc] init];
  28. });
  29. return singleton;
  30. }
  31. - (id)init {
  32. if (self = [super initWithWindowNibName:@"KMRecommondPopWindow"]) {
  33. }
  34. return self;
  35. }
  36. - (void)setRecommondInfo:(id)recommondInfo {
  37. _recommondInfo = recommondInfo;
  38. _info = (KMAdvertisementItemInfo *)recommondInfo;
  39. }
  40. - (void)windowDidLoad {
  41. [super windowDidLoad];
  42. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  43. self.window.delegate = self;
  44. [self.window standardWindowButton:NSWindowMiniaturizeButton].hidden = YES;
  45. [self.window standardWindowButton:NSWindowZoomButton].hidden = YES;
  46. self.titleLbl.textColor = [KMAppearance KMColor_Layout_H0];
  47. self.subTitleLbl.textColor = [KMAppearance KMColor_Layout_H0];
  48. self.subTitleLbl.lineBreakMode = NSLineBreakByWordWrapping;
  49. self.expireDateLbl.textColor = [KMAppearance KMColor_Layout_H0];
  50. self.buyBtn.wantsLayer = YES;
  51. self.buyBtn.layer.backgroundColor = [KMAppearance KMColor_Interactive_M0].CGColor;
  52. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:_info.image highlight: YES]];
  53. __weak typeof(self)weakSelf = self;
  54. [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  55. weakSelf.infoImg.image = image;
  56. }];
  57. self.titleLbl.stringValue = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.name];
  58. NSString *subT = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.newSubTitle];
  59. if ([subT containsString:@"\\n"]) {
  60. subT = [subT stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];
  61. }
  62. self.subTitleLbl.stringValue = subT;
  63. self.expireDateLbl.stringValue = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.otherTitle];
  64. [self.buyBtn setTitle:[KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.btnTitle]];
  65. [self.buyBtn setTitleColor:[KMAppearance KMColor_Layout_W0]];
  66. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recommondInfoUpdateNoti:) name:@"KMRecommondInfoUpdateNoti" object:nil];
  67. }
  68. #pragma mark - Setter
  69. #pragma mark - IBAction
  70. - (IBAction)buyAction:(NSButton *)sender {
  71. if (_info.version) {
  72. if ([_info.jumpType isEqualToString:@"Comparison Sheet"]) {
  73. if ([KMMemberInfo shared].isLogin) {
  74. if ([[KMMemberInfo shared].vip_levels isEqualToString:@"1"]) {
  75. [[KMProductCompareWC shared] setOrientation:YES];
  76. #if VERSION_FREE
  77. #if VERSION_DMG
  78. // DMG
  79. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  80. #else
  81. // AppStore 免费版本
  82. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  83. #endif
  84. #else
  85. // AppStore 付费版
  86. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  87. #endif
  88. [[KMProductCompareWC shared] showWindow:nil];
  89. } else {
  90. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeNone];
  91. }
  92. } else {
  93. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  94. if (success) {
  95. if ([[KMMemberInfo shared].vip_levels isEqualToString:@"1"]) {
  96. [[KMProductCompareWC shared] setOrientation:YES];
  97. #if VERSION_FREE
  98. #if VERSION_DMG
  99. // DMG
  100. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  101. #else
  102. // AppStore 免费版本
  103. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  104. #endif
  105. #else
  106. // AppStore 付费版
  107. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  108. #endif
  109. [[KMProductCompareWC shared] showWindow:nil];
  110. } else {
  111. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeNone];
  112. }
  113. }
  114. }];
  115. }
  116. } else {
  117. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.linkURL]]];
  118. }
  119. if (_info.firebase != nil) {
  120. [KMAdvertisementModelTransition sendFireBaseEventWithFirebase:_info.firebase];
  121. }
  122. }
  123. }
  124. #pragma mark - NSWindowDelegate
  125. - (BOOL)windowShouldClose:(NSWindow *)sender {
  126. if (self.closeHandle) {
  127. self.closeHandle(self);
  128. }
  129. return YES;
  130. }
  131. #pragma mark - Noti
  132. - (void)recommondInfoUpdateNoti:(NSNotification *)noti {
  133. if ([noti.object[@"unique"] isEqualToString:_info.version]) {
  134. __weak typeof(self) weakSelf = self;
  135. dispatch_async(dispatch_get_main_queue(), ^{
  136. weakSelf.infoImg.image = weakSelf.info.iconImage;
  137. });
  138. }
  139. }
  140. @end