KMDiscountToSaveWindowController.m 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // KMDiscountToSaveWindowController.m
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by tangchao on 2024/7/14.
  6. //
  7. #import "KMDiscountToSaveWindowController.h"
  8. @interface KMDiscountToSaveWindowController ()
  9. @property (assign) IBOutlet NSBox *box;
  10. @property (assign) IBOutlet NSImageView *imgIv;
  11. @property (assign) IBOutlet NSButton *cancelButton;
  12. @property (assign) IBOutlet NSButton *okButton;
  13. @end
  14. @implementation KMDiscountToSaveWindowController
  15. - (void)windowDidLoad {
  16. [super windowDidLoad];
  17. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  18. self.window.backgroundColor = NSColor.clearColor;
  19. self.window.contentView.wantsLayer = true;
  20. self.window.contentView.layer.backgroundColor = NSColor.clearColor.CGColor;
  21. self.window.contentView.superview.wantsLayer = true;
  22. self.window.contentView.superview.layer.backgroundColor = NSColor.purpleColor.CGColor;
  23. // self.window.view
  24. self.box.fillColor = NSColor.clearColor;
  25. // self.imgIv.image = [NSImage imageNamed:@"KMImageNameDiscountToSaveIcon"];
  26. self.window.titleVisibility = NSWindowTitleHidden;
  27. self.window.titlebarAppearsTransparent = true;
  28. // KMRecommondInfo *recoveryInfo = KMRecommondManager.manager.userRecoveryRecommond.recommondInfoArrM.firstObject;
  29. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowdidEndLiveResizeNotification:) name:NSWindowDidUpdateNotification object:self.window];
  30. self.cancelButton.target = self;
  31. self.cancelButton.action = @selector(cancelButtonAction:);
  32. self.okButton.target = self;
  33. self.okButton.action = @selector(okButtonAction:);
  34. [[NSUserDefaults standardUserDefaults] setObject:@([NSDate date].timeIntervalSince1970) forKey:@"KMDiscountToSaveWindowShowDate"];
  35. NSInteger count = [[NSUserDefaults standardUserDefaults] integerForKey:@"KMDiscountToSaveWindowShowCount"];
  36. [[NSUserDefaults standardUserDefaults] setInteger:count+1 forKey:@"KMDiscountToSaveWindowShowCount"];
  37. }
  38. - (void)windowdidEndLiveResizeNotification:(NSNotification *)sender {
  39. NSView *frameView = self.window.contentView.superview;
  40. for (NSView *sv in frameView.subviews) {
  41. if ([sv isKindOfClass:[NSVisualEffectView class]]) {
  42. sv.hidden = true;
  43. // sv.wantsLayer = true;
  44. // sv.layer.backgroundColor = NSColor.clearColor.CGColor;
  45. }
  46. }
  47. }
  48. - (void)cancelButtonAction:(NSButton *)sender {
  49. if (self.itemClick != nil) {
  50. self.itemClick(1);
  51. }
  52. }
  53. - (void)okButtonAction:(NSButton *)sender {
  54. if (self.itemClick != nil) {
  55. self.itemClick(2);
  56. }
  57. }
  58. + (BOOL)needShow {
  59. NSInteger count = [[NSUserDefaults standardUserDefaults] integerForKey:@"KMDiscountToSaveWindowShowCount"];
  60. if (count >= 3) { // 已经显示3次
  61. return false;
  62. }
  63. if (count == 0) { // 第一次显示
  64. return true;
  65. }
  66. // 第二、三次显示
  67. NSTimeInterval time = [NSDate date].timeIntervalSince1970;
  68. NSTimeInterval preTime = [[[NSUserDefaults standardUserDefaults] objectForKey:@"KMDiscountToSaveWindowShowDate"] doubleValue];
  69. NSTimeInterval threeDays = 24 * 60 * 60 * 3;
  70. if (time - preTime > threeDays) {
  71. return true;
  72. }
  73. return false;
  74. }
  75. @end