// // KMRecommondPopWindow.m // PDF Reader Pro Edition // // Created by Niehaoyu on 2023/07/12. // #import "KMRecommondPopWindow.h" #import "PDF_Reader_Pro-Swift.h" @interface KMRecommondPopWindow ()< NSWindowDelegate> @property (assign) IBOutlet NSView *contendView; @property (assign) IBOutlet NSImageView *infoImg; @property (assign) IBOutlet NSTextField *titleLbl; @property (assign) IBOutlet NSTextField *subTitleLbl; @property (assign) IBOutlet NSTextField *expireDateLbl; @property (assign) IBOutlet NSButton *buyBtn; @property (nonatomic, strong) KMAdvertisementItemInfo *info; @end @implementation KMRecommondPopWindow - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } + (KMRecommondPopWindow *)defaultWindow { static KMRecommondPopWindow *singleton = nil; static dispatch_once_t pred; dispatch_once(&pred, ^{ singleton = [[KMRecommondPopWindow alloc] init]; }); return singleton; } - (id)init { if (self = [super initWithWindowNibName:@"KMRecommondPopWindow"]) { } return self; } - (void)setRecommondInfo:(id)recommondInfo { _recommondInfo = recommondInfo; _info = (KMAdvertisementItemInfo *)recommondInfo; } - (void)windowDidLoad { [super windowDidLoad]; // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. self.window.delegate = self; [self.window standardWindowButton:NSWindowMiniaturizeButton].hidden = YES; [self.window standardWindowButton:NSWindowZoomButton].hidden = YES; self.titleLbl.textColor = [KMAppearance KMColor_Layout_H0]; self.subTitleLbl.textColor = [KMAppearance KMColor_Layout_H0]; self.expireDateLbl.textColor = [KMAppearance KMColor_Layout_H0]; self.buyBtn.wantsLayer = YES; self.buyBtn.layer.backgroundColor = [KMAppearance KMColor_Interactive_M0].CGColor; NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:_info.image highlight: YES]]; __weak typeof(self)weakSelf = self; [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) { weakSelf.infoImg.image = image; }]; self.titleLbl.stringValue = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.name]; NSString *subT = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.newSubTitle]; if ([subT containsString:@"\\n"]) { subT = [subT stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"]; } self.subTitleLbl.stringValue = subT; self.expireDateLbl.stringValue = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.otherTitle]; [self.buyBtn setTitle:[KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.btnTitle]]; [self.buyBtn setTitleColor:[KMAppearance KMColor_Layout_W0]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recommondInfoUpdateNoti:) name:@"KMRecommondInfoUpdateNoti" object:nil]; } #pragma mark - Setter #pragma mark - IBAction - (IBAction)buyAction:(NSButton *)sender { if (_info.version) { if ([_info.jumpType isEqualToString:@"Comparison Sheet"]) { if ([KMMemberInfo shared].isLogin) { if ([[KMMemberInfo shared].vip_levels isEqualToString:@"1"]) { [[KMProductCompareWC shared] setOrientation:YES]; #if VERSION_FREE #if VERSION_DMG // DMG [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base]; #else // AppStore 免费版本 [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base]; #endif #else // AppStore 付费版 [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base]; #endif [[KMProductCompareWC shared] showWindow:nil]; } else { [[KMMemberInfo shared] advancedFunctionUsage]; } } else { [[KMLoginWindowsController shared] openWindow:^(BOOL success) { if (success) { if ([[KMMemberInfo shared].vip_levels isEqualToString:@"1"]) { [[KMProductCompareWC shared] setOrientation:YES]; #if VERSION_FREE #if VERSION_DMG // DMG [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base]; #else // AppStore 免费版本 [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base]; #endif #else // AppStore 付费版 [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base]; #endif [[KMProductCompareWC shared] showWindow:nil]; } else { [[KMMemberInfo shared] advancedFunctionUsage]; } } }]; } } else { [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[KMAdvertisementModelTransition transitionLanguageWithLangeuage:_info.linkURL]]]; } if (_info.firebase != nil) { [KMAdvertisementModelTransition sendFireBaseEventWithFirebase:_info.firebase]; } } } #pragma mark - NSWindowDelegate - (BOOL)windowShouldClose:(NSWindow *)sender { if (self.closeHandle) { self.closeHandle(self); } return YES; } #pragma mark - Noti - (void)recommondInfoUpdateNoti:(NSNotification *)noti { if ([noti.object[@"unique"] isEqualToString:_info.version]) { __weak typeof(self) weakSelf = self; dispatch_async(dispatch_get_main_queue(), ^{ weakSelf.infoImg.image = weakSelf.info.iconImage; }); } } @end