KMWelcomeWindowController.swift 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. //
  2. // KMWelcomeWindowController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/10/10.
  6. //
  7. import Cocoa
  8. private let kKMWelcomeHasShowKey = "WelcomeHasShowKey"
  9. private let kKMWelcomeRemindMeLaterKey = "WelcomeRemindMeLaterKey"
  10. typealias KMWelcomeWindowC = KMWelcomeWindowController
  11. extension KMWelcomeWindowController.Key {
  12. public static let hasShow = kKMWelcomeHasShowKey
  13. public static let remindMeLater = kKMWelcomeRemindMeLaterKey
  14. }
  15. class KMWelcomeWindowController: NSWindowController {
  16. @IBOutlet weak var scrollView: NSScrollView!
  17. @IBOutlet weak var content1View: NSView!
  18. @IBOutlet weak var content2View: NSView!
  19. @IBOutlet weak var content3View: NSView!
  20. @IBOutlet weak var content4View: NSView!
  21. @IBOutlet weak var content5View: NSView!
  22. @IBOutlet weak var content6View: NSView!
  23. @IBOutlet weak var imageView1: NSImageView!
  24. @IBOutlet weak var imageView2: NSImageView!
  25. @IBOutlet weak var imageView3: NSImageView!
  26. @IBOutlet weak var imageView4: NSImageView!
  27. @IBOutlet weak var imageView6: NSImageView!
  28. @IBOutlet weak var imageView5: NSImageView!
  29. @IBOutlet weak var title1Label: NSTextField!
  30. @IBOutlet weak var subtitle1Label: NSTextField!
  31. @IBOutlet weak var title2Label: NSTextField!
  32. @IBOutlet weak var subtitle2Label: NSTextField!
  33. @IBOutlet weak var title3Label: NSTextField!
  34. @IBOutlet weak var subtitle3Label: NSTextField!
  35. @IBOutlet weak var title4Label: NSTextField!
  36. @IBOutlet weak var subtitle4Label: NSTextField!
  37. @IBOutlet weak var title5Label: NSTextField!
  38. @IBOutlet weak var subtitle5Label: NSTextField!
  39. @IBOutlet weak var title6Label: NSTextField!
  40. @IBOutlet weak var subtitle6Label: NSTextField!
  41. @IBOutlet weak var preBox: NSBox!
  42. @IBOutlet weak var nextBox: NSBox!
  43. private var _preButtonVC: KMDesignButton?
  44. var preButtonVC: KMDesignButton? {
  45. get {
  46. return self._preButtonVC
  47. }
  48. }
  49. private var _nextButtonVC: KMDesignButton?
  50. var nextButtonVC: KMDesignButton? {
  51. get {
  52. return self._nextButtonVC
  53. }
  54. }
  55. @IBOutlet weak var next1Box: NSBox!
  56. @IBOutlet weak var remindMeLaterBox: NSBox!
  57. @IBOutlet weak var next2Box: NSBox!
  58. @IBOutlet weak var next3Box: NSBox!
  59. @IBOutlet weak var next4Box: NSBox!
  60. @IBOutlet weak var next5Box: NSBox!
  61. @IBOutlet weak var signUpBox: NSBox!
  62. private var _next1ButtonVC: KMDesignButton?
  63. private var _remindMeLaterButtonVC: KMDesignButton?
  64. private var _next2ButtonVC: KMDesignButton?
  65. private var _next3ButtonVC: KMDesignButton?
  66. private var _next4ButtonVC: KMDesignButton?
  67. private var _signUpButtonVC: KMDesignButton?
  68. @IBOutlet weak var pageIndicator1: KMPageIndicator!
  69. @IBOutlet weak var pageIndicator2: KMPageIndicator!
  70. @IBOutlet weak var pageIndicator3: KMPageIndicator!
  71. @IBOutlet weak var pageIndicator4: KMPageIndicator!
  72. @IBOutlet weak var pageIndicator5: KMPageIndicator!
  73. @IBOutlet weak var pageIndicator6: KMPageIndicator!
  74. @IBOutlet weak var closeButton: NSButton!
  75. @IBOutlet weak var closeBox: KMBox!
  76. private var _contentViews: [NSView] = []
  77. var contentViews: [NSView] {
  78. get {
  79. return self._contentViews
  80. }
  81. }
  82. private var _currentIndex: Int = 0
  83. var itemClick: KMCommonClickBlock?
  84. public struct Key {}
  85. deinit {
  86. Swift.debugPrint("WelcomeWindowController 已释放")
  87. }
  88. convenience init() {
  89. self.init(windowNibName: "WelcomeWindowController")
  90. // 处理再次提醒
  91. if (UserDefaults.standard.bool(forKey: KMWelcomeWindowC.Key.remindMeLater)) {
  92. UserDefaults.standard.set(false, forKey: KMWelcomeWindowC.Key.remindMeLater)
  93. UserDefaults.standard.set(false, forKey: KMWelcomeWindowC.Key.hasShow)
  94. UserDefaults.standard.synchronize()
  95. }
  96. }
  97. override func awakeFromNib() {
  98. super.awakeFromNib()
  99. let clipView = self.scrollView.contentView
  100. // ,self.content4View
  101. self._contentViews = [self.content1View, self.content2View, self.content3View, self.content4View, self.content6View, self.content5View]
  102. for i in 0 ..< self.contentViews.count {
  103. let view = self.contentViews[i]
  104. view.frame = NSMakeRect(i.cgFloat*clipView.bounds.size.width, 0, clipView.bounds.size.width, clipView.bounds.size.height)
  105. self.scrollView.documentView?.addSubview(view)
  106. }
  107. self.scrollView.documentView?.frame = NSMakeRect(0, 0, clipView.bounds.size.width*self.contentViews.count.cgFloat, clipView.bounds.size.height)
  108. }
  109. override func windowDidLoad() {
  110. super.windowDidLoad()
  111. self._localizedString()
  112. self.initSubViews()
  113. self.setupUI()
  114. self._reloadData()
  115. // 设置【显示】标识
  116. UserDefaults.standard.set(true, forKey: KMWelcomeWindowC.Key.hasShow)
  117. UserDefaults.standard.synchronize()
  118. }
  119. func initSubViews() {
  120. self.preBox.borderType = .noBorder
  121. self._preButtonVC = KMDesignButton(withType: .Image)
  122. self.preBox.contentView?.addSubview(self.preButtonVC!.view)
  123. self.preButtonVC?.view.frame = self.preBox.contentView!.bounds
  124. self.preButtonVC?.view.autoresizingMask = [.width, .height]
  125. self.preButtonVC?.image = NSImage(named: "KMImageNamePreviousPageImage")!
  126. self.preButtonVC?.pagination()
  127. self.preButtonVC?.target = self
  128. self.preButtonVC?.action = #selector(_previousButtonAction)
  129. self.nextBox.borderType = .noBorder;
  130. self._nextButtonVC = KMDesignButton(withType: .Image)
  131. self.nextBox.contentView?.addSubview(self.nextButtonVC!.view)
  132. self.nextButtonVC?.view.frame = self.nextBox.contentView!.bounds
  133. self.nextButtonVC?.view.autoresizingMask = [.width, .height]
  134. self.nextButtonVC?.image = NSImage(named: "KMImageNameNextPageImage")!
  135. self.nextButtonVC?.pagination()
  136. self.nextButtonVC?.target = self
  137. self.nextButtonVC?.action = #selector(_nextButtonAction)
  138. for box in [self.next1Box, self.next2Box, self.next3Box, self.next4Box, self.next5Box] {
  139. box!.borderType = .noBorder
  140. let nextButtonVC = KMDesignButton(withType: .Text)
  141. box?.contentView?.addSubview(nextButtonVC.view)
  142. nextButtonVC.view.frame = box?.contentView?.bounds ?? NSZeroRect
  143. nextButtonVC.view.autoresizingMask = [.width, .height]
  144. nextButtonVC.target = self
  145. nextButtonVC.action = #selector(_signUpButtonAction)
  146. nextButtonVC.button(type: .Cta, size: .l)
  147. if (box!.isEqual(to: self.next1Box)) {
  148. self._next1ButtonVC = nextButtonVC
  149. } else if (box!.isEqual(to: self.next2Box)) {
  150. self._next2ButtonVC = nextButtonVC
  151. } else if (box!.isEqual(to: self.next3Box)) {
  152. self._next3ButtonVC = nextButtonVC
  153. } else if (box!.isEqual(to: self.next4Box)) {
  154. self._next4ButtonVC = nextButtonVC
  155. } else if (box!.isEqual(to: self.next5Box)) {
  156. // self.next5
  157. }
  158. }
  159. self.remindMeLaterBox.borderType = .noBorder
  160. self._remindMeLaterButtonVC = KMDesignButton(withType: .Text)
  161. self.remindMeLaterBox.contentView?.addSubview(self._remindMeLaterButtonVC!.view)
  162. self._remindMeLaterButtonVC?.view.frame = self.remindMeLaterBox.contentView!.bounds
  163. self._remindMeLaterButtonVC?.view.autoresizingMask = [.width, .height]
  164. self._remindMeLaterButtonVC?.stringValue = KMLocalizedString("Remind Me Later")
  165. self._remindMeLaterButtonVC?.target = self
  166. self._remindMeLaterButtonVC?.action = #selector(_remindMeLaterButtonAction)
  167. self._remindMeLaterButtonVC?.button(type: .Text, size: .m)
  168. self.signUpBox.borderType = .noBorder
  169. self._signUpButtonVC = KMDesignButton(withType: .Text)
  170. self.signUpBox.contentView?.addSubview(self._signUpButtonVC!.view)
  171. self._signUpButtonVC?.view.frame = self.signUpBox.contentView!.bounds
  172. self._signUpButtonVC?.view.autoresizingMask = [.width, .height]
  173. self._signUpButtonVC?.target = self;
  174. self._signUpButtonVC?.action = #selector(_signUpButtonAction)
  175. self._signUpButtonVC?.button(type: .Cta, size: .l)
  176. // , self.pageIndicator5
  177. for pageindicator in [self.pageIndicator1, self.pageIndicator2, self.pageIndicator3, self.pageIndicator4, self.pageIndicator5, self.pageIndicator6] {
  178. pageindicator?.numberOfPages = 6
  179. pageindicator?.selectedColor = NSColor(red: 39.0/255.0, green: 60.0/255.0, blue: 98.0/255.0, alpha: 1)
  180. pageindicator?.normalColor = NSColor(red: 0, green: 0, blue: 0, alpha: 0.2)
  181. pageindicator?.pageIndicatorSize = NSMakeSize(6, 6)
  182. pageindicator?.enabled = false
  183. if (pageindicator!.isEqual(to: self.pageIndicator1)) {
  184. pageindicator?.currentPage = 0
  185. } else if (pageindicator!.isEqual(to: self.pageIndicator2)) {
  186. pageindicator?.currentPage = 1
  187. } else if (pageindicator!.isEqual(to: self.pageIndicator3)) {
  188. pageindicator?.currentPage = 2
  189. } else if (pageindicator!.isEqual(to: self.pageIndicator4)) {
  190. pageindicator?.currentPage = 3
  191. } else if (pageindicator!.isEqual(to: self.pageIndicator5)) {
  192. pageindicator?.currentPage = 5
  193. } else if (pageindicator!.isEqual(to: self.pageIndicator6)) {
  194. pageindicator?.currentPage = 4
  195. }
  196. }
  197. self.closeBox.moveCallback = { [weak self] mouseEntered, mouseBox in
  198. if (mouseEntered) {
  199. self?.closeButton.image = NSImage(named: "control_btn_icon_close_hov")
  200. } else {
  201. self?.closeButton.image = NSImage(named: "control_btn_icon_close")
  202. }
  203. }
  204. for view in self.contentViews {
  205. let label = NSTextField(labelWithString: KMLocalizedString("Sign up to Unlock Premium Features"))
  206. view.addSubview(label)
  207. label.frame = NSMakeRect(0, 14, NSWidth(view.frame), 18)
  208. label.alignment = .center
  209. label.font = NSFont(name: "SFProText-Regular", size: 14)
  210. label.textColor = NSColor(red: 23.0/255.0, green: 112.0/255.0, blue: 244.0/255.0, alpha: 1)
  211. label.isHidden = false
  212. }
  213. self.remindMeLaterBox.isHidden = true
  214. }
  215. func setupUI() {
  216. for titleLabel in [self.title1Label, self.title2Label, self.title3Label,
  217. self.title4Label, self.title6Label, self.title5Label] {
  218. titleLabel?.font = .SFProTextSemiboldFont(20)
  219. titleLabel?.textColor = NSColor(red: 37.0/255.0, green: 38.0/255.0, blue: 41.0/255.0, alpha:1)
  220. }
  221. let ps = NSMutableParagraphStyle()
  222. ps.lineSpacing = 6
  223. ps.alignment = .center
  224. for subtitleLabel in [self.subtitle1Label, self.subtitle2Label, self.subtitle3Label,
  225. self.subtitle4Label, self.subtitle6Label, self.subtitle5Label] {
  226. subtitleLabel?.attributedStringValue = NSAttributedString(string: subtitleLabel!.stringValue, attributes: [.font : NSFont.SFProTextRegularFont(14),
  227. .foregroundColor : NSColor(red: 97.0/255.0, green: 100.0/255.0, blue: 105.0/255.0, alpha: 1),
  228. .paragraphStyle : ps])
  229. }
  230. }
  231. @IBAction func closeAction(_ sender: Any) {
  232. self._closeAction()
  233. }
  234. // MARK: - Private Methods
  235. private func _localizedString() {
  236. self.imageView1.image = NSImage(named: "KMImageNameWelcome1")
  237. self.imageView2.image = NSImage(named: "KMImageNameWelcome2")
  238. self.imageView3.image = NSImage(named: "KMImageNameWelcomeAnnotation")
  239. self.imageView4.image = NSImage(named: "KMImageNameWelcomeEdit")
  240. self.imageView5.image = NSImage(named: "KMImageNameWelcomePageEdit")
  241. self.imageView6.image = NSImage(named: "KMImageNameWelcomeConvert")
  242. self.title1Label.stringValue = KMLocalizedString("The Brand New PDF Reader Pro")
  243. 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")
  244. self.title2Label.stringValue = KMLocalizedString("Process PDF Document wit AI Robot")
  245. 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.")
  246. self.title3Label.stringValue = KMLocalizedString("Comment PDFs with Rich Annotation Tools")
  247. self.subtitle3Label.stringValue = KMLocalizedString("Add highlights, freehand, text, stamps, links, shapes, and notes to your documents. Easily mark up your PDFs anytime!")
  248. self.title4Label.stringValue = KMLocalizedString("Edit Original Text and Images Like Word")
  249. 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.")
  250. self.title6Label.stringValue = KMLocalizedString("Organize PDF Pages with Ease")
  251. self.subtitle6Label.stringValue = KMLocalizedString("Drag and drop page thumbnails to rearrange pages. Or easily delete, insert, rotate, split pages.")
  252. self.title5Label.stringValue = KMLocalizedString("Convert PDF to Office Fast and Easily")
  253. self.subtitle5Label.stringValue = KMLocalizedString("Convert PDF to editable Word, Excel, PPT, Text and image with all your fonts and formatting preserved.")
  254. }
  255. @objc private func _previousButtonAction() {
  256. if (self._currentIndex <= 0) {
  257. return
  258. }
  259. self._currentIndex -= 1
  260. NSAnimationContext.beginGrouping()
  261. let clipView = self.scrollView.contentView
  262. var newOrigin = clipView.bounds.origin
  263. newOrigin.x = clipView.bounds.size.width*self._currentIndex.cgFloat
  264. clipView.animator().setBoundsOrigin(newOrigin)
  265. NSAnimationContext.endGrouping()
  266. self._reloadData()
  267. }
  268. @objc private func _nextButtonAction() {
  269. if (self._currentIndex >= self.contentViews.count-1) {
  270. return
  271. }
  272. self._currentIndex += 1
  273. NSAnimationContext.beginGrouping()
  274. let clipView = self.scrollView.contentView
  275. var newOrigin = clipView.bounds.origin
  276. newOrigin.x = clipView.bounds.size.width*self._currentIndex.cgFloat
  277. clipView.animator().setBoundsOrigin(newOrigin)
  278. NSAnimationContext.endGrouping()
  279. self._reloadData()
  280. }
  281. @objc private func _signUpButtonAction() {
  282. }
  283. private func _closeAction() {
  284. if let callback = self.itemClick {
  285. callback(1, self)
  286. }
  287. self.close()
  288. }
  289. @objc private func _remindMeLaterButtonAction() {
  290. UserDefaults.standard.set(true, forKey: KMWelcomeWindowC.Key.remindMeLater)
  291. UserDefaults.standard.synchronize()
  292. if let callback = self.itemClick {
  293. callback(2, self)
  294. }
  295. self.close()
  296. }
  297. private func _reloadData() {
  298. self.preBox.isHidden = false
  299. self.nextBox.isHidden = false
  300. if (self._currentIndex == 0) {
  301. self.preBox.isHidden = true
  302. } else if (self._currentIndex == 1) {
  303. } else if (self._currentIndex == 2) {
  304. // self.nextBox.hidden = YES;
  305. } else if (self._currentIndex == 3) {
  306. } else if (self._currentIndex == 4){
  307. } else if (self._currentIndex == 5) {
  308. self.nextBox.isHidden = true
  309. }
  310. }
  311. class func welcomeHasShow() -> Bool {
  312. return UserDefaults.standard.bool(forKey: KMWelcomeWindowC.Key.hasShow)
  313. }
  314. }