KMRecommondPopWindow.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. self.infoImg.image = _info.iconImage;
  44. self.titleLbl.stringValue = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.name];
  45. NSString *subT = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.subTitle];
  46. if ([subT containsString:@"\\n"]) {
  47. subT = [subT stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];
  48. }
  49. self.subTitleLbl.stringValue = subT;
  50. self.expireDateLbl.stringValue = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.otherTitle];
  51. [self.buyBtn setTitle:[KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.btnTitle]];
  52. [self.buyBtn setTitleColor:[KMAppearance KMColor_Layout_W0]];
  53. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recommondInfoUpdateNoti:) name:@"KMRecommondInfoUpdateNoti" object:nil];
  54. }
  55. #pragma mark - Setter
  56. #pragma mark - IBAction
  57. - (IBAction)buyAction:(NSButton *)sender {
  58. if (_info.versionKey) {
  59. [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:_info.linkURL]];
  60. }
  61. }
  62. #pragma mark - NSWindowDelegate
  63. - (BOOL)windowShouldClose:(NSWindow *)sender {
  64. if (self.closeHandle) {
  65. self.closeHandle(self);
  66. }
  67. return YES;
  68. }
  69. #pragma mark - Noti
  70. - (void)recommondInfoUpdateNoti:(NSNotification *)noti {
  71. if ([noti.object[@"unique"] isEqualToString:_info.versionKey]) {
  72. dispatch_async(dispatch_get_main_queue(), ^{
  73. self.infoImg.image = _info.iconImage;
  74. });
  75. }
  76. }
  77. @end