KMGuideInfoWindowController.swift 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. //
  2. // KMGuideInfoWindowController.swift
  3. // Cisdem PDFMaster
  4. //
  5. // Created by Niehaoyu on 2023/12/5.
  6. //
  7. import Cocoa
  8. class KMGuideInfoWindowController: NSWindowController {
  9. @IBOutlet weak var contendBox: NSBox!
  10. @objc var coverView: KMGuideCoverView!
  11. @objc var openFileGuidePanel: KMOpenFileGuidePanel!
  12. @objc var openFileGuideProperty: KMOpenFileGuideProperty!
  13. @objc var openFileGuideToolbar: KMOpenFileGuideToolbar!
  14. @objc var openFileFunctionView: KMOpenFileFunctionView!
  15. @objc var convertGuideView: KMConvertGuideView!
  16. @objc var customColorGuideView: KMCustomColorGuideView!
  17. @objc var aiIconGuideView: KMAIIconGuideView!
  18. @objc var _type: KMGuideInfoType = .none
  19. @objc var openPanelRect: CGRect = .zero
  20. @objc var rightPanelRect: CGRect = .zero
  21. @objc var _digitalBoxRect: CGRect = .zero
  22. @objc var compareItemRect: CGRect = .zero
  23. @objc var purchaseHandle: ((_ view: KMGuideInfoWindowController)->Void)?
  24. @objc var normalGuideFinishHandle: ((_ view: KMGuideInfoWindowController)->Void)?
  25. @objc var finishHandle: ((_ view: KMGuideInfoWindowController, _ actionType: KMGuideActionType)->Void)?
  26. @objc var openFileToggleHandle: ((_ view: KMGuideInfoWindowController, _ infoType: KMGuideInfoType)->Void)?
  27. //MARK: Static Method
  28. @objc static func availableShow(_ type: KMGuideInfoType) -> Bool {
  29. if type == .openFileNormal {
  30. if (UserDefaults.standard.object(forKey: kKMGuideInfoOpenFileNormalKey) == nil) {
  31. return true
  32. }
  33. } else if type == .digitalSignGuide {
  34. if (UserDefaults.standard.object(forKey: kKMGuideInfoDigitalSignKey) == nil) {
  35. return true
  36. }
  37. } else if type == .pdfCompareGuide {
  38. if (UserDefaults.standard.object(forKey: kKMGuideInfoPDFCompareKey) == nil) {
  39. return true
  40. }
  41. } else if type == .convertGuide {
  42. if (UserDefaults.standard.object(forKey: kKMGuideInfoFileConvertKey) == nil) {
  43. return true
  44. }
  45. } else if type == .customColor {
  46. if (UserDefaults.standard.object(forKey: kKMGuideInfoCustomColorKey) == nil) {
  47. return true
  48. }
  49. } else if type == .aiTipIconInfo {
  50. if (UserDefaults.standard.object(forKey: kKMGuideInfoAITipIconViewKey) == nil) {
  51. return true
  52. }
  53. }
  54. return false
  55. }
  56. static func setDidShowFor(_ type: KMGuideInfoType) -> Void {
  57. if type == .openFileNormal {
  58. UserDefaults.standard.setValue("Show", forKey: kKMGuideInfoOpenFileNormalKey)
  59. UserDefaults.standard.synchronize()
  60. } else if type == .digitalSignGuide {
  61. UserDefaults.standard.setValue("Show", forKey: kKMGuideInfoDigitalSignKey)
  62. UserDefaults.standard.synchronize()
  63. } else if type == .pdfCompareGuide {
  64. UserDefaults.standard.setValue("Show", forKey: kKMGuideInfoPDFCompareKey)
  65. UserDefaults.standard.synchronize()
  66. } else if type == .convertGuide {
  67. UserDefaults.standard.setValue("Show", forKey: kKMGuideInfoFileConvertKey)
  68. UserDefaults.standard.synchronize()
  69. } else if type == .customColor {
  70. UserDefaults.standard.setValue("Show", forKey: kKMGuideInfoCustomColorKey)
  71. UserDefaults.standard.synchronize()
  72. } else if type == .aiTipIconInfo {
  73. UserDefaults.standard.setValue("Show", forKey: kKMGuideInfoAITipIconViewKey)
  74. UserDefaults.standard.synchronize()
  75. }
  76. }
  77. static var currentWindowController: KMGuideInfoWindowController!
  78. @objc static func currentWC() -> KMGuideInfoWindowController {
  79. if currentWindowController != nil {
  80. return currentWindowController
  81. } else {
  82. let guideInfoWC: KMGuideInfoWindowController = KMGuideInfoWindowController.init(windowNibName: "KMGuideInfoWindowController")
  83. currentWindowController = guideInfoWC;
  84. return guideInfoWC
  85. }
  86. }
  87. deinit {
  88. print("deinit Action")
  89. }
  90. //MARK: SystemMethod
  91. override func showWindow(_ sender: Any?) {
  92. super.showWindow(sender)
  93. self.show()
  94. }
  95. override func windowDidLoad() {
  96. super.windowDidLoad()
  97. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  98. self.window?.backgroundColor = NSColor.clear
  99. self.window?.contentView?.wantsLayer = true
  100. self.window?.contentView?.layer?.backgroundColor = NSColor.clear.cgColor;
  101. self.window?.isOpaque = false
  102. self.contendBox.fillColor = NSColor.clear
  103. self.coverView = KMGuideCoverView.createFromNib()
  104. self.coverView.frame = self.contendBox.bounds
  105. self.contendBox.contentView = self.coverView
  106. }
  107. //MARK: Setter
  108. @objc var type: KMGuideInfoType {
  109. set {
  110. _type = newValue;
  111. }
  112. get {
  113. return _type;
  114. }
  115. }
  116. @objc var digitalBoxRect: CGRect {
  117. set {
  118. _digitalBoxRect = newValue;
  119. }
  120. get {
  121. return _digitalBoxRect;
  122. }
  123. }
  124. //MARK: Public Method
  125. @objc func show() {
  126. if self.type == .openFileNormal {
  127. self.type = .openFileNormalPanel
  128. }
  129. self.loadGuideInfoView()
  130. }
  131. func clearViews() {
  132. let viewsArr = NSArray.init(array: self.coverView.subviews)
  133. for view in viewsArr {
  134. if view is KMOpenFileGuidePanel {
  135. (view as AnyObject).removeFromSuperview()
  136. } else if view is KMOpenFileGuideProperty {
  137. (view as AnyObject).removeFromSuperview()
  138. } else if view is KMOpenFileGuideToolbar {
  139. (view as AnyObject).removeFromSuperview()
  140. } else if view is KMOpenFileFunctionView {
  141. (view as AnyObject).removeFromSuperview()
  142. } else if view is KMConvertGuideView {
  143. (view as AnyObject).removeFromSuperview()
  144. } else if view is KMCustomColorGuideView {
  145. (view as AnyObject).removeFromSuperview()
  146. } else if view is KMAIIconGuideView {
  147. (view as AnyObject).removeFromSuperview()
  148. }
  149. }
  150. self.coverView.display()
  151. if self.window != nil {
  152. var rect = self.window?.frame
  153. rect?.size.width += 1
  154. self.window?.setFrame(rect!, display: true)
  155. }
  156. }
  157. func loadGuideInfoView() {
  158. DispatchQueue.main.async {
  159. self.clearViews()
  160. self.contendBox.contentView = self.coverView
  161. if self.type == .openFileNormalPanel {
  162. if self.openFileGuidePanel == nil {
  163. self.openFileGuidePanel = KMOpenFileGuidePanel.createFromNib()
  164. }
  165. self.openFileGuidePanel.frame = self.coverView.bounds
  166. self.openFileGuidePanel.autoresizingMask = [.width, .height]
  167. self.openFileGuidePanel.clickHandle = {[weak self] view, actionType in
  168. guard let self = self else { return }
  169. if actionType == .skip {
  170. //Skip->数字签名
  171. //Skip->
  172. guard let callBack = self.normalGuideFinishHandle else {
  173. return
  174. }
  175. callBack(self)
  176. if KMGuideInfoWindowController.availableShow(.digitalSignGuide) &&
  177. (CGRectGetWidth(self.window!.frame) > CGRectGetMinX(self.digitalBoxRect) + 260) &&
  178. CGRectGetMinX(self.digitalBoxRect) > 450 {
  179. self.type = .digitalSignGuide
  180. self.loadGuideInfoView()
  181. } else {
  182. guard let callBack = self.finishHandle else {
  183. return
  184. }
  185. callBack(self, .windowNewFinish)
  186. self.closeAction()
  187. }
  188. } else if actionType == .next {
  189. //Next
  190. self.type = .openFileNormalProperty
  191. self.loadGuideInfoView()
  192. // guard let callBack = self.openFileToggleHandle else {
  193. // return
  194. // }
  195. // callBack(self, .openFileNormalProperty)
  196. // self.closeAction()
  197. }
  198. }
  199. self.openFileGuidePanel.circleRect = self.openPanelRect
  200. self.coverView.addSubview(self.openFileGuidePanel)
  201. self.openFileGuidePanel.updateViewColor()
  202. KMGuideInfoWindowController.setDidShowFor(.openFileNormal)//记录布局介绍
  203. } else if self.type == .openFileNormalProperty {
  204. guard let callBack = self.normalGuideFinishHandle else {
  205. return
  206. }
  207. callBack(self)
  208. if self.openFileGuideProperty == nil {
  209. self.openFileGuideProperty = KMOpenFileGuideProperty.createFromNib()
  210. }
  211. self.openFileGuideProperty.frame = self.coverView.bounds
  212. self.openFileGuideProperty.autoresizingMask = [.width, .height]
  213. self.openFileGuideProperty.clickHandle = {[weak self] view, actionType in
  214. guard let self = self else { return }
  215. if actionType == .skip {
  216. //Skip->数字签名
  217. //Skip->
  218. guard let callBack = self.normalGuideFinishHandle else {
  219. return
  220. }
  221. callBack(self)
  222. if KMGuideInfoWindowController.availableShow(.digitalSignGuide) &&
  223. (CGRectGetWidth(self.window!.frame) > CGRectGetMinX(self.digitalBoxRect) + 260) &&
  224. CGRectGetMinX(self.digitalBoxRect) > 450 {
  225. self.type = .digitalSignGuide
  226. self.loadGuideInfoView()
  227. } else {
  228. guard let callBack = self.finishHandle else {
  229. return
  230. }
  231. callBack(self, .windowNewFinish)
  232. self.closeAction()
  233. }
  234. } else if actionType == .previous {
  235. //Previous
  236. self.type = .openFileNormalPanel
  237. self.loadGuideInfoView()
  238. guard let callBack = self.normalGuideFinishHandle else {
  239. return
  240. }
  241. callBack(self)
  242. // guard let callBack = self.openFileToggleHandle else {
  243. // return
  244. // }
  245. // callBack(self, .openFileNormalPanel)
  246. // self.closeAction()
  247. } else if actionType == .next {
  248. //Next
  249. self.type = .openFileNormalToolbar
  250. self.loadGuideInfoView()
  251. // guard let callBack = self.openFileToggleHandle else {
  252. // return
  253. // }
  254. // callBack(self, .openFileNormalToolbar)
  255. // self.closeAction()
  256. }
  257. }
  258. self.openFileGuideProperty.circleRect = self.rightPanelRect
  259. self.coverView.addSubview(self.openFileGuideProperty)
  260. self.openFileGuideProperty.updateViewColor()
  261. } else if self.type == .openFileNormalToolbar {
  262. if self.openFileGuideToolbar == nil {
  263. self.openFileGuideToolbar = KMOpenFileGuideToolbar.createFromNib()
  264. }
  265. self.openFileGuideToolbar.frame = self.coverView.bounds
  266. self.openFileGuideToolbar.autoresizingMask = [.width, .height]
  267. self.openFileGuideToolbar.clickHandle = {[weak self] view, actionType in
  268. guard let self = self else { return }
  269. if actionType == .skip {
  270. //Skip->数字签名
  271. //Skip->
  272. guard let callBack = self.normalGuideFinishHandle else {
  273. return
  274. }
  275. callBack(self)
  276. if KMGuideInfoWindowController.availableShow(.digitalSignGuide) &&
  277. (CGRectGetWidth(self.window!.frame) > CGRectGetMinX(self.digitalBoxRect) + 260) &&
  278. CGRectGetMinX(self.digitalBoxRect) > 450 {
  279. self.type = .digitalSignGuide
  280. self.loadGuideInfoView()
  281. } else {
  282. guard let callBack = self.finishHandle else {
  283. return
  284. }
  285. callBack(self, .windowNewFinish)
  286. self.closeAction()
  287. }
  288. } else if actionType == .previous {
  289. //Next
  290. self.type = .openFileNormalProperty
  291. self.loadGuideInfoView()
  292. // guard let callBack = self.openFileToggleHandle else {
  293. // return
  294. // }
  295. // callBack(self, .openFileNormalProperty)
  296. // self.closeAction()
  297. } else if actionType == .finish {
  298. guard let callBack = self.normalGuideFinishHandle else {
  299. return
  300. }
  301. callBack(self)
  302. if KMGuideInfoWindowController.availableShow(.digitalSignGuide) &&
  303. (CGRectGetWidth(self.window!.frame) > CGRectGetMinX(self.digitalBoxRect) + 260) &&
  304. CGRectGetMinX(self.digitalBoxRect) > 450 {
  305. self.type = .digitalSignGuide
  306. self.loadGuideInfoView()
  307. } else {
  308. guard let callBack = self.finishHandle else {
  309. return
  310. }
  311. callBack(self, .windowNewFinish)
  312. self.closeAction()
  313. }
  314. }
  315. }
  316. self.coverView.addSubview(self.openFileGuideToolbar)
  317. } else if self.type == .digitalSignGuide || self.type == .pdfCompareGuide {
  318. if self.type == .digitalSignGuide {
  319. KMGuideInfoWindowController.setDidShowFor(.digitalSignGuide)//记录数字签名介绍
  320. } else if self.type == .pdfCompareGuide {
  321. KMGuideInfoWindowController.setDidShowFor(.pdfCompareGuide)//记录文件对比介绍
  322. }
  323. if self.openFileFunctionView == nil {
  324. self.openFileFunctionView = KMOpenFileFunctionView.createFromNib()
  325. }
  326. self.openFileFunctionView.circleRect = self.digitalBoxRect
  327. self.openFileFunctionView.frame = self.coverView.bounds
  328. self.openFileFunctionView.autoresizingMask = [.width, .height]
  329. self.openFileFunctionView.type = self.type
  330. self.openFileFunctionView.clickHandle = {[weak self] view, actionType in
  331. guard let self = self else { return }
  332. if self.type == .digitalSignGuide {
  333. guard let callBack = self.finishHandle else {
  334. return
  335. }
  336. callBack(self, .windowDigitalFinish)
  337. if actionType == .getIt {
  338. self.closeAction()
  339. }
  340. } else if self.type == .pdfCompareGuide {
  341. if actionType == .getIt {
  342. self.closeAction()
  343. }
  344. }
  345. }
  346. self.coverView.addSubview(self.openFileFunctionView)
  347. self.openFileFunctionView.updateViewColor()
  348. } else if self.type == .convertGuide {
  349. if self.convertGuideView == nil {
  350. self.convertGuideView = KMConvertGuideView.createFromNib()
  351. }
  352. self.convertGuideView.frame = self.coverView.bounds
  353. self.convertGuideView.autoresizingMask = [.width, .height]
  354. self.convertGuideView.clickHandle = {[weak self] view, actionType in
  355. guard let self = self else { return }
  356. if actionType == .skip {
  357. self.closeAction()
  358. } else if actionType == .purchase {
  359. guard let callBack = self.purchaseHandle else {
  360. return
  361. }
  362. callBack(self)
  363. self.closeAction()
  364. }
  365. }
  366. self.convertGuideView.circleRect = self.digitalBoxRect
  367. self.coverView.addSubview(self.convertGuideView)
  368. self.convertGuideView.updateViewColor()
  369. KMGuideInfoWindowController.setDidShowFor(.convertGuide)//记录转档介绍
  370. } else if self.type == .customColor {
  371. if self.customColorGuideView == nil {
  372. self.customColorGuideView = KMCustomColorGuideView.createFromNib()
  373. }
  374. self.customColorGuideView.frame = self.coverView.bounds
  375. self.customColorGuideView.autoresizingMask = [.width, .height]
  376. self.customColorGuideView.clickHandle = {[weak self] view, actionType in
  377. if actionType == .getIt {
  378. self?.closeAction()
  379. }
  380. }
  381. self.customColorGuideView.circleRect = self.digitalBoxRect
  382. self.customColorGuideView.updateViewColor()
  383. self.coverView.addSubview(self.customColorGuideView)
  384. KMGuideInfoWindowController.setDidShowFor(.customColor)//记录自定义颜色介绍
  385. } else if self.type == .aiTipIconInfo {
  386. if self.aiIconGuideView == nil {
  387. self.aiIconGuideView = KMAIIconGuideView.createFromNib()
  388. }
  389. self.aiIconGuideView.frame = self.coverView.bounds
  390. self.aiIconGuideView.autoresizingMask = [.width, .height]
  391. self.aiIconGuideView.clickHandle = {[weak self] view, actionType in
  392. guard let self = self else { return }
  393. if actionType == .getIt {
  394. self.closeAction()
  395. }
  396. }
  397. self.aiIconGuideView.updateViewColor()
  398. self.aiIconGuideView.wantsLayer = true
  399. self.coverView.addSubview(self.aiIconGuideView)
  400. KMGuideInfoWindowController.setDidShowFor(.aiTipIconInfo)//记录自定义颜色介绍
  401. }
  402. }
  403. }
  404. func closeAction() {
  405. self.clearViews()
  406. self.close()
  407. }
  408. }