KMGuideInfoWindowController.swift 21 KB

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