KMRecommondPopWindow.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. [[KMProductCompareWC shared] setOrientation:NO];
  73. [[KMProductCompareWC shared] showWindow:nil];
  74. } else {
  75. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.linkURL]]];
  76. }
  77. if (_info.firebase != nil) {
  78. [KMAdvertisementModelTransition sendFireBaseEventWithFirebase:_info.firebase];
  79. }
  80. }
  81. }
  82. #pragma mark - NSWindowDelegate
  83. - (BOOL)windowShouldClose:(NSWindow *)sender {
  84. if (self.closeHandle) {
  85. self.closeHandle(self);
  86. }
  87. return YES;
  88. }
  89. #pragma mark - Noti
  90. - (void)recommondInfoUpdateNoti:(NSNotification *)noti {
  91. if ([noti.object[@"unique"] isEqualToString:_info.version]) {
  92. __weak typeof(self) weakSelf = self;
  93. dispatch_async(dispatch_get_main_queue(), ^{
  94. weakSelf.infoImg.image = weakSelf.info.iconImage;
  95. });
  96. }
  97. }
  98. @end