AppDelegate.swift 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. //
  2. // AppDelegate.swift
  3. // PDF Master
  4. //
  5. // Created by Niehaoyu on 2022/9/23.
  6. //
  7. import Cocoa
  8. @main
  9. class AppDelegate: NSObject, NSApplicationDelegate {
  10. func applicationWillFinishLaunching(_ notification: Notification) {
  11. #if VERSION_FREE
  12. 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=")
  13. CPDFConvertKit.setLicenseKey("HcZ7sehqdnIvgtFnAF85D2B6tQjbMAklBEZyrSKYYSY/bdNOfGvcNIKpDTUchwAtZLw1fkJ3uN49bgUVSz8UEHm2LpoXPcRK9b+laQ17UHE7qFx6twVZ2IIyEURhMClmFSDD5yAxxpndYl8mmwjIoWspgAdDGX8pixFDQUE3/9w=", secret: "mG0c3O3Mzeu5dkZJW3gpqh188cTuhYlGRPrbR/gfX4qccr16WMBclnQACarlyblNUvAm/S8uFbhXMvxwgBSgULSsrbuyF/SIZ3I+dl0qU8GohiEHQBcAOj1ste3ppDvnC1Ca6fL/tThqwHk5EkhX8DeDWXm8oYxIQxh+yoOd+MxU9avJIxe/9rGTVfLJgjbpoOXUTNa/8X/QbDtDTanKkAwWgQy2MrGRWbL6WItb270=")
  14. #endif
  15. #if VERSION_PRO
  16. 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=")
  17. CPDFConvertKit.setLicenseKey("HcZ7sehqdnIvgtFnAF85D2B6tQjbMAklBEZyrSKYYSY/bdNOfGvcNIKpDTUchwAtZLw1fkJ3uN49bgUVSz8UEHm2LpoXPcRK9b+laQ17UHE7qFx6twVZ2IIyEURhMClmFSDD5yAxxpndYl8mmwjIoWspgAdDGX8pixFDQUE3/9w=", secret: "mG0c3O3Mzeu5dkZJW3gpqh188cTuhYlGRPrbR/gfX4qccr16WMBclnQACarlyblNUvAm/S8uFbhXMvxwgBSgULSsrbuyF/SIZ3I+dl0qU8GohiEHQBcAOj1ste3ppDvnC1Ca6fL/tThqwHk5EkhX8DeDWXm8oYxIQxh+yoOd+MxU9avJIxe/9rGTVfLJgjbpoOXUTNa/8X/QbDtDTanKkAwWgQy2MrGRWbL6WItb270=")
  18. #endif
  19. #if VERSION_DMG
  20. CPDFKit.setLicenseKey("anWsjwnFLewcxYRZbdvBVgX9bZ2Ofz9Yy+tje+KJ6BktwciBCx51vZBUDXpFdUrDugu0t4yVSEh+yOhXXRPgiaeCh1dJX+IR7ztnArFoCS8HQDk3ROXjYWkFOmWioOljbNuORZ/zrsv8l0jRNMLUCPxPbga271sOcUVDeHNn/8c=", secret: "mG0c3O3Mzeu5dkZJW3gpqh188cTuhYlGRPrbR/gfX4rCrm/O2+fI9yUYXNZ/JY1KPbFCeKgG+lEVwrbGHrpAyXATqjrt8ApqRYhafFooQjwAFgayISwZT/pa4NjR459gu4aGVjtYuk+Uxs/kosIBw9vgMz/YdzEMZoMhFEbmUEc6H4o/0cJmYd/bLPc1WFIlJ3VN41JnIqAKG97dQtCXYUplTxrh5mQs6SZcN0B2PF/dEupdk9Zstt+VbVf6kPXvj9NGZMFeJwC3Ilgq78L0gg==")
  21. CPDFConvertKit.setLicenseKey("SVRr1XuTMVrF85Sp+DpK2q/NpcumFDTxBWajzl08eWpk7DomcFajxwMpgfhLCSCNn5jgMumR/diO8X+tZhrBuPs0UP2gYX1lstnpKPqRx8ZnHCTFMyS06zkIrVGTghH+DHNWyXfMFVGQtIVO/+X77wGOtmn5S4/uUHLJDSgLkmw=", secret: "mG0c3O3Mzeu5dkZJW3gpqh188cTuhYlGRPrbR/gfX4qccr16WMBclnQACarlyblNUvAm/S8uFbhXMvxwgBSgULSsrbuyF/SIZ3I+dl0qU8GohiEHQBcAOj1ste3ppDvnC1Ca6fL/tThqwHk5EkhX8DeDWXm8oYxIQxh+yoOd+MwekFC/LCdvQ96bASGL15ECoOXUTNa/8X/QbDtDTanKkAwWgQy2MrGRWbL6WItb270=")
  22. #endif
  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. //Firebase RemoteConfig
  36. #if VERSION_FREE
  37. KMKdanRemoteConfig.remoteConfig().fetch { _status, error in
  38. }
  39. #endif
  40. KMKdanRemoteConfig.remoteConfig().fetchWithRemoteConfigCompletionHandler { status, error in
  41. }
  42. // MARK: 广告数据初始化
  43. KMAdvertisementManager.manager.initConfig(appName: .PDFReaderProMac,
  44. subscribeType: .unknow,
  45. platform: .Mac)
  46. // 测试模式,默认false
  47. KMAdvertisementManager.manager.debug = true
  48. // 初版不支持暗黑模式
  49. NSApp.appearance = NSAppearance.current
  50. KMAnalytics.configure()
  51. //第一次开启app
  52. var info = UserDefaults.standard.value(forKey: "kFirstOpenAppCount")
  53. var count = 0
  54. if info != nil {
  55. count = info as? Int ?? 0
  56. }
  57. count += 1
  58. UserDefaults.standard.set(count, forKey: "kFirstOpenAppCount")
  59. UserDefaults.standard.synchronize()
  60. // //restore
  61. if KMInAppPurchaseManager.manager.state == .subscription {
  62. debugPrint("是订阅状态 需要restore")
  63. KMPurchaseManager.manager.restorePurchases { isSuccess, error in
  64. }
  65. }
  66. self.initMainMenu()
  67. /// pro
  68. // [DBClientsManager setupWithAppKeyDesktop:@"amipzwtlg9lrwyl"];
  69. DBClientsManager.setup(withAppKeyDesktop: "jxjlqfm1cfp2mjj")
  70. reopenDocument(forPaths: [])
  71. KMPreference.shared.initDataForAppLaunch()
  72. let appleEventManager = NSAppleEventManager.shared()
  73. appleEventManager.setEventHandler(self,
  74. andSelector: #selector(handleGetURLEvent(_:withReplyEvent:)),
  75. forEventClass: AEEventClass(kInternetEventClass),
  76. andEventID: AEEventID(kAEGetURL))
  77. DistributedNotificationCenter.default().addObserver(self, selector: #selector(_themeChanged), name: NSApplication.interfaceThemeChangedNotification, object: nil)
  78. }
  79. @objc func handleGetURLEvent(_ event: NSAppleEventDescriptor, withReplyEvent replyEvent: NSAppleEventDescriptor) {
  80. if let urlString = event.paramDescriptor(forKeyword: AEKeyword(keyDirectObject))?.stringValue,
  81. let url = URL(string: urlString) {
  82. // 在这里处理收到的 URL Scheme
  83. KMPrint("Received URL Scheme: \(url.scheme ?? "")")
  84. KMPrint("Path: \(url.path)")
  85. if NSApp.mainWindow == nil {
  86. let bundleIdentifier: String = Bundle.main.bundleIdentifier ?? ""
  87. launchApp(bundleIdentifier: bundleIdentifier)
  88. }
  89. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  90. #if VERSION_DMG
  91. // 执行相应的操作
  92. if url.scheme == "subscriptiondmgschemes" {
  93. if urlString.contains("open=expired") {
  94. KMPrint("刷新用户信息")
  95. if !KMLightMemberManager.manager.isLogin() && NSApp.mainWindow != nil {
  96. KMLoginWindowController.show(window: NSApp.mainWindow!)
  97. } else {
  98. if NSApp.mainWindow != nil && KMLightMemberManager.manager.isLogin() {
  99. KMAccountInfoWindowController.show(window: NSApp.mainWindow!)
  100. }
  101. }
  102. } else if urlString.contains("open=success") {
  103. if !KMLightMemberManager.manager.isLogin() && NSApp.mainWindow != nil {
  104. KMLoginWindowController.show(window: NSApp.mainWindow!)
  105. } else {
  106. KMPurchaseManager.manager.restorePurchases { isSuccess, error in
  107. if isSuccess {
  108. } else {
  109. KMComparativeTableViewController.purchasefailed(view: NSApp.mainWindow?.contentView, state: error)
  110. }
  111. }
  112. }
  113. }
  114. }
  115. #endif
  116. #if VERSION_FREE
  117. // 执行相应的操作
  118. if url.scheme == "subscriptionSchemes" {
  119. //刷新用户信息
  120. KMRequestServerManager.manager.getUserInfo { [weak self] success, data, error, isLocal in
  121. }
  122. if url.path == "/open" {
  123. // 执行打开操作
  124. } else if url.path == "/close" {
  125. // 执行关闭操作
  126. }
  127. }
  128. #endif
  129. }
  130. }
  131. }
  132. func launchApp(bundleIdentifier: String) {
  133. let workspace = NSWorkspace.shared
  134. // Launch the application with the specified bundle identifier
  135. if let appURL = NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleIdentifier) {
  136. do {
  137. try workspace.launchApplication(at: appURL, options: .default, configuration: [:])
  138. } catch {
  139. print("Error launching the application: \(error)")
  140. }
  141. } else {
  142. print("Application with bundle identifier '\(bundleIdentifier)' not found.")
  143. }
  144. }
  145. func application(_ application: NSApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  146. }
  147. func application(_ application: NSApplication, didReceiveRemoteNotification userInfo: [String : Any]) {
  148. }
  149. func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
  150. if !flag {
  151. let browser: KMBrowser = KMBrowser.init()
  152. browser.windowController = KMBrowserWindowController.init(browser: browser)
  153. browser.addHomeTabContents()
  154. browser.windowController.showWindow(self)
  155. }
  156. return flag
  157. }
  158. func applicationShouldOpenUntitledFile(_ sender: NSApplication) -> Bool {
  159. if (KMPreferenceManager.shared.openLastUnclosedDocumentWhenAppStart == false) {
  160. return false
  161. }
  162. let filepaths = KMPreferenceManager.shared.lastOpenFilepaths
  163. if (filepaths == nil || filepaths!.count == 0) {
  164. return false
  165. }
  166. DispatchQueue.main.async {
  167. for filepath in filepaths! {
  168. NSDocumentController.shared.km_safe_openDocument(withContentsOf: URL(fileURLWithPath: filepath), display: true) { _, _, _ in
  169. }
  170. }
  171. }
  172. return false
  173. }
  174. func applicationWillTerminate(_ aNotification: Notification) {
  175. if (NSApp.orderedDocuments.count > 0) {
  176. var filepaths: [String] = []
  177. for document in NSApp.orderedDocuments {
  178. // KMPrint(document.fileURL as Any)
  179. if (document.fileURL?.path != nil) {
  180. filepaths.append((document.fileURL?.path)!)
  181. }
  182. }
  183. KMPreferenceManager.shared.lastOpenFilepaths = filepaths
  184. } else {
  185. KMPreferenceManager.shared.lastOpenFilepaths = nil
  186. }
  187. }
  188. func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
  189. return true
  190. }
  191. // MARK: private
  192. func reopenDocument(forPaths paths: [String]) -> Void {
  193. let browser = KMBrowser.init() as KMBrowser
  194. browser.windowController = KMBrowserWindowController.init(browser: browser)
  195. browser.addHomeTabContents()
  196. browser.windowController.showWindow(self)
  197. }
  198. @objc private func _themeChanged(_ sender: Notification) {
  199. if let data = NSApp.appearance?.name, data == .darkAqua {
  200. NSApp.appearance = .init(named: .aqua)
  201. } else {
  202. NSApp.appearance = .init(named: .darkAqua)
  203. }
  204. NotificationCenter.default.post(name: Notification.Name(rawValue: "kEffectiveAppearance"), object: nil)
  205. }
  206. // MARK: Menu
  207. func initMainMenu() {
  208. // 处理菜单栏多语
  209. let mainMenu = NSApp.mainMenu
  210. if (mainMenu == nil) {
  211. return
  212. }
  213. for menu in mainMenu!.items {
  214. let subMenu = menu.submenu
  215. for item in subMenu!.items {
  216. item.title = NSLocalizedString(item.title, comment: "")
  217. let itemSubMenu = item.submenu
  218. if (itemSubMenu == nil) {
  219. continue
  220. }
  221. for item in itemSubMenu!.items {
  222. item.title = NSLocalizedString(item.title, comment: "")
  223. }
  224. }
  225. }
  226. let PDFOfficeMenu = mainMenu?.item(at: 0)?.submenu
  227. #if VERSION_DMG
  228. PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Check for Updates", comment: ""), action: #selector(checkForUpdates), target: self, at: 1)
  229. let accountRefreshItem = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Account Refresh", comment: ""), action: #selector(accountRefreshAction), target: self, at: 8)
  230. accountRefreshItem?.tag = kKMMainMenuAccountRefreshItemTag
  231. #endif
  232. #if VERSION_FREE
  233. _ = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Restore Previous Purchase ", comment: ""), action: #selector(restoreSubscriptions), target: self, at: 1)
  234. #endif
  235. if let items = PDFOfficeMenu?.items {
  236. for menu in items {
  237. let ranges = menu.title.ranges(of: "PDF Master")
  238. if let _range = ranges.range.first {
  239. menu.title.replaceSubrange(_range, with: KMTools.getAppName())
  240. }
  241. }
  242. }
  243. let fileMenu = mainMenu?.item(at: 1)?.submenu
  244. var shareItem: NSMenuItem?
  245. if let item = fileMenu?.item(withTitle: NSLocalizedString("Save Archive…", comment: "")) {
  246. shareItem = NSMenuItem(title: NSLocalizedString("Share", comment: ""), action: nil, target: nil)
  247. fileMenu?.insertItem(shareItem!, at: item.index)
  248. fileMenu?.insertItem(.separator(), at: item.index)
  249. } else {
  250. shareItem = NSMenuItem(title: NSLocalizedString("Share", comment: ""), action: nil, target: nil)
  251. fileMenu?.insertItem(shareItem!, at: (fileMenu?.items.count)!-1)
  252. }
  253. shareItem?.submenu = NSSharingServicePicker.menu(forSharingItems: [""], subjectContext: "", withTarget: self, selector: #selector(sharePageItemAction), serviceDelegate: nil)
  254. let deviceCameraMenuItem = NSMenuItem(title: NSLocalizedString("Import From Camera", comment: ""), action: #selector(deviceCameraMenuItemAciton), target: self)
  255. let deviceScannerMenuItem = NSMenuItem(title: NSLocalizedString("Import From Scanner", comment: ""), action: #selector(deviceScannerMenuItemAciton), target: self)
  256. fileMenu?.insertItem(deviceCameraMenuItem, at: (fileMenu?.items.count)!-1)
  257. fileMenu?.insertItem(deviceScannerMenuItem, at: (fileMenu?.items.count)!-1)
  258. fileMenu?.insertItem(.separator(), at: (fileMenu?.items.count)!-1)
  259. let viewMenu = mainMenu?.item(at: 3)?.submenu
  260. var zoomMenu: NSMenu?
  261. for item in viewMenu!.items {
  262. if (item.title == NSLocalizedString("Zoom", comment: "")) {
  263. zoomMenu = item.submenu
  264. break
  265. }
  266. }
  267. if (zoomMenu != nil) {
  268. for item in zoomMenu!.items {
  269. if (item.title == NSLocalizedString("Zoom In", comment: "")) {
  270. item.keyEquivalent = "+"
  271. item.keyEquivalentModifierMask = [.command]
  272. break
  273. }
  274. }
  275. }
  276. }
  277. @objc func sharePageItemAction(sender: NSMenuItem) {
  278. if ((NSApp.mainWindow?.windowController is KMBrowserWindowController) == false) {
  279. return
  280. }
  281. let windowControler = NSApp.mainWindow?.windowController as! KMBrowserWindowController
  282. let model: CTTabStripModel = windowControler.browser.tabStripModel
  283. if (model.count() <= 0) {
  284. return
  285. }
  286. if (model.activeTabContents().isHome) {
  287. return
  288. }
  289. let document: KMMainDocument = model.activeTabContents() as! KMMainDocument
  290. if let data = document.mainViewController?.saveWatermarkFlag, !data {
  291. let represent : NSSharingService = sender.representedObject as! NSSharingService
  292. represent.perform(withItems: [document.fileURL as Any])
  293. return
  294. }
  295. // 有使用付费功能
  296. Task { @MainActor in
  297. if await (KMLightMemberManager.manager.canPayFunction() == false) {
  298. let _ = KMSubscribeWaterMarkWindowController.show(window: NSApp.mainWindow!, isContinue: true) { isSubscribeSuccess, isWaterMarkExport, isClose in
  299. if (isClose) {
  300. return
  301. }
  302. if (isSubscribeSuccess) {
  303. let represent : NSSharingService = sender.representedObject as! NSSharingService
  304. represent.perform(withItems: [document.fileURL as Any])
  305. return
  306. }
  307. if (isWaterMarkExport) {
  308. let doucumentURL = document.fileURL
  309. let docDir = NSTemporaryDirectory()
  310. let documentName : String = doucumentURL!.path.lastPathComponent
  311. let path = docDir.stringByAppendingPathComponent(documentName)
  312. let data = KMTools.saveWatermarkDocument(document: document.mainViewController!.document!, to: URL(fileURLWithPath: path), secureOptions: document.mainViewController!.secureOptions, removePWD: document.mainViewController!.removeSecureFlag)
  313. let writeSuccess = data != nil
  314. if writeSuccess == false {
  315. __NSBeep()
  316. return;
  317. }
  318. let represent : NSSharingService = sender.representedObject as! NSSharingService
  319. represent.perform(withItems: [data as Any])
  320. return
  321. }
  322. }
  323. return
  324. }
  325. let represent : NSSharingService = sender.representedObject as! NSSharingService
  326. represent.perform(withItems: [document.fileURL as Any])
  327. }
  328. }
  329. @objc func deviceCameraMenuItemAciton(sender: NSMenuItem) {
  330. KMPrint("deviceCameraMenuItemAciton")
  331. }
  332. @objc func deviceScannerMenuItemAciton(sender: NSMenuItem) {
  333. KMPrint("deviceScannerMenuItemAciton")
  334. }
  335. // MARK: PDF Master Menu
  336. @IBAction func openPreferenceWindow(_ sender: Any) {
  337. // KMPreferenceWindowController.shared.showWindow(nil)
  338. KMPreferenceController.shared.showWindow(self)
  339. }
  340. @objc @IBAction func manageAcctounMenuAction(_ sender: Any) {
  341. if KMLightMemberManager.manager.isLogin() {
  342. KMAccountInfoWindowController.show(window: NSApp.mainWindow!)
  343. }
  344. }
  345. @IBAction func loginMenuItemAction(_ sender: Any) {
  346. // Login & Logout
  347. if KMLightMemberManager.manager.isLogin() {
  348. } else {
  349. KMLoginWindowController.show(window: NSApp.mainWindow!)
  350. }
  351. }
  352. @IBAction func logoutMenuItemAction(_ sender: Any) {
  353. // Login & Logout
  354. if KMLightMemberManager.manager.isLogin() {
  355. KMRequestServerManager.manager.logout { success, result in
  356. if success {
  357. KMPrint("登出成功")
  358. }
  359. }
  360. }
  361. }
  362. @IBAction func restoreMenuItemAction(_ sender: Any) {
  363. KMPurchaseManager.manager.restorePurchases { isSuccess, error in
  364. if isSuccess {
  365. } else {
  366. if error != .restoreSuccess {
  367. KMComparativeTableViewController.purchasefailed(view: NSApp.mainWindow?.contentView, state: error)
  368. }
  369. }
  370. }
  371. }
  372. @objc func accountRefreshAction() {
  373. KMLightMemberManager.manager.updateNetworkingUserInfo { isDidLogout in
  374. }
  375. }
  376. @objc func showAccount() {
  377. }
  378. @objc func resumePurchase() {
  379. }
  380. // MARK: help Menu
  381. @IBAction func menuItemAction_quickStudy(_ sender: NSMenuItem) -> Void {
  382. KMTools.openQuickStartStudy()
  383. }
  384. @IBAction func menuItemAction_onlineHelp(_ sender: NSMenuItem) -> Void {
  385. KMTools.openFAQWebsite()
  386. }
  387. @IBAction func menuItemAction_morePudact(_ sender: NSMenuItem) -> Void {
  388. KMTools.openMoreProductWebsite()
  389. }
  390. @IBAction func menuItemAction_freePDFTemplate(_ sender: NSMenuItem) -> Void {
  391. KMTools.openFreePDFTemplatesWebsite()
  392. }
  393. @IBAction func menuItemAction_payEmail(_ sender: NSMenuItem) -> Void {
  394. KMEmailSubWindowController().showWindow(nil)
  395. }
  396. @IBAction func menuItemAction_poweredByComPDFKit(_ sender: NSMenuItem) -> Void {
  397. KMTools.openComPDFKitPowerWebsite()
  398. }
  399. @IBAction func menuItemAction_feekback(_ sender: NSMenuItem) -> Void {
  400. KMTools.feekback()
  401. }
  402. @IBAction func menuItemAction_giveFiveStar(_ sender: NSMenuItem) -> Void {
  403. KMPrint("menuItemAction_giveFiveStar ...")
  404. }
  405. @objc func restoreSubscriptions(_ sender: NSMenuItem) {
  406. #if VERSION_FREE
  407. KMPrint("restoreSubscriptions ...")
  408. #endif
  409. }
  410. // MARK:- DMG
  411. @objc func checkForUpdates(_ sender: NSMenuItem) {
  412. #if VERSION_DMG
  413. SUUpdater.shared().checkForUpdates(sender)
  414. #endif
  415. }
  416. @IBAction func volumeDiscount(_ sender: NSMenuItem) {
  417. let tStrHttpUrl = "https://www.pdfreaderpro.com/vpp-purchase-program"
  418. guard let url = URL(string: tStrHttpUrl) else {
  419. return
  420. }
  421. let tWorkSpace = NSWorkspace.shared
  422. if tWorkSpace.open(url) == false {
  423. tWorkSpace.open(url)
  424. }
  425. }
  426. @IBAction func crossPlatformAction(_ sender: NSMenuItem) {
  427. let tStrHttpUrl = "https://www.pdfreaderpro.com/store/pdf-pro-permanent-cross-platform-package?utm_source=pdf_pro_dmgs&utm_medium=toptbr_help&utm_campaign=cross_platform"
  428. // if ([SKInspectPublicTool currentisLanguageHans]) {
  429. // tStrHttpUrl = @"https://www.pdfreaderpro.com/zh-cn/store/pdf-pro-permanent-cross-platform-package?utm_source=pdf_pro_dmg&utm_medium=toptbr_help_cn&utm_campaign=cross_platform";
  430. // }
  431. guard let url = URL(string: tStrHttpUrl) else {
  432. return
  433. }
  434. let tWorkSpace = NSWorkspace.shared
  435. if tWorkSpace.open(url) == false {
  436. tWorkSpace.open(url)
  437. }
  438. // #if VERSION_DMG
  439. // [[FMTrackEventManager manager] trackEvent:@"Menubar" withProperties:@{@"Menubar_Btn":@"Menubar_Btn_Help_CrossPlatform"}];
  440. // #endif
  441. }
  442. @IBAction func EducationDiscountAction(_ sender: NSMenuItem) {
  443. let tStrHttpUrl = KMLocalizedString("https://www.pdfreaderpro.com/store?mode=edu#utm_source=mac_app&utm_medium=pdf_pro_dmg&utm_content=menu_bar_click", nil)
  444. guard let url = URL(string: tStrHttpUrl) else {
  445. return
  446. }
  447. let tWorkSpace = NSWorkspace.shared
  448. if tWorkSpace.open(url) == false {
  449. tWorkSpace.open(url)
  450. }
  451. // #if VERSION_DMG
  452. // [[FMTrackEventManager manager] trackEvent:@"Menubar" withProperties:@{@"Menubar_Btn":@"Menubar_Btn_Help_EduDiscount"}];
  453. // #endif
  454. }
  455. @IBAction func orderFrontLineInspector(_ sender: Any?) {
  456. if let win = KMLineInspector.shared.window {
  457. if win.isVisible {
  458. win.orderOut(sender)
  459. } else {
  460. win.orderFront(sender)
  461. }
  462. }
  463. }
  464. @IBAction func showDownloads(_ sender: NSMenuItem) -> Void {
  465. KMPrint("showDownloads ...")
  466. }
  467. @IBAction func showWelcomeWindow(_ sender: NSMenuItem) -> Void {
  468. KMPrint("showWelcomeWindow ...")
  469. }
  470. @IBAction func newsletter(_ sender: NSMenuItem) -> Void {
  471. KMPrint("newsletter ...")
  472. }
  473. @IBAction func feedback(_ sender: NSMenuItem) -> Void {
  474. KMPrint("feedback ...")
  475. }
  476. @IBAction func reportBug(_ sender: NSMenuItem) -> Void {
  477. KMPrint("reportBug ...")
  478. }
  479. @IBAction func reportGeneralQuestions(_ sender: NSMenuItem) -> Void {
  480. KMPrint("reportGeneralQuestions ...")
  481. }
  482. }
  483. extension AppDelegate : NSMenuDelegate,NSMenuItemValidation {
  484. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  485. let action = menuItem.action
  486. if action == #selector(manageAcctounMenuAction) {
  487. self.updateLoginMenuItem()
  488. return KMLightMemberManager.manager.isLogin()
  489. }
  490. if action == #selector(loginMenuItemAction) {
  491. self.updateLoginMenuItem()
  492. return !KMLightMemberManager.manager.isLogin()
  493. }
  494. if action == #selector(logoutMenuItemAction) {
  495. self.updateLoginMenuItem()
  496. return KMLightMemberManager.manager.isLogin()
  497. }
  498. if (action == #selector(sharePageItemAction)) {
  499. guard let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController else {
  500. return false
  501. }
  502. return !_windowC.browser.activeTabContents().isHome
  503. }
  504. return true
  505. }
  506. func updateLoginMenuItem() {
  507. let firstItem = NSApp.mainMenu?.item(at: 0)?.submenu
  508. if firstItem != nil {
  509. let item1 = firstItem?.item(withTag: 11)
  510. let item2 = firstItem?.item(withTag: 12)
  511. let item3 = firstItem?.item(withTag: 13)
  512. let item4 = firstItem?.item(withTag: 14)
  513. // let item5 = firstItem?.item(withTag: 15)
  514. let item6 = firstItem?.item(withTag: kKMMainMenuAccountRefreshItemTag)
  515. // if KMLightMemberManager.manager.isLogin() {
  516. // item1?.title = KMLightMemberManager.manager.info.email
  517. // item1?.isHidden = false
  518. // item2?.isHidden = true
  519. // item3?.isHidden = false
  520. // item4?.isHidden = false
  521. //// item5?.isHidden = false
  522. // item6?.isHidden = false
  523. // } else {
  524. // item1?.isHidden = true
  525. // item2?.isHidden = false
  526. // item3?.isHidden = true
  527. // item4?.isHidden = true
  528. //// item5?.isHidden = true
  529. // item6?.isHidden = true
  530. // }
  531. item1?.isHidden = true
  532. item2?.isHidden = true
  533. item3?.isHidden = true
  534. item4?.isHidden = true
  535. // item5?.isHidden = true
  536. item6?.isHidden = true
  537. }
  538. }
  539. @objc func clickOutline(menuItem: NSMenuItem) {
  540. KMPrint("更新菜单栏")
  541. }
  542. func menu(_ menu: NSMenu, update item: NSMenuItem, at index: Int, shouldCancel: Bool) -> Bool {
  543. return true
  544. }
  545. }
  546. #if VERSION_DMG
  547. extension AppDelegate : SUUpdaterDelegate {
  548. func updaterWillRelaunchApplication(_ updater: SUUpdater) {
  549. }
  550. func feedURLString(for updater: SUUpdater) -> String? {
  551. #if DEBUG
  552. return "http://test-pdf-pro.kdan.cn:3021/downloads/pdfmasterprocast.xml"
  553. #else
  554. return "https://www.pdfreaderpro.com/downloads/pdfmasterprocast.xml"
  555. #endif
  556. }
  557. func updaterShouldPromptForPermissionToCheck(forUpdates updater: SUUpdater) -> Bool {
  558. return false
  559. }
  560. func upgradeAPP(with updater: SUUpdater) {
  561. let string = "macappstore://apps.apple.com/cn/app/pdf-master-ai-pdf/id6446781258?mt=12"
  562. let url: URL = URL(string: string)!
  563. NSWorkspace.shared.open(url)
  564. }
  565. func upgradeButtonString(for updater: SUUpdater) -> String {
  566. return NSLocalizedString("PDF Master", comment: "")
  567. }
  568. }
  569. #endif