AppDelegate.swift 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. //
  2. // AppDelegate.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by Niehaoyu on 2022/9/23.
  6. //
  7. import Cocoa
  8. import UserNotifications
  9. @main
  10. class AppDelegate: NSObject, NSApplicationDelegate, iRateDelegate{
  11. var rateWindowVC: KMRateWindowController!
  12. func applicationWillFinishLaunching(_ notification: Notification) {
  13. #if VERSION_FREE
  14. #if VERSION_DMG
  15. // CPDFKit.setLicenseKey("1vz4jXcu5aWfQMr627tGjHjWHG+72WKPzgwSoeGqDlRtLAxe4CTHas7qUep1D46CjreeqLWWV06cFepolm8wCBlZscJaV9/dCyDMi/zMTh47O+sIky0oYdusH/8+jyGruF4pgtinJ/oZg/P95jw4/E0HpoZ9AH9eGpD2XRy8mHk=", secret: "mG0c3O3Mzeu5dkZJW3gpqh188cTuhYlGRPrbR/gfX4rCrm/O2+fI9yUYXNZ/JY1KPbFCeKgG+lEVwrbGHrpAyXATqjrt8ApqRYhafFooQjwAFgayISwZT/pa4NjR459gu4aGVjtYuk+Uxs/kosIBwyxQV1SVCQFsC27oMGz5P/rBQYv0T/D0N0z+Um3U+I+tG7BHAIgXXXaVusko5CeqTvQgas5D7/+aJEhkQvgEI0O+1BYV01oFLnRch1j6tFihDymhFKcLuOq5fKgsuDdHcA==")
  16. CPDFConvertKit.setLicenseKey("6zZWsJZxS0gKqledWY3Wo8AC+0IQ0EU1u9Wp7IVHvMsHpPe/0IPk9aNAbMUZwpTHMicme3hvjORzGJYnpBvb3/Z82a1GikkQmNZd+v5w339rXeJw+v0hhIv5Q4btZUOscw80t3c1bXxpLq3B6fv6psGJP0+FMyQOerBP6u4YYan9tCSe6rawjumJYCQMT5YNHtN/72HTYtc9HAcQzdMudePhw3hYY3747Z6Sq7DCCqgbK+BnM11gxblULiTgFkYLZsuBudusbqrM7WktIkcfpLfh15Y+TZ04iXpI9LWkgKoeYZ1VAJMTcrfwCs63g/8nUiZ59kpdetHbzONEIhsi+Wu0lH1oY17eVN2TRW5amzrZsD0yy20WxEXrssgDJq7xPzi1sOZ56C+jdE/8p9tNUW4KYJ5GoqCVh5w0Ajkc3xRqWrpmJXUollqL+u9K6VDPqy3tmvVGdknJxHlX4q+ufAQa+Tb3qlEJwp14dhrbJERqUs5Gygc6W5Fk18+uJ6IjwvilMe8T8+t3vLDZPlOgVg4lqZaxlBn/t+RvkJ/76CDO1/Byfqmig2vE4qETJmxV+pK4Lftqjsxibe087g3EFlaO/7ZpewBkqMhR1sG/D/3Jjsevjbb32Ut+5f8JWMFL7gFHikJx6PJwxlEEfVHP/dqNkFfBJKTqjjZoj9LNxxkOngdfNDsnWigFkZUSivLNCXAJ+a4C/mHaaRf95ad20LA0NahljpcTQ7x8TR8fuAHZkFK4DnFK+ST8zSP17/yW3x9ACHU6arojAbZ0IAz2pZRRuYYl9YB07NckfhpuE2qQAu+IaHm32opV2P/l/7HZUt7hsw7wAHIKJqnBs4cNag==")
  17. #else
  18. // CPDFKit.setLicenseKey("1vz4jXcu5aWfQMr627tGjHjWHG+72WKPzgwSoeGqDlRtLAxe4CTHas7qUep1D46CjreeqLWWV06cFepolm8wCBlZscJaV9/dCyDMi/zMTh47O+sIky0oYdusH/8+jyGruF4pgtinJ/oZg/P95jw4/E0HpoZ9AH9eGpD2XRy8mHk=", secret: "mG0c3O3Mzeu5dkZJW3gpqh188cTuhYlGRPrbR/gfX4rCrm/O2+fI9yUYXNZ/JY1KPbFCeKgG+lEVwrbGHrpAyXATqjrt8ApqRYhafFooQjwAFgayISwZT/pa4NjR459gu4aGVjtYuk+Uxs/kosIBwyxQV1SVCQFsC27oMGz5P/rBQYv0T/D0N0z+Um3U+I+tG7BHAIgXXXaVusko5CeqTvQgas5D7/+aJEhkQvgEI0O+1BYV01oFLnRch1j6tFihDymhFKcLuOq5fKgsuDdHcA==")
  19. CPDFConvertKit.setLicenseKey("6zZWsJZxS0gKqledWY3Wo8AC+0IQ0EU1u9Wp7IVHvMsHpPe/0IPk9aNAbMUZwpTHMicme3hvjORzGJYnpBvb3/Z82a1GikkQmNZd+v5w339rXeJw+v0hhIv5Q4btZUOscw80t3c1bXxpLq3B6fv6psGJP0+FMyQOerBP6u4YYan9tCSe6rawjumJYCQMT5YNHtN/72HTYtc9HAcQzdMudePhw3hYY3747Z6Sq7DCCqgbK+BnM11gxblULiTgFkYLZsuBudusbqrM7WktIkcfpLfh15Y+TZ04iXpI9LWkgKoeYZ1VAJMTcrfwCs63g/8nUiZ59kpdetHbzONEIhsi+Wu0lH1oY17eVN2TRW5amzrZsD0yy20WxEXrssgDJq7xPzi1sOZ56C+jdE/8p9tNUW4KYJ5GoqCVh5w0Ajkc3xRqWrpmJXUollqL+u9K6VDPqy3tmvVGdknJxHlX4q+ufAQa+Tb3qlEJwp14dhrbJERqUs5Gygc6W5Fk18+uJ6IjwvilMe8T8+t3vLDZPlOgVg4lqZaxlBn/t+RvkJ/76CDO1/Byfqmig2vE4qETJmxV+pK4Lftqjsxibe087g3EFlaO/7ZpewBkqMhR1sG/D/3Jjsevjbb32Ut+5f8JWMFL7gFHikJx6PJwxlEEfVHP/dqNkFfBJKTqjjZoj9LNxxkOngdfNDsnWigFkZUSivLNCXAJ+a4C/mHaaRf95ad20LA0NahljpcTQ7x8TR8fuAHZkFK4DnFK+ST8zSP17/yW3x9ACHU6arojAbZ0IAz2pZRRuYYl9YB07NckfhpuE2qQAu+IaHm32opV2P/l/7HZUt7hsw7wAHIKJqnBs4cNag==")
  20. #endif
  21. #else
  22. // CPDFKit.setLicenseKey("vEeYzYqkir/aYIfrBDmhQEj2omreQNEjmVvLFlAV82dFc/aIwVlR4TZX9zgHb2zFW9+cK5/DeiisEwS5yrto3CFY2Q9MqLwIATeSF1vlV0bhRLYexOw8Sabyzl9iOYufVyFQz68T7jCZVkXEKukJMi06Zpqwc5F/tGnrnrzkydk=", secret: "mG0c3O3Mzeu5dkZJW3gpqh188cTuhYlGRPrbR/gfX4rCrm/O2+fI9yUYXNZ/JY1KPbFCeKgG+lEVwrbGHrpAyXATqjrt8ApqRYhafFooQjwAFgayISwZT/pa4NjR459gu4aGVjtYuk+Uxs/kosIBwyxQV1SVCQFsC27oMGz5P/rBQYv0T/D0N0z+Um3U+I+tG7BHAIgXXXaVusko5CeqTkm+stgaO9rjBr8W89IPRRCg5dRM1r/xf9BsO0NNqcqQDBaBDLYysZFZsvpYi1vbvQ==")
  23. CPDFConvertKit.setLicenseKey("6zZWsJZxS0gKqledWY3Wo8AC+0IQ0EU1u9Wp7IVHvMsHpPe/0IPk9aNAbMUZwpTHMicme3hvjORzGJYnpBvb3/Z82a1GikkQmNZd+v5w339rXeJw+v0hhIv5Q4btZUOscw80t3c1bXxpLq3B6fv6psGJP0+FMyQOerBP6u4YYan9tCSe6rawjumJYCQMT5YNHtN/72HTYtc9HAcQzdMudePhw3hYY3747Z6Sq7DCCqgbK+BnM11gxblULiTgFkYLZsuBudusbqrM7WktIkcfpLfh15Y+TZ04iXpI9LWkgKoeYZ1VAJMTcrfwCs63g/8nUiZ59kpdetHbzONEIhsi+Wu0lH1oY17eVN2TRW5amzrZsD0yy20WxEXrssgDJq7xPzi1sOZ56C+jdE/8p9tNUW4KYJ5GoqCVh5w0Ajkc3xRqWrpmJXUollqL+u9K6VDPqy3tmvVGdknJxHlX4q+ufAQa+Tb3qlEJwp14dhrbJERqUs5Gygc6W5Fk18+uJ6IjwvilMe8T8+t3vLDZPlOgVg4lqZaxlBn/t+RvkJ/76CDO1/Byfqmig2vE4qETJmxV+pK4Lftqjsxibe087g3EFlaO/7ZpewBkqMhR1sG/D/3Jjsevjbb32Ut+5f8JWMFL7gFHikJx6PJwxlEEfVHP/dqNkFfBJKTqjjZoj9LNxxkOngdfNDsnWigFkZUSivLNCXAJ+a4C/mHaaRf95ad20LA0NahljpcTQ7x8TR8fuAHZkFK4DnFK+ST8zSP17/yW3x9ACHU6arojAbZ0IAz2pZRRuYYl9YB07NckfhpuE2qQAu+IaHm32opV2P/l/7HZUt7hsw7wAHIKJqnBs4cNag==")
  24. #endif
  25. CPDFKit.verify(withKey: "gMFiX0z5iLRx4DWXB1YzzszTXi8P1RGbs2t6D//Sowj62gyYAbZ2QqbLiIvwPt6N9mO4+kppY6mjsHQYLJIM4qyVkdOLyrRoET55leUlys2xv/vAuxkQ8RqQJYgFv0WhmC+IpenDmk3/XrKPcvGsERUyEuLO4FifqOncSuh6GHy4bbo0PkSWJhKZASN8hmzTMkKtI79ppkJ6CgjxZewhelUbJM07e0wdmJR9DF1x0EIntYoXxZ6z1fc6cjsRblPhDGEcUBTvbF6DMGXXRzJxlUFMzG7ka5InMav4dBW5CFLNpSEpGnzWO99DFwA9L4XZdGV2vKMNLXBhmYQF1PibTWu0lH1oY17eVN2TRW5amzrZsD0yy20WxEXrssgDJq7xPzi1sOZ56C+jdE/8p9tNUW4KYJ5GoqCVh5w0Ajkc3xRqWrpmJXUollqL+u9K6VDPiGAwpSBmox6oux68kbF7jkiCZDxHK7wfU3XrdhO8pmKn37TM/hBROJ3ufWlCiyNQy5AlRqzN1AAIKVmJzmOQCOcohtAQS/ULdkM2FO7GcxWLAf1YhWUmCAiDfm1c1lrdjqG0V0XpnGga69npgRspIG1y9kaZz89k1E7lWRj5bPVsGo+cInV8gEE9jyu1d/w+z+IoMv/64lho9GX2iJoq9a2ZlLQs3Nchtt3ztkLOIrL83eqpD+OFl7xBMsabCVNViM2vieVHPpj+ryaMGUv809szrKYrmDEsg4RKbxuXysKB3jpAHRMF+rSFAwQSTXQlmZfbxpitFoKX83UBkha60z3+yyZvjzxnVmPLWTnX0u13CDIXEvC3V6mR2aaKvVJnE5h5fVw9F2s3H5Q55YkTYg==")
  26. ComPDFUIConfig.initializeUIConfig()
  27. KMDesignToken.shared.parserExcel(withPath: "")
  28. }
  29. func applicationDidFinishLaunching(_ aNotification: Notification) {
  30. // Insert code here to initialize your application
  31. //通知
  32. UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
  33. if granted {
  34. KMPrint("User authorized notifications")
  35. } else {
  36. KMPrint("User denied notifications")
  37. }
  38. }
  39. /**本地推送测试
  40. UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
  41. if granted {
  42. // 创建本地推送通知
  43. let content = UNMutableNotificationContent()
  44. content.title = "Test Notification"
  45. content.body = "This is a test notification!"
  46. // 触发条件,例如延迟 5 秒触发
  47. let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
  48. // 创建通知请求
  49. let request = UNNotificationRequest(identifier: "LocalNotification", content: content, trigger: trigger)
  50. // 添加通知请求到用户通知中心
  51. UNUserNotificationCenter.current().add(request) { error in
  52. if let error = error {
  53. print("Error adding notification request: \(error)")
  54. } else {
  55. print("Local notification scheduled")
  56. }
  57. }
  58. } else {
  59. print("User denied notifications")
  60. }
  61. }
  62. **/
  63. DispatchQueue.main.async {
  64. NSApplication.shared.registerForRemoteNotifications()
  65. }
  66. #if VERSION_DMG
  67. let updater = SUUpdater.shared()
  68. updater?.delegate = self
  69. updater?.automaticallyChecksForUpdates = true
  70. #else
  71. #endif
  72. //Firebase RemoteConfig
  73. #if VERSION_FREE
  74. KMKdanRemoteConfig.remoteConfig.fetch { _status, error in
  75. }
  76. #endif
  77. let versionString = MainBundle.infoDictionary?[kCFBundleVersionKey as String] as? String ?? ""
  78. let lastVersionString = KMDataManager.ud_string(forKey: SKLastVersionLaunchedKey)
  79. if lastVersionString == nil || SKVersionNumber.compareVersionString(lastVersionString, toVersionString: versionString) == .orderedAscending {
  80. let sud = UserDefaults.standard
  81. if versionString.isEmpty == false {
  82. sud.set(versionString, forKey: SKLastVersionLaunchedKey)
  83. }
  84. // [sud setBool:NO forKey:@"kShowRecentGuideKey"];
  85. // [sud removeObjectForKey:@"kToolbarTipIsShow"];
  86. // [sud removeObjectForKey:@"kShowNoPermissionAlertKey"];
  87. // [sud removeObjectForKey:@"KMTabbingHintShowFlag"];
  88. // [sud removeObjectForKey:@"KMConverthHaveOpenConvertDetails"];
  89. sud.synchronize()
  90. }
  91. UserDefaults.standard.register(defaults: ["NSApplicationCrashOnExceptions" : true])
  92. NSApp.servicesProvider = self
  93. KMKdanRemoteConfig.remoteConfig.fetchWithRemoteConfigCompletionHandler { status, error in
  94. }
  95. KMStatusBar.system()
  96. // MARK: 广告数据初始化
  97. var appName: KMAdvertisementAppNameType = .PDFReaderProMac
  98. #if VERSION_FREE
  99. #if VERSION_DMG
  100. appName = .PDFReaderProMacDMG
  101. #else
  102. #endif
  103. #else
  104. appName = .PDFReaderProMacPro
  105. #endif
  106. KMAdvertisementManager.manager.initConfig(appName: appName,
  107. subscribeType: .unknow,
  108. platform: .Mac)
  109. // 测试模式,默认false
  110. KMAdvertisementManager.manager.debug = true
  111. NSApp.appearance = NSAppearance.current
  112. KMAnalytics.configure()
  113. //第一次开启app
  114. let info = UserDefaults.standard.value(forKey: "kFirstOpenAppCount")
  115. var count = 0
  116. if info != nil {
  117. count = info as? Int ?? 0
  118. }
  119. count += 1
  120. UserDefaults.standard.set(count, forKey: "kFirstOpenAppCount")
  121. UserDefaults.standard.synchronize()
  122. self.initMainMenu()
  123. /// pro
  124. // [DBClientsManager setupWithAppKeyDesktop:@"amipzwtlg9lrwyl"];
  125. DBClientsManager.setup(withAppKeyDesktop: "jxjlqfm1cfp2mjj")
  126. reopenDocument(forPaths: [])
  127. KMPreference.shared.initDataForAppLaunch()
  128. self.initiRateData()
  129. let appleEventManager = NSAppleEventManager.shared()
  130. appleEventManager.setEventHandler(self,
  131. andSelector: #selector(handleGetURLEvent(_:withReplyEvent:)),
  132. forEventClass: AEEventClass(kInternetEventClass),
  133. andEventID: AEEventID(kAEGetURL))
  134. DistributedNotificationCenter.default().addObserver(self, selector: #selector(_themeChanged), name: NSApplication.interfaceThemeChangedNotification, object: nil)
  135. #if VERSION_DMG
  136. VerificationManager.default()
  137. KMDMGProductsManager.shareInstance.getProductDatas()
  138. #else
  139. self.initiVersionData()
  140. IAPProductsManager.default().initIAP()
  141. #endif
  142. //AI相关
  143. AIInfoManager.default()
  144. NotificationCenter.default.addObserver(self, selector: #selector(AIDeviceStatusChangeNotification), name: NSNotification.Name(rawValue: "kDeviceAIStatusChangeNotification"), object: nil)
  145. for string in ["Ubuntu-Bold","Ubuntu-Medium"] {
  146. let fontURL = Bundle.main.url(forResource: string, withExtension: "ttf")
  147. var error: Unmanaged<CFError>?
  148. if !CTFontManagerRegisterFontsForURL(fontURL! as CFURL, .process, &error) {
  149. print("Failed to register font!")
  150. } else {
  151. print("Font registered successfully!")
  152. }
  153. }
  154. let appMenu = NSApp.mainMenu?.item(at: 0)?.submenu
  155. for item in appMenu!.items {
  156. if item.action == #selector(aiToolsAction) {
  157. if let tManager = VerificationManager.default() {
  158. let status = tManager.status
  159. if status == ActivityStatusNone {
  160. item.isHidden = true
  161. }
  162. }
  163. }
  164. }
  165. NotificationCenter.default.addObserver(self, selector: #selector(deviceActivateStatusChangeNotification), name: NSNotification.Name(rawValue: "kDeviceActivateNotification"), object: nil)
  166. }
  167. func initiRateData() {
  168. iRate.sharedInstance().delegate = self
  169. #if VERSION_FREE
  170. iRate.sharedInstance().appStoreID = 919472673
  171. #else
  172. iRate.sharedInstance().appStoreID = 825459243
  173. #endif
  174. iRate.sharedInstance().onlyPromptIfLatestVersion = false
  175. iRate.sharedInstance().onlyPromptIfMainWindowIsAvailable = true
  176. }
  177. //MARK: iRateDelegate
  178. func iRateUserDidDeclineToRateApp() {
  179. KMVerificationWindowController.verificationFeedback()
  180. }
  181. func iRateShouldPromptForRating() -> Bool {
  182. let notShow: Bool = UserDefaults.standard.bool(forKey: "kUserHaveClickRateUsKey")
  183. if !notShow {
  184. UserDefaults.standard.setValue(true, forKey: "kUserHaveClickRateUsKey")
  185. UserDefaults.standard.synchronize()
  186. NotificationCenter.default.post(name: Notification.Name(rawValue: "kUserHaveClickRateUsNotification"), object: self)
  187. }
  188. self.rateWindowVC = KMRateWindowController.init(windowNibName: "KMRateWindowController")
  189. self.rateWindowVC.closeBlock = { wc in
  190. }
  191. self.rateWindowVC.closeBlock = { wc in
  192. }
  193. self.rateWindowVC.showWindow(nil)
  194. return false
  195. }
  196. @objc func handleGetURLEvent(_ event: NSAppleEventDescriptor, withReplyEvent replyEvent: NSAppleEventDescriptor) {
  197. if let urlString = event.paramDescriptor(forKeyword: AEKeyword(keyDirectObject))?.stringValue,
  198. let url = URL(string: urlString) {
  199. // 在这里处理收到的 URL Scheme
  200. KMPrint("Received URL Scheme: \(url.scheme ?? "")")
  201. KMPrint("Path: \(url.path)")
  202. if NSApp.mainWindow == nil {
  203. let bundleIdentifier: String = Bundle.main.bundleIdentifier ?? ""
  204. launchApp(bundleIdentifier: bundleIdentifier)
  205. }
  206. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  207. #if VERSION_DMG
  208. // 执行相应的操作
  209. if url.scheme == "subscriptiondmgschemes" {
  210. if urlString.contains("open=expired") {
  211. KMPrint("刷新用户信息")
  212. if !KMLightMemberManager.manager.isLogin() && NSApp.mainWindow != nil {
  213. _ = KMLoginWindowController.show(window: NSApp.mainWindow!)
  214. } else {
  215. if NSApp.mainWindow != nil && KMLightMemberManager.manager.isLogin() {
  216. _ = KMAccountInfoWindowController.show(window: NSApp.mainWindow!)
  217. }
  218. }
  219. } else if urlString.contains("open=success") {
  220. if !KMLightMemberManager.manager.isLogin() && NSApp.mainWindow != nil {
  221. _ = KMLoginWindowController.show(window: NSApp.mainWindow!)
  222. } else {
  223. KMPurchaseManager.manager.restorePurchases { isSuccess, error in
  224. if isSuccess {
  225. } else {
  226. KMComparativeTableViewController.purchasefailed(view: NSApp.mainWindow?.contentView, state: error)
  227. }
  228. }
  229. }
  230. }
  231. }
  232. #endif
  233. #if VERSION_FREE
  234. // 执行相应的操作
  235. if url.scheme == "subscriptionSchemes" {
  236. //刷新用户信息
  237. KMRequestServerManager.manager.getUserInfo { success, data, error, isLocal in
  238. }
  239. if url.path == "/open" {
  240. // 执行打开操作
  241. } else if url.path == "/close" {
  242. // 执行关闭操作
  243. }
  244. }
  245. #endif
  246. }
  247. }
  248. }
  249. func launchApp(bundleIdentifier: String) {
  250. let workspace = NSWorkspace.shared
  251. // Launch the application with the specified bundle identifier
  252. if let appURL = NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleIdentifier) {
  253. do {
  254. try workspace.launchApplication(at: appURL, options: .default, configuration: [:])
  255. } catch {
  256. print("Error launching the application: \(error)")
  257. }
  258. } else {
  259. print("Application with bundle identifier '\(bundleIdentifier)' not found.")
  260. }
  261. }
  262. func application(_ application: NSApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  263. let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
  264. print("Device token:", token)
  265. }
  266. func application(_ application: NSApplication, didReceiveRemoteNotification userInfo: [String : Any]) {
  267. }
  268. func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
  269. if !flag {
  270. let browser: KMBrowser = KMBrowser.init()
  271. browser.windowController = KMBrowserWindowController.init(browser: browser)
  272. browser.addHomeTabContents()
  273. browser.windowController.showWindow(self)
  274. }
  275. return flag
  276. }
  277. @IBAction func closeDocument(_ sender: Any) {
  278. if ((NSApp.mainWindow?.windowController is KMBrowserWindowController) == false) {
  279. guard let windowControler = NSApp.mainWindow?.windowController else {
  280. return
  281. }
  282. windowControler.window?.performClose(nil)
  283. return
  284. }
  285. let windowControler = NSApp.mainWindow?.windowController as? KMBrowserWindowController
  286. if let data = windowControler?.browser, data.tabCount() >= 2 { // 有两个以上的标签
  287. if data.activeTabIndex() == 0 { // 主页不允许关闭,暂时处理为无反应
  288. return
  289. }
  290. }
  291. if let browser = windowControler?.browser {
  292. if browser.tabCount() == 1 {
  293. windowControler?.window?.close()
  294. } else {
  295. if let _ = windowControler?.window?.attachedSheet {
  296. NSSound.beep()
  297. return
  298. }
  299. browser.closeTab()
  300. }
  301. } else {
  302. windowControler?.window?.close()
  303. }
  304. }
  305. func applicationShouldOpenUntitledFile(_ sender: NSApplication) -> Bool {
  306. if (KMPreferenceManager.shared.openLastUnclosedDocumentWhenAppStart == false) {
  307. return false
  308. }
  309. let filepaths = KMPreferenceManager.shared.lastOpenFilepaths
  310. if (filepaths == nil || filepaths!.count == 0) {
  311. return false
  312. }
  313. DispatchQueue.main.async {
  314. for filepath in filepaths! {
  315. NSDocumentController.shared.km_safe_openDocument(withContentsOf: URL(fileURLWithPath: filepath), display: true) { _, _, _ in
  316. }
  317. }
  318. }
  319. return false
  320. }
  321. func applicationWillTerminate(_ aNotification: Notification) {
  322. if (NSDocumentController.shared.documents.count > 0) {
  323. var filepaths: [String] = []
  324. for document in NSDocumentController.shared.documents {
  325. // KMPrint(document.fileURL as Any)
  326. if (document.fileURL?.path != nil) {
  327. filepaths.append((document.fileURL?.path)!)
  328. }
  329. }
  330. KMPreferenceManager.shared.lastOpenFilepaths = filepaths
  331. } else {
  332. KMPreferenceManager.shared.lastOpenFilepaths = nil
  333. }
  334. }
  335. func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
  336. return true
  337. }
  338. // MARK: private
  339. func reopenDocument(forPaths paths: [String]) -> Void {
  340. let browser = KMBrowser.init() as KMBrowser
  341. browser.windowController = KMBrowserWindowController.init(browser: browser)
  342. browser.addHomeTabContents()
  343. browser.windowController.showWindow(self)
  344. }
  345. @objc private func _themeChanged(_ sender: Notification) {
  346. let isDarkModel = KMAdvertisementConfig.isDarkModel()
  347. if isDarkModel {
  348. NSApp.appearance = .init(named: .darkAqua)
  349. } else {
  350. NSApp.appearance = .init(named: .aqua)
  351. }
  352. // if let data = NSApp.appearance?.name, data == .darkAqua {
  353. // NSApp.appearance = .init(named: .aqua)
  354. // } else {
  355. // NSApp.appearance = .init(named: .darkAqua)
  356. // }
  357. NotificationCenter.default.post(name: Notification.Name(rawValue: "kEffectiveAppearance"), object: nil)
  358. }
  359. @objc func AIDeviceStatusChangeNotification() {
  360. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  361. self.refreshAIMenuItemInfo()
  362. }
  363. }
  364. @objc func deviceActivateStatusChangeNotification() {
  365. let appMenu = NSApp.mainMenu?.item(at: 0)?.submenu
  366. for item in appMenu!.items {
  367. if item.action == #selector(aiToolsAction) {
  368. if let tManager = VerificationManager.default() {
  369. let status = tManager.status
  370. if status == ActivityStatusNone {
  371. item.isHidden = true
  372. }
  373. }
  374. }
  375. }
  376. }
  377. func refreshAIMenuItemInfo() -> Void {
  378. let appMenu = NSApp.mainMenu?.item(at: 0)?.submenu
  379. for item in appMenu!.items {
  380. if item.action == #selector(aiToolsAction) {
  381. item.isHidden = true
  382. }
  383. }
  384. }
  385. //MARK: - iVersion
  386. func initiVersionData() -> Void{
  387. #if VERSION_DMG
  388. #else
  389. let tVersion = iVersion.sharedInstance()
  390. tVersion?.applicationBundleID = Bundle.main.bundleIdentifier
  391. var tStr = "New Update Available"
  392. tVersion?.updateAvailableTitle = (tVersion?.localizedString(forKey: tStr, withDefault: tStr) ?? "") + "\n"
  393. tVersion?.versionLabelFormat = ""
  394. tVersion?.groupNotesByVersion = true
  395. tVersion?.showOnFirstLaunch = false
  396. tVersion?.checkPeriod = 2
  397. tVersion?.remindPeriod = 5
  398. let infoDictionary = Bundle .main.infoDictionary!
  399. var appName: String = infoDictionary["CFBundleDisplayName"] as! String
  400. if appName.count < 1 {
  401. appName = infoDictionary["CFBundleName"] as! String
  402. }
  403. tStr = "The new version of %@ is available now. Go update for new features.";
  404. tStr = (tVersion?.localizedString(forKey: tStr, withDefault: tStr))!
  405. tStr = String(format: tStr, appName)
  406. tVersion?.inThisVersionTitle = tStr
  407. tStr = "UPDATE NOW";
  408. tVersion!.downloadButtonLabel = tVersion?.localizedString(forKey: tStr, withDefault: tStr)
  409. tStr = "LATER";
  410. tVersion!.remindButtonLabel = tVersion?.localizedString(forKey: tStr, withDefault: tStr)
  411. tVersion!.ignoreButtonLabel = ""
  412. #endif
  413. }
  414. // MARK: - Menu
  415. func initMainMenu() {
  416. // 处理菜单栏多语
  417. let mainMenu = NSApp.mainMenu
  418. if (mainMenu == nil) {
  419. return
  420. }
  421. for menu in mainMenu!.items {
  422. let subMenu = menu.submenu
  423. for item in subMenu!.items {
  424. item.title = NSLocalizedString(item.title, comment: "")
  425. let itemSubMenu = item.submenu
  426. if (itemSubMenu == nil) {
  427. continue
  428. }
  429. for item in itemSubMenu!.items {
  430. item.title = NSLocalizedString(item.title, comment: "")
  431. let itemSubMenu = item.submenu
  432. if (itemSubMenu == nil) {
  433. continue
  434. }
  435. for item in itemSubMenu!.items {
  436. item.title = NSLocalizedString(item.title, comment: "")
  437. }
  438. }
  439. }
  440. }
  441. let PDFOfficeMenu = mainMenu?.item(at: 0)?.submenu
  442. #if VERSION_DMG
  443. _ = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Check for Updates", comment: ""), action: #selector(checkForUpdates), target: self, at: 3)
  444. _ = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Enter License", comment: ""), action: #selector(enterLicense), target: self, at: 4)
  445. // if ([VerificationManager manager].needUpgradeLicense == NO) {
  446. if VerificationManager.default().needUpgradeLicense {
  447. _ = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("PDF to Office Pack", comment: ""), action: #selector(pdftoOfficeMenuItemAction), target: self, at: 5)
  448. }
  449. let accountRefreshItem = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Account Refresh", comment: ""), action: #selector(accountRefreshAction), target: self, at: 8)
  450. accountRefreshItem?.tag = kKMMainMenuAccountRefreshItemTag
  451. #endif
  452. #if !VERSION_DMG
  453. _ = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Restore Previous Purchase", comment: ""), action: #selector(restoreSubscriptions), target: self, at: 1)
  454. #endif
  455. if let items = PDFOfficeMenu?.items {
  456. for menu in items {
  457. let ranges = menu.title.ranges(of: "PDF Reader Pro")
  458. if let _range = ranges.range.first {
  459. menu.title.replaceSubrange(_range, with: KMTools.getAppName())
  460. }
  461. }
  462. }
  463. if let item = PDFOfficeMenu?.item(withTitle: NSLocalizedString("Volume Discount", comment: "")) {
  464. item.isHidden = true
  465. }
  466. if let item = PDFOfficeMenu?.item(withTitle: NSLocalizedString("One License for Mac and Windows", comment: "")) {
  467. item.isHidden = true
  468. }
  469. if let item = PDFOfficeMenu?.item(withTitle: NSLocalizedString("Education Discount", comment: "")) {
  470. item.isHidden = true
  471. }
  472. let fileMenu = mainMenu?.item(at: 1)?.submenu
  473. var shareItem: NSMenuItem?
  474. if let item = fileMenu?.item(withTitle: NSLocalizedString("Save Archive…", comment: "")) {
  475. shareItem = NSMenuItem(title: NSLocalizedString("Share", comment: ""), action: nil, target: nil)
  476. fileMenu?.insertItem(shareItem!, at: item.index)
  477. fileMenu?.insertItem(.separator(), at: item.index)
  478. } else {
  479. shareItem = NSMenuItem(title: NSLocalizedString("Share", comment: ""), action: nil, target: nil)
  480. fileMenu?.insertItem(shareItem!, at: (fileMenu?.items.count)!-1)
  481. }
  482. shareItem?.submenu = NSSharingServicePicker.menu(forSharingItems: [""], subjectContext: "", withTarget: self, selector: #selector(sharePageItemAction), serviceDelegate: nil)
  483. let deviceCameraMenuItem = NSMenuItem(title: NSLocalizedString("Import From Camera", comment: ""), action: #selector(deviceCameraMenuItemAciton), target: self)
  484. let deviceScannerMenuItem = NSMenuItem(title: NSLocalizedString("Import From Scanner", comment: ""), action: #selector(deviceScannerMenuItemAciton), target: self)
  485. fileMenu?.insertItem(deviceCameraMenuItem, at: (fileMenu?.items.count)!-1)
  486. fileMenu?.insertItem(deviceScannerMenuItem, at: (fileMenu?.items.count)!-1)
  487. fileMenu?.insertItem(.separator(), at: (fileMenu?.items.count)!-1)
  488. }
  489. @objc func sharePageItemAction(sender: NSMenuItem) {
  490. if ((NSApp.mainWindow?.windowController is KMBrowserWindowController) == false) {
  491. return
  492. }
  493. let windowControler = NSApp.mainWindow?.windowController as! KMBrowserWindowController
  494. let model = windowControler.browser?.tabStripModel
  495. if let cnt = model?.count(), cnt <= 0 {
  496. return
  497. }
  498. if let data = model?.activeTabContents()?.isHome, data {
  499. return
  500. }
  501. let document: KMMainDocument = model?.activeTabContents() as! KMMainDocument
  502. if let data = document.mainViewController?.saveWatermarkFlag, !data {
  503. let represent : NSSharingService = sender.representedObject as! NSSharingService
  504. represent.perform(withItems: [document.fileURL as Any])
  505. return
  506. }
  507. let represent : NSSharingService = sender.representedObject as! NSSharingService
  508. represent.perform(withItems: [document.fileURL as Any])
  509. }
  510. @objc func deviceCameraMenuItemAciton(sender: NSMenuItem) {
  511. KMPrint("deviceCameraMenuItemAciton")
  512. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "kDeviceCameraMenuItemNotification"), object: nil)
  513. }
  514. @objc func deviceScannerMenuItemAciton(sender: NSMenuItem) {
  515. KMPrint("deviceScannerMenuItemAciton")
  516. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "kDeviceScannerMenuItemNotification"), object: nil)
  517. }
  518. // MARK: PDF Reader Pro Menu
  519. @IBAction func openPreferenceWindow(_ sender: Any) {
  520. KMPreferenceController.shared.showWindow(self)
  521. }
  522. @objc @IBAction func manageAcctounMenuAction(_ sender: Any) {
  523. if KMLightMemberManager.manager.isLogin() {
  524. _ = KMAccountInfoWindowController.show(window: NSApp.mainWindow!)
  525. }
  526. }
  527. @IBAction func loginMenuItemAction(_ sender: Any) {
  528. // Login & Logout
  529. if KMLightMemberManager.manager.isLogin() {
  530. } else {
  531. _ = KMLoginWindowController.show(window: NSApp.mainWindow!)
  532. }
  533. }
  534. @IBAction func logoutMenuItemAction(_ sender: Any) {
  535. // Login & Logout
  536. if KMLightMemberManager.manager.isLogin() {
  537. KMRequestServerManager.manager.logout { success, result in
  538. if success {
  539. KMPrint("登出成功")
  540. }
  541. }
  542. }
  543. }
  544. @IBAction func restoreMenuItemAction(_ sender: Any) {
  545. KMPurchaseManager.manager.restorePurchases { isSuccess, error in
  546. if isSuccess {
  547. } else {
  548. if error != .restoreSuccess {
  549. KMComparativeTableViewController.purchasefailed(view: NSApp.mainWindow?.contentView, state: error)
  550. }
  551. }
  552. }
  553. }
  554. @objc func accountRefreshAction() {
  555. KMLightMemberManager.manager.updateNetworkingUserInfo { isDidLogout in
  556. }
  557. }
  558. @objc func showAccount() {
  559. }
  560. @objc func resumePurchase() {
  561. }
  562. // MARK: help Menu
  563. @IBAction func menuItemAction_quickStudy(_ sender: NSMenuItem) -> Void {
  564. KMTools.openQuickStartStudy()
  565. }
  566. @IBAction func menuItemAction_onlineHelp(_ sender: NSMenuItem) -> Void {
  567. KMTools.openFAQWebsite()
  568. }
  569. @IBAction func menuItemAction_morePudact(_ sender: NSMenuItem) -> Void {
  570. KMTools.openMoreProductWebsite()
  571. }
  572. @IBAction func menuItemAction_freePDFTemplate(_ sender: NSMenuItem) -> Void {
  573. KMTools.openFreePDFTemplatesWebsite()
  574. }
  575. @IBAction func menuItemAction_payEmail(_ sender: NSMenuItem) -> Void {
  576. KMEmailSubWindowController().showWindow(nil)
  577. }
  578. @IBAction func menuItemAction_poweredByComPDFKit(_ sender: NSMenuItem) -> Void {
  579. KMTools.openComPDFKitPowerWebsite()
  580. }
  581. @IBAction func menuItemAction_feekback(_ sender: NSMenuItem) -> Void {
  582. KMTools.proposeNewFeature()
  583. }
  584. @IBAction func menuItemAction_giveFiveStar(_ sender: NSMenuItem) -> Void {
  585. KMTools.rateUs()
  586. }
  587. @objc func restoreSubscriptions(_ sender: NSMenuItem) {
  588. #if VERSION_FREE
  589. KMPrint("restoreSubscriptions ...")
  590. let compareWindowVC: KMPurchaseCompareWindowController = KMPurchaseCompareWindowController.sharedInstance() as! KMPurchaseCompareWindowController
  591. compareWindowVC.showWindowRestore(nil)
  592. #else
  593. var vc: KMToolCompareWindowController? = nil
  594. vc = KMToolCompareWindowController.toolCompare(toolType: .Convert, selectNum: 0)
  595. vc!.showWindowRestore(sender: (Any).self)
  596. #endif
  597. }
  598. // MARK:- DMG
  599. @objc func checkForUpdates(_ sender: NSMenuItem) {
  600. #if VERSION_DMG
  601. SUUpdater.shared().checkForUpdates(sender)
  602. #endif
  603. }
  604. @objc func enterLicense(_ sender: NSMenuItem) {
  605. #if VERSION_DMG
  606. if let tManager = VerificationManager.default() {
  607. let status = tManager.status
  608. if status == ActivityStatusVerifExpire {
  609. let vc = KMVerificationWindowController.verification(with: .activateExpired)
  610. vc?.showWindow(nil)
  611. } else if status == ActivityStatusVerification {
  612. let vc = KMVerificationWindowController.verification(with: .info)
  613. vc?.showWindow(nil)
  614. } else {
  615. let vc = KMVerificationWindowController.verification(with: .activate)
  616. vc?.showWindow(nil)
  617. }
  618. }
  619. #endif
  620. }
  621. @objc func pdftoOfficeMenuItemAction(_ sender: NSMenuItem) {
  622. #if VERSION_DMG
  623. // var url = URL(string: Store_Link + "?product_code=product_2")
  624. // let tWorkSpace = NSWorkspace.shared
  625. // if tWorkSpace.open(url!) == false {
  626. // tWorkSpace.open(url!)
  627. // }
  628. let embeddedWC = KMPurchaseEmbeddedWindowController.currentFirstTrialWC("com.brother.pdfreaderpro.mac.product_2")
  629. embeddedWC.showWindow(nil)
  630. embeddedWC.window?.center()
  631. #endif
  632. }
  633. @IBAction func volumeDiscount(_ sender: NSMenuItem) {
  634. var tStrHttpUrl = "https://www.pdfreaderpro.com/vpp-purchase-program"
  635. #if VERSION_DMG
  636. tStrHttpUrl = APPMain_Link + "/vpp-purchase-program?utm_source=pdfdmg&utm_campaign=menubar_vpp"
  637. #else
  638. tStrHttpUrl = APPMain_Link + "/vpp-purchase-program?utm_source=pdfmacstore&utm_campaign=menubar_vpp"
  639. #endif
  640. guard let url = URL(string: tStrHttpUrl) else {
  641. NSSound.beep()
  642. return
  643. }
  644. let tWorkSpace = NSWorkspace.shared
  645. if tWorkSpace.open(url) == false {
  646. tWorkSpace.open(url)
  647. }
  648. }
  649. @IBAction func crossPlatformAction(_ sender: NSMenuItem) {
  650. var tStrHttpUrl = CrossPlatform_Link
  651. guard let url = URL(string: tStrHttpUrl) else {
  652. return
  653. }
  654. let tWorkSpace = NSWorkspace.shared
  655. if tWorkSpace.open(url) == false {
  656. tWorkSpace.open(url)
  657. }
  658. #if VERSION_DMG
  659. FMTrackEventManager.defaultManager.trackEvent(event: "Menubar", withProperties: ["Menubar_Btn" : "Menubar_Btn_Help_CrossPlatform"])
  660. #endif
  661. }
  662. @IBAction func EducationDiscountAction(_ sender: NSMenuItem) {
  663. let tStrHttpUrl = Store_Edu_Link
  664. guard let url = URL(string: tStrHttpUrl) else {
  665. return
  666. }
  667. let tWorkSpace = NSWorkspace.shared
  668. if tWorkSpace.open(url) == false {
  669. tWorkSpace.open(url)
  670. }
  671. #if VERSION_DMG
  672. FMTrackEventManager.defaultManager.trackEvent(event: "Menubar", withProperties: ["Menubar_Btn" : "Menubar_Btn_Help_EduDiscount"])
  673. #endif
  674. }
  675. @IBAction func aiToolsAction(_ sender: NSMenuItem) {
  676. #if VERSION_DMG
  677. KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
  678. #else
  679. AIPurchaseWindowController.currentWC().showWindow(nil)
  680. #endif
  681. }
  682. @IBAction func orderFrontLineInspector(_ sender: Any?) {
  683. if let win = KMLineInspector.shared.window {
  684. if win.isVisible {
  685. win.orderOut(sender)
  686. } else {
  687. win.orderFront(sender)
  688. }
  689. }
  690. }
  691. @IBAction func showDownloads(_ sender: NSMenuItem) -> Void {
  692. KMPrint("showDownloads ...")
  693. }
  694. @IBAction func showWelcomeWindow(_ sender: NSMenuItem) -> Void {
  695. self.reopenDocument(forPaths: [])
  696. }
  697. @IBAction func newsletter(_ sender: NSMenuItem) -> Void {
  698. KMEmailSubWindowController().showWindow(nil)
  699. }
  700. @IBAction func feedback(_ sender: NSMenuItem) -> Void {
  701. KMTools.feekback()
  702. }
  703. @IBAction func reportBug(_ sender: NSMenuItem) -> Void {
  704. KMTools.reportBug()
  705. }
  706. @IBAction func reportGeneralQuestions(_ sender: NSMenuItem) -> Void {
  707. KMTools.reportGeneralQuestions()
  708. }
  709. }
  710. extension AppDelegate : NSMenuDelegate,NSMenuItemValidation {
  711. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  712. let action = menuItem.action
  713. if action == #selector(manageAcctounMenuAction) {
  714. self.updateLoginMenuItem()
  715. return KMLightMemberManager.manager.isLogin()
  716. }
  717. if action == #selector(loginMenuItemAction) {
  718. self.updateLoginMenuItem()
  719. return !KMLightMemberManager.manager.isLogin()
  720. }
  721. if action == #selector(logoutMenuItemAction) {
  722. self.updateLoginMenuItem()
  723. return KMLightMemberManager.manager.isLogin()
  724. }
  725. if (action == #selector(sharePageItemAction)) {
  726. guard let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController else {
  727. return false
  728. }
  729. let isHome = _windowC.browser?.activeTabContents()?.isHome ?? false
  730. return !isHome
  731. }
  732. if action == #selector(closeDocument) {
  733. guard let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController else {
  734. if NSApp.mainWindow?.windowController != nil {
  735. return true
  736. }
  737. return false
  738. }
  739. let isNewTab = _windowC.browser?.activeTabContents()?.isNewTab ?? false
  740. if isNewTab {
  741. return true
  742. }
  743. // let isHome = _windowC.browser?.activeTabContents()?.isHome ?? false
  744. // return !isHome
  745. }
  746. return true
  747. }
  748. func updateLoginMenuItem() {
  749. let firstItem = NSApp.mainMenu?.item(at: 0)?.submenu
  750. if firstItem != nil {
  751. let item1 = firstItem?.item(withTag: 11)
  752. let item2 = firstItem?.item(withTag: 12)
  753. let item3 = firstItem?.item(withTag: 13)
  754. let item4 = firstItem?.item(withTag: 14)
  755. // let item5 = firstItem?.item(withTag: 15)
  756. let item6 = firstItem?.item(withTag: kKMMainMenuAccountRefreshItemTag)
  757. // if KMLightMemberManager.manager.isLogin() {
  758. // item1?.title = KMLightMemberManager.manager.info.email
  759. // item1?.isHidden = false
  760. // item2?.isHidden = true
  761. // item3?.isHidden = false
  762. // item4?.isHidden = false
  763. //// item5?.isHidden = false
  764. // item6?.isHidden = false
  765. // } else {
  766. // item1?.isHidden = true
  767. // item2?.isHidden = false
  768. // item3?.isHidden = true
  769. // item4?.isHidden = true
  770. //// item5?.isHidden = true
  771. // item6?.isHidden = true
  772. // }
  773. item1?.isHidden = true
  774. item2?.isHidden = true
  775. item3?.isHidden = true
  776. item4?.isHidden = true
  777. // item5?.isHidden = true
  778. item6?.isHidden = true
  779. }
  780. }
  781. @objc func clickOutline(menuItem: NSMenuItem) {
  782. KMPrint("更新菜单栏")
  783. }
  784. func menu(_ menu: NSMenu, update item: NSMenuItem, at index: Int, shouldCancel: Bool) -> Bool {
  785. return true
  786. }
  787. }
  788. #if VERSION_DMG
  789. extension AppDelegate : SUUpdaterDelegate {
  790. func updaterWillRelaunchApplication(_ updater: SUUpdater) {
  791. }
  792. func feedURLString(for updater: SUUpdater) -> String? {
  793. var hostURL = "https://www.pdfreaderpro.com/downloads/"
  794. #if DEBUG
  795. hostURL = "http://test-pdf-pro.kdan.cn:3021/downloads/"
  796. #else
  797. hostURL = "https://www.pdfreaderpro.com/downloads/"
  798. #endif
  799. return hostURL+NSLocalizedString("pdfreaderprocast.xml", comment: "")
  800. }
  801. func updaterShouldPromptForPermissionToCheck(forUpdates updater: SUUpdater) -> Bool {
  802. return false
  803. }
  804. func upgradeAPP(with updater: SUUpdater) {
  805. let string = "macappstore://apps.apple.com/app/id825459243?mt=12"
  806. let url: URL = URL(string: string)!
  807. NSWorkspace.shared.open(url)
  808. }
  809. func upgradeButtonString(for updater: SUUpdater) -> String {
  810. return NSLocalizedString("PDF Reader Pro", comment: "")
  811. }
  812. }
  813. #endif
  814. extension AppDelegate {
  815. // MARK: - Services Support
  816. func openDocumentFromURLOnPboard(_ pboard: NSPasteboard, userData: String?, error errorString: inout String?) {
  817. var error: NSError?
  818. if let document = NSDocumentController.shared.openDocumentWithURLFromPasteboard(pboard, showNotes: false, outError: &error) {
  819. // Document opened successfully
  820. } else if let error = error {
  821. errorString = error.localizedDescription
  822. }
  823. }
  824. func openDocumentFromDataOnPboard(_ pboard: NSPasteboard, userData: String?, error errorString: inout String?) {
  825. var error: NSError?
  826. if let document = NSDocumentController.shared.openDocumentWithImageFromPasteboard(pboard, error: &error) {
  827. // Document opened successfully
  828. } else if let error = error {
  829. errorString = error.localizedDescription
  830. }
  831. }
  832. func openNotesDocumentFromURLOnPboard(_ pboard: NSPasteboard, userData: String?, error errorString: inout String?) {
  833. var error: NSError?
  834. if let document = NSDocumentController.shared.openDocumentWithURLFromPasteboard(pboard, showNotes: true, outError: &error) {
  835. // Document opened successfully
  836. } else if let error = error {
  837. errorString = error.localizedDescription
  838. }
  839. }
  840. }
  841. extension AppDelegate: UNUserNotificationCenterDelegate {
  842. func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
  843. // 处理用户点击推送通知的操作
  844. completionHandler()
  845. }
  846. }