AppDelegate.swift 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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 applicationWillBecomeActive(_ notification: Notification) {
  12. // NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMApplicationWillBecomeActive"), object: nil)
  13. }
  14. func applicationDidBecomeActive(_ notification: Notification) {
  15. }
  16. func applicationWillFinishLaunching(_ notification: Notification) {
  17. let appTarget = KMTools_OC.getAppTarget()
  18. if (appTarget == .free) {
  19. 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=")
  20. CPDFConvertKit.setLicenseKey("HcZ7sehqdnIvgtFnAF85D2B6tQjbMAklBEZyrSKYYSY/bdNOfGvcNIKpDTUchwAtZLw1fkJ3uN49bgUVSz8UEHm2LpoXPcRK9b+laQ17UHE7qFx6twVZ2IIyEURhMClmFSDD5yAxxpndYl8mmwjIoWspgAdDGX8pixFDQUE3/9w=", secret: "mG0c3O3Mzeu5dkZJW3gpqh188cTuhYlGRPrbR/gfX4qccr16WMBclnQACarlyblNUvAm/S8uFbhXMvxwgBSgULSsrbuyF/SIZ3I+dl0qU8GohiEHQBcAOj1ste3ppDvnC1Ca6fL/tThqwHk5EkhX8DeDWXm8oYxIQxh+yoOd+MxU9avJIxe/9rGTVfLJgjbpoOXUTNa/8X/QbDtDTanKkAwWgQy2MrGRWbL6WItb270=")
  21. } else if (appTarget == .DMG) {
  22. CPDFKit.setLicenseKey("anWsjwnFLewcxYRZbdvBVgX9bZ2Ofz9Yy+tje+KJ6BktwciBCx51vZBUDXpFdUrDugu0t4yVSEh+yOhXXRPgiaeCh1dJX+IR7ztnArFoCS8HQDk3ROXjYWkFOmWioOljbNuORZ/zrsv8l0jRNMLUCPxPbga271sOcUVDeHNn/8c=", secret: "mG0c3O3Mzeu5dkZJW3gpqh188cTuhYlGRPrbR/gfX4rCrm/O2+fI9yUYXNZ/JY1KPbFCeKgG+lEVwrbGHrpAyXATqjrt8ApqRYhafFooQjwAFgayISwZT/pa4NjR459gu4aGVjtYuk+Uxs/kosIBw9vgMz/YdzEMZoMhFEbmUEc6H4o/0cJmYd/bLPc1WFIlJ3VN41JnIqAKG97dQtCXYUplTxrh5mQs6SZcN0B2PF/dEupdk9Zstt+VbVf6kPXvj9NGZMFeJwC3Ilgq78L0gg==")
  23. CPDFConvertKit.setLicenseKey("SVRr1XuTMVrF85Sp+DpK2q/NpcumFDTxBWajzl08eWpk7DomcFajxwMpgfhLCSCNn5jgMumR/diO8X+tZhrBuPs0UP2gYX1lstnpKPqRx8ZnHCTFMyS06zkIrVGTghH+DHNWyXfMFVGQtIVO/+X77wGOtmn5S4/uUHLJDSgLkmw=", secret: "mG0c3O3Mzeu5dkZJW3gpqh188cTuhYlGRPrbR/gfX4qccr16WMBclnQACarlyblNUvAm/S8uFbhXMvxwgBSgULSsrbuyF/SIZ3I+dl0qU8GohiEHQBcAOj1ste3ppDvnC1Ca6fL/tThqwHk5EkhX8DeDWXm8oYxIQxh+yoOd+MwekFC/LCdvQ96bASGL15ECoOXUTNa/8X/QbDtDTanKkAwWgQy2MrGRWbL6WItb270=")
  24. } else {
  25. 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=")
  26. CPDFConvertKit.setLicenseKey("HcZ7sehqdnIvgtFnAF85D2B6tQjbMAklBEZyrSKYYSY/bdNOfGvcNIKpDTUchwAtZLw1fkJ3uN49bgUVSz8UEHm2LpoXPcRK9b+laQ17UHE7qFx6twVZ2IIyEURhMClmFSDD5yAxxpndYl8mmwjIoWspgAdDGX8pixFDQUE3/9w=", secret: "mG0c3O3Mzeu5dkZJW3gpqh188cTuhYlGRPrbR/gfX4qccr16WMBclnQACarlyblNUvAm/S8uFbhXMvxwgBSgULSsrbuyF/SIZ3I+dl0qU8GohiEHQBcAOj1ste3ppDvnC1Ca6fL/tThqwHk5EkhX8DeDWXm8oYxIQxh+yoOd+MxU9avJIxe/9rGTVfLJgjbpoOXUTNa/8X/QbDtDTanKkAwWgQy2MrGRWbL6WItb270=")
  27. }
  28. // CDocumentAIKit.sharedInstance().setLicenseKey("1F8B081800599C640000616C7068610034413635373236463644363535393631364536370001F0010FFE33C3D4634F3E0B148EA10B8E59B57FA6B17EC34749CDBBD02D697F1A481C00666DCDDC517B4F576C4F8A9961080E556DF332DA7C816D3A3C212DCBE34749B6845E561A60C7E13BF8F84EC77FCF314333E1DFFC92E88A6CD97F65F6153452E9677F7A248FD45C98E87647367A29D678DA15EECB5E28854C674FE4DFE810740CB43F4DC1A7444B1EFA3C8C3E3F4D5859A9BAEDF1CF87917E86E6541B924A1AD0FBEC61BDFA0886A1E8FDFECCDE64FCCB645A89323F0177FE0B3CB7E3D72EA9A3DE1823FEB5D967F90751F46B6C97A1C250B669FD145747ADF6571859F78FDA05DA5B963B799DA5CC53ECE0FB8D53165EB3B0188FF8BB201D8AD7A34F01EC1BA855378F2CB8B9176EE463B1F2B1D8BD776113BAEF4C9A78EE7BC12EF192DABD2FBAB2E252A09B38A85BFCD76B4AFBEFF5A4E9FFE499A77B76E97B9C01CC7485688CD696FD1145D47AD969074FD300783583B70460617A0EC2D7579D0EC5AC33DB3F32E0CC920AC25B6D8F177D2F73FF26457534D6233844BEB4B223A37AA59EFB3D2469C8367C0CBF29C8A3E505AA53E62661FFC59771E77C3C274B51E2C066E87C796BA6AC2D2567D25560A7E9DFE3433FC5233A2C0CB4320D57EB8C0422B416CB5E25F94DB1CC0DCE1A39684827B61BCAE552A05607748113F3D6194A29A8C5C400A02FE3C69204D754550FA5E24BC3FF068B99DDF0010000")
  29. ComPDFUIConfig.initializeUIConfig();
  30. KMDesignToken.shared.parserExcel(withPath: "")
  31. }
  32. func applicationDidFinishLaunching(_ aNotification: Notification) {
  33. // Insert code here to initialize your application
  34. KMResourceDownload().downloadFramework()
  35. #if VERSION_DMG
  36. let updater = SUUpdater.shared()
  37. updater!.delegate = self
  38. updater!.automaticallyChecksForUpdates = true
  39. #else
  40. #endif
  41. // MARK: 广告数据初始化
  42. KMAdvertisementManager.manager.initConfig(appName: .PDFReaderProMac,
  43. subscribeType: .unsubscribed,
  44. platform: .Mac)
  45. // 测试模式,默认false
  46. KMAdvertisementManager.manager.debug = true
  47. // 初版不支持暗黑模式
  48. NSApp.appearance = NSAppearance(named: .aqua)
  49. KMAnalytics.configure()
  50. //第一次开启app
  51. var info = UserDefaults.standard.value(forKey: "kFirstOpenAppCount")
  52. var count = 0
  53. if info != nil {
  54. count = info as? Int ?? 0
  55. }
  56. count += 1
  57. UserDefaults.standard.set(count, forKey: "kFirstOpenAppCount")
  58. UserDefaults.standard.synchronize()
  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 VERSION_DMG
  78. // 执行相应的操作
  79. if url.scheme == "subscriptiondmgSchemes" {
  80. if !KMLightMemberManager.manager.isLogin() && NSApp.mainWindow != nil {
  81. KMLoginWindowController.show(window: NSApp.mainWindow!)
  82. } else {
  83. KMPurchaseManager.manager.restorePurchases { isSuccess, error in
  84. if isSuccess {
  85. } else {
  86. KMComparativeTableViewController.purchasefailed(view: NSApp.mainWindow?.contentView, state: error)
  87. }
  88. }
  89. }
  90. if url.path == "/open" {
  91. // 执行打开操作
  92. } else if url.path == "/close" {
  93. // 执行关闭操作
  94. }
  95. }
  96. #endif
  97. #if VERSION_FREE
  98. // 执行相应的操作
  99. if url.scheme == "subscriptionSchemes" {
  100. //刷新用户信息
  101. KMRequestServerManager.manager.getUserInfo { [weak self] success, data, error, isLocal in
  102. }
  103. if url.path == "/open" {
  104. // 执行打开操作
  105. } else if url.path == "/close" {
  106. // 执行关闭操作
  107. }
  108. }
  109. #endif
  110. }
  111. }
  112. func application(_ application: NSApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  113. }
  114. func application(_ application: NSApplication, didReceiveRemoteNotification userInfo: [String : Any]) {
  115. }
  116. func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
  117. if !flag {
  118. let browser: KMBrowser = KMBrowser.init()
  119. browser.windowController = KMBrowserWindowController.init(browser: browser)
  120. browser.addHomeTabContents()
  121. browser.windowController.showWindow(self)
  122. }
  123. return flag
  124. }
  125. func applicationShouldOpenUntitledFile(_ sender: NSApplication) -> Bool {
  126. if (KMPreferenceManager.shared.openLastUnclosedDocumentWhenAppStart == false) {
  127. return false
  128. }
  129. let filepaths = KMPreferenceManager.shared.lastOpenFilepaths
  130. if (filepaths == nil || filepaths!.count == 0) {
  131. return false
  132. }
  133. DispatchQueue.main.async {
  134. for filepath in filepaths! {
  135. if filepath.isPDFValid() {
  136. NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: filepath), display: true) { document, result, error in
  137. }
  138. } else {
  139. let alert = NSAlert()
  140. alert.alertStyle = .critical
  141. alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
  142. alert.runModal()
  143. }
  144. }
  145. }
  146. return false
  147. }
  148. func applicationWillTerminate(_ aNotification: Notification) {
  149. if (NSApp.orderedDocuments.count > 0) {
  150. var filepaths: [String] = []
  151. for document in NSApp.orderedDocuments {
  152. // KMPrint(document.fileURL as Any)
  153. if (document.fileURL?.path != nil) {
  154. filepaths.append((document.fileURL?.path)!)
  155. }
  156. }
  157. KMPreferenceManager.shared.lastOpenFilepaths = filepaths
  158. } else {
  159. KMPreferenceManager.shared.lastOpenFilepaths = nil
  160. }
  161. }
  162. func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
  163. return true
  164. }
  165. // MARK: private
  166. func reopenDocument(forPaths paths: [String]) -> Void {
  167. let browser = KMBrowser.init() as KMBrowser
  168. browser.windowController = KMBrowserWindowController.init(browser: browser)
  169. browser.addHomeTabContents()
  170. browser.windowController.showWindow(self)
  171. }
  172. // MARK: Menu
  173. func initMainMenu() {
  174. // 处理菜单栏多语
  175. let mainMenu = NSApp.mainMenu
  176. if (mainMenu == nil) {
  177. return
  178. }
  179. for menu in mainMenu!.items {
  180. let subMenu = menu.submenu
  181. for item in subMenu!.items {
  182. item.title = NSLocalizedString(item.title, comment: "")
  183. let itemSubMenu = item.submenu
  184. if (itemSubMenu == nil) {
  185. continue
  186. }
  187. for item in itemSubMenu!.items {
  188. item.title = NSLocalizedString(item.title, comment: "")
  189. }
  190. }
  191. }
  192. let PDFOfficeMenu = mainMenu?.item(at: 0)?.submenu
  193. let appTarget = KMTools_OC.getAppTarget()
  194. if (appTarget == .DMG) {
  195. PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Check for Updates", comment: ""), action: #selector(checkForUpdates), target: self, at: 1)
  196. }
  197. if let items = PDFOfficeMenu?.items {
  198. for menu in items {
  199. let ranges = menu.title.ranges(of: "PDF Master")
  200. let appTarget = KMTools_OC.getAppTarget()
  201. var appName = "PDF Master"
  202. if (appTarget == .pro) {
  203. appName = "PDF Master Pro"
  204. } else if (appTarget == .DMG) {
  205. // appName = "PDF Master DMG"
  206. appName = "PDF Master"
  207. }
  208. if let _range = ranges.range.first {
  209. menu.title.replaceSubrange(_range, with: appName)
  210. }
  211. }
  212. }
  213. let fileMenu = mainMenu?.item(at: 1)?.submenu
  214. let shareItem: NSMenuItem = NSMenuItem(title: NSLocalizedString("Share", comment: ""), action: nil, target: nil)
  215. fileMenu!.insertItem(shareItem, at: (fileMenu?.items.count)!-1)
  216. shareItem.submenu = NSSharingServicePicker.menu(forSharingItems: [""], subjectContext: "", withTarget: self, selector: #selector(sharePageItemAction), serviceDelegate: nil)
  217. let viewMenu = mainMenu?.item(at: 3)?.submenu
  218. var zoomMenu: NSMenu?
  219. for item in viewMenu!.items {
  220. if (item.title == NSLocalizedString("Zoom", comment: "")) {
  221. zoomMenu = item.submenu
  222. break
  223. }
  224. }
  225. if (zoomMenu != nil) {
  226. for item in zoomMenu!.items {
  227. if (item.title == NSLocalizedString("Zoom In", comment: "")) {
  228. item.keyEquivalent = "+"
  229. item.keyEquivalentModifierMask = [.command]
  230. break
  231. }
  232. }
  233. }
  234. }
  235. @objc func sharePageItemAction(sender: NSMenuItem) {
  236. if ((NSApp.mainWindow?.windowController is KMBrowserWindowController) == false) {
  237. return
  238. }
  239. let windowControler = NSApp.mainWindow?.windowController as! KMBrowserWindowController
  240. let model: CTTabStripModel = windowControler.browser.tabStripModel
  241. if (model.count() <= 0) {
  242. return
  243. }
  244. if (model.activeTabContents().isHome) {
  245. return
  246. }
  247. let document: KMMainDocument = model.activeTabContents() as! KMMainDocument
  248. if let data = document.mainViewController?.saveWatermarkFlag, !data {
  249. let represent : NSSharingService = sender.representedObject as! NSSharingService
  250. represent.perform(withItems: [document.fileURL as Any])
  251. return
  252. }
  253. // 有使用付费功能
  254. Task { @MainActor in
  255. if await (KMLightMemberManager.manager.canPayFunction() == false) {
  256. let _ = KMSubscribeWaterMarkWindowController.show(window: NSApp.mainWindow!, isContinue: true) { isSubscribeSuccess, isWaterMarkExport, isClose in
  257. if (isClose) {
  258. return
  259. }
  260. if (isSubscribeSuccess) {
  261. let represent : NSSharingService = sender.representedObject as! NSSharingService
  262. represent.perform(withItems: [document.fileURL as Any])
  263. return
  264. }
  265. if (isWaterMarkExport) {
  266. let doucumentURL = document.fileURL
  267. let docDir = NSTemporaryDirectory()
  268. let documentName : String = doucumentURL!.path.lastPathComponent
  269. let path = docDir.stringByAppendingPathComponent(documentName)
  270. let data = KMTools.saveWatermarkDocument(document: document.mainViewController!.document!, to: URL(fileURLWithPath: path), secureOptions: document.mainViewController!.secureOptions, removePWD: document.mainViewController!.removeSecureFlag)
  271. let writeSuccess = data != nil
  272. if writeSuccess == false {
  273. __NSBeep()
  274. return;
  275. }
  276. let represent : NSSharingService = sender.representedObject as! NSSharingService
  277. represent.perform(withItems: [data as Any])
  278. return
  279. }
  280. }
  281. return
  282. }
  283. let represent : NSSharingService = sender.representedObject as! NSSharingService
  284. represent.perform(withItems: [document.fileURL as Any])
  285. }
  286. }
  287. // MARK: PDF Master Menu
  288. @IBAction func openPreferenceWindow(_ sender: Any) {
  289. KMPreferenceWindowController.shared.showWindow(nil)
  290. }
  291. @objc @IBAction func manageAcctounMenuAction(_ sender: Any) {
  292. if KMLightMemberManager.manager.isLogin() {
  293. KMAccountInfoWindowController.show(window: NSApp.mainWindow!)
  294. }
  295. }
  296. @IBAction func loginMenuItemAction(_ sender: Any) {
  297. // Login & Logout
  298. if KMLightMemberManager.manager.isLogin() {
  299. } else {
  300. KMLoginWindowController.show(window: NSApp.mainWindow!)
  301. }
  302. }
  303. @IBAction func logoutMenuItemAction(_ sender: Any) {
  304. // Login & Logout
  305. if KMLightMemberManager.manager.isLogin() {
  306. KMRequestServerManager.manager.logout { success, result in
  307. if success {
  308. KMPrint("登出成功")
  309. }
  310. }
  311. }
  312. }
  313. @IBAction func restoreMenuItemAction(_ sender: Any) {
  314. KMPurchaseManager.manager.restorePurchases { isSuccess, error in
  315. if isSuccess {
  316. } else {
  317. if error != .restoreSuccess {
  318. KMComparativeTableViewController.purchasefailed(view: NSApp.mainWindow?.contentView, state: error)
  319. }
  320. }
  321. }
  322. }
  323. @objc func showAccount() {
  324. }
  325. @objc func resumePurchase() {
  326. }
  327. // MARK: help Menu
  328. @IBAction func menuItemAction_quickStudy(_ sender: NSMenuItem) -> Void {
  329. KMTools.openQuickStartStudy()
  330. }
  331. @IBAction func menuItemAction_onlineHelp(_ sender: NSMenuItem) -> Void {
  332. KMTools.openFAQWebsite()
  333. }
  334. @IBAction func menuItemAction_morePudact(_ sender: NSMenuItem) -> Void {
  335. KMTools.openMoreProductWebsite()
  336. }
  337. @IBAction func menuItemAction_freePDFTemplate(_ sender: NSMenuItem) -> Void {
  338. KMTools.openFreePDFTemplatesWebsite()
  339. }
  340. @IBAction func menuItemAction_payEmail(_ sender: NSMenuItem) -> Void {
  341. KMEmailSubWindowController().showWindow(nil)
  342. }
  343. @IBAction func menuItemAction_poweredByComPDFKit(_ sender: NSMenuItem) -> Void {
  344. KMTools.openComPDFKitPowerWebsite()
  345. }
  346. @IBAction func menuItemAction_feekback(_ sender: NSMenuItem) -> Void {
  347. KMTools.feekback()
  348. }
  349. @IBAction func menuItemAction_giveFiveStar(_ sender: NSMenuItem) -> Void {
  350. }
  351. // MARK:- DMG
  352. @objc func checkForUpdates(_ sender: NSMenuItem) {
  353. let appTarget = KMTools_OC.getAppTarget()
  354. if (appTarget != .DMG) {
  355. return
  356. }
  357. #if VERSION_DMG
  358. SUUpdater.shared().checkForUpdates(sender)
  359. #endif
  360. }
  361. }
  362. extension AppDelegate : NSMenuDelegate,NSMenuItemValidation {
  363. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  364. let action = menuItem.action
  365. if action == #selector(manageAcctounMenuAction) {
  366. self.updateLoginMenuItem()
  367. return KMLightMemberManager.manager.isLogin()
  368. }
  369. if action == #selector(loginMenuItemAction) {
  370. self.updateLoginMenuItem()
  371. return !KMLightMemberManager.manager.isLogin()
  372. }
  373. if action == #selector(logoutMenuItemAction) {
  374. self.updateLoginMenuItem()
  375. return KMLightMemberManager.manager.isLogin()
  376. }
  377. return true
  378. }
  379. func updateLoginMenuItem() {
  380. let firstItem = NSApp.mainMenu?.item(at: 0)?.submenu
  381. if firstItem != nil {
  382. let item1 = firstItem?.item(withTag: 11)
  383. let item2 = firstItem?.item(withTag: 12)
  384. let item3 = firstItem?.item(withTag: 13)
  385. let item4 = firstItem?.item(withTag: 14)
  386. // let item5 = firstItem?.item(withTag: 15)
  387. if KMLightMemberManager.manager.isLogin() {
  388. item1?.title = KMLightMemberManager.manager.info.email
  389. item1?.isHidden = false
  390. item2?.isHidden = true
  391. item3?.isHidden = false
  392. item4?.isHidden = false
  393. // item5?.isHidden = false
  394. } else {
  395. item1?.isHidden = true
  396. item2?.isHidden = false
  397. item3?.isHidden = true
  398. item4?.isHidden = true
  399. // item5?.isHidden = true
  400. }
  401. }
  402. }
  403. @objc func clickOutline(menuItem: NSMenuItem) {
  404. KMPrint("更新菜单栏")
  405. }
  406. func menuNeedsUpdate(_ menu: NSMenu) {
  407. KMPrint("menuNeedsUpdate")
  408. // menu.removeAllItems()
  409. //
  410. // var item = NSMenuItem()
  411. // item = menu.addItem(withTitle: NSLocalizedString("Insert", comment: ""), action: nil, target: self)
  412. // item.representedObject = row
  413. //
  414. // var subMenu = NSMenu()
  415. // var subitem = NSMenuItem()
  416. // subitem = subMenu.addItem(withTitle: NSLocalizedString("Insert File", comment: ""), action: #selector(insertPageItemAction), target: self, tag:0)
  417. // subitem.representedObject = row
  418. // subitem = subMenu.addItem(withTitle: NSLocalizedString("Insert blank page", comment: ""), action: #selector(insertPageItemAction), target: self, tag:1)
  419. // subitem.representedObject = row
  420. // subitem = subMenu.addItem(withTitle: NSLocalizedString("Insert page", comment: ""), action: #selector(insertPageItemAction), target: self, tag:2)
  421. // subitem.representedObject = row
  422. // item.submenu = subMenu
  423. //
  424. // item = menu.addItem(withTitle: NSLocalizedString("Extract", comment: ""), action: #selector(extractPageItemAction), target: self)
  425. // item.representedObject = row
  426. // item = menu.addItem(withTitle: NSLocalizedString("Delete Page", comment: ""), action: #selector(deletePageItemAction), target: self)
  427. // item.representedObject = row
  428. // item = menu.addItem(withTitle: NSLocalizedString("Page Edit", comment: ""), action: #selector(pageEditItemAction), target: self)
  429. // item.representedObject = row
  430. //
  431. // menu.addItem(NSMenuItem.separator())
  432. //
  433. // item = menu.addItem(withTitle: NSLocalizedString("90 Rotate", comment: ""), action: #selector(rotatePageItemAction), target: self)
  434. // item.representedObject = row
  435. // item = menu.addItem(withTitle: NSLocalizedString("-90 Rotate", comment: ""), action: #selector(leftRotatePageItemAction), target: self)
  436. // item.representedObject = row
  437. //
  438. // menu.addItem(NSMenuItem.separator())
  439. //
  440. // item = menu.addItem(withTitle: NSLocalizedString("copy", comment: ""), action: #selector(copyItemAction), target: self)
  441. // item.representedObject = row
  442. // item = menu.addItem(withTitle: NSLocalizedString("cut", comment: ""), action: #selector(cutItemAction), target: self)
  443. // item.representedObject = row
  444. // item = menu.addItem(withTitle: NSLocalizedString("paste", comment: ""), action: #selector(pastePageItemAction), target: self)
  445. //
  446. // menu.addItem(NSMenuItem.separator())
  447. //
  448. // item = menu.addItem(withTitle: NSLocalizedString("print", comment: ""), action: #selector(printItemAction), target: self)
  449. //
  450. // item = menu.addItem(withTitle: NSLocalizedString("Share", comment: ""), action: nil, target: self)
  451. //
  452. // item.submenu = NSSharingServicePicker.menu(forSharingItems: [self.listView.document.documentURL ?? ""], subjectContext: "", withTarget: self, selector: #selector(sharePageItemAction), serviceDelegate: nil)
  453. // }
  454. }
  455. func menu(_ menu: NSMenu, update item: NSMenuItem, at index: Int, shouldCancel: Bool) -> Bool {
  456. return true
  457. }
  458. }
  459. #if VERSION_DMG
  460. extension AppDelegate : SUUpdaterDelegate {
  461. func updaterWillRelaunchApplication(_ updater: SUUpdater) {
  462. }
  463. func feedURLString(for updater: SUUpdater) -> String? {
  464. #if DEBUG
  465. return "http://test-pdf-pro.kdan.cn:3021/downloads/pdfmasterprocast.xml"
  466. #else
  467. return "https://www.pdfreaderpro.com/downloads/pdfmasterprocast.xml"
  468. #endif
  469. }
  470. func updaterShouldPromptForPermissionToCheck(forUpdates updater: SUUpdater) -> Bool {
  471. return false
  472. }
  473. func upgradeAPP(with updater: SUUpdater) {
  474. let string = "macappstore://apps.apple.com/cn/app/pdf-master-ai-pdf/id6446781258?mt=12"
  475. let url: URL = URL(string: string)!
  476. NSWorkspace.shared.open(url)
  477. }
  478. func upgradeButtonString(for updater: SUUpdater) -> String {
  479. return NSLocalizedString("PDF Master", comment: "")
  480. }
  481. }
  482. #endif