KMPurchaseFirstTrialWindowController.swift 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. //
  2. // KMPurchaseFirstTrialWindowController.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by zenghong on 11/22/23.
  6. //
  7. import Cocoa
  8. @objc class KMPurchaseFirstTrialWindowController: NSWindowController,NSTextFieldDelegate,NSTextViewDelegate, NSWindowDelegate {
  9. @IBOutlet weak var contentImageView: NSImageView!
  10. @IBOutlet weak var titleField: NSTextField!
  11. @IBOutlet weak var rView: NSView!
  12. @IBOutlet weak var trialTitleField: NSTextField!
  13. @IBOutlet weak var trialMessageField: NSTextField!
  14. @IBOutlet weak var trialFeaturesField: NSTextField!
  15. @IBOutlet weak var imageView1: NSImageView!
  16. @IBOutlet weak var imageView2: NSImageView!
  17. @IBOutlet weak var imageView3: NSImageView!
  18. @IBOutlet weak var imageView4: NSImageView!
  19. @IBOutlet weak var imageView5: NSImageView!
  20. @IBOutlet weak var imageView6: NSImageView!
  21. @IBOutlet weak var imageView7: NSImageView!
  22. @IBOutlet weak var features1Field: NSTextField!
  23. @IBOutlet weak var features2Field: NSTextField!
  24. @IBOutlet weak var features3Field: NSTextField!
  25. @IBOutlet weak var features4Field: NSTextField!
  26. @IBOutlet weak var features5Field: NSTextField!
  27. @IBOutlet weak var features6Field: NSTextField!
  28. @IBOutlet weak var nameTextFieldView: NSView!
  29. @IBOutlet weak var nameTextField: NSTextField!
  30. @IBOutlet weak var nameInvalidLabel: NSTextField!
  31. @IBOutlet weak var emailTextFieldView: NSView!
  32. @IBOutlet weak var emailTextField: NSTextField!
  33. @IBOutlet weak var emailInvalidLabel: NSTextField!
  34. @IBOutlet var bottomTextView: NSTextView! //CustomTextView!
  35. @IBOutlet weak var btnBox: NSBox!
  36. @IBOutlet weak var activateTrialNowBtn: KMButton!
  37. @IBOutlet weak var buyNowBox: NSBox!
  38. @IBOutlet weak var buyNowBtn: HyperLinkButton!
  39. @IBOutlet weak var enterLicenseBox: NSBox!
  40. @IBOutlet weak var enterLicenseBtn: HyperLinkButton!
  41. static var currentWindowController: KMPurchaseFirstTrialWindowController!
  42. @objc var buttonActionBlock: ((_ firstTrialWinVC: KMPurchaseFirstTrialWindowController, _ btn: KMButton, _ email : String, _ name : String)->Void)?
  43. //MARK: 打开文件
  44. @objc static func currentFirstTrialWC() -> KMPurchaseFirstTrialWindowController {
  45. if currentWindowController != nil {
  46. return currentWindowController
  47. } else {
  48. let configWC: KMPurchaseFirstTrialWindowController = KMPurchaseFirstTrialWindowController.init(windowNibName: "KMPurchaseFirstTrialWindowController")
  49. currentWindowController = configWC;
  50. return currentWindowController
  51. }
  52. }
  53. deinit {
  54. DistributedNotificationCenter.default.removeObserver(self)
  55. NotificationCenter.default.removeObserver(self)
  56. }
  57. override func windowDidLoad() {
  58. super.windowDidLoad()
  59. DistributedNotificationCenter.default.addObserver(self, selector: #selector(themeChanged(_:)), name: NSNotification.Name(rawValue:"AppleInterfaceThemeChangedNotification"), object: nil)
  60. NotificationCenter.default.addObserver(self, selector: #selector(windowDidBecomeVisible(_:)), name: NSWindow.didBecomeKeyNotification, object: nil)
  61. self.window?.delegate = self
  62. self.activateTrialNowBtn.tag = 10001
  63. self.buyNowBtn.tag = 10002
  64. self.enterLicenseBtn.tag = 10003
  65. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  66. self.emailTextField.delegate = self
  67. self.nameTextField.delegate = self
  68. self.nameTextFieldView.wantsLayer = true
  69. self.nameTextFieldView.layer?.masksToBounds = true
  70. self.nameTextFieldView.layer?.cornerRadius = 4.0
  71. self.emailTextFieldView.wantsLayer = true
  72. self.emailTextFieldView.layer?.masksToBounds = true
  73. self.emailTextFieldView.layer?.cornerRadius = 4.0
  74. self.bottomTextView.delegate = self;
  75. self.titleField.wantsLayer = true
  76. self.titleField.alphaValue = 0.8
  77. self.imageView2.wantsLayer = true
  78. self.imageView2.alphaValue = 0.8
  79. self.imageView3.wantsLayer = true
  80. self.imageView3.alphaValue = 0.8
  81. self.imageView4.wantsLayer = true
  82. self.imageView4.alphaValue = 0.8
  83. self.imageView5.wantsLayer = true
  84. self.imageView5.alphaValue = 0.8
  85. self.imageView6.wantsLayer = true
  86. self.imageView6.alphaValue = 0.8
  87. self.imageView7.wantsLayer = true
  88. self.imageView7.alphaValue = 0.8
  89. self.features1Field.wantsLayer = true
  90. self.features1Field.alphaValue = 0.8
  91. self.features2Field.wantsLayer = true
  92. self.features2Field.alphaValue = 0.8
  93. self.features2Field.wantsLayer = true
  94. self.features2Field.alphaValue = 0.8
  95. self.features2Field.wantsLayer = true
  96. self.features2Field.alphaValue = 0.8
  97. self.features2Field.wantsLayer = true
  98. self.features2Field.alphaValue = 0.8
  99. self.features2Field.wantsLayer = true
  100. self.features2Field.alphaValue = 0.8
  101. self.reloadData()
  102. }
  103. @objc func reloadData () {
  104. self.titleField.stringValue = NSLocalizedString("Unlock All Advanced Features", comment: "")
  105. let customFont = NSFont(name: "Ubuntu Bold", size: 16)
  106. self.titleField.font = customFont
  107. self.trialTitleField.stringValue = "👋🏻 " + NSLocalizedString("7-day Free Trial", comment: "")
  108. self.trialTitleField.font = NSFont(name: "Ubuntu-Bold", size: 26)
  109. self.trialMessageField.stringValue = NSLocalizedString("PDF Reader Pro offers a 7-day free trial of the full functions.", comment: "")
  110. self.trialMessageField.font = NSFont(name: "SFProText-Regular", size: 14)
  111. self.trialFeaturesField.stringValue = NSLocalizedString("Enter your email to get free trial:", comment: "")
  112. self.trialFeaturesField.font = NSFont(name: "SFProText-Semibold", size: 16)
  113. self.features1Field.stringValue = NSLocalizedString("Edit PDF", comment: "")
  114. self.features2Field.stringValue = NSLocalizedString("Organize pages", comment: "")
  115. self.features3Field.stringValue = NSLocalizedString("Convert PDFs ", comment: "")
  116. self.features4Field.stringValue = NSLocalizedString("Digital signature", comment: "")
  117. self.features5Field.stringValue = NSLocalizedString("Create & fill form", comment: "")
  118. self.features6Field.stringValue = NSLocalizedString("OCR", comment: "")
  119. self.features1Field.font = NSFont(name: "SFProText-Regular", size: 13)
  120. self.features2Field.font = NSFont(name: "SFProText-Regular", size: 13)
  121. self.features3Field.font = NSFont(name: "SFProText-Regular", size: 13)
  122. self.features4Field.font = NSFont(name: "SFProText-Regular", size: 13)
  123. self.features5Field.font = NSFont(name: "SFProText-Regular", size: 13)
  124. self.features6Field.font = NSFont(name: "SFProText-Regular", size: 13)
  125. self.nameTextField.placeholderString = NSLocalizedString("User name", comment: "")
  126. self.emailTextField.placeholderString = NSLocalizedString("Email", comment: "")
  127. self.nameTextField.font = NSFont(name: "SFProText-Regular", size: 14)
  128. self.emailTextField.font = NSFont(name: "SFProText-Regular", size: 14)
  129. self.nameTextField.becomeFirstResponder()
  130. self.nameInvalidLabel.stringValue = NSLocalizedString("Please enter valid username", comment: "")
  131. self.emailInvalidLabel.stringValue = NSLocalizedString("Please enter valid email", comment: "")
  132. self.nameInvalidLabel.isHidden = true
  133. self.emailInvalidLabel.isHidden = true
  134. self.activateTrialNowBtn.title = NSLocalizedString("Apply", comment: "")
  135. self.activateTrialNowBtn.font = NSFont(name: "Ubuntu-Medium", size: 16)
  136. self.buyNowBtn.font = NSFont(name: "SFProText-semibold", size: 14)
  137. self.enterLicenseBtn.font = NSFont(name: "SFProText-semibold", size: 14)
  138. self.rView.wantsLayer = true
  139. self.rView.layer?.cornerRadius = 8
  140. self.rView.layer?.masksToBounds = true
  141. self.btnBox.wantsLayer = true
  142. self.btnBox.layer?.cornerRadius = 24
  143. self.updateViewColor()
  144. }
  145. //MARK: Noti
  146. @objc func themeChanged(_ notification: NSNotification) {
  147. DispatchQueue.main.async {
  148. self.reloadData()
  149. }
  150. }
  151. @objc func windowDidBecomeVisible(_ obj: Notification) {
  152. self.reloadData()
  153. }
  154. @objc func updateViewColor () {
  155. self.trialMessageField.textColor = KMAppearance.Layout.h0Color()
  156. self.trialFeaturesField.textColor = KMAppearance.Layout.h0Color()
  157. self.features1Field.textColor = NSColor(red: 14.0/255.0, green: 17.0/255.0, blue: 20.0/255.0, alpha: 1)
  158. self.features2Field.textColor = NSColor(red: 14.0/255.0, green: 17.0/255.0, blue: 20.0/255.0, alpha: 1)
  159. self.features3Field.textColor = NSColor(red: 14.0/255.0, green: 17.0/255.0, blue: 20.0/255.0, alpha: 1)
  160. self.features4Field.textColor = NSColor(red: 14.0/255.0, green: 17.0/255.0, blue: 20.0/255.0, alpha: 1)
  161. self.features5Field.textColor = NSColor(red: 14.0/255.0, green: 17.0/255.0, blue: 20.0/255.0, alpha: 1)
  162. self.features6Field.textColor = NSColor(red: 14.0/255.0, green: 17.0/255.0, blue: 20.0/255.0, alpha: 1)
  163. self.nameTextFieldView.layer?.borderWidth = 1.0
  164. if (KMAppearance.isDarkMode)(){
  165. self.nameTextFieldView.layer?.borderColor = KMAppearance.Layout.w30Color().cgColor
  166. } else {
  167. self.nameTextFieldView.layer?.borderColor = NSColor(red: 0.0/255.0, green: 85.0/255.0, blue: 251.0/255.0, alpha: 1).cgColor
  168. }
  169. self.emailTextFieldView.layer?.borderWidth = 1.0
  170. if (KMAppearance.isDarkMode)(){
  171. self.emailTextFieldView.layer?.borderColor = KMAppearance.Layout.w30Color().cgColor
  172. } else {
  173. self.emailTextFieldView.layer?.borderColor = NSColor(red: 0.0/255.0, green: 85.0/255.0, blue: 251.0/255.0, alpha: 1).cgColor
  174. }
  175. if (KMAppearance.isDarkMode)() {
  176. self.nameTextField.textColor = KMAppearance.Layout.w0Color()
  177. self.emailTextField.textColor = KMAppearance.Layout.w0Color()
  178. self.rView.layer?.backgroundColor = NSColor(red: 24.0/255.0, green: 22.0/255.0, blue: 31.0/255.0, alpha: 0.9).cgColor
  179. self.activateTrialNowBtn.title = NSLocalizedString("Free Trial", comment: "")
  180. self.btnBox.fillColor = NSColor(red: 181.0/255.0, green: 177.0/255.0, blue: 239.0/255.0, alpha: 1)
  181. self.btnBox.layer?.backgroundColor = NSColor(red: 181.0/255.0, green: 177.0/255.0, blue: 239.0/255.0, alpha: 1).cgColor
  182. self.activateTrialNowBtn.layer?.backgroundColor = NSColor(red: 181.0/255.0, green: 177.0/255.0, blue: 239.0/255.0, alpha: 1).cgColor
  183. self.activateTrialNowBtn.setTitleColor(NSColor(red: 7.0/255.0, green: 1.0/255.0, blue: 34.0/255.0, alpha: 1))
  184. self.activateTrialNowBtn.mouseMoveCallback = {[weak self] (mouseEntered) in
  185. if mouseEntered {
  186. self?.activateTrialNowBtn.layer?.backgroundColor = NSColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1).cgColor
  187. self?.btnBox.fillColor = NSColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1)
  188. self?.btnBox.layer?.backgroundColor = NSColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1).cgColor
  189. } else {
  190. self?.btnBox.fillColor = NSColor(red: 181.0/255.0, green: 177.0/255.0, blue: 239.0/255.0, alpha: 1)
  191. self?.btnBox.layer?.backgroundColor = NSColor(red: 181.0/255.0, green: 177.0/255.0, blue: 239.0/255.0, alpha: 1).cgColor
  192. self?.activateTrialNowBtn.layer?.backgroundColor = NSColor(red: 181.0/255.0, green: 177.0/255.0, blue: 239.0/255.0, alpha: 1).cgColor
  193. }
  194. }
  195. // self.activateTrialNowBtn.setBaseLineOffset(2)
  196. self.titleField.textColor = NSColor(red: 0.0/255.0, green: 33.0/255.0, blue: 67.0/255.0, alpha: 1)
  197. self.trialTitleField.textColor = NSColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1)
  198. self.buyNowBtn.title = NSLocalizedString("Buy Now", comment: "")
  199. self.buyNowBtn.setTitleColor(NSColor(red: 181.0/255.0, green: 177.0/255.0, blue: 239.0/255.0, alpha: 1))
  200. self.buyNowBtn.mouseMoveCallback = {[weak self] (mouseEntered) in
  201. if mouseEntered {
  202. self?.buyNowBtn.setTitleColor(NSColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1))
  203. } else {
  204. self?.buyNowBtn.setTitleColor(NSColor(red: 181.0/255.0, green: 177.0/255.0, blue: 239.0/255.0, alpha: 1))
  205. }
  206. }
  207. self.enterLicenseBtn.title = NSLocalizedString("Enter License", comment: "")
  208. self.enterLicenseBtn.setTitleColor(NSColor(red: 181.0/255.0, green: 177.0/255.0, blue: 239.0/255.0, alpha: 1))
  209. self.enterLicenseBtn.mouseMoveCallback = {[weak self] (mouseEntered) in
  210. if mouseEntered {
  211. self?.enterLicenseBtn.setTitleColor(NSColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1))
  212. } else {
  213. self?.enterLicenseBtn.setTitleColor(NSColor(red: 181.0/255.0, green: 177.0/255.0, blue: 239.0/255.0, alpha: 1))
  214. }
  215. }
  216. self.nameTextFieldView.layer?.backgroundColor = NSColor(red: 57.0/255.0, green: 58.0/255.0, blue: 70.0/255.0, alpha: 1).cgColor
  217. self.emailTextFieldView.layer?.backgroundColor = NSColor(red: 57.0/255.0, green: 58.0/255.0, blue: 70.0/255.0, alpha: 1).cgColor
  218. let stringValue : String = NSLocalizedString("By applying for free trial, you confirm that you agree this Privacy Policy.", comment: "")
  219. let attributedString: NSMutableAttributedString = NSMutableAttributedString(string: NSLocalizedString("By applying for free trial, you confirm that you agree this Privacy Policy.", comment: ""))
  220. let privacyPolicy : String = NSLocalizedString("Privacy Policy.", comment: "")
  221. let allRange = (stringValue as NSString).range(of: stringValue)
  222. attributedString.addAttributes([NSAttributedString.Key.foregroundColor : KMAppearance.Layout.w70Color()], range: allRange)
  223. attributedString.addAttributes([NSAttributedString.Key.font :NSFont(name: "SFProText-Regular", size: 12.0) as Any], range: allRange)
  224. let urlString : String = "https://www.pdfreaderpro.com/privacy-policy"
  225. let encodedURLString : String = urlString.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)!
  226. let linkRange = (stringValue as NSString).range(of: privacyPolicy)
  227. attributedString.addAttribute(.link, value: NSURL(string: encodedURLString)!, range: linkRange)
  228. attributedString.addAttribute(.underlineStyle, value: NSUnderlineStyle.single.rawValue, range: linkRange)
  229. self.bottomTextView.linkTextAttributes = [
  230. NSAttributedString.Key.foregroundColor: KMAppearance.Interactive.a0Color(),
  231. NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue
  232. ]
  233. self.bottomTextView.textStorage?.setAttributedString(attributedString)
  234. self.bottomTextView.isEditable = false // TextView不可编辑
  235. self.bottomTextView.isSelectable = true // TextView可选择
  236. self.bottomTextView.sizeToFit()
  237. } else {
  238. self.nameTextField.textColor = KMAppearance.Layout.h0Color()
  239. self.emailTextField.textColor = KMAppearance.Layout.h0Color()
  240. self.rView.layer?.backgroundColor = NSColor(red: 248.0/255.0, green: 249.0/255.0, blue: 255.0/255.0, alpha: 1).cgColor
  241. self.btnBox.fillColor = NSColor(red: 39.0/255.0, green: 60.0/255.0, blue: 98.0/255.0, alpha: 1)
  242. self.btnBox.layer?.backgroundColor = NSColor(red: 39.0/255.0, green: 60.0/255.0, blue: 98.0/255.0, alpha: 1).cgColor
  243. self.activateTrialNowBtn.layer?.backgroundColor = NSColor(red: 39.0/255.0, green: 60.0/255.0, blue: 98.0/255.0, alpha: 1).cgColor
  244. self.activateTrialNowBtn.setTitleColor(NSColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1))
  245. self.activateTrialNowBtn.mouseMoveCallback = {[weak self] (mouseEntered) in
  246. if mouseEntered {
  247. self?.activateTrialNowBtn.layer?.backgroundColor = NSColor(red: 0.0/255.0, green: 207.0/255.0, blue: 133.0/255.0, alpha: 1).cgColor
  248. self?.btnBox.fillColor = NSColor(red: 0.0/255.0, green: 207.0/255.0, blue: 133.0/255.0, alpha: 1)
  249. self?.btnBox.layer?.backgroundColor = NSColor(red: 0.0/255.0, green: 207.0/255.0, blue: 133.0/255.0, alpha: 1).cgColor
  250. } else {
  251. self?.activateTrialNowBtn.layer?.backgroundColor = NSColor(red: 39.0/255.0, green: 60.0/255.0, blue: 98.0/255.0, alpha: 1).cgColor
  252. self?.btnBox.fillColor = NSColor(red: 39.0/255.0, green: 60.0/255.0, blue: 98.0/255.0, alpha: 1)
  253. self?.btnBox.layer?.backgroundColor = NSColor(red: 39.0/255.0, green: 60.0/255.0, blue: 98.0/255.0, alpha: 1).cgColor
  254. }
  255. }
  256. self.titleField.textColor = NSColor(red: 0.0/255.0, green: 33.0/255.0, blue: 67.0/255.0, alpha: 1)
  257. self.trialTitleField.textColor = NSColor(red: 0.0/255.0, green: 33.0/255.0, blue: 67.0/255.0, alpha: 1)
  258. self.buyNowBtn.title = NSLocalizedString("Buy Now", comment: "")
  259. self.buyNowBtn.setTitleColor(NSColor(red: 39.0/255.0, green: 60.0/255.0, blue: 98.0/255.0, alpha: 1))
  260. self.buyNowBtn.mouseMoveCallback = {[weak self] (mouseEntered) in
  261. if mouseEntered {
  262. self?.buyNowBtn.setTitleColor(NSColor(red: 8.0/255.0, green: 124.0/255.0, blue: 255.0/255.0, alpha: 1))
  263. } else {
  264. self?.buyNowBtn.setTitleColor(NSColor(red: 39.0/255.0, green: 60.0/255.0, blue: 98.0/255.0, alpha: 1))
  265. }
  266. }
  267. self.enterLicenseBtn.title = NSLocalizedString("Enter License", comment: "")
  268. self.enterLicenseBtn.setTitleColor(NSColor(red: 39.0/255.0, green: 60.0/255.0, blue: 98.0/255.0, alpha: 1))
  269. self.enterLicenseBtn.mouseMoveCallback = {[weak self] (mouseEntered) in
  270. if mouseEntered {
  271. self?.enterLicenseBtn.setTitleColor(NSColor(red: 8.0/255.0, green: 124.0/255.0, blue: 255.0/255.0, alpha: 1))
  272. } else {
  273. self?.enterLicenseBtn.setTitleColor(NSColor(red: 39.0/255.0, green: 60.0/255.0, blue: 98.0/255.0, alpha: 1))
  274. }
  275. }
  276. self.nameTextFieldView.layer?.backgroundColor = NSColor(red: 235.0/255.0, green: 236.0/255.0, blue: 250.0/255.0, alpha: 1).cgColor
  277. self.emailTextFieldView.layer?.backgroundColor = NSColor(red: 235.0/255.0, green: 236.0/255.0, blue: 250.0/255.0, alpha: 1).cgColor
  278. let stringValue : String = NSLocalizedString("By applying for free trial, you confirm that you agree this Privacy Policy.", comment: "")
  279. let attributedString: NSMutableAttributedString = NSMutableAttributedString(string: NSLocalizedString("By applying for free trial, you confirm that you agree this Privacy Policy.", comment: ""))
  280. let privacyPolicy : String = NSLocalizedString("Privacy Policy.", comment: "")
  281. let urlString : String = "https://www.pdfreaderpro.com/privacy-policy"
  282. let encodedURLString : String = urlString.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)!
  283. let linkRange = (stringValue as NSString).range(of: privacyPolicy)
  284. attributedString.addAttribute(NSAttributedString.Key.link, value: NSURL(string: encodedURLString)!, range: linkRange)
  285. attributedString.addAttribute(NSAttributedString.Key.underlineStyle, value: NSUnderlineStyle.single.rawValue, range: linkRange)
  286. let allRange = (stringValue as NSString).range(of: stringValue)
  287. attributedString.addAttributes([NSAttributedString.Key.foregroundColor : KMAppearance.Layout.h1Color()], range: allRange)
  288. attributedString.addAttributes([NSAttributedString.Key.font :NSFont(name: "SFProText-Regular", size: 12.0) as Any], range: allRange)
  289. // 设置悬停时链接文本颜色
  290. // let hoverColor = NSColor.blue
  291. // attributedString.addAttribute(NSAttributedString.Key(rawValue: "NSMouseInRectAttribute"), value: hoverColor, range: linkRange)
  292. // 设置TextView的富文本属性
  293. self.bottomTextView.linkTextAttributes = [
  294. NSAttributedString.Key.foregroundColor: KMAppearance.Interactive.a0Color(),
  295. NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue
  296. ]
  297. self.bottomTextView.textStorage?.setAttributedString(attributedString)
  298. self.bottomTextView.isEditable = false // TextView不可编辑
  299. self.bottomTextView.isSelectable = true // TextView可选择
  300. self.bottomTextView.sizeToFit()
  301. }
  302. self.buyNowBtn.sizeToFit()
  303. self.enterLicenseBtn.sizeToFit()
  304. }
  305. func validateEmail(_ strEmail: String) -> Bool {
  306. let emailRegex = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"
  307. let emailTest: NSPredicate = NSPredicate(format: "SELF MATCHES %@", emailRegex)
  308. return emailTest.evaluate(with: strEmail)
  309. }
  310. //MARK: Btn Action
  311. @IBAction func activateTrialNowAction(_ sender: KMButton) {
  312. guard let callBack = self.buttonActionBlock else {
  313. return
  314. }
  315. var isValidate: Bool = true
  316. if self.validateEmail(self.emailTextField.stringValue) == true {
  317. self.emailInvalidLabel.isHidden = true
  318. isValidate = true && isValidate
  319. } else {
  320. self.emailInvalidLabel.isHidden = false
  321. isValidate = false && isValidate
  322. }
  323. if self.nameTextField.stringValue.isEmpty == false {
  324. self.nameInvalidLabel.isHidden = true
  325. isValidate = true && isValidate
  326. } else {
  327. self.nameInvalidLabel.isHidden = false
  328. isValidate = false && isValidate
  329. }
  330. if isValidate == false {
  331. return
  332. }
  333. callBack(self,sender,self.emailTextField.stringValue,self.nameTextField.stringValue)
  334. FMTrackEventManager.defaultManager.trackOnceEvent(event: "PUW", withProperties: ["PUW_Btn":"Btn_PUW_ActivateTrialNow"])
  335. }
  336. @IBAction func buyNowAction(_ sender: HyperLinkButton) {
  337. // guard let callBack = self.buttonActionBlock else {
  338. // return
  339. // }
  340. // callBack(self,sender,self.emailTextField.stringValue,self.nameTextField.stringValue)
  341. // FMTrackEventManager.defaultManager.trackOnceEvent(event: "PUW", withProperties: ["PUW_Btn":"Btn_PUW_BuyNow"])
  342. #if VERSION_DMG
  343. let singleTon = KMPurchaseCompareDMGWindowController.init()
  344. singleTon.showWindow(nil)
  345. singleTon.window?.center()
  346. #endif
  347. }
  348. @IBAction func enterLicenseAction(_ sender: HyperLinkButton) {
  349. guard let callBack = self.buttonActionBlock else {
  350. return
  351. }
  352. callBack(self,sender,self.emailTextField.stringValue,self.nameTextField.stringValue)
  353. FMTrackEventManager.defaultManager.trackOnceEvent(event: "PUW", withProperties: ["PUW_Btn":"Btn_PUW_Enter_The_License"])
  354. }
  355. //MARK: NSTextFieldDelegate
  356. func controlTextDidChange(_ obj: Notification) {
  357. if obj.object == nil {
  358. return
  359. }
  360. let textField = obj.object as! NSTextField
  361. if self.emailTextField.isEqual(textField) {
  362. self.emailInvalidLabel.isHidden = true
  363. self.nameTextFieldView.layer?.borderWidth = 0.0
  364. if (KMAppearance.isDarkMode)(){
  365. self.nameTextFieldView.layer?.borderColor = KMAppearance.Layout.w30Color().cgColor
  366. } else {
  367. self.nameTextFieldView.layer?.borderColor = NSColor(red: 0.0/255.0, green: 85.0/255.0, blue: 251.0/255.0, alpha: 1).cgColor
  368. }
  369. self.emailTextFieldView.layer?.borderWidth = 1.0
  370. if (KMAppearance.isDarkMode)(){
  371. self.emailTextFieldView.layer?.borderColor = KMAppearance.Layout.w30Color().cgColor
  372. } else {
  373. self.emailTextFieldView.layer?.borderColor = NSColor(red: 0.0/255.0, green: 85.0/255.0, blue: 251.0/255.0, alpha: 1).cgColor
  374. }
  375. }
  376. if self.nameTextField.isEqual(textField) {
  377. self.nameInvalidLabel.isHidden = true
  378. self.nameTextFieldView.layer?.borderWidth = 1.0
  379. if (KMAppearance.isDarkMode)(){
  380. self.nameTextFieldView.layer?.borderColor = KMAppearance.Layout.w30Color().cgColor
  381. } else {
  382. self.nameTextFieldView.layer?.borderColor = NSColor(red: 0.0/255.0, green: 85.0/255.0, blue: 251.0/255.0, alpha: 1).cgColor
  383. }
  384. self.emailTextFieldView.layer?.borderWidth = 0.0
  385. if (KMAppearance.isDarkMode)(){
  386. self.emailTextFieldView.layer?.borderColor = KMAppearance.Layout.w30Color().cgColor
  387. } else {
  388. self.emailTextFieldView.layer?.borderColor = NSColor(red: 0.0/255.0, green: 85.0/255.0, blue: 251.0/255.0, alpha: 1).cgColor
  389. }
  390. }
  391. }
  392. func controlTextDidEndEditing(_ obj: Notification) {
  393. let fied: NSTextField = obj.object as! NSTextField;
  394. if fied.isEqual(self.emailTextField) {
  395. if self.validateEmail(self.emailTextField.stringValue) == true {
  396. self.emailInvalidLabel.isHidden = true
  397. } else {
  398. self.emailInvalidLabel.isHidden = false;
  399. }
  400. self.nameTextFieldView.layer?.borderWidth = 1.0
  401. if (KMAppearance.isDarkMode)(){
  402. self.nameTextFieldView.layer?.borderColor = KMAppearance.Layout.w30Color().cgColor
  403. } else {
  404. self.nameTextFieldView.layer?.borderColor = NSColor(red: 0.0/255.0, green: 85.0/255.0, blue: 251.0/255.0, alpha: 1).cgColor
  405. }
  406. self.emailTextFieldView.layer?.borderWidth = 0.0
  407. if (KMAppearance.isDarkMode)(){
  408. self.emailTextFieldView.layer?.borderColor = KMAppearance.Layout.w30Color().cgColor
  409. } else {
  410. self.emailTextFieldView.layer?.borderColor = NSColor(red: 0.0/255.0, green: 85.0/255.0, blue: 251.0/255.0, alpha: 1).cgColor
  411. }
  412. }
  413. if fied.isEqual(self.nameTextField) {
  414. if self.nameTextField.stringValue.isEmpty == false {
  415. self.nameInvalidLabel.isHidden = true
  416. } else {
  417. self.nameInvalidLabel.isHidden = false;
  418. }
  419. self.nameTextFieldView.layer?.borderWidth = 0.0
  420. if (KMAppearance.isDarkMode)(){
  421. self.nameTextFieldView.layer?.borderColor = KMAppearance.Layout.w30Color().cgColor
  422. } else {
  423. self.nameTextFieldView.layer?.borderColor = NSColor(red: 0.0/255.0, green: 85.0/255.0, blue: 251.0/255.0, alpha: 1).cgColor
  424. }
  425. self.emailTextFieldView.layer?.borderWidth = 1.0
  426. if (KMAppearance.isDarkMode)(){
  427. self.emailTextFieldView.layer?.borderColor = KMAppearance.Layout.w30Color().cgColor
  428. } else {
  429. self.emailTextFieldView.layer?.borderColor = NSColor(red: 0.0/255.0, green: 85.0/255.0, blue: 251.0/255.0, alpha: 1).cgColor
  430. }
  431. }
  432. }
  433. func textView(_ textView: NSTextView, clickedOnLink link: Any, at charIndex: Int) -> Bool {
  434. guard let url = link as? URL else {
  435. return false
  436. }
  437. NSWorkspace.shared.open(url)
  438. return true
  439. }
  440. func windowWillClose(_ notification: Notification) {
  441. KMPurchaseFirstTrialWindowController.currentWindowController = nil
  442. }
  443. }