// // KMWelcomeWindowController.swift // PDF Reader Pro // // Created by tangchao on 2023/10/10. // import Cocoa private let kKMWelcomeHasShowKey = "WelcomeHasShowKey" private let kKMWelcomeRemindMeLaterKey = "WelcomeRemindMeLaterKey" typealias KMWelcomeWindowC = KMWelcomeWindowController extension KMWelcomeWindowController.Key { public static let hasShow = kKMWelcomeHasShowKey public static let remindMeLater = kKMWelcomeRemindMeLaterKey } class KMWelcomeWindowController: NSWindowController { @IBOutlet weak var scrollView: NSScrollView! @IBOutlet weak var content1View: NSView! @IBOutlet weak var content2View: NSView! @IBOutlet weak var content3View: NSView! @IBOutlet weak var content4View: NSView! @IBOutlet weak var content5View: NSView! @IBOutlet weak var content6View: NSView! @IBOutlet weak var imageView1: NSImageView! @IBOutlet weak var imageView2: NSImageView! @IBOutlet weak var imageView3: NSImageView! @IBOutlet weak var imageView4: NSImageView! @IBOutlet weak var imageView6: NSImageView! @IBOutlet weak var imageView5: NSImageView! @IBOutlet weak var title1Label: NSTextField! @IBOutlet weak var subtitle1Label: NSTextField! @IBOutlet weak var title2Label: NSTextField! @IBOutlet weak var subtitle2Label: NSTextField! @IBOutlet weak var title3Label: NSTextField! @IBOutlet weak var subtitle3Label: NSTextField! @IBOutlet weak var title4Label: NSTextField! @IBOutlet weak var subtitle4Label: NSTextField! @IBOutlet weak var title5Label: NSTextField! @IBOutlet weak var subtitle5Label: NSTextField! @IBOutlet weak var title6Label: NSTextField! @IBOutlet weak var subtitle6Label: NSTextField! @IBOutlet weak var preBox: NSBox! @IBOutlet weak var nextBox: NSBox! private var _preButtonVC: KMDesignButton? var preButtonVC: KMDesignButton? { get { return self._preButtonVC } } private var _nextButtonVC: KMDesignButton? var nextButtonVC: KMDesignButton? { get { return self._nextButtonVC } } @IBOutlet weak var next1Box: NSBox! @IBOutlet weak var remindMeLaterBox: NSBox! @IBOutlet weak var next2Box: NSBox! @IBOutlet weak var next3Box: NSBox! @IBOutlet weak var next4Box: NSBox! @IBOutlet weak var next5Box: NSBox! @IBOutlet weak var signUpBox: NSBox! private var _next1ButtonVC: KMDesignButton? private var _remindMeLaterButtonVC: KMDesignButton? private var _next2ButtonVC: KMDesignButton? private var _next3ButtonVC: KMDesignButton? private var _next4ButtonVC: KMDesignButton? private var _signUpButtonVC: KMDesignButton? @IBOutlet weak var pageIndicator1: KMPageIndicator! @IBOutlet weak var pageIndicator2: KMPageIndicator! @IBOutlet weak var pageIndicator3: KMPageIndicator! @IBOutlet weak var pageIndicator4: KMPageIndicator! @IBOutlet weak var pageIndicator5: KMPageIndicator! @IBOutlet weak var pageIndicator6: KMPageIndicator! @IBOutlet weak var closeButton: NSButton! @IBOutlet weak var closeBox: KMBox! private var _contentViews: [NSView] = [] var contentViews: [NSView] { get { return self._contentViews } } private var _currentIndex: Int = 0 var itemClick: KMCommonClickBlock? public struct Key {} deinit { Swift.debugPrint("WelcomeWindowController 已释放") } convenience init() { self.init(windowNibName: "WelcomeWindowController") // 处理再次提醒 if (UserDefaults.standard.bool(forKey: KMWelcomeWindowC.Key.remindMeLater)) { UserDefaults.standard.set(false, forKey: KMWelcomeWindowC.Key.remindMeLater) UserDefaults.standard.set(false, forKey: KMWelcomeWindowC.Key.hasShow) UserDefaults.standard.synchronize() } } override func awakeFromNib() { super.awakeFromNib() let clipView = self.scrollView.contentView // ,self.content4View self._contentViews = [self.content1View, self.content2View, self.content3View, self.content4View, self.content6View, self.content5View] for i in 0 ..< self.contentViews.count { let view = self.contentViews[i] view.frame = NSMakeRect(i.cgFloat*clipView.bounds.size.width, 0, clipView.bounds.size.width, clipView.bounds.size.height) self.scrollView.documentView?.addSubview(view) } self.scrollView.documentView?.frame = NSMakeRect(0, 0, clipView.bounds.size.width*self.contentViews.count.cgFloat, clipView.bounds.size.height) } override func windowDidLoad() { super.windowDidLoad() self._localizedString() self.initSubViews() self.setupUI() self._reloadData() // 设置【显示】标识 UserDefaults.standard.set(true, forKey: KMWelcomeWindowC.Key.hasShow) UserDefaults.standard.synchronize() } func initSubViews() { self.preBox.borderType = .noBorder self._preButtonVC = KMDesignButton(withType: .Image) self.preBox.contentView?.addSubview(self.preButtonVC!.view) self.preButtonVC?.view.frame = self.preBox.contentView!.bounds self.preButtonVC?.view.autoresizingMask = [.width, .height] self.preButtonVC?.image = NSImage(named: "KMImageNamePreviousPageImage")! self.preButtonVC?.pagination() self.preButtonVC?.target = self self.preButtonVC?.action = #selector(_previousButtonAction) self.nextBox.borderType = .noBorder; self._nextButtonVC = KMDesignButton(withType: .Image) self.nextBox.contentView?.addSubview(self.nextButtonVC!.view) self.nextButtonVC?.view.frame = self.nextBox.contentView!.bounds self.nextButtonVC?.view.autoresizingMask = [.width, .height] self.nextButtonVC?.image = NSImage(named: "KMImageNameNextPageImage")! self.nextButtonVC?.pagination() self.nextButtonVC?.target = self self.nextButtonVC?.action = #selector(_nextButtonAction) for box in [self.next1Box, self.next2Box, self.next3Box, self.next4Box, self.next5Box] { box!.borderType = .noBorder let nextButtonVC = KMDesignButton(withType: .Text) box?.contentView?.addSubview(nextButtonVC.view) nextButtonVC.view.frame = box?.contentView?.bounds ?? NSZeroRect nextButtonVC.view.autoresizingMask = [.width, .height] nextButtonVC.target = self nextButtonVC.action = #selector(_signUpButtonAction) nextButtonVC.button(type: .Cta, size: .l) if (box!.isEqual(to: self.next1Box)) { self._next1ButtonVC = nextButtonVC } else if (box!.isEqual(to: self.next2Box)) { self._next2ButtonVC = nextButtonVC } else if (box!.isEqual(to: self.next3Box)) { self._next3ButtonVC = nextButtonVC } else if (box!.isEqual(to: self.next4Box)) { self._next4ButtonVC = nextButtonVC } else if (box!.isEqual(to: self.next5Box)) { // self.next5 } } self.remindMeLaterBox.borderType = .noBorder self._remindMeLaterButtonVC = KMDesignButton(withType: .Text) self.remindMeLaterBox.contentView?.addSubview(self._remindMeLaterButtonVC!.view) self._remindMeLaterButtonVC?.view.frame = self.remindMeLaterBox.contentView!.bounds self._remindMeLaterButtonVC?.view.autoresizingMask = [.width, .height] self._remindMeLaterButtonVC?.stringValue = KMLocalizedString("Remind Me Later") self._remindMeLaterButtonVC?.target = self self._remindMeLaterButtonVC?.action = #selector(_remindMeLaterButtonAction) self._remindMeLaterButtonVC?.button(type: .Text, size: .m) self.signUpBox.borderType = .noBorder self._signUpButtonVC = KMDesignButton(withType: .Text) self.signUpBox.contentView?.addSubview(self._signUpButtonVC!.view) self._signUpButtonVC?.view.frame = self.signUpBox.contentView!.bounds self._signUpButtonVC?.view.autoresizingMask = [.width, .height] self._signUpButtonVC?.target = self; self._signUpButtonVC?.action = #selector(_signUpButtonAction) self._signUpButtonVC?.button(type: .Cta, size: .l) // , self.pageIndicator5 for pageindicator in [self.pageIndicator1, self.pageIndicator2, self.pageIndicator3, self.pageIndicator4, self.pageIndicator5, self.pageIndicator6] { pageindicator?.numberOfPages = 6 pageindicator?.selectedColor = NSColor(red: 39.0/255.0, green: 60.0/255.0, blue: 98.0/255.0, alpha: 1) pageindicator?.normalColor = NSColor(red: 0, green: 0, blue: 0, alpha: 0.2) pageindicator?.pageIndicatorSize = NSMakeSize(6, 6) pageindicator?.enabled = false if (pageindicator!.isEqual(to: self.pageIndicator1)) { pageindicator?.currentPage = 0 } else if (pageindicator!.isEqual(to: self.pageIndicator2)) { pageindicator?.currentPage = 1 } else if (pageindicator!.isEqual(to: self.pageIndicator3)) { pageindicator?.currentPage = 2 } else if (pageindicator!.isEqual(to: self.pageIndicator4)) { pageindicator?.currentPage = 3 } else if (pageindicator!.isEqual(to: self.pageIndicator5)) { pageindicator?.currentPage = 5 } else if (pageindicator!.isEqual(to: self.pageIndicator6)) { pageindicator?.currentPage = 4 } } self.closeBox.moveCallback = { [weak self] mouseEntered, mouseBox in if (mouseEntered) { self?.closeButton.image = NSImage(named: "control_btn_icon_close_hov") } else { self?.closeButton.image = NSImage(named: "control_btn_icon_close") } } for view in self.contentViews { let label = NSTextField(labelWithString: KMLocalizedString("Sign up to Unlock Premium Features")) view.addSubview(label) label.frame = NSMakeRect(0, 14, NSWidth(view.frame), 18) label.alignment = .center label.font = NSFont(name: "SFProText-Regular", size: 14) label.textColor = NSColor(red: 23.0/255.0, green: 112.0/255.0, blue: 244.0/255.0, alpha: 1) label.isHidden = false } self.remindMeLaterBox.isHidden = true } func setupUI() { for titleLabel in [self.title1Label, self.title2Label, self.title3Label, self.title4Label, self.title6Label, self.title5Label] { titleLabel?.font = .SFProTextSemiboldFont(20) titleLabel?.textColor = NSColor(red: 37.0/255.0, green: 38.0/255.0, blue: 41.0/255.0, alpha:1) } let ps = NSMutableParagraphStyle() ps.lineSpacing = 6 ps.alignment = .center for subtitleLabel in [self.subtitle1Label, self.subtitle2Label, self.subtitle3Label, self.subtitle4Label, self.subtitle6Label, self.subtitle5Label] { subtitleLabel?.attributedStringValue = NSAttributedString(string: subtitleLabel!.stringValue, attributes: [.font : NSFont.SFProTextRegularFont(14), .foregroundColor : NSColor(red: 97.0/255.0, green: 100.0/255.0, blue: 105.0/255.0, alpha: 1), .paragraphStyle : ps]) } } @IBAction func closeAction(_ sender: Any) { self._closeAction() } // MARK: - Private Methods private func _localizedString() { self.imageView1.image = NSImage(named: "KMImageNameWelcome1") self.imageView2.image = NSImage(named: "KMImageNameWelcome2") self.imageView3.image = NSImage(named: "KMImageNameWelcomeAnnotation") self.imageView4.image = NSImage(named: "KMImageNameWelcomeEdit") self.imageView5.image = NSImage(named: "KMImageNameWelcomePageEdit") self.imageView6.image = NSImage(named: "KMImageNameWelcomeConvert") self.title1Label.stringValue = KMLocalizedString("The Brand New PDF Reader Pro") self.subtitle1Label.stringValue = KMLocalizedString("PDF Reader Pro Invites You to Enjoy All Advanced Features! Use the new powerful software integrated with AI technology to edit your PDFs") self.title2Label.stringValue = KMLocalizedString("Process PDF Document wit AI Robot") self.subtitle2Label.stringValue = KMLocalizedString("Smart PDF AI robot, powered by Chatgpt helps you translate, rewrite, and correct PDFs with ease, bringing you an enhanced PDF experience.") self.title3Label.stringValue = KMLocalizedString("Comment PDFs with Rich Annotation Tools") self.subtitle3Label.stringValue = KMLocalizedString("Add highlights, freehand, text, stamps, links, shapes, and notes to your documents. Easily mark up your PDFs anytime!") self.title4Label.stringValue = KMLocalizedString("Edit Original Text and Images Like Word") self.subtitle4Label.stringValue = KMLocalizedString("Fix a typo or add a new text box in a PDF effortlessly. Crop, replace, rotate, flip, and export images as desired.") self.title6Label.stringValue = KMLocalizedString("Organize PDF Pages with Ease") self.subtitle6Label.stringValue = KMLocalizedString("Drag and drop page thumbnails to rearrange pages. Or easily delete, insert, rotate, split pages.") self.title5Label.stringValue = KMLocalizedString("Convert PDF to Office Fast and Easily") self.subtitle5Label.stringValue = KMLocalizedString("Convert PDF to editable Word, Excel, PPT, Text and image with all your fonts and formatting preserved.") } @objc private func _previousButtonAction() { if (self._currentIndex <= 0) { return } self._currentIndex -= 1 NSAnimationContext.beginGrouping() let clipView = self.scrollView.contentView var newOrigin = clipView.bounds.origin newOrigin.x = clipView.bounds.size.width*self._currentIndex.cgFloat clipView.animator().setBoundsOrigin(newOrigin) NSAnimationContext.endGrouping() self._reloadData() } @objc private func _nextButtonAction() { if (self._currentIndex >= self.contentViews.count-1) { return } self._currentIndex += 1 NSAnimationContext.beginGrouping() let clipView = self.scrollView.contentView var newOrigin = clipView.bounds.origin newOrigin.x = clipView.bounds.size.width*self._currentIndex.cgFloat clipView.animator().setBoundsOrigin(newOrigin) NSAnimationContext.endGrouping() self._reloadData() } @objc private func _signUpButtonAction() { } private func _closeAction() { if let callback = self.itemClick { callback(1, self) } self.close() } @objc private func _remindMeLaterButtonAction() { UserDefaults.standard.set(true, forKey: KMWelcomeWindowC.Key.remindMeLater) UserDefaults.standard.synchronize() if let callback = self.itemClick { callback(2, self) } self.close() } private func _reloadData() { self.preBox.isHidden = false self.nextBox.isHidden = false if (self._currentIndex == 0) { self.preBox.isHidden = true } else if (self._currentIndex == 1) { } else if (self._currentIndex == 2) { // self.nextBox.hidden = YES; } else if (self._currentIndex == 3) { } else if (self._currentIndex == 4){ } else if (self._currentIndex == 5) { self.nextBox.isHidden = true } } class func welcomeHasShow() -> Bool { return UserDefaults.standard.bool(forKey: KMWelcomeWindowC.Key.hasShow) } }