AppDelegate.swift 40 KB

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