// // KMTrialGuideWindowController.swift // PDF Reader Pro // // Created by Niehaoyu on 2024/7/23. // import Cocoa class KMTrialGuideWindowController: NSWindowController { @IBOutlet var contendBox: NSBox! @IBOutlet var businessBox: NSBox! @IBOutlet var businessTitleLabel: NSTextField! @IBOutlet var businessSubTitleLabel1: NSTextField! @IBOutlet var businessSubTitleLabel2: NSTextField! @IBOutlet var businessSubTitleLabel3: NSTextField! @IBOutlet var businessSubTitleLabel4: NSTextField! @IBOutlet var businessSubTitleLabel5: NSTextField! @IBOutlet var freeLicenseBox: NSBox! @IBOutlet var freeLicenseTitleLabel: NSTextField! @IBOutlet var freeLicenseSubTitleLabel: NSTextField! @IBOutlet var freeLicenseGuideLabel: NSTextField! @IBOutlet var freeLicenseGuideSubLabel1: NSTextField! @IBOutlet var freeLicenseGuideSubLabel2: NSTextField! @IBOutlet var freeLicenseGuideSubLabel3: NSTextField! @IBOutlet var adminConsoleLinkBtn: HyperLinkButton! @IBOutlet var applyForTrialBtn: HyperLinkButton! @IBOutlet var applyForTrialLabel: NSTextField! @IBOutlet var enterLicenseBox: NSBox! @IBOutlet var enterlicenseBtn: KMButton! @IBOutlet var buynowBtn: HyperLinkButton! @IBOutlet var emailTipBtn: HyperLinkButton! static var didAutoShow = false @objc var startFrame = CGRectZero @objc var originalFrame = CGRectZero @objc var shouldMinSizeAnimate: Bool = false var shouldClose: Bool = false @objc var noEmailBlock: (() -> Void)? convenience init() { self.init(windowNibName: "KMTrialGuideWindowController") } deinit { DistributedNotificationCenter.default().removeObserver(self) } @objc static func currentWC() -> KMTrialGuideWindowController { if let controller: KMTrialGuideWindowController = KMTrialGuideWindowController.fetchSampleController() { return controller } else { let purchaseLimitWC: KMTrialGuideWindowController = KMTrialGuideWindowController.init(windowNibName: "KMTrialGuideWindowController") return purchaseLimitWC } } static func fetchSampleController() -> KMTrialGuideWindowController? { for window in NSApp.windows { let controller = window.windowController if controller is KMTrialGuideWindowController { return controller as? KMTrialGuideWindowController } } return nil } override func 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.initViewInfo() self.refreshViewColor() DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChange), name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil) } func initViewInfo() { self.businessBox.borderWidth = 0 self.businessTitleLabel.font = NSFont.UbuntuBoldFontWithSize(16) self.businessSubTitleLabel1.font = NSFont.UbuntuRegularFontWithSize(12) self.businessSubTitleLabel2.font = NSFont.UbuntuRegularFontWithSize(12) self.businessSubTitleLabel3.font = NSFont.UbuntuRegularFontWithSize(12) self.businessSubTitleLabel4.font = NSFont.UbuntuRegularFontWithSize(12) self.businessSubTitleLabel5.font = NSFont.UbuntuRegularFontWithSize(12) self.freeLicenseTitleLabel.font = NSFont.UbuntuBoldFontWithSize(26) self.freeLicenseSubTitleLabel.font = NSFont.UbuntuRegularFontWithSize(14) self.freeLicenseGuideLabel.font = NSFont.UbuntuBoldFontWithSize(16) self.freeLicenseGuideSubLabel1.font = NSFont.UbuntuRegularFontWithSize(14) self.freeLicenseGuideSubLabel2.font = NSFont.UbuntuRegularFontWithSize(14) self.freeLicenseGuideSubLabel3.font = NSFont.UbuntuRegularFontWithSize(14) self.applyForTrialLabel.font = NSFont.UbuntuRegularFontWithSize(14) self.adminConsoleLinkBtn.font = NSFont.UbuntuRegularFontWithSize(14) self.applyForTrialBtn.font = NSFont.UbuntuRegularFontWithSize(14) self.buynowBtn.font = NSFont.UbuntuRegularFontWithSize(14) self.emailTipBtn.font = NSFont.UbuntuRegularFontWithSize(14) self.enterlicenseBtn.font = NSFont.UbuntuMediumFontWithSize(16) self.businessTitleLabel.stringValue = NSLocalizedString("Business Service", comment: "") self.businessSubTitleLabel1.stringValue = NSLocalizedString("Manage license and team with Admin Console", comment: "") self.businessSubTitleLabel2.stringValue = NSLocalizedString("On-premise deployment for high-level data security", comment: "") self.businessSubTitleLabel3.stringValue = NSLocalizedString("Multiple deployment methods", comment: "") self.businessSubTitleLabel4.stringValue = NSLocalizedString("Support SSO (Single Sign-on)", comment: "") self.businessSubTitleLabel5.stringValue = NSLocalizedString("Customized features and services for specific need", comment: "") self.freeLicenseBox.borderWidth = 0 self.freeLicenseBox.cornerRadius = 16 self.enterLicenseBox.cornerRadius = 24 self.freeLicenseTitleLabel.stringValue = NSLocalizedString("Obtain Free License", comment: "") + " 👋🏻 " self.freeLicenseSubTitleLabel.stringValue = NSLocalizedString("Free trial LynxPDF Editor and Admin Console for 14 days!", comment: "") self.freeLicenseGuideLabel.stringValue = NSLocalizedString("Where to receive free license?", comment: "") self.freeLicenseGuideSubLabel1.stringValue = NSLocalizedString("Go to your mailbox to confirm your login information for Admin Console.", comment: "") self.freeLicenseGuideSubLabel2.stringValue = NSLocalizedString("Log in to Admin Console. Go to \"Manage License\" and copy your license code.", comment: "") self.freeLicenseGuideSubLabel3.stringValue = NSLocalizedString("Enter license code in LynxPDF Editor.", comment: "") self.applyForTrialLabel.stringValue = NSLocalizedString("(if you have applied, please check your email)", comment: "") self.adminConsoleLinkBtn.title = NSLocalizedString("Log in to Admin Console directly.", comment: "") self.applyForTrialBtn.title = NSLocalizedString("Apply for trial", comment: "") self.enterlicenseBtn.title = NSLocalizedString("Enter License Code", comment: "") self.buynowBtn.title = NSLocalizedString("Buy Now", comment: "") self.emailTipBtn.title = NSLocalizedString("No mail received?", comment: "") self.emailTipBtn.isHidden = true } func refreshViewColor() { self.businessTitleLabel.textColor = NSColor.white self.businessSubTitleLabel1.textColor = NSColor.white self.businessSubTitleLabel2.textColor = NSColor.white self.businessSubTitleLabel3.textColor = NSColor.white self.businessSubTitleLabel4.textColor = NSColor.white self.businessSubTitleLabel5.textColor = NSColor.white self.freeLicenseBox.fillColor = NSColor.white self.enterLicenseBox.fillColor = NSColor(red: 75/255, green: 100/255, blue: 236/255, alpha: 1) self.freeLicenseTitleLabel.textColor = NSColor(red: 0, green: 33/255, blue: 67/255, alpha: 1) self.freeLicenseSubTitleLabel.textColor = NSColor(red: 0, green: 33/255, blue: 67/255, alpha: 1) self.freeLicenseGuideLabel.textColor = NSColor(red: 0, green: 33/255, blue: 67/255, alpha: 1) self.freeLicenseGuideSubLabel1.textColor = NSColor(red: 0, green: 33/255, blue: 67/255, alpha: 1) self.freeLicenseGuideSubLabel2.textColor = NSColor(red: 0, green: 33/255, blue: 67/255, alpha: 1) self.freeLicenseGuideSubLabel3.textColor = NSColor(red: 0, green: 33/255, blue: 67/255, alpha: 1) self.applyForTrialLabel.textColor = NSColor(red: 0, green: 33/255, blue: 67/255, alpha: 1) self.adminConsoleLinkBtn.setTitleColor(KMAppearance.Interactive.a0Color()) self.applyForTrialBtn.setTitleColor(KMAppearance.Interactive.a0Color()) self.enterlicenseBtn.setTitleColor(NSColor.white) self.buynowBtn.setTitleColor(KMAppearance.Interactive.a0Color()) self.emailTipBtn.setTitleColor(KMAppearance.Interactive.a0Color()) } //MARK: IBAction @IBAction func applyForTrialAction(_ sender: Any) { guard let block = self.noEmailBlock else { return } block() } @IBAction func loginAdminConsole(_ sender: Any) { let string = KAdminConsoleLoginURL let url: URL = URL(string: string)! NSWorkspace.shared.open(url) } @IBAction func enterlicenseCode(_ sender: Any) { self.close() let vc = KMVerificationWindowController.verification(with:.activate) vc?.callback = { [weak self] in } vc?.showWindow(nil) } @IBAction func buyNowAction(_ sender: Any) { FMTrackEventManager.defaultManager.lynxTrackEvent(event: "OnbrdTop", withProperties: ["OnbrdTop_Tbr" : "OnbrdTop_Tbr_BuyNowTrial"]) let string = "https://www.pdfreaderpro.com/store/lynxpdfeditor" let url: URL = URL(string: string)! NSWorkspace.shared.open(url) self.close() } @IBAction func noEmailAction(_ sender: Any) { guard let block = self.noEmailBlock else { return } block() } @objc func themeChange() { DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) { self.refreshViewColor() } } } extension KMTrialGuideWindowController { @objc func animateScaling() { let originalFrame = self.originalFrame NSAnimationContext.runAnimationGroup({ context in context.duration = 0.5 // 动画持续时间 self.window?.animator().setFrame(NSRect(x: originalFrame.origin.x , y: originalFrame.origin.y , width: originalFrame.size.width, height: originalFrame.size.height), display: true) }) { } } @objc func minAnimateScaling() { let originalFrame = self.startFrame NSAnimationContext.runAnimationGroup({ context in context.duration = 0.5 // 动画持续时间 self.window?.animator().setFrame(NSRect(x: originalFrame.origin.x , y: originalFrame.origin.y , width: originalFrame.size.width, height: originalFrame.size.height), display: true) }) { self.window?.close() } } } extension KMTrialGuideWindowController: NSWindowDelegate { func windowShouldClose(_ sender: NSWindow) -> Bool { if self.shouldMinSizeAnimate { self.minAnimateScaling() return shouldClose } return true } }