1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- //
- // KMDiscountToSaveWindowController.m
- // PDF Reader Pro Edition
- //
- // Created by tangchao on 2024/7/14.
- //
- #import "KMDiscountToSaveWindowController.h"
- @interface KMDiscountToSaveWindowController ()
- @property (assign) IBOutlet NSBox *box;
- @property (assign) IBOutlet NSImageView *imgIv;
- @property (assign) IBOutlet NSButton *cancelButton;
- @property (assign) IBOutlet NSButton *okButton;
- @end
- @implementation KMDiscountToSaveWindowController
- - (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.backgroundColor = NSColor.clearColor;
- self.window.contentView.wantsLayer = true;
- self.window.contentView.layer.backgroundColor = NSColor.clearColor.CGColor;
- self.window.contentView.superview.wantsLayer = true;
- self.window.contentView.superview.layer.backgroundColor = NSColor.purpleColor.CGColor;
- // self.window.view
- self.box.fillColor = NSColor.clearColor;
- // self.imgIv.image = [NSImage imageNamed:@"KMImageNameDiscountToSaveIcon"];
- self.window.titleVisibility = NSWindowTitleHidden;
- self.window.titlebarAppearsTransparent = true;
-
- // KMRecommondInfo *recoveryInfo = KMRecommondManager.manager.userRecoveryRecommond.recommondInfoArrM.firstObject;
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowdidEndLiveResizeNotification:) name:NSWindowDidUpdateNotification object:self.window];
-
- self.cancelButton.target = self;
- self.cancelButton.action = @selector(cancelButtonAction:);
- self.okButton.target = self;
- self.okButton.action = @selector(okButtonAction:);
-
- [[NSUserDefaults standardUserDefaults] setObject:@([NSDate date].timeIntervalSince1970) forKey:@"KMDiscountToSaveWindowShowDate"];
- NSInteger count = [[NSUserDefaults standardUserDefaults] integerForKey:@"KMDiscountToSaveWindowShowCount"];
- [[NSUserDefaults standardUserDefaults] setInteger:count+1 forKey:@"KMDiscountToSaveWindowShowCount"];
- }
- - (void)windowdidEndLiveResizeNotification:(NSNotification *)sender {
- NSView *frameView = self.window.contentView.superview;
- for (NSView *sv in frameView.subviews) {
- if ([sv isKindOfClass:[NSVisualEffectView class]]) {
- sv.hidden = true;
- // sv.wantsLayer = true;
- // sv.layer.backgroundColor = NSColor.clearColor.CGColor;
- }
- }
- }
- - (void)cancelButtonAction:(NSButton *)sender {
- if (self.itemClick != nil) {
- self.itemClick(1);
- }
- }
- - (void)okButtonAction:(NSButton *)sender {
- if (self.itemClick != nil) {
- self.itemClick(2);
- }
- }
- + (BOOL)needShow {
- NSInteger count = [[NSUserDefaults standardUserDefaults] integerForKey:@"KMDiscountToSaveWindowShowCount"];
- if (count >= 3) { // 已经显示3次
- return false;
- }
- if (count == 0) { // 第一次显示
- return true;
- }
- // 第二、三次显示
- NSTimeInterval time = [NSDate date].timeIntervalSince1970;
- NSTimeInterval preTime = [[[NSUserDefaults standardUserDefaults] objectForKey:@"KMDiscountToSaveWindowShowDate"] doubleValue];
- NSTimeInterval threeDays = 24 * 60 * 60 * 3;
- if (time - preTime > threeDays) {
- return true;
- }
- return false;
- }
- @end
|