KMComparativeTableViewController.swift 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. //
  2. // KMComparativeTableViewController.swift
  3. // PDF Master
  4. //
  5. // Created by lizhe on 2023/2/24.
  6. //
  7. import Cocoa
  8. typealias KMComparativeTableViewControllerLoginAction = (_ controller: KMComparativeTableViewController) -> Void
  9. typealias KMComparativeTableViewControllerSignUpAction = (_ controller: KMComparativeTableViewController) -> Void
  10. typealias KMComparativeTableViewControllerSubscriptionAction = (_ controller: KMComparativeTableViewController) -> Void
  11. typealias KMComparativeTableViewControllerRestoreAction = (_ controller: KMComparativeTableViewController) -> Void
  12. var comparativeController: KMComparativeTableViewController?
  13. var comparativeMainWindow: NSWindow?
  14. enum KMComparativeInputType: Int {
  15. case unknown = 0
  16. case login = 1 //登录界面
  17. case register = 2 //注册界面
  18. case resetPassword = 3 //重置密码
  19. case verificationCode = 4 //验证码
  20. case registerSuccess = 5 //注册成功
  21. case loginInputPassword = 6 //登录密码输入
  22. case accountInfo = 7 //用户信息
  23. case compress = 8 // 压缩
  24. case convert = 9 // 转档
  25. case secure = 10 // 安全
  26. case pageEdit = 11 // 页面编辑
  27. case merge = 12 // 合并
  28. case crop = 13 // 裁切
  29. //后续添加
  30. }
  31. class KMComparativeTableViewController: NSWindowController {
  32. @IBOutlet weak var comparativeTableView: KMComparativeTableView!
  33. @IBOutlet weak var comparativeView: KMComparativeView!
  34. var inputType: KMComparativeInputType?
  35. var loginAction: KMComparativeTableViewControllerLoginAction?
  36. var signUpAction: KMComparativeTableViewControllerSignUpAction?
  37. var subscriptionAction: KMComparativeTableViewControllerSubscriptionAction?
  38. var restoreAction: KMComparativeTableViewControllerRestoreAction?
  39. deinit {
  40. print("KMComparativeTableViewController 释放")
  41. }
  42. //MARK: 打开文件
  43. /**
  44. @abstract 弹出比较表
  45. @param window 弹出window
  46. @param type 从什么页面跳转到比较表 默认batch
  47. */
  48. static func show(window: NSWindow, _ type: KMComparativeInputType = .unknown) -> KMComparativeTableViewController? {
  49. #if VERSION_DMG
  50. if KMLightMemberManager.manager.isLogin() {
  51. KMPurchaseManager.manager.purchaseProduct(productIdentifier: "") { isSuccess, error in
  52. }
  53. } else {
  54. var email: String = UserDefaults.standard.value(forKey: "kLoginEmail") as? String ?? ""
  55. if email.count == 0 {
  56. KMLoginWindowController.show(window: NSApp.mainWindow!, .Batch, .register)
  57. } else {
  58. KMLoginWindowController.show(window: NSApp.mainWindow!)
  59. }
  60. }
  61. #endif
  62. #if VERSION_FREE
  63. let controller: KMComparativeTableViewController = KMComparativeTableViewController.init(windowNibName: "KMComparativeTableViewController")
  64. controller.inputType = type
  65. controller.loginAction = { controller in
  66. comparativeController = nil
  67. comparativeMainWindow?.endSheet(controller.window!)
  68. comparativeMainWindow = nil
  69. controller.close()
  70. if NSApp.mainWindow != nil {
  71. KMLoginWindowController.show(window: NSApp.mainWindow!, .Batch, .login)
  72. }
  73. }
  74. controller.signUpAction = { controller in
  75. comparativeController = nil
  76. comparativeMainWindow?.endSheet(controller.window!)
  77. comparativeMainWindow = nil
  78. controller.close()
  79. if NSApp.mainWindow != nil {
  80. KMLoginWindowController.show(window: NSApp.mainWindow!, .Batch, .register)
  81. }
  82. }
  83. controller.subscriptionAction = { controller in
  84. if KMLightMemberManager.manager.isLogin() {
  85. KMPurchaseManager.manager.purchaseProduct(productIdentifier: PRODUCT_1) { isSuccess, error in
  86. if isSuccess {
  87. print("订阅成功")
  88. comparativeController = nil
  89. comparativeMainWindow?.endSheet(controller.window!)
  90. comparativeMainWindow = nil
  91. controller.close()
  92. if NSApp.mainWindow != nil {
  93. KMSubscribeSuccessWindowController.show(window: NSApp.mainWindow!)
  94. }
  95. }
  96. }
  97. } else {
  98. comparativeController = nil
  99. comparativeMainWindow?.endSheet(controller.window!)
  100. comparativeMainWindow = nil
  101. controller.close()
  102. var email: String = UserDefaults.standard.value(forKey: "kLoginEmail") as? String ?? ""
  103. if email.count == 0 {
  104. KMLoginWindowController.show(window: controller.window!, .ComparativeTable, .register)
  105. } else {
  106. KMLoginWindowController.show(window: controller.window!, .ComparativeTable)
  107. }
  108. }
  109. }
  110. controller.restoreAction = { controller in
  111. KMPurchaseManager.manager.restorePurchases()
  112. }
  113. window.beginSheet(controller.window!)
  114. comparativeController = controller
  115. comparativeMainWindow = window
  116. return controller
  117. #endif
  118. return nil
  119. }
  120. override func windowDidLoad() {
  121. super.windowDidLoad()
  122. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  123. self.setup()
  124. print("订阅状态: \(KMInAppPurchaseManager.manager.state)")
  125. }
  126. func setup() {
  127. self.window?.contentView?.backgroundColor(NSColor(hex: "FFFFFF"))
  128. // self.comparativeTableView.closeAction = { view in
  129. // print("关闭")
  130. // comparativeMainWindow?.endSheet(view.window!)
  131. // view.window?.close()
  132. // comparativeController = nil
  133. // comparativeMainWindow = nil
  134. // }
  135. //
  136. // self.comparativeTableView.signUpAction = { [weak self] view in
  137. // print("注册")
  138. // guard let callBack = self?.signUpAction else { return }
  139. //
  140. // callBack(self!)
  141. // }
  142. //
  143. // self.comparativeTableView.loginAction = { [weak self] view in
  144. // print("登录")
  145. // guard let callBack = self?.loginAction else { return }
  146. //
  147. // callBack(self!)
  148. // }
  149. //
  150. // self.comparativeTableView.subscriptionAction = { [weak self] view in
  151. // print("订阅")
  152. // guard let callBack = self?.subscriptionAction else { return }
  153. //
  154. // callBack(self!)
  155. // }
  156. //
  157. // self.comparativeTableView.restoreAction = { [weak self] view in
  158. // print("订阅")
  159. // guard let callBack = self?.restoreAction else { return }
  160. //
  161. // callBack(self!)
  162. // }
  163. self.comparativeView.closeAction = { view in
  164. print("关闭")
  165. comparativeMainWindow?.endSheet(view.window!)
  166. view.window?.close()
  167. comparativeController = nil
  168. comparativeMainWindow = nil
  169. }
  170. self.comparativeView.signUpAction = { [weak self] view in
  171. print("注册")
  172. guard let callBack = self?.signUpAction else { return }
  173. callBack(self!)
  174. }
  175. // self.comparativeTableView.loginAction = { [weak self] view in
  176. // print("登录")
  177. // guard let callBack = self?.loginAction else { return }
  178. //
  179. // callBack(self!)
  180. // }
  181. //
  182. self.comparativeView.subscriptionAction = { [weak self] view in
  183. print("订阅")
  184. guard let callBack = self?.subscriptionAction else { return }
  185. callBack(self!)
  186. }
  187. self.comparativeView.restoreAction = { [weak self] view in
  188. print("restore订阅")
  189. guard let callBack = self?.restoreAction else { return }
  190. callBack(self!)
  191. }
  192. }
  193. }