KMWelcomeWindowController.swift 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. //
  2. // KMWelcomeWindowController.swift
  3. // PDF Master
  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 = CGRectMake(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 = CGRectMake(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 = { [unowned 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. // if ([subtitleLabel isEqual:self.subtitle1Label]) {
  243. // NSMutableParagraphStyle *ps_ = [[NSMutableParagraphStyle alloc] init];
  244. // ps_.lineSpacing = 6;
  245. // ps_.alignment = NSTextAlignmentCenter;
  246. // subtitleLabel.attributedStringValue = [[NSAttributedString alloc] initWithString:subtitleLabel.stringValue attributes:@{
  247. // NSFontAttributeName : [NSFont fontWithName:@"SFProText-Regular" size:14],
  248. // NSForegroundColorAttributeName : [NSColor colorWithRed:97/255.f green:100/255.f blue:105/255.f alpha:1.f],
  249. // NSParagraphStyleAttributeName : ps_
  250. // }];
  251. // } else {
  252. subtitleLabel?.attributedStringValue = NSAttributedString(string: subtitleLabel!.stringValue, attributes: [.font : NSFont.SFProTextRegularFont(14),
  253. .foregroundColor : NSColor(red: 97.0/255.0, green: 100.0/255.0, blue: 105.0/255.0, alpha: 1),
  254. .paragraphStyle : ps])
  255. // }
  256. }
  257. }
  258. @IBAction func closeAction(_ sender: Any) {
  259. self._closeAction()
  260. }
  261. // MARK: - Private Methods
  262. private func _localizedString() {
  263. self.imageView1.image = NSImage(named: "KMImageNameWelcome1")
  264. self.imageView2.image = NSImage(named: "KMImageNameWelcome2")
  265. self.imageView3.image = NSImage(named: "KMImageNameWelcomeAnnotation")
  266. self.imageView4.image = NSImage(named: "KMImageNameWelcomeEdit")
  267. self.imageView5.image = NSImage(named: "KMImageNameWelcomePageEdit")
  268. self.imageView6.image = NSImage(named: "KMImageNameWelcomeConvert")
  269. self.title1Label.stringValue = KMLocalizedString("The Brand New PDF Master", nil)
  270. self.subtitle1Label.stringValue = KMLocalizedString("PDF Master Invites You to Enjoy All Advanced Features! Use the new powerful software integrated with AI technology to edit your PDFs", nil)
  271. self.title2Label.stringValue = KMLocalizedString("Process PDF Document wit AI Robot", nil)
  272. 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)
  273. self.title3Label.stringValue = KMLocalizedString("Comment PDFs with Rich Annotation Tools", nil)
  274. self.subtitle3Label.stringValue = KMLocalizedString("Add highlights, freehand, text, stamps, links, shapes, and notes to your documents. Easily mark up your PDFs anytime!", nil)
  275. self.title4Label.stringValue = KMLocalizedString("Edit Original Text and Images Like Word", nil)
  276. 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)
  277. self.title6Label.stringValue = KMLocalizedString("Organize PDF Pages with Ease", nil)
  278. self.subtitle6Label.stringValue = KMLocalizedString("Drag and drop page thumbnails to rearrange pages. Or easily delete, insert, rotate, split pages.", nil)
  279. self.title5Label.stringValue = KMLocalizedString("Convert PDF to Office Fast and Easily", nil)
  280. self.subtitle5Label.stringValue = KMLocalizedString("Convert PDF to editable Word, Excel, PPT, Text and image with all your fonts and formatting preserved.", nil)
  281. }
  282. @objc private func _previousButtonAction() {
  283. if (self._currentIndex <= 0) {
  284. return
  285. }
  286. self._currentIndex -= 1
  287. NSAnimationContext.beginGrouping()
  288. let clipView = self.scrollView.contentView
  289. var newOrigin = clipView.bounds.origin
  290. newOrigin.x = clipView.bounds.size.width*self._currentIndex.cgFloat
  291. clipView.animator().setBoundsOrigin(newOrigin)
  292. NSAnimationContext.endGrouping()
  293. self._reloadData()
  294. }
  295. @objc private func _nextButtonAction() {
  296. if (self._currentIndex >= self.contentViews.count-1) {
  297. return
  298. }
  299. self._currentIndex += 1
  300. NSAnimationContext.beginGrouping()
  301. let clipView = self.scrollView.contentView
  302. var newOrigin = clipView.bounds.origin
  303. newOrigin.x = clipView.bounds.size.width*self._currentIndex.cgFloat
  304. clipView.animator().setBoundsOrigin(newOrigin)
  305. NSAnimationContext.endGrouping()
  306. self._reloadData()
  307. }
  308. @objc private func _signUpButtonAction() {
  309. if (KMLightMemberManager.manager.isLogin()) {
  310. self._closeAction()
  311. } else {
  312. if let callback = self.itemClick {
  313. callback(3, self)
  314. }
  315. self.close()
  316. }
  317. }
  318. private func _closeAction() {
  319. if let callback = self.itemClick {
  320. callback(1, self)
  321. }
  322. self.close()
  323. }
  324. @objc private func _remindMeLaterButtonAction() {
  325. UserDefaults.standard.set(true, forKey: KMWelcomeWindowC.Key.remindMeLater)
  326. UserDefaults.standard.synchronize()
  327. if let callback = self.itemClick {
  328. callback(2, self)
  329. }
  330. self.close()
  331. }
  332. private func _reloadData() {
  333. self.preBox.isHidden = false
  334. self.nextBox.isHidden = false
  335. if (self._currentIndex == 0) {
  336. self.preBox.isHidden = true
  337. } else if (self._currentIndex == 1) {
  338. } else if (self._currentIndex == 2) {
  339. // self.nextBox.hidden = YES;
  340. } else if (self._currentIndex == 3) {
  341. } else if (self._currentIndex == 4){
  342. } else if (self._currentIndex == 5) {
  343. self.nextBox.isHidden = true
  344. }
  345. }
  346. class func welcomeHasShow() -> Bool {
  347. return UserDefaults.standard.bool(forKey: KMWelcomeWindowC.Key.hasShow)
  348. }
  349. }