KMRecommondPopWindow.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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.expireDateLbl.textColor = [KMAppearance KMColor_Layout_H0];
  49. self.buyBtn.wantsLayer = YES;
  50. self.buyBtn.layer.backgroundColor = [KMAppearance KMColor_Interactive_M0].CGColor;
  51. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:_info.image highlight: YES]];
  52. __weak typeof(self)weakSelf = self;
  53. [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  54. weakSelf.infoImg.image = image;
  55. }];
  56. self.titleLbl.stringValue = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.name];
  57. NSString *subT = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.newSubTitle];
  58. if ([subT containsString:@"\\n"]) {
  59. subT = [subT stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];
  60. }
  61. self.subTitleLbl.stringValue = subT;
  62. self.expireDateLbl.stringValue = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.otherTitle];
  63. [self.buyBtn setTitle:[KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.btnTitle]];
  64. [self.buyBtn setTitleColor:[KMAppearance KMColor_Layout_W0]];
  65. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recommondInfoUpdateNoti:) name:@"KMRecommondInfoUpdateNoti" object:nil];
  66. }
  67. #pragma mark - Setter
  68. #pragma mark - IBAction
  69. - (IBAction)buyAction:(NSButton *)sender {
  70. if (_info.version) {
  71. if ([_info.jumpType isEqualToString:@"Comparison Sheet"]) {
  72. if ([KMMemberInfo shared].isLogin) {
  73. if ([[KMMemberInfo shared].vip_levels isEqualToString:@"1"]) {
  74. [[KMProductCompareWC shared] setOrientation:YES];
  75. #if VERSION_FREE
  76. #if VERSION_DMG
  77. // DMG
  78. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  79. #else
  80. // AppStore 免费版本
  81. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  82. #endif
  83. #else
  84. // AppStore 付费版
  85. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  86. #endif
  87. [[KMProductCompareWC shared] showWindow:nil];
  88. } else {
  89. [[KMMemberInfo shared] advancedFunctionUsage];
  90. }
  91. } else {
  92. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  93. if (success) {
  94. if ([[KMMemberInfo shared].vip_levels isEqualToString:@"1"]) {
  95. [[KMProductCompareWC shared] setOrientation:YES];
  96. #if VERSION_FREE
  97. #if VERSION_DMG
  98. // DMG
  99. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  100. #else
  101. // AppStore 免费版本
  102. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  103. #endif
  104. #else
  105. // AppStore 付费版
  106. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  107. #endif
  108. [[KMProductCompareWC shared] showWindow:nil];
  109. } else {
  110. [[KMMemberInfo shared] advancedFunctionUsage];
  111. }
  112. }
  113. }];
  114. }
  115. } else {
  116. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.linkURL]]];
  117. }
  118. if (_info.firebase != nil) {
  119. [KMAdvertisementModelTransition sendFireBaseEventWithFirebase:_info.firebase];
  120. }
  121. }
  122. }
  123. #pragma mark - NSWindowDelegate
  124. - (BOOL)windowShouldClose:(NSWindow *)sender {
  125. if (self.closeHandle) {
  126. self.closeHandle(self);
  127. }
  128. return YES;
  129. }
  130. #pragma mark - Noti
  131. - (void)recommondInfoUpdateNoti:(NSNotification *)noti {
  132. if ([noti.object[@"unique"] isEqualToString:_info.version]) {
  133. __weak typeof(self) weakSelf = self;
  134. dispatch_async(dispatch_get_main_queue(), ^{
  135. weakSelf.infoImg.image = weakSelf.info.iconImage;
  136. });
  137. }
  138. }
  139. @end