KMNBaseViewController.swift 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // KMNBaseViewController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/5/5.
  6. //
  7. import Cocoa
  8. class KMNBaseViewController: NSViewController {
  9. var progressC: SKProgressController?
  10. deinit {
  11. KMPrint(self.className + " deinit.")
  12. self.removeNotifations()
  13. }
  14. override func viewDidLoad() {
  15. super.viewDidLoad()
  16. initContentView()
  17. self.addNotifations()
  18. }
  19. // Noti
  20. func addNotifations() {
  21. updateUIThemeColor()
  22. NotificationCenter.default.addObserver(self, selector: #selector(updateUIThemeColor), name: APPAppearanceChangedNotificationName, object: nil)
  23. updateUILanguage()
  24. NotificationCenter.default.addObserver(self, selector: #selector(updateUILanguage), name: APPLanguageChangedNotificationName, object: nil)
  25. }
  26. func removeNotifations() {
  27. NotificationCenter.default.removeObserver(self)
  28. }
  29. @objc func updateUIThemeColor() {}
  30. @objc func updateUILanguage() {}
  31. func initContentView() {}
  32. func showProgressWindow(message: String = "") {
  33. if (self.progressC != nil) {
  34. self.hiddenProgressWindow()
  35. }
  36. let progressC = SKProgressController()
  37. progressC.window?.backgroundColor = NSColor.km_init(hex: "#36383B")
  38. progressC.window?.contentView?.wantsLayer = true
  39. progressC.window?.contentView?.layer?.backgroundColor = NSColor.km_init(hex: "#36383B").cgColor
  40. progressC.progressField.textColor = NSColor.white
  41. progressC.showClose = false
  42. progressC.message = message
  43. self.progressC = progressC
  44. self.view.window?.beginSheet(progressC.window!)
  45. }
  46. func hiddenProgressWindow() {
  47. if let _progressC = self.progressC {
  48. if let _window = _progressC.window {
  49. self.view.window?.endSheet(_window)
  50. }
  51. self.progressC = nil
  52. }
  53. }
  54. }