KMPurchaseFirstTrialWindowController.swift 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. //
  2. // KMPurchaseFirstTrialWindowController.swift
  3. // Cisdem PDFMaster
  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 imageView1: NSImageView!
  15. @IBOutlet weak var imageView2: NSImageView!
  16. @IBOutlet weak var imageView3: NSImageView!
  17. @IBOutlet weak var imageView4: NSImageView!
  18. @IBOutlet weak var imageView5: NSImageView!
  19. @IBOutlet weak var imageView6: NSImageView!
  20. @IBOutlet weak var imageView7: NSImageView!
  21. @IBOutlet weak var features1Field: NSTextField!
  22. @IBOutlet weak var features2Field: NSTextField!
  23. @IBOutlet weak var features3Field: NSTextField!
  24. @IBOutlet weak var features4Field: NSTextField!
  25. @IBOutlet weak var features5Field: NSTextField!
  26. @IBOutlet weak var features6Field: NSTextField!
  27. @IBOutlet var bottomTextView: NSTextView! //CustomTextView!
  28. @IBOutlet weak var btnBox: NSBox!
  29. @IBOutlet weak var activateTrialNowBtn: KMButton!
  30. @IBOutlet weak var buyNowBox: NSBox!
  31. @IBOutlet weak var buyNowBtn: HyperLinkButton!
  32. @IBOutlet weak var enterLicenseBox: NSBox!
  33. @IBOutlet weak var enterLicenseBtn: HyperLinkButton!
  34. static var currentWindowController: KMPurchaseFirstTrialWindowController!
  35. @objc var buttonActionBlock: ((_ firstTrialWinVC: KMPurchaseFirstTrialWindowController, _ btn: KMButton, _ email : String, _ name : String)->Void)?
  36. //MARK: 打开文件
  37. @objc static func currentFirstTrialWC() -> KMPurchaseFirstTrialWindowController {
  38. if currentWindowController != nil {
  39. return currentWindowController
  40. } else {
  41. let configWC: KMPurchaseFirstTrialWindowController = KMPurchaseFirstTrialWindowController.init(windowNibName: "KMPurchaseFirstTrialWindowController")
  42. currentWindowController = configWC;
  43. return currentWindowController
  44. }
  45. }
  46. deinit {
  47. DistributedNotificationCenter.default.removeObserver(self)
  48. NotificationCenter.default.removeObserver(self)
  49. }
  50. override func windowDidLoad() {
  51. super.windowDidLoad()
  52. DistributedNotificationCenter.default.addObserver(self, selector: #selector(themeChanged(_:)), name: NSNotification.Name(rawValue:"AppleInterfaceThemeChangedNotification"), object: nil)
  53. NotificationCenter.default.addObserver(self, selector: #selector(windowDidBecomeVisible(_:)), name: NSWindow.didBecomeKeyNotification, object: nil)
  54. self.window?.delegate = self
  55. self.activateTrialNowBtn.tag = 10001
  56. self.buyNowBtn.tag = 10002
  57. self.enterLicenseBtn.tag = 10003
  58. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  59. self.bottomTextView.delegate = self;
  60. self.titleField.wantsLayer = true
  61. self.titleField.alphaValue = 0.8
  62. self.imageView2.wantsLayer = true
  63. self.imageView2.alphaValue = 0.8
  64. self.imageView3.wantsLayer = true
  65. self.imageView3.alphaValue = 0.8
  66. self.imageView4.wantsLayer = true
  67. self.imageView4.alphaValue = 0.8
  68. self.imageView5.wantsLayer = true
  69. self.imageView5.alphaValue = 0.8
  70. self.imageView6.wantsLayer = true
  71. self.imageView6.alphaValue = 0.8
  72. self.imageView7.wantsLayer = true
  73. self.imageView7.alphaValue = 0.8
  74. self.features1Field.wantsLayer = true
  75. self.features1Field.alphaValue = 0.8
  76. self.features2Field.wantsLayer = true
  77. self.features2Field.alphaValue = 0.8
  78. self.features2Field.wantsLayer = true
  79. self.features2Field.alphaValue = 0.8
  80. self.features2Field.wantsLayer = true
  81. self.features2Field.alphaValue = 0.8
  82. self.features2Field.wantsLayer = true
  83. self.features2Field.alphaValue = 0.8
  84. self.features2Field.wantsLayer = true
  85. self.features2Field.alphaValue = 0.8
  86. self.reloadData()
  87. }
  88. @objc func reloadData () {
  89. self.titleField.stringValue = NSLocalizedString("Unlock All Advanced Features", comment: "")
  90. let customFont = NSFont(name: "Ubuntu Bold", size: 16)
  91. self.titleField.font = customFont
  92. self.trialTitleField.stringValue = "👋🏻 " + NSLocalizedString("7-day Free Trial", comment: "")
  93. self.trialTitleField.font = NSFont(name: "Ubuntu-Bold", size: 26)
  94. self.trialMessageField.stringValue = NSLocalizedString("Cisdem PDFMaster offers a 7-day free trial of the full functions.", comment: "")
  95. self.trialMessageField.font = NSFont(name: "SFProText-Regular", size: 14)
  96. self.features1Field.stringValue = NSLocalizedString("Edit PDF", comment: "")
  97. self.features2Field.stringValue = NSLocalizedString("Organize pages", comment: "")
  98. self.features3Field.stringValue = NSLocalizedString("Convert PDFs ", comment: "")
  99. self.features4Field.stringValue = NSLocalizedString("Digital signature", comment: "")
  100. self.features5Field.stringValue = NSLocalizedString("Create & fill form", comment: "")
  101. self.features6Field.stringValue = NSLocalizedString("OCR", comment: "")
  102. self.features1Field.font = NSFont(name: "SFProText-Regular", size: 13)
  103. self.features2Field.font = NSFont(name: "SFProText-Regular", size: 13)
  104. self.features3Field.font = NSFont(name: "SFProText-Regular", size: 13)
  105. self.features4Field.font = NSFont(name: "SFProText-Regular", size: 13)
  106. self.features5Field.font = NSFont(name: "SFProText-Regular", size: 13)
  107. self.features6Field.font = NSFont(name: "SFProText-Regular", size: 13)
  108. self.activateTrialNowBtn.title = NSLocalizedString("Apply", comment: "")
  109. self.activateTrialNowBtn.font = NSFont(name: "Ubuntu-Medium", size: 16)
  110. self.buyNowBtn.font = NSFont(name: "SFProText-semibold", size: 14)
  111. self.enterLicenseBtn.font = NSFont(name: "SFProText-semibold", size: 14)
  112. self.rView.wantsLayer = true
  113. self.rView.layer?.cornerRadius = 8
  114. self.rView.layer?.masksToBounds = true
  115. self.btnBox.wantsLayer = true
  116. self.btnBox.layer?.cornerRadius = 24
  117. self.updateViewColor()
  118. }
  119. //MARK: Noti
  120. @objc func themeChanged(_ notification: NSNotification) {
  121. DispatchQueue.main.async {
  122. self.reloadData()
  123. }
  124. }
  125. @objc func windowDidBecomeVisible(_ obj: Notification) {
  126. self.reloadData()
  127. }
  128. @objc func updateViewColor () {
  129. self.trialMessageField.textColor = KMAppearance.Layout.h0Color()
  130. self.features1Field.textColor = NSColor(red: 14.0/255.0, green: 17.0/255.0, blue: 20.0/255.0, alpha: 1)
  131. self.features2Field.textColor = NSColor(red: 14.0/255.0, green: 17.0/255.0, blue: 20.0/255.0, alpha: 1)
  132. self.features3Field.textColor = NSColor(red: 14.0/255.0, green: 17.0/255.0, blue: 20.0/255.0, alpha: 1)
  133. self.features4Field.textColor = NSColor(red: 14.0/255.0, green: 17.0/255.0, blue: 20.0/255.0, alpha: 1)
  134. self.features5Field.textColor = NSColor(red: 14.0/255.0, green: 17.0/255.0, blue: 20.0/255.0, alpha: 1)
  135. self.features6Field.textColor = NSColor(red: 14.0/255.0, green: 17.0/255.0, blue: 20.0/255.0, alpha: 1)
  136. if (KMAppearance.isDarkMode)() {
  137. self.rView.layer?.backgroundColor = NSColor(red: 24.0/255.0, green: 22.0/255.0, blue: 31.0/255.0, alpha: 0.9).cgColor
  138. self.activateTrialNowBtn.title = NSLocalizedString("Free Trial", comment: "")
  139. self.btnBox.fillColor = NSColor(red: 181.0/255.0, green: 177.0/255.0, blue: 239.0/255.0, alpha: 1)
  140. self.btnBox.layer?.backgroundColor = NSColor(red: 181.0/255.0, green: 177.0/255.0, blue: 239.0/255.0, alpha: 1).cgColor
  141. self.activateTrialNowBtn.layer?.backgroundColor = NSColor(red: 181.0/255.0, green: 177.0/255.0, blue: 239.0/255.0, alpha: 1).cgColor
  142. self.activateTrialNowBtn.setTitleColor(NSColor(red: 7.0/255.0, green: 1.0/255.0, blue: 34.0/255.0, alpha: 1))
  143. self.activateTrialNowBtn.mouseMoveCallback = {[unowned self] (mouseEntered) in
  144. if mouseEntered {
  145. self.activateTrialNowBtn.layer?.backgroundColor = NSColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1).cgColor
  146. self.btnBox.fillColor = NSColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1)
  147. self.btnBox.layer?.backgroundColor = NSColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1).cgColor
  148. } else {
  149. self.btnBox.fillColor = NSColor(red: 181.0/255.0, green: 177.0/255.0, blue: 239.0/255.0, alpha: 1)
  150. self.btnBox.layer?.backgroundColor = NSColor(red: 181.0/255.0, green: 177.0/255.0, blue: 239.0/255.0, alpha: 1).cgColor
  151. self.activateTrialNowBtn.layer?.backgroundColor = NSColor(red: 181.0/255.0, green: 177.0/255.0, blue: 239.0/255.0, alpha: 1).cgColor
  152. }
  153. }
  154. // self.activateTrialNowBtn.setBaseLineOffset(2)
  155. self.titleField.textColor = NSColor(red: 0.0/255.0, green: 33.0/255.0, blue: 67.0/255.0, alpha: 1)
  156. self.trialTitleField.textColor = NSColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1)
  157. self.buyNowBtn.title = NSLocalizedString("Buy Now", comment: "")
  158. self.buyNowBtn.setTitleColor(NSColor(red: 181.0/255.0, green: 177.0/255.0, blue: 239.0/255.0, alpha: 1))
  159. self.buyNowBtn.mouseMoveCallback = {[unowned self] (mouseEntered) in
  160. if mouseEntered {
  161. self.buyNowBtn.setTitleColor(NSColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1))
  162. } else {
  163. self.buyNowBtn.setTitleColor(NSColor(red: 181.0/255.0, green: 177.0/255.0, blue: 239.0/255.0, alpha: 1))
  164. }
  165. }
  166. self.enterLicenseBtn.title = NSLocalizedString("Enter License", comment: "")
  167. self.enterLicenseBtn.setTitleColor(NSColor(red: 181.0/255.0, green: 177.0/255.0, blue: 239.0/255.0, alpha: 1))
  168. self.enterLicenseBtn.mouseMoveCallback = {[unowned self] (mouseEntered) in
  169. if mouseEntered {
  170. self.enterLicenseBtn.setTitleColor(NSColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1))
  171. } else {
  172. self.enterLicenseBtn.setTitleColor(NSColor(red: 181.0/255.0, green: 177.0/255.0, blue: 239.0/255.0, alpha: 1))
  173. }
  174. }
  175. // let stringValue : String = NSLocalizedString("By applying for free trial, you confirm that you agree this Privacy Policy.", comment: "")
  176. // let attributedString: NSMutableAttributedString = NSMutableAttributedString(string: NSLocalizedString("By applying for free trial, you confirm that you agree this Privacy Policy.", comment: ""))
  177. // let privacyPolicy : String = NSLocalizedString("Privacy Policy.", comment: "")
  178. //
  179. // let allRange = (stringValue as NSString).range(of: stringValue)
  180. // attributedString.addAttributes([NSAttributedString.Key.foregroundColor : KMAppearance.Layout.w70Color()], range: allRange)
  181. // attributedString.addAttributes([NSAttributedString.Key.font :NSFont(name: "SFProText-Regular", size: 12.0) as Any], range: allRange)
  182. //
  183. // let urlString : String = "https://www.pdfreaderpro.com/privacy-policy"
  184. // let encodedURLString : String = urlString.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)!
  185. // let linkRange = (stringValue as NSString).range(of: privacyPolicy)
  186. // attributedString.addAttribute(.link, value: NSURL(string: encodedURLString)!, range: linkRange)
  187. // attributedString.addAttribute(.underlineStyle, value: NSUnderlineStyle.single.rawValue, range: linkRange)
  188. self.bottomTextView.linkTextAttributes = [
  189. NSAttributedString.Key.foregroundColor: KMAppearance.Interactive.a0Color(),
  190. NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue
  191. ]
  192. // self.bottomTextView.textStorage?.setAttributedString(attributedString)
  193. self.bottomTextView.isEditable = false // TextView不可编辑
  194. self.bottomTextView.isSelectable = true // TextView可选择
  195. self.bottomTextView.sizeToFit()
  196. } else {
  197. self.rView.layer?.backgroundColor = NSColor(red: 248.0/255.0, green: 249.0/255.0, blue: 255.0/255.0, alpha: 1).cgColor
  198. self.btnBox.fillColor = NSColor(red: 39.0/255.0, green: 60.0/255.0, blue: 98.0/255.0, alpha: 1)
  199. self.btnBox.layer?.backgroundColor = NSColor(red: 39.0/255.0, green: 60.0/255.0, blue: 98.0/255.0, alpha: 1).cgColor
  200. self.activateTrialNowBtn.layer?.backgroundColor = NSColor(red: 39.0/255.0, green: 60.0/255.0, blue: 98.0/255.0, alpha: 1).cgColor
  201. self.activateTrialNowBtn.setTitleColor(NSColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1))
  202. self.activateTrialNowBtn.mouseMoveCallback = {[unowned self] (mouseEntered) in
  203. if mouseEntered {
  204. self.activateTrialNowBtn.layer?.backgroundColor = NSColor(red: 0.0/255.0, green: 207.0/255.0, blue: 133.0/255.0, alpha: 1).cgColor
  205. self.btnBox.fillColor = NSColor(red: 0.0/255.0, green: 207.0/255.0, blue: 133.0/255.0, alpha: 1)
  206. self.btnBox.layer?.backgroundColor = NSColor(red: 0.0/255.0, green: 207.0/255.0, blue: 133.0/255.0, alpha: 1).cgColor
  207. } else {
  208. self.activateTrialNowBtn.layer?.backgroundColor = NSColor(red: 39.0/255.0, green: 60.0/255.0, blue: 98.0/255.0, alpha: 1).cgColor
  209. self.btnBox.fillColor = NSColor(red: 39.0/255.0, green: 60.0/255.0, blue: 98.0/255.0, alpha: 1)
  210. self.btnBox.layer?.backgroundColor = NSColor(red: 39.0/255.0, green: 60.0/255.0, blue: 98.0/255.0, alpha: 1).cgColor
  211. }
  212. }
  213. self.titleField.textColor = NSColor(red: 0.0/255.0, green: 33.0/255.0, blue: 67.0/255.0, alpha: 1)
  214. self.trialTitleField.textColor = NSColor(red: 0.0/255.0, green: 33.0/255.0, blue: 67.0/255.0, alpha: 1)
  215. self.buyNowBtn.title = NSLocalizedString("Buy Now", comment: "")
  216. self.buyNowBtn.setTitleColor(NSColor(red: 39.0/255.0, green: 60.0/255.0, blue: 98.0/255.0, alpha: 1))
  217. self.buyNowBtn.mouseMoveCallback = {[unowned self] (mouseEntered) in
  218. if mouseEntered {
  219. self.buyNowBtn.setTitleColor(NSColor(red: 8.0/255.0, green: 124.0/255.0, blue: 255.0/255.0, alpha: 1))
  220. } else {
  221. self.buyNowBtn.setTitleColor(NSColor(red: 39.0/255.0, green: 60.0/255.0, blue: 98.0/255.0, alpha: 1))
  222. }
  223. }
  224. self.enterLicenseBtn.title = NSLocalizedString("Enter License", comment: "")
  225. self.enterLicenseBtn.setTitleColor(NSColor(red: 39.0/255.0, green: 60.0/255.0, blue: 98.0/255.0, alpha: 1))
  226. self.enterLicenseBtn.mouseMoveCallback = {[unowned self] (mouseEntered) in
  227. if mouseEntered {
  228. self.enterLicenseBtn.setTitleColor(NSColor(red: 8.0/255.0, green: 124.0/255.0, blue: 255.0/255.0, alpha: 1))
  229. } else {
  230. self.enterLicenseBtn.setTitleColor(NSColor(red: 39.0/255.0, green: 60.0/255.0, blue: 98.0/255.0, alpha: 1))
  231. }
  232. }
  233. // let stringValue : String = NSLocalizedString("By applying for free trial, you confirm that you agree this Privacy Policy.", comment: "")
  234. // let attributedString: NSMutableAttributedString = NSMutableAttributedString(string: NSLocalizedString("By applying for free trial, you confirm that you agree this Privacy Policy.", comment: ""))
  235. // let privacyPolicy : String = NSLocalizedString("Privacy Policy.", comment: "")
  236. //
  237. // let urlString : String = "https://www.pdfreaderpro.com/privacy-policy"
  238. // let encodedURLString : String = urlString.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)!
  239. // let linkRange = (stringValue as NSString).range(of: privacyPolicy)
  240. // attributedString.addAttribute(NSAttributedString.Key.link, value: NSURL(string: encodedURLString)!, range: linkRange)
  241. // attributedString.addAttribute(NSAttributedString.Key.underlineStyle, value: NSUnderlineStyle.single.rawValue, range: linkRange)
  242. //
  243. // let allRange = (stringValue as NSString).range(of: stringValue)
  244. // attributedString.addAttributes([NSAttributedString.Key.foregroundColor : KMAppearance.Layout.h1Color()], range: allRange)
  245. // attributedString.addAttributes([NSAttributedString.Key.font :NSFont(name: "SFProText-Regular", size: 12.0) as Any], range: allRange)
  246. // 设置悬停时链接文本颜色
  247. // let hoverColor = NSColor.blue
  248. // attributedString.addAttribute(NSAttributedString.Key(rawValue: "NSMouseInRectAttribute"), value: hoverColor, range: linkRange)
  249. // 设置TextView的富文本属性
  250. self.bottomTextView.linkTextAttributes = [
  251. NSAttributedString.Key.foregroundColor: KMAppearance.Interactive.a0Color(),
  252. NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue
  253. ]
  254. // self.bottomTextView.textStorage?.setAttributedString(attributedString)
  255. self.bottomTextView.isEditable = false // TextView不可编辑
  256. self.bottomTextView.isSelectable = true // TextView可选择
  257. self.bottomTextView.sizeToFit()
  258. }
  259. self.buyNowBtn.sizeToFit()
  260. self.enterLicenseBtn.sizeToFit()
  261. }
  262. func validateEmail(_ strEmail: String) -> Bool {
  263. let emailRegex = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"
  264. let emailTest: NSPredicate = NSPredicate(format: "SELF MATCHES %@", emailRegex)
  265. return emailTest.evaluate(with: strEmail)
  266. }
  267. //MARK: Btn Action
  268. @IBAction func activateTrialNowAction(_ sender: KMButton) {
  269. guard let callBack = self.buttonActionBlock else {
  270. return
  271. }
  272. callBack(self,sender, "", "")
  273. FMTrackEventManager.defaultManager.trackOnceEvent(event: "PUW", withProperties: ["PUW_Btn":"Btn_PUW_ActivateTrialNow"])
  274. }
  275. @IBAction func buyNowAction(_ sender: HyperLinkButton) {
  276. guard let callBack = self.buttonActionBlock else {
  277. return
  278. }
  279. callBack(self,sender, "", "")
  280. FMTrackEventManager.defaultManager.trackOnceEvent(event: "PUW", withProperties: ["PUW_Btn":"Btn_PUW_BuyNow"])
  281. }
  282. @IBAction func enterLicenseAction(_ sender: HyperLinkButton) {
  283. guard let callBack = self.buttonActionBlock else {
  284. return
  285. }
  286. callBack(self,sender, "", "")
  287. FMTrackEventManager.defaultManager.trackOnceEvent(event: "PUW", withProperties: ["PUW_Btn":"Btn_PUW_Enter_The_License"])
  288. }
  289. //MARK: NSTextFieldDelegate
  290. func controlTextDidChange(_ obj: Notification) {
  291. if obj.object == nil {
  292. return
  293. }
  294. let textField = obj.object as! NSTextField
  295. }
  296. func controlTextDidEndEditing(_ obj: Notification) {
  297. let fied: NSTextField = obj.object as! NSTextField;
  298. }
  299. func textView(_ textView: NSTextView, clickedOnLink link: Any, at charIndex: Int) -> Bool {
  300. guard let url = link as? URL else {
  301. return false
  302. }
  303. NSWorkspace.shared.open(url)
  304. return true
  305. }
  306. func windowWillClose(_ notification: Notification) {
  307. KMPurchaseFirstTrialWindowController.currentWindowController = nil
  308. }
  309. }