KMWelcomeWindowController.swift 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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.stringValue = NSLocalizedString(@"Next", nil);
  145. if (KMLightMemberManager.manager.isLogin()) { // let’s start
  146. nextButtonVC.stringValue = KMLocalizedString("Let's Start", nil)
  147. } else {
  148. nextButtonVC.stringValue = KMLocalizedString("Sign up", nil)
  149. }
  150. nextButtonVC.target = self
  151. // nextButtonVC.action = @selector(nextButtonAction:);
  152. nextButtonVC.action = #selector(_signUpButtonAction)
  153. nextButtonVC.button(type: .Cta, size: .l)
  154. if (box!.isEqual(to: self.next1Box)) {
  155. self._next1ButtonVC = nextButtonVC
  156. } else if (box!.isEqual(to: self.next2Box)) {
  157. self._next2ButtonVC = nextButtonVC
  158. } else if (box!.isEqual(to: self.next3Box)) {
  159. self._next3ButtonVC = nextButtonVC
  160. } else if (box!.isEqual(to: self.next4Box)) {
  161. self._next4ButtonVC = nextButtonVC
  162. } else if (box!.isEqual(to: self.next5Box)) {
  163. // self.next5
  164. }
  165. }
  166. self.remindMeLaterBox.borderType = .noBorder
  167. self._remindMeLaterButtonVC = KMDesignButton(withType: .Text)
  168. self.remindMeLaterBox.contentView?.addSubview(self._remindMeLaterButtonVC!.view)
  169. self._remindMeLaterButtonVC?.view.frame = self.remindMeLaterBox.contentView!.bounds
  170. self._remindMeLaterButtonVC?.view.autoresizingMask = [.width, .height]
  171. self._remindMeLaterButtonVC?.stringValue = KMLocalizedString("Remind Me Later", nil)
  172. self._remindMeLaterButtonVC?.target = self
  173. self._remindMeLaterButtonVC?.action = #selector(_remindMeLaterButtonAction)
  174. self._remindMeLaterButtonVC?.button(type: .Text, size: .m)
  175. self.signUpBox.borderType = .noBorder
  176. self._signUpButtonVC = KMDesignButton(withType: .Text)
  177. self.signUpBox.contentView?.addSubview(self._signUpButtonVC!.view)
  178. self._signUpButtonVC?.view.frame = self.signUpBox.contentView!.bounds
  179. self._signUpButtonVC?.view.autoresizingMask = [.width, .height]
  180. if (KMLightMemberManager.manager.isLogin()) { // let’s start
  181. self._signUpButtonVC?.stringValue = KMLocalizedString("Let's Start", nil)
  182. } else {
  183. self._signUpButtonVC?.stringValue = KMLocalizedString("Sign up", nil)
  184. }
  185. self._signUpButtonVC?.target = self;
  186. self._signUpButtonVC?.action = #selector(_signUpButtonAction)
  187. self._signUpButtonVC?.button(type: .Cta, size: .l)
  188. // , self.pageIndicator5
  189. for pageindicator in [self.pageIndicator1, self.pageIndicator2, self.pageIndicator3, self.pageIndicator4, self.pageIndicator5, self.pageIndicator6] {
  190. pageindicator?.numberOfPages = 6
  191. pageindicator?.selectedColor = NSColor(red: 39.0/255.0, green: 60.0/255.0, blue: 98.0/255.0, alpha: 1)
  192. pageindicator?.normalColor = NSColor(red: 0, green: 0, blue: 0, alpha: 0.2)
  193. pageindicator?.pageIndicatorSize = NSMakeSize(6, 6)
  194. pageindicator?.enabled = false
  195. if (pageindicator!.isEqual(to: self.pageIndicator1)) {
  196. pageindicator?.currentPage = 0
  197. } else if (pageindicator!.isEqual(to: self.pageIndicator2)) {
  198. pageindicator?.currentPage = 1
  199. } else if (pageindicator!.isEqual(to: self.pageIndicator3)) {
  200. pageindicator?.currentPage = 2
  201. } else if (pageindicator!.isEqual(to: self.pageIndicator4)) {
  202. pageindicator?.currentPage = 3
  203. } else if (pageindicator!.isEqual(to: self.pageIndicator5)) {
  204. pageindicator?.currentPage = 5
  205. } else if (pageindicator!.isEqual(to: self.pageIndicator6)) {
  206. pageindicator?.currentPage = 4
  207. }
  208. }
  209. self.closeBox.moveCallback = { [weak self] mouseEntered, mouseBox in
  210. if (mouseEntered) {
  211. self?.closeButton.image = NSImage(named: "control_btn_icon_close_hov")
  212. } else {
  213. self?.closeButton.image = NSImage(named: "control_btn_icon_close")
  214. }
  215. }
  216. for view in self.contentViews {
  217. let label = NSTextField(labelWithString: KMLocalizedString("Sign up to Unlock Premium Features", nil))
  218. view.addSubview(label)
  219. label.frame = NSMakeRect(0, 14, NSWidth(view.frame), 18)
  220. label.alignment = .center
  221. label.font = NSFont(name: "SFProText-Regular", size: 14)
  222. label.textColor = NSColor(red: 23.0/255.0, green: 112.0/255.0, blue: 244.0/255.0, alpha: 1)
  223. if (KMLightMemberManager.manager.isLogin()) {
  224. label.isHidden = true
  225. } else {
  226. label.isHidden = false
  227. }
  228. }
  229. self.remindMeLaterBox.isHidden = true
  230. }
  231. func setupUI() {
  232. for titleLabel in [self.title1Label, self.title2Label, self.title3Label,
  233. self.title4Label, self.title6Label, self.title5Label] {
  234. titleLabel?.font = .SFProTextSemiboldFont(20)
  235. titleLabel?.textColor = NSColor(red: 37.0/255.0, green: 38.0/255.0, blue: 41.0/255.0, alpha:1)
  236. }
  237. let ps = NSMutableParagraphStyle()
  238. ps.lineSpacing = 6
  239. ps.alignment = .center
  240. for subtitleLabel in [self.subtitle1Label, self.subtitle2Label, self.subtitle3Label,
  241. self.subtitle4Label, self.subtitle6Label, self.subtitle5Label] {
  242. subtitleLabel?.attributedStringValue = NSAttributedString(string: subtitleLabel!.stringValue, attributes: [.font : NSFont.SFProTextRegularFont(14),
  243. .foregroundColor : NSColor(red: 97.0/255.0, green: 100.0/255.0, blue: 105.0/255.0, alpha: 1),
  244. .paragraphStyle : ps])
  245. }
  246. }
  247. @IBAction func closeAction(_ sender: Any) {
  248. self._closeAction()
  249. }
  250. // MARK: - Private Methods
  251. private func _localizedString() {
  252. self.imageView1.image = NSImage(named: "KMImageNameWelcome1")
  253. self.imageView2.image = NSImage(named: "KMImageNameWelcome2")
  254. self.imageView3.image = NSImage(named: "KMImageNameWelcomeAnnotation")
  255. self.imageView4.image = NSImage(named: "KMImageNameWelcomeEdit")
  256. self.imageView5.image = NSImage(named: "KMImageNameWelcomePageEdit")
  257. self.imageView6.image = NSImage(named: "KMImageNameWelcomeConvert")
  258. self.title1Label.stringValue = KMLocalizedString("The Brand New PDF Reader Pro", nil)
  259. 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", nil)
  260. self.title2Label.stringValue = KMLocalizedString("Process PDF Document wit AI Robot", nil)
  261. 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.", nil)
  262. self.title3Label.stringValue = KMLocalizedString("Comment PDFs with Rich Annotation Tools", nil)
  263. self.subtitle3Label.stringValue = KMLocalizedString("Add highlights, freehand, text, stamps, links, shapes, and notes to your documents. Easily mark up your PDFs anytime!", nil)
  264. self.title4Label.stringValue = KMLocalizedString("Edit Original Text and Images Like Word", nil)
  265. 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.", nil)
  266. self.title6Label.stringValue = KMLocalizedString("Organize PDF Pages with Ease", nil)
  267. self.subtitle6Label.stringValue = KMLocalizedString("Drag and drop page thumbnails to rearrange pages. Or easily delete, insert, rotate, split pages.", nil)
  268. self.title5Label.stringValue = KMLocalizedString("Convert PDF to Office Fast and Easily", nil)
  269. self.subtitle5Label.stringValue = KMLocalizedString("Convert PDF to editable Word, Excel, PPT, Text and image with all your fonts and formatting preserved.", nil)
  270. }
  271. @objc private func _previousButtonAction() {
  272. if (self._currentIndex <= 0) {
  273. return
  274. }
  275. self._currentIndex -= 1
  276. NSAnimationContext.beginGrouping()
  277. let clipView = self.scrollView.contentView
  278. var newOrigin = clipView.bounds.origin
  279. newOrigin.x = clipView.bounds.size.width*self._currentIndex.cgFloat
  280. clipView.animator().setBoundsOrigin(newOrigin)
  281. NSAnimationContext.endGrouping()
  282. self._reloadData()
  283. }
  284. @objc private func _nextButtonAction() {
  285. if (self._currentIndex >= self.contentViews.count-1) {
  286. return
  287. }
  288. self._currentIndex += 1
  289. NSAnimationContext.beginGrouping()
  290. let clipView = self.scrollView.contentView
  291. var newOrigin = clipView.bounds.origin
  292. newOrigin.x = clipView.bounds.size.width*self._currentIndex.cgFloat
  293. clipView.animator().setBoundsOrigin(newOrigin)
  294. NSAnimationContext.endGrouping()
  295. self._reloadData()
  296. }
  297. @objc private func _signUpButtonAction() {
  298. if (KMLightMemberManager.manager.isLogin()) {
  299. self._closeAction()
  300. } else {
  301. if let callback = self.itemClick {
  302. callback(3, self)
  303. }
  304. self.close()
  305. }
  306. }
  307. private func _closeAction() {
  308. if let callback = self.itemClick {
  309. callback(1, self)
  310. }
  311. self.close()
  312. }
  313. @objc private func _remindMeLaterButtonAction() {
  314. UserDefaults.standard.set(true, forKey: KMWelcomeWindowC.Key.remindMeLater)
  315. UserDefaults.standard.synchronize()
  316. if let callback = self.itemClick {
  317. callback(2, self)
  318. }
  319. self.close()
  320. }
  321. private func _reloadData() {
  322. self.preBox.isHidden = false
  323. self.nextBox.isHidden = false
  324. if (self._currentIndex == 0) {
  325. self.preBox.isHidden = true
  326. } else if (self._currentIndex == 1) {
  327. } else if (self._currentIndex == 2) {
  328. // self.nextBox.hidden = YES;
  329. } else if (self._currentIndex == 3) {
  330. } else if (self._currentIndex == 4){
  331. } else if (self._currentIndex == 5) {
  332. self.nextBox.isHidden = true
  333. }
  334. }
  335. class func welcomeHasShow() -> Bool {
  336. return UserDefaults.standard.bool(forKey: KMWelcomeWindowC.Key.hasShow)
  337. }
  338. }