KMTrialGuideWindowController.swift 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. //
  2. // KMTrialGuideWindowController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by Niehaoyu on 2024/7/23.
  6. //
  7. import Cocoa
  8. class KMTrialGuideWindowController: NSWindowController {
  9. @IBOutlet var contendBox: NSBox!
  10. @IBOutlet var businessBox: NSBox!
  11. @IBOutlet var businessTitleLabel: NSTextField!
  12. @IBOutlet var businessSubTitleLabel1: NSTextField!
  13. @IBOutlet var businessSubTitleLabel2: NSTextField!
  14. @IBOutlet var businessSubTitleLabel3: NSTextField!
  15. @IBOutlet var businessSubTitleLabel4: NSTextField!
  16. @IBOutlet var businessSubTitleLabel5: NSTextField!
  17. @IBOutlet var freeLicenseBox: NSBox!
  18. @IBOutlet var freeLicenseTitleLabel: NSTextField!
  19. @IBOutlet var freeLicenseSubTitleLabel: NSTextField!
  20. @IBOutlet var freeLicenseGuideLabel: NSTextField!
  21. @IBOutlet var freeLicenseGuideSubLabel1: NSTextField!
  22. @IBOutlet var freeLicenseGuideSubLabel2: NSTextField!
  23. @IBOutlet var freeLicenseGuideSubLabel3: NSTextField!
  24. @IBOutlet var adminConsoleLinkBtn: HyperLinkButton!
  25. @IBOutlet var applyForTrialBtn: HyperLinkButton!
  26. @IBOutlet var applyForTrialLabel: NSTextField!
  27. @IBOutlet var enterLicenseBox: NSBox!
  28. @IBOutlet var enterlicenseBtn: KMButton!
  29. @IBOutlet var buynowBtn: HyperLinkButton!
  30. @IBOutlet var emailTipBtn: HyperLinkButton!
  31. static var didAutoShow = false
  32. @objc var startFrame = CGRectZero
  33. @objc var originalFrame = CGRectZero
  34. @objc var shouldMinSizeAnimate: Bool = false
  35. var shouldClose: Bool = false
  36. @objc var noEmailBlock: (() -> Void)?
  37. convenience init() {
  38. self.init(windowNibName: "KMTrialGuideWindowController")
  39. }
  40. deinit {
  41. DistributedNotificationCenter.default().removeObserver(self)
  42. }
  43. @objc static func currentWC() -> KMTrialGuideWindowController {
  44. if let controller: KMTrialGuideWindowController = KMTrialGuideWindowController.fetchSampleController() {
  45. return controller
  46. } else {
  47. let purchaseLimitWC: KMTrialGuideWindowController = KMTrialGuideWindowController.init(windowNibName: "KMTrialGuideWindowController")
  48. return purchaseLimitWC
  49. }
  50. }
  51. static func fetchSampleController() -> KMTrialGuideWindowController? {
  52. for window in NSApp.windows {
  53. let controller = window.windowController
  54. if controller is KMTrialGuideWindowController {
  55. return controller as? KMTrialGuideWindowController
  56. }
  57. }
  58. return nil
  59. }
  60. override func windowDidLoad() {
  61. super.windowDidLoad()
  62. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  63. self.window?.delegate = self
  64. self.initViewInfo()
  65. self.refreshViewColor()
  66. DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChange), name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil)
  67. }
  68. func initViewInfo() {
  69. self.businessBox.borderWidth = 0
  70. self.businessTitleLabel.font = NSFont.UbuntuBoldFontWithSize(16)
  71. self.businessSubTitleLabel1.font = NSFont.UbuntuRegularFontWithSize(12)
  72. self.businessSubTitleLabel2.font = NSFont.UbuntuRegularFontWithSize(12)
  73. self.businessSubTitleLabel3.font = NSFont.UbuntuRegularFontWithSize(12)
  74. self.businessSubTitleLabel4.font = NSFont.UbuntuRegularFontWithSize(12)
  75. self.businessSubTitleLabel5.font = NSFont.UbuntuRegularFontWithSize(12)
  76. self.freeLicenseTitleLabel.font = NSFont.UbuntuBoldFontWithSize(26)
  77. self.freeLicenseSubTitleLabel.font = NSFont.UbuntuRegularFontWithSize(14)
  78. self.freeLicenseGuideLabel.font = NSFont.UbuntuBoldFontWithSize(16)
  79. self.freeLicenseGuideSubLabel1.font = NSFont.UbuntuRegularFontWithSize(14)
  80. self.freeLicenseGuideSubLabel2.font = NSFont.UbuntuRegularFontWithSize(14)
  81. self.freeLicenseGuideSubLabel3.font = NSFont.UbuntuRegularFontWithSize(14)
  82. self.applyForTrialLabel.font = NSFont.UbuntuRegularFontWithSize(14)
  83. self.adminConsoleLinkBtn.font = NSFont.UbuntuRegularFontWithSize(14)
  84. self.applyForTrialBtn.font = NSFont.UbuntuRegularFontWithSize(14)
  85. self.buynowBtn.font = NSFont.UbuntuRegularFontWithSize(14)
  86. self.emailTipBtn.font = NSFont.UbuntuRegularFontWithSize(14)
  87. self.enterlicenseBtn.font = NSFont.UbuntuMediumFontWithSize(16)
  88. self.businessTitleLabel.stringValue = NSLocalizedString("Business Service", comment: "")
  89. self.businessSubTitleLabel1.stringValue = NSLocalizedString("Manage license and team with Admin Console", comment: "")
  90. self.businessSubTitleLabel2.stringValue = NSLocalizedString("On-premise deployment for high-level data security", comment: "")
  91. self.businessSubTitleLabel3.stringValue = NSLocalizedString("Multiple deployment methods", comment: "")
  92. self.businessSubTitleLabel4.stringValue = NSLocalizedString("Support SSO (Single Sign-on)", comment: "")
  93. self.businessSubTitleLabel5.stringValue = NSLocalizedString("Customized features and services for specific need", comment: "")
  94. self.freeLicenseBox.borderWidth = 0
  95. self.freeLicenseBox.cornerRadius = 16
  96. self.enterLicenseBox.cornerRadius = 24
  97. self.freeLicenseTitleLabel.stringValue = NSLocalizedString("Obtain Free License", comment: "") + " 👋🏻 "
  98. self.freeLicenseSubTitleLabel.stringValue = NSLocalizedString("Free trial LynxPDF Editor and Admin Console for 14 days!", comment: "")
  99. self.freeLicenseGuideLabel.stringValue = NSLocalizedString("Where to receive free license?", comment: "")
  100. self.freeLicenseGuideSubLabel1.stringValue = NSLocalizedString("Go to your mailbox to confirm your login information for Admin Console.", comment: "")
  101. self.freeLicenseGuideSubLabel2.stringValue = NSLocalizedString("Log in to Admin Console. Go to \"Manage License\" and copy your license code.", comment: "")
  102. self.freeLicenseGuideSubLabel3.stringValue = NSLocalizedString("Enter license code in LynxPDF Editor.", comment: "")
  103. self.applyForTrialLabel.stringValue = NSLocalizedString("(if you have applied, please check your email)", comment: "")
  104. self.adminConsoleLinkBtn.title = NSLocalizedString("Log in to Admin Console directly.", comment: "")
  105. self.applyForTrialBtn.title = NSLocalizedString("Apply for trial", comment: "")
  106. self.enterlicenseBtn.title = NSLocalizedString("Enter License Code", comment: "")
  107. self.buynowBtn.title = NSLocalizedString("Buy Now", comment: "")
  108. self.emailTipBtn.title = NSLocalizedString("No mail received?", comment: "")
  109. self.emailTipBtn.isHidden = true
  110. }
  111. func refreshViewColor() {
  112. self.businessTitleLabel.textColor = NSColor.white
  113. self.businessSubTitleLabel1.textColor = NSColor.white
  114. self.businessSubTitleLabel2.textColor = NSColor.white
  115. self.businessSubTitleLabel3.textColor = NSColor.white
  116. self.businessSubTitleLabel4.textColor = NSColor.white
  117. self.businessSubTitleLabel5.textColor = NSColor.white
  118. self.freeLicenseBox.fillColor = NSColor.white
  119. self.enterLicenseBox.fillColor = NSColor(red: 75/255, green: 100/255, blue: 236/255, alpha: 1)
  120. self.freeLicenseTitleLabel.textColor = NSColor(red: 0, green: 33/255, blue: 67/255, alpha: 1)
  121. self.freeLicenseSubTitleLabel.textColor = NSColor(red: 0, green: 33/255, blue: 67/255, alpha: 1)
  122. self.freeLicenseGuideLabel.textColor = NSColor(red: 0, green: 33/255, blue: 67/255, alpha: 1)
  123. self.freeLicenseGuideSubLabel1.textColor = NSColor(red: 0, green: 33/255, blue: 67/255, alpha: 1)
  124. self.freeLicenseGuideSubLabel2.textColor = NSColor(red: 0, green: 33/255, blue: 67/255, alpha: 1)
  125. self.freeLicenseGuideSubLabel3.textColor = NSColor(red: 0, green: 33/255, blue: 67/255, alpha: 1)
  126. self.applyForTrialLabel.textColor = NSColor(red: 0, green: 33/255, blue: 67/255, alpha: 1)
  127. self.adminConsoleLinkBtn.setTitleColor(KMAppearance.Interactive.a0Color())
  128. self.applyForTrialBtn.setTitleColor(KMAppearance.Interactive.a0Color())
  129. self.enterlicenseBtn.setTitleColor(NSColor.white)
  130. self.buynowBtn.setTitleColor(KMAppearance.Interactive.a0Color())
  131. self.emailTipBtn.setTitleColor(KMAppearance.Interactive.a0Color())
  132. }
  133. //MARK: IBAction
  134. @IBAction func applyForTrialAction(_ sender: Any) {
  135. guard let block = self.noEmailBlock else {
  136. return
  137. }
  138. block()
  139. }
  140. @IBAction func loginAdminConsole(_ sender: Any) {
  141. let string = KAdminConsoleLoginURL
  142. let url: URL = URL(string: string)!
  143. NSWorkspace.shared.open(url)
  144. }
  145. @IBAction func enterlicenseCode(_ sender: Any) {
  146. self.close()
  147. let vc = KMVerificationWindowController.verification(with:.activate)
  148. vc?.callback = { [weak self] in
  149. }
  150. vc?.showWindow(nil)
  151. }
  152. @IBAction func buyNowAction(_ sender: Any) {
  153. FMTrackEventManager.defaultManager.lynxTrackEvent(event: "OnbrdTop", withProperties: ["OnbrdTop_Tbr" : "OnbrdTop_Tbr_BuyNowTrial"])
  154. let string = "https://www.pdfreaderpro.com/store/lynxpdfeditor"
  155. let url: URL = URL(string: string)!
  156. NSWorkspace.shared.open(url)
  157. self.close()
  158. }
  159. @IBAction func noEmailAction(_ sender: Any) {
  160. guard let block = self.noEmailBlock else {
  161. return
  162. }
  163. block()
  164. }
  165. @objc func themeChange() {
  166. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  167. self.refreshViewColor()
  168. }
  169. }
  170. }
  171. extension KMTrialGuideWindowController {
  172. @objc func animateScaling() {
  173. let originalFrame = self.originalFrame
  174. NSAnimationContext.runAnimationGroup({ context in
  175. context.duration = 0.5 // 动画持续时间
  176. self.window?.animator().setFrame(NSRect(x: originalFrame.origin.x ,
  177. y: originalFrame.origin.y ,
  178. width: originalFrame.size.width,
  179. height: originalFrame.size.height),
  180. display: true)
  181. }) {
  182. }
  183. }
  184. @objc func minAnimateScaling() {
  185. let originalFrame = self.startFrame
  186. NSAnimationContext.runAnimationGroup({ context in
  187. context.duration = 0.5 // 动画持续时间
  188. self.window?.animator().setFrame(NSRect(x: originalFrame.origin.x ,
  189. y: originalFrame.origin.y ,
  190. width: originalFrame.size.width,
  191. height: originalFrame.size.height),
  192. display: true)
  193. }) {
  194. self.window?.close()
  195. }
  196. }
  197. }
  198. extension KMTrialGuideWindowController: NSWindowDelegate {
  199. func windowShouldClose(_ sender: NSWindow) -> Bool {
  200. if self.shouldMinSizeAnimate {
  201. self.minAnimateScaling()
  202. return shouldClose
  203. }
  204. return true
  205. }
  206. }