AppDelegate.swift 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. //
  2. // AppDelegate.swift
  3. // PDF Master
  4. //
  5. // Created by Niehaoyu on 2022/9/23.
  6. //
  7. import Cocoa
  8. import KMAdvertisement
  9. @main
  10. class AppDelegate: NSObject, NSApplicationDelegate {
  11. func applicationWillFinishLaunching(_ notification: Notification) {
  12. let appTarget = KMTools_OC.getAppTarget()
  13. if (appTarget == .free) {
  14. CPDFKit.setLicenseKey("cdq2EJ0yq9HmBQy/AlHPtC/+pnZCKi9HaV8t+N2McjPDNTB0Z8xK+4hw4/xn55GNsnWlNbSB7RTkRMQ45T0IZ4Bhsb2wTjMKZgLHXOYCVs+y/A54hwA/v1fm5F6/mdCjqyFpy2uq7LVxNwsCbVVT+PuHmXDUuWqkErl02537Y3E=", secret: "mG0c3O3Mzeu5dkZJW3gpqh188cTuhYlGRPrbR/gfX4p9ms/F1zY6gZ1RBu8mNJH8VDCh7HQsi+BJS7RukFVBsD3jYTYlv7OHV9TgoY0SmO6Ptvguf6vCH30IoM4xINMau4aGVjtYuk+Uxs/kosIBwyxQV1SVCQFsC27oMGz5P/rBQYv0T/D0N0z+Um3U+I+tTRwFO+iE6+0emjaIlX2OMDXw8/CDEmc6oakb9zq80YfY7KtZ0LxrqSdyM0ZMT4i8IZqTxD9KkvMj3/O+zX155uoFv1BTjCeXlkEOSDvmglU=")
  15. CPDFConvertKit.setLicenseKey("HcZ7sehqdnIvgtFnAF85D2B6tQjbMAklBEZyrSKYYSY/bdNOfGvcNIKpDTUchwAtZLw1fkJ3uN49bgUVSz8UEHm2LpoXPcRK9b+laQ17UHE7qFx6twVZ2IIyEURhMClmFSDD5yAxxpndYl8mmwjIoWspgAdDGX8pixFDQUE3/9w=", secret: "mG0c3O3Mzeu5dkZJW3gpqh188cTuhYlGRPrbR/gfX4qccr16WMBclnQACarlyblNUvAm/S8uFbhXMvxwgBSgULSsrbuyF/SIZ3I+dl0qU8GohiEHQBcAOj1ste3ppDvnC1Ca6fL/tThqwHk5EkhX8DeDWXm8oYxIQxh+yoOd+MxU9avJIxe/9rGTVfLJgjbpoOXUTNa/8X/QbDtDTanKkAwWgQy2MrGRWbL6WItb270=")
  16. } else if (appTarget == .DMG) {
  17. CPDFKit.setLicenseKey("anWsjwnFLewcxYRZbdvBVgX9bZ2Ofz9Yy+tje+KJ6BktwciBCx51vZBUDXpFdUrDugu0t4yVSEh+yOhXXRPgiaeCh1dJX+IR7ztnArFoCS8HQDk3ROXjYWkFOmWioOljbNuORZ/zrsv8l0jRNMLUCPxPbga271sOcUVDeHNn/8c=", secret: "mG0c3O3Mzeu5dkZJW3gpqh188cTuhYlGRPrbR/gfX4rCrm/O2+fI9yUYXNZ/JY1KPbFCeKgG+lEVwrbGHrpAyXATqjrt8ApqRYhafFooQjwAFgayISwZT/pa4NjR459gu4aGVjtYuk+Uxs/kosIBw9vgMz/YdzEMZoMhFEbmUEc6H4o/0cJmYd/bLPc1WFIlJ3VN41JnIqAKG97dQtCXYUplTxrh5mQs6SZcN0B2PF/dEupdk9Zstt+VbVf6kPXvj9NGZMFeJwC3Ilgq78L0gg==")
  18. CPDFConvertKit.setLicenseKey("SVRr1XuTMVrF85Sp+DpK2q/NpcumFDTxBWajzl08eWpk7DomcFajxwMpgfhLCSCNn5jgMumR/diO8X+tZhrBuPs0UP2gYX1lstnpKPqRx8ZnHCTFMyS06zkIrVGTghH+DHNWyXfMFVGQtIVO/+X77wGOtmn5S4/uUHLJDSgLkmw=", secret: "mG0c3O3Mzeu5dkZJW3gpqh188cTuhYlGRPrbR/gfX4qccr16WMBclnQACarlyblNUvAm/S8uFbhXMvxwgBSgULSsrbuyF/SIZ3I+dl0qU8GohiEHQBcAOj1ste3ppDvnC1Ca6fL/tThqwHk5EkhX8DeDWXm8oYxIQxh+yoOd+MwekFC/LCdvQ96bASGL15ECoOXUTNa/8X/QbDtDTanKkAwWgQy2MrGRWbL6WItb270=")
  19. } else {
  20. CPDFKit.setLicenseKey("cdq2EJ0yq9HmBQy/AlHPtC/+pnZCKi9HaV8t+N2McjPDNTB0Z8xK+4hw4/xn55GNsnWlNbSB7RTkRMQ45T0IZ4Bhsb2wTjMKZgLHXOYCVs+y/A54hwA/v1fm5F6/mdCjqyFpy2uq7LVxNwsCbVVT+PuHmXDUuWqkErl02537Y3E=", secret: "mG0c3O3Mzeu5dkZJW3gpqh188cTuhYlGRPrbR/gfX4p9ms/F1zY6gZ1RBu8mNJH8VDCh7HQsi+BJS7RukFVBsD3jYTYlv7OHV9TgoY0SmO6Ptvguf6vCH30IoM4xINMau4aGVjtYuk+Uxs/kosIBwyxQV1SVCQFsC27oMGz5P/rBQYv0T/D0N0z+Um3U+I+tTRwFO+iE6+0emjaIlX2OMDXw8/CDEmc6oakb9zq80YfY7KtZ0LxrqSdyM0ZMT4i8IZqTxD9KkvMj3/O+zX155uoFv1BTjCeXlkEOSDvmglU=")
  21. CPDFConvertKit.setLicenseKey("HcZ7sehqdnIvgtFnAF85D2B6tQjbMAklBEZyrSKYYSY/bdNOfGvcNIKpDTUchwAtZLw1fkJ3uN49bgUVSz8UEHm2LpoXPcRK9b+laQ17UHE7qFx6twVZ2IIyEURhMClmFSDD5yAxxpndYl8mmwjIoWspgAdDGX8pixFDQUE3/9w=", secret: "mG0c3O3Mzeu5dkZJW3gpqh188cTuhYlGRPrbR/gfX4qccr16WMBclnQACarlyblNUvAm/S8uFbhXMvxwgBSgULSsrbuyF/SIZ3I+dl0qU8GohiEHQBcAOj1ste3ppDvnC1Ca6fL/tThqwHk5EkhX8DeDWXm8oYxIQxh+yoOd+MxU9avJIxe/9rGTVfLJgjbpoOXUTNa/8X/QbDtDTanKkAwWgQy2MrGRWbL6WItb270=")
  22. }
  23. // CDocumentAIKit.sharedInstance().setLicenseKey("1F8B081800599C640000616C7068610034413635373236463644363535393631364536370001F0010FFE33C3D4634F3E0B148EA10B8E59B57FA6B17EC34749CDBBD02D697F1A481C00666DCDDC517B4F576C4F8A9961080E556DF332DA7C816D3A3C212DCBE34749B6845E561A60C7E13BF8F84EC77FCF314333E1DFFC92E88A6CD97F65F6153452E9677F7A248FD45C98E87647367A29D678DA15EECB5E28854C674FE4DFE810740CB43F4DC1A7444B1EFA3C8C3E3F4D5859A9BAEDF1CF87917E86E6541B924A1AD0FBEC61BDFA0886A1E8FDFECCDE64FCCB645A89323F0177FE0B3CB7E3D72EA9A3DE1823FEB5D967F90751F46B6C97A1C250B669FD145747ADF6571859F78FDA05DA5B963B799DA5CC53ECE0FB8D53165EB3B0188FF8BB201D8AD7A34F01EC1BA855378F2CB8B9176EE463B1F2B1D8BD776113BAEF4C9A78EE7BC12EF192DABD2FBAB2E252A09B38A85BFCD76B4AFBEFF5A4E9FFE499A77B76E97B9C01CC7485688CD696FD1145D47AD969074FD300783583B70460617A0EC2D7579D0EC5AC33DB3F32E0CC920AC25B6D8F177D2F73FF26457534D6233844BEB4B223A37AA59EFB3D2469C8367C0CBF29C8A3E505AA53E62661FFC59771E77C3C274B51E2C066E87C796BA6AC2D2567D25560A7E9DFE3433FC5233A2C0CB4320D57EB8C0422B416CB5E25F94DB1CC0DCE1A39684827B61BCAE552A05607748113F3D6194A29A8C5C400A02FE3C69204D754550FA5E24BC3FF068B99DDF0010000")
  24. ComPDFUIConfig.initializeUIConfig();
  25. KMDesignToken.shared.parserExcel(withPath: "")
  26. }
  27. func applicationDidFinishLaunching(_ aNotification: Notification) {
  28. // Insert code here to initialize your application
  29. #if VERSION_DMG
  30. let updater = SUUpdater.shared()
  31. updater!.delegate = self
  32. updater!.automaticallyChecksForUpdates = true
  33. #else
  34. #endif
  35. // MARK: 广告数据初始化
  36. KMAdvertisementManager.manager.initConfig(appName: .PDFReaderProMac,
  37. subscribeType: .unsubscribed,
  38. platform: .Mac)
  39. // 测试模式,默认false
  40. KMAdvertisementManager.manager.debug = true
  41. // 初版不支持暗黑模式
  42. NSApp.appearance = NSAppearance(named: .aqua)
  43. KMAnalytics.configure()
  44. //第一次开启app
  45. var info = UserDefaults.standard.value(forKey: "kFirstOpenAppCount")
  46. var count = 0
  47. if info != nil {
  48. count = info as? Int ?? 0
  49. }
  50. count += 1
  51. UserDefaults.standard.set(count, forKey: "kFirstOpenAppCount")
  52. UserDefaults.standard.synchronize()
  53. // //restore
  54. if KMInAppPurchaseManager.manager.state == .subscription {
  55. debugPrint("是订阅状态 需要restore")
  56. KMPurchaseManager.manager.restorePurchases { isSuccess, error in
  57. }
  58. }
  59. self.initMainMenu()
  60. /// pro
  61. // [DBClientsManager setupWithAppKeyDesktop:@"amipzwtlg9lrwyl"];
  62. DBClientsManager.setup(withAppKeyDesktop: "jxjlqfm1cfp2mjj")
  63. reopenDocument(forPaths: [])
  64. KMPreference.shared.initDataForAppLaunch()
  65. let appleEventManager = NSAppleEventManager.shared()
  66. appleEventManager.setEventHandler(self,
  67. andSelector: #selector(handleGetURLEvent(_:withReplyEvent:)),
  68. forEventClass: AEEventClass(kInternetEventClass),
  69. andEventID: AEEventID(kAEGetURL))
  70. }
  71. @objc func handleGetURLEvent(_ event: NSAppleEventDescriptor, withReplyEvent replyEvent: NSAppleEventDescriptor) {
  72. if let urlString = event.paramDescriptor(forKeyword: AEKeyword(keyDirectObject))?.stringValue,
  73. let url = URL(string: urlString) {
  74. // 在这里处理收到的 URL Scheme
  75. KMPrint("Received URL Scheme: \(url.scheme ?? "")")
  76. KMPrint("Path: \(url.path)")
  77. if NSApp.mainWindow == nil {
  78. let bundleIdentifier: String = Bundle.main.bundleIdentifier ?? ""
  79. launchApp(bundleIdentifier: bundleIdentifier)
  80. }
  81. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  82. #if VERSION_DMG
  83. // 执行相应的操作
  84. if url.scheme == "subscriptiondmgschemes" {
  85. if urlString.contains("open=expired") {
  86. KMPrint("刷新用户信息")
  87. if !KMLightMemberManager.manager.isLogin() && NSApp.mainWindow != nil {
  88. KMLoginWindowController.show(window: NSApp.mainWindow!)
  89. } else {
  90. if NSApp.mainWindow != nil && KMLightMemberManager.manager.isLogin() {
  91. KMAccountInfoWindowController.show(window: NSApp.mainWindow!)
  92. }
  93. }
  94. } else if urlString.contains("open=success") {
  95. if !KMLightMemberManager.manager.isLogin() && NSApp.mainWindow != nil {
  96. KMLoginWindowController.show(window: NSApp.mainWindow!)
  97. } else {
  98. KMPurchaseManager.manager.restorePurchases { isSuccess, error in
  99. if isSuccess {
  100. } else {
  101. KMComparativeTableViewController.purchasefailed(view: NSApp.mainWindow?.contentView, state: error)
  102. }
  103. }
  104. }
  105. }
  106. }
  107. #endif
  108. #if VERSION_FREE
  109. // 执行相应的操作
  110. if url.scheme == "subscriptionSchemes" {
  111. //刷新用户信息
  112. KMRequestServerManager.manager.getUserInfo { [weak self] success, data, error, isLocal in
  113. }
  114. if url.path == "/open" {
  115. // 执行打开操作
  116. } else if url.path == "/close" {
  117. // 执行关闭操作
  118. }
  119. }
  120. #endif
  121. }
  122. }
  123. }
  124. func launchApp(bundleIdentifier: String) {
  125. let workspace = NSWorkspace.shared
  126. // Launch the application with the specified bundle identifier
  127. if let appURL = NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleIdentifier) {
  128. do {
  129. try workspace.launchApplication(at: appURL, options: .default, configuration: [:])
  130. } catch {
  131. print("Error launching the application: \(error)")
  132. }
  133. } else {
  134. print("Application with bundle identifier '\(bundleIdentifier)' not found.")
  135. }
  136. }
  137. func application(_ application: NSApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  138. }
  139. func application(_ application: NSApplication, didReceiveRemoteNotification userInfo: [String : Any]) {
  140. }
  141. func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
  142. if !flag {
  143. let browser: KMBrowser = KMBrowser.init()
  144. browser.windowController = KMBrowserWindowController.init(browser: browser)
  145. browser.addHomeTabContents()
  146. browser.windowController.showWindow(self)
  147. }
  148. return flag
  149. }
  150. func applicationShouldOpenUntitledFile(_ sender: NSApplication) -> Bool {
  151. if (KMPreferenceManager.shared.openLastUnclosedDocumentWhenAppStart == false) {
  152. return false
  153. }
  154. let filepaths = KMPreferenceManager.shared.lastOpenFilepaths
  155. if (filepaths == nil || filepaths!.count == 0) {
  156. return false
  157. }
  158. DispatchQueue.main.async {
  159. for filepath in filepaths! {
  160. NSDocumentController.shared.km_safe_openDocument(withContentsOf: URL(fileURLWithPath: filepath), display: true) { _, _, _ in
  161. }
  162. }
  163. }
  164. return false
  165. }
  166. func applicationWillTerminate(_ aNotification: Notification) {
  167. if (NSApp.orderedDocuments.count > 0) {
  168. var filepaths: [String] = []
  169. for document in NSApp.orderedDocuments {
  170. // KMPrint(document.fileURL as Any)
  171. if (document.fileURL?.path != nil) {
  172. filepaths.append((document.fileURL?.path)!)
  173. }
  174. }
  175. KMPreferenceManager.shared.lastOpenFilepaths = filepaths
  176. } else {
  177. KMPreferenceManager.shared.lastOpenFilepaths = nil
  178. }
  179. }
  180. func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
  181. return true
  182. }
  183. // MARK: private
  184. func reopenDocument(forPaths paths: [String]) -> Void {
  185. let browser = KMBrowser.init() as KMBrowser
  186. browser.windowController = KMBrowserWindowController.init(browser: browser)
  187. browser.addHomeTabContents()
  188. browser.windowController.showWindow(self)
  189. }
  190. // MARK: Menu
  191. func initMainMenu() {
  192. // 处理菜单栏多语
  193. let mainMenu = NSApp.mainMenu
  194. if (mainMenu == nil) {
  195. return
  196. }
  197. for menu in mainMenu!.items {
  198. let subMenu = menu.submenu
  199. for item in subMenu!.items {
  200. item.title = NSLocalizedString(item.title, comment: "")
  201. let itemSubMenu = item.submenu
  202. if (itemSubMenu == nil) {
  203. continue
  204. }
  205. for item in itemSubMenu!.items {
  206. item.title = NSLocalizedString(item.title, comment: "")
  207. }
  208. }
  209. }
  210. let PDFOfficeMenu = mainMenu?.item(at: 0)?.submenu
  211. let appTarget = KMTools_OC.getAppTarget()
  212. if (appTarget == .DMG) {
  213. PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Check for Updates", comment: ""), action: #selector(checkForUpdates), target: self, at: 1)
  214. let accountRefreshItem = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Account Refresh", comment: ""), action: #selector(accountRefreshAction), target: self, at: 8)
  215. accountRefreshItem?.tag = kKMMainMenuAccountRefreshItemTag
  216. }
  217. if let items = PDFOfficeMenu?.items {
  218. for menu in items {
  219. let ranges = menu.title.ranges(of: "PDF Master")
  220. let appTarget = KMTools_OC.getAppTarget()
  221. var appName = "PDF Master"
  222. if (appTarget == .pro) {
  223. appName = "PDF Master Pro"
  224. } else if (appTarget == .DMG) {
  225. appName = "PDF Master"
  226. }
  227. if let _range = ranges.range.first {
  228. menu.title.replaceSubrange(_range, with: appName)
  229. }
  230. }
  231. }
  232. let fileMenu = mainMenu?.item(at: 1)?.submenu
  233. let shareItem: NSMenuItem = NSMenuItem(title: NSLocalizedString("Share", comment: ""), action: nil, target: nil)
  234. fileMenu!.insertItem(shareItem, at: (fileMenu?.items.count)!-1)
  235. shareItem.submenu = NSSharingServicePicker.menu(forSharingItems: [""], subjectContext: "", withTarget: self, selector: #selector(sharePageItemAction), serviceDelegate: nil)
  236. let viewMenu = mainMenu?.item(at: 3)?.submenu
  237. var zoomMenu: NSMenu?
  238. for item in viewMenu!.items {
  239. if (item.title == NSLocalizedString("Zoom", comment: "")) {
  240. zoomMenu = item.submenu
  241. break
  242. }
  243. }
  244. if (zoomMenu != nil) {
  245. for item in zoomMenu!.items {
  246. if (item.title == NSLocalizedString("Zoom In", comment: "")) {
  247. item.keyEquivalent = "+"
  248. item.keyEquivalentModifierMask = [.command]
  249. break
  250. }
  251. }
  252. }
  253. }
  254. @objc func sharePageItemAction(sender: NSMenuItem) {
  255. if ((NSApp.mainWindow?.windowController is KMBrowserWindowController) == false) {
  256. return
  257. }
  258. let windowControler = NSApp.mainWindow?.windowController as! KMBrowserWindowController
  259. let model: CTTabStripModel = windowControler.browser.tabStripModel
  260. if (model.count() <= 0) {
  261. return
  262. }
  263. if (model.activeTabContents().isHome) {
  264. return
  265. }
  266. let document: KMMainDocument = model.activeTabContents() as! KMMainDocument
  267. if let data = document.mainViewController?.saveWatermarkFlag, !data {
  268. let represent : NSSharingService = sender.representedObject as! NSSharingService
  269. represent.perform(withItems: [document.fileURL as Any])
  270. return
  271. }
  272. // 有使用付费功能
  273. Task { @MainActor in
  274. if await (KMLightMemberManager.manager.canPayFunction() == false) {
  275. let _ = KMSubscribeWaterMarkWindowController.show(window: NSApp.mainWindow!, isContinue: true) { isSubscribeSuccess, isWaterMarkExport, isClose in
  276. if (isClose) {
  277. return
  278. }
  279. if (isSubscribeSuccess) {
  280. let represent : NSSharingService = sender.representedObject as! NSSharingService
  281. represent.perform(withItems: [document.fileURL as Any])
  282. return
  283. }
  284. if (isWaterMarkExport) {
  285. let doucumentURL = document.fileURL
  286. let docDir = NSTemporaryDirectory()
  287. let documentName : String = doucumentURL!.path.lastPathComponent
  288. let path = docDir.stringByAppendingPathComponent(documentName)
  289. let data = KMTools.saveWatermarkDocument(document: document.mainViewController!.document!, to: URL(fileURLWithPath: path), secureOptions: document.mainViewController!.secureOptions, removePWD: document.mainViewController!.removeSecureFlag)
  290. let writeSuccess = data != nil
  291. if writeSuccess == false {
  292. __NSBeep()
  293. return;
  294. }
  295. let represent : NSSharingService = sender.representedObject as! NSSharingService
  296. represent.perform(withItems: [data as Any])
  297. return
  298. }
  299. }
  300. return
  301. }
  302. let represent : NSSharingService = sender.representedObject as! NSSharingService
  303. represent.perform(withItems: [document.fileURL as Any])
  304. }
  305. }
  306. // MARK: PDF Master Menu
  307. @IBAction func openPreferenceWindow(_ sender: Any) {
  308. KMPreferenceWindowController.shared.showWindow(nil)
  309. }
  310. @objc @IBAction func manageAcctounMenuAction(_ sender: Any) {
  311. if KMLightMemberManager.manager.isLogin() {
  312. KMAccountInfoWindowController.show(window: NSApp.mainWindow!)
  313. }
  314. }
  315. @IBAction func loginMenuItemAction(_ sender: Any) {
  316. // Login & Logout
  317. if KMLightMemberManager.manager.isLogin() {
  318. } else {
  319. KMLoginWindowController.show(window: NSApp.mainWindow!)
  320. }
  321. }
  322. @IBAction func logoutMenuItemAction(_ sender: Any) {
  323. // Login & Logout
  324. if KMLightMemberManager.manager.isLogin() {
  325. KMRequestServerManager.manager.logout { success, result in
  326. if success {
  327. KMPrint("登出成功")
  328. }
  329. }
  330. }
  331. }
  332. @IBAction func restoreMenuItemAction(_ sender: Any) {
  333. KMPurchaseManager.manager.restorePurchases { isSuccess, error in
  334. if isSuccess {
  335. } else {
  336. if error != .restoreSuccess {
  337. KMComparativeTableViewController.purchasefailed(view: NSApp.mainWindow?.contentView, state: error)
  338. }
  339. }
  340. }
  341. }
  342. @objc func accountRefreshAction() {
  343. KMLightMemberManager.manager.updateNetworkingUserInfo { isDidLogout in
  344. }
  345. }
  346. @objc func showAccount() {
  347. }
  348. @objc func resumePurchase() {
  349. }
  350. // MARK: help Menu
  351. @IBAction func menuItemAction_quickStudy(_ sender: NSMenuItem) -> Void {
  352. KMTools.openQuickStartStudy()
  353. }
  354. @IBAction func menuItemAction_onlineHelp(_ sender: NSMenuItem) -> Void {
  355. KMTools.openFAQWebsite()
  356. }
  357. @IBAction func menuItemAction_morePudact(_ sender: NSMenuItem) -> Void {
  358. KMTools.openMoreProductWebsite()
  359. }
  360. @IBAction func menuItemAction_freePDFTemplate(_ sender: NSMenuItem) -> Void {
  361. KMTools.openFreePDFTemplatesWebsite()
  362. }
  363. @IBAction func menuItemAction_payEmail(_ sender: NSMenuItem) -> Void {
  364. KMEmailSubWindowController().showWindow(nil)
  365. }
  366. @IBAction func menuItemAction_poweredByComPDFKit(_ sender: NSMenuItem) -> Void {
  367. KMTools.openComPDFKitPowerWebsite()
  368. }
  369. @IBAction func menuItemAction_feekback(_ sender: NSMenuItem) -> Void {
  370. KMTools.feekback()
  371. }
  372. @IBAction func menuItemAction_giveFiveStar(_ sender: NSMenuItem) -> Void {
  373. }
  374. // MARK:- DMG
  375. @objc func checkForUpdates(_ sender: NSMenuItem) {
  376. let appTarget = KMTools_OC.getAppTarget()
  377. if (appTarget != .DMG) {
  378. return
  379. }
  380. #if VERSION_DMG
  381. SUUpdater.shared().checkForUpdates(sender)
  382. #endif
  383. }
  384. }
  385. extension AppDelegate : NSMenuDelegate,NSMenuItemValidation {
  386. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  387. let action = menuItem.action
  388. if action == #selector(manageAcctounMenuAction) {
  389. self.updateLoginMenuItem()
  390. return KMLightMemberManager.manager.isLogin()
  391. }
  392. if action == #selector(loginMenuItemAction) {
  393. self.updateLoginMenuItem()
  394. return !KMLightMemberManager.manager.isLogin()
  395. }
  396. if action == #selector(logoutMenuItemAction) {
  397. self.updateLoginMenuItem()
  398. return KMLightMemberManager.manager.isLogin()
  399. }
  400. if (action == #selector(sharePageItemAction)) {
  401. guard let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController else {
  402. return false
  403. }
  404. return !_windowC.browser.activeTabContents().isHome
  405. }
  406. return true
  407. }
  408. func updateLoginMenuItem() {
  409. let firstItem = NSApp.mainMenu?.item(at: 0)?.submenu
  410. if firstItem != nil {
  411. let item1 = firstItem?.item(withTag: 11)
  412. let item2 = firstItem?.item(withTag: 12)
  413. let item3 = firstItem?.item(withTag: 13)
  414. let item4 = firstItem?.item(withTag: 14)
  415. // let item5 = firstItem?.item(withTag: 15)
  416. let item6 = firstItem?.item(withTag: kKMMainMenuAccountRefreshItemTag)
  417. if KMLightMemberManager.manager.isLogin() {
  418. item1?.title = KMLightMemberManager.manager.info.email
  419. item1?.isHidden = false
  420. item2?.isHidden = true
  421. item3?.isHidden = false
  422. item4?.isHidden = false
  423. // item5?.isHidden = false
  424. item6?.isHidden = false
  425. } else {
  426. item1?.isHidden = true
  427. item2?.isHidden = false
  428. item3?.isHidden = true
  429. item4?.isHidden = true
  430. // item5?.isHidden = true
  431. item6?.isHidden = true
  432. }
  433. }
  434. }
  435. @objc func clickOutline(menuItem: NSMenuItem) {
  436. KMPrint("更新菜单栏")
  437. }
  438. func menu(_ menu: NSMenu, update item: NSMenuItem, at index: Int, shouldCancel: Bool) -> Bool {
  439. return true
  440. }
  441. }
  442. #if VERSION_DMG
  443. extension AppDelegate : SUUpdaterDelegate {
  444. func updaterWillRelaunchApplication(_ updater: SUUpdater) {
  445. }
  446. func feedURLString(for updater: SUUpdater) -> String? {
  447. #if DEBUG
  448. return "http://test-pdf-pro.kdan.cn:3021/downloads/pdfmasterprocast.xml"
  449. #else
  450. return "https://www.pdfreaderpro.com/downloads/pdfmasterprocast.xml"
  451. #endif
  452. }
  453. func updaterShouldPromptForPermissionToCheck(forUpdates updater: SUUpdater) -> Bool {
  454. return false
  455. }
  456. func upgradeAPP(with updater: SUUpdater) {
  457. let string = "macappstore://apps.apple.com/cn/app/pdf-master-ai-pdf/id6446781258?mt=12"
  458. let url: URL = URL(string: string)!
  459. NSWorkspace.shared.open(url)
  460. }
  461. func upgradeButtonString(for updater: SUUpdater) -> String {
  462. return NSLocalizedString("PDF Master", comment: "")
  463. }
  464. }
  465. #endif