KMRecommondPopWindow.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. - (id)init {
  24. if (self = [super initWithWindowNibName:@"KMRecommondPopWindow"]) {
  25. }
  26. return self;
  27. }
  28. - (void)setRecommondInfo:(id)recommondInfo {
  29. _recommondInfo = recommondInfo;
  30. _info = (KMAdvertisementItemInfo *)recommondInfo;
  31. }
  32. - (void)windowDidLoad {
  33. [super windowDidLoad];
  34. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  35. self.window.delegate = self;
  36. [self.window standardWindowButton:NSWindowMiniaturizeButton].hidden = YES;
  37. [self.window standardWindowButton:NSWindowZoomButton].hidden = YES;
  38. self.titleLbl.textColor = [KMAppearance KMColor_Layout_H0];
  39. self.subTitleLbl.textColor = [KMAppearance KMColor_Layout_H0];
  40. self.expireDateLbl.textColor = [KMAppearance KMColor_Layout_H0];
  41. self.buyBtn.wantsLayer = YES;
  42. self.buyBtn.layer.backgroundColor = [KMAppearance KMColor_Interactive_M0].CGColor;
  43. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:_info.image highlight: YES]];
  44. __weak typeof(self)weakSelf = self;
  45. [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  46. weakSelf.infoImg.image = image;
  47. }];
  48. self.titleLbl.stringValue = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.name];
  49. NSString *subT = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.subTitle];
  50. if ([subT containsString:@"\\n"]) {
  51. subT = [subT stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];
  52. }
  53. self.subTitleLbl.stringValue = subT;
  54. self.expireDateLbl.stringValue = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.otherTitle];
  55. [self.buyBtn setTitle:[KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.btnTitle]];
  56. [self.buyBtn setTitleColor:[KMAppearance KMColor_Layout_W0]];
  57. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recommondInfoUpdateNoti:) name:@"KMRecommondInfoUpdateNoti" object:nil];
  58. }
  59. #pragma mark - Setter
  60. #pragma mark - IBAction
  61. - (IBAction)buyAction:(NSButton *)sender {
  62. if (_info.version) {
  63. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.linkURL]]];
  64. if (_info.firebase != nil) {
  65. [KMAdvertisementModelTransition sendFireBaseEventWithFirebase:_info.firebase];
  66. }
  67. }
  68. }
  69. #pragma mark - NSWindowDelegate
  70. - (BOOL)windowShouldClose:(NSWindow *)sender {
  71. if (self.closeHandle) {
  72. self.closeHandle(self);
  73. }
  74. return YES;
  75. }
  76. #pragma mark - Noti
  77. - (void)recommondInfoUpdateNoti:(NSNotification *)noti {
  78. if ([noti.object[@"unique"] isEqualToString:_info.version]) {
  79. dispatch_async(dispatch_get_main_queue(), ^{
  80. self.infoImg.image = _info.iconImage;
  81. });
  82. }
  83. }
  84. @end