AppDelegate.swift 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  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. rate.showWindow(nil)
  180. return false
  181. }
  182. @objc func handleGetURLEvent(_ event: NSAppleEventDescriptor, withReplyEvent replyEvent: NSAppleEventDescriptor) {
  183. if let urlString = event.paramDescriptor(forKeyword: AEKeyword(keyDirectObject))?.stringValue,
  184. let url = URL(string: urlString) {
  185. // 在这里处理收到的 URL Scheme
  186. KMPrint("Received URL Scheme: \(url.scheme ?? "")")
  187. KMPrint("Path: \(url.path)")
  188. if NSApp.mainWindow == nil {
  189. let bundleIdentifier: String = Bundle.main.bundleIdentifier ?? ""
  190. launchApp(bundleIdentifier: bundleIdentifier)
  191. }
  192. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  193. #if VERSION_DMG
  194. // 执行相应的操作
  195. if url.scheme == "subscriptiondmgschemes" {
  196. if urlString.contains("open=expired") {
  197. KMPrint("刷新用户信息")
  198. if !KMLightMemberManager.manager.isLogin() && NSApp.mainWindow != nil {
  199. _ = KMLoginWindowController.show(window: NSApp.mainWindow!)
  200. } else {
  201. if NSApp.mainWindow != nil && KMLightMemberManager.manager.isLogin() {
  202. _ = KMAccountInfoWindowController.show(window: NSApp.mainWindow!)
  203. }
  204. }
  205. } else if urlString.contains("open=success") {
  206. if !KMLightMemberManager.manager.isLogin() && NSApp.mainWindow != nil {
  207. _ = KMLoginWindowController.show(window: NSApp.mainWindow!)
  208. } else {
  209. KMPurchaseManager.manager.restorePurchases { isSuccess, error in
  210. if isSuccess {
  211. } else {
  212. KMComparativeTableViewController.purchasefailed(view: NSApp.mainWindow?.contentView, state: error)
  213. }
  214. }
  215. }
  216. }
  217. }
  218. #endif
  219. #if VERSION_FREE
  220. // 执行相应的操作
  221. if url.scheme == "subscriptionSchemes" {
  222. //刷新用户信息
  223. KMRequestServerManager.manager.getUserInfo { success, data, error, isLocal in
  224. }
  225. if url.path == "/open" {
  226. // 执行打开操作
  227. } else if url.path == "/close" {
  228. // 执行关闭操作
  229. }
  230. }
  231. #endif
  232. }
  233. }
  234. }
  235. func launchApp(bundleIdentifier: String) {
  236. let workspace = NSWorkspace.shared
  237. // Launch the application with the specified bundle identifier
  238. if let appURL = NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleIdentifier) {
  239. do {
  240. try workspace.launchApplication(at: appURL, options: .default, configuration: [:])
  241. } catch {
  242. print("Error launching the application: \(error)")
  243. }
  244. } else {
  245. print("Application with bundle identifier '\(bundleIdentifier)' not found.")
  246. }
  247. }
  248. func application(_ application: NSApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  249. let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
  250. print("Device token:", token)
  251. }
  252. func application(_ application: NSApplication, didReceiveRemoteNotification userInfo: [String : Any]) {
  253. }
  254. func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
  255. if !flag {
  256. let browser: KMBrowser = KMBrowser.init()
  257. browser.windowController = KMBrowserWindowController.init(browser: browser)
  258. browser.addHomeTabContents()
  259. browser.windowController.showWindow(self)
  260. }
  261. return flag
  262. }
  263. @IBAction func closeDocument(_ sender: Any) {
  264. if ((NSApp.mainWindow?.windowController is KMBrowserWindowController) == false) {
  265. guard let windowControler = NSApp.mainWindow?.windowController else {
  266. return
  267. }
  268. windowControler.window?.performClose(nil)
  269. return
  270. }
  271. let windowControler = NSApp.mainWindow?.windowController as! KMBrowserWindowController
  272. if let data = windowControler.browser, data.tabCount() >= 2 { // 有两个以上的标签
  273. if data.activeTabIndex() == 0 { // 主页不允许关闭,暂时处理为无反应
  274. return
  275. }
  276. }
  277. windowControler.browser.closeTab()
  278. }
  279. func applicationShouldOpenUntitledFile(_ sender: NSApplication) -> Bool {
  280. if (KMPreferenceManager.shared.openLastUnclosedDocumentWhenAppStart == false) {
  281. return false
  282. }
  283. let filepaths = KMPreferenceManager.shared.lastOpenFilepaths
  284. if (filepaths == nil || filepaths!.count == 0) {
  285. return false
  286. }
  287. DispatchQueue.main.async {
  288. for filepath in filepaths! {
  289. NSDocumentController.shared.km_safe_openDocument(withContentsOf: URL(fileURLWithPath: filepath), display: true) { _, _, _ in
  290. }
  291. }
  292. }
  293. return false
  294. }
  295. func applicationWillTerminate(_ aNotification: Notification) {
  296. if (NSApp.orderedDocuments.count > 0) {
  297. var filepaths: [String] = []
  298. for document in NSApp.orderedDocuments {
  299. // KMPrint(document.fileURL as Any)
  300. if (document.fileURL?.path != nil) {
  301. filepaths.append((document.fileURL?.path)!)
  302. }
  303. }
  304. KMPreferenceManager.shared.lastOpenFilepaths = filepaths
  305. } else {
  306. KMPreferenceManager.shared.lastOpenFilepaths = nil
  307. }
  308. }
  309. func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
  310. return true
  311. }
  312. // MARK: private
  313. func reopenDocument(forPaths paths: [String]) -> Void {
  314. let browser = KMBrowser.init() as KMBrowser
  315. browser.windowController = KMBrowserWindowController.init(browser: browser)
  316. browser.addHomeTabContents()
  317. browser.windowController.showWindow(self)
  318. }
  319. @objc private func _themeChanged(_ sender: Notification) {
  320. let isDarkModel = KMAdvertisementConfig.isDarkModel()
  321. if isDarkModel {
  322. NSApp.appearance = .init(named: .darkAqua)
  323. } else {
  324. NSApp.appearance = .init(named: .aqua)
  325. }
  326. // if let data = NSApp.appearance?.name, data == .darkAqua {
  327. // NSApp.appearance = .init(named: .aqua)
  328. // } else {
  329. // NSApp.appearance = .init(named: .darkAqua)
  330. // }
  331. NotificationCenter.default.post(name: Notification.Name(rawValue: "kEffectiveAppearance"), object: nil)
  332. }
  333. @objc func AIDeviceStatusChangeNotification() {
  334. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  335. self.refreshAIMenuItemInfo()
  336. }
  337. }
  338. func refreshAIMenuItemInfo() -> Void {
  339. let appMenu = NSApp.mainMenu?.item(at: 0)?.submenu
  340. for item in appMenu!.items {
  341. if item.action == #selector(aiToolsAction) {
  342. item.isHidden = true
  343. }
  344. }
  345. }
  346. //MARK: - iVersion
  347. func initiVersionData() -> Void{
  348. #if VERSION_DMG
  349. #else
  350. let tVersion = iVersion.sharedInstance()
  351. tVersion?.applicationBundleID = Bundle.main.bundleIdentifier
  352. var tStr = "New Update Available"
  353. tVersion?.updateAvailableTitle = (tVersion?.localizedString(forKey: tStr, withDefault: tStr) ?? "") + "\n"
  354. tVersion?.versionLabelFormat = ""
  355. tVersion?.groupNotesByVersion = true
  356. tVersion?.showOnFirstLaunch = false
  357. tVersion?.checkPeriod = 2
  358. tVersion?.remindPeriod = 5
  359. let infoDictionary = Bundle .main.infoDictionary!
  360. var appName: String = infoDictionary["CFBundleDisplayName"] as! String
  361. if appName.count < 1 {
  362. appName = infoDictionary["CFBundleName"] as! String
  363. }
  364. tStr = "The new version of %@ is available now. Go update for new features.";
  365. tStr = (tVersion?.localizedString(forKey: tStr, withDefault: tStr))!
  366. tStr = String(format: tStr, appName)
  367. tVersion?.inThisVersionTitle = tStr
  368. tStr = "UPDATE NOW";
  369. tVersion!.downloadButtonLabel = tVersion?.localizedString(forKey: tStr, withDefault: tStr)
  370. tStr = "LATER";
  371. tVersion!.remindButtonLabel = tVersion?.localizedString(forKey: tStr, withDefault: tStr)
  372. tVersion!.ignoreButtonLabel = ""
  373. #endif
  374. }
  375. // MARK: - Menu
  376. func initMainMenu() {
  377. // 处理菜单栏多语
  378. let mainMenu = NSApp.mainMenu
  379. if (mainMenu == nil) {
  380. return
  381. }
  382. for menu in mainMenu!.items {
  383. let subMenu = menu.submenu
  384. for item in subMenu!.items {
  385. item.title = NSLocalizedString(item.title, comment: "")
  386. let itemSubMenu = item.submenu
  387. if (itemSubMenu == nil) {
  388. continue
  389. }
  390. for item in itemSubMenu!.items {
  391. item.title = NSLocalizedString(item.title, comment: "")
  392. }
  393. }
  394. }
  395. let PDFOfficeMenu = mainMenu?.item(at: 0)?.submenu
  396. #if VERSION_DMG
  397. _ = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Check for Updates", comment: ""), action: #selector(checkForUpdates), target: self, at: 3)
  398. _ = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Enter License", comment: ""), action: #selector(enterLicense), target: self, at: 4)
  399. // if ([VerificationManager manager].needUpgradeLicense == NO) {
  400. if VerificationManager.default().needUpgradeLicense {
  401. _ = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("PDF to Office Pack", comment: ""), action: #selector(pdftoOfficeMenuItemAction), target: self, at: 5)
  402. }
  403. let accountRefreshItem = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Account Refresh", comment: ""), action: #selector(accountRefreshAction), target: self, at: 8)
  404. accountRefreshItem?.tag = kKMMainMenuAccountRefreshItemTag
  405. #endif
  406. #if !VERSION_DMG
  407. _ = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Restore Previous Purchase", comment: ""), action: #selector(restoreSubscriptions), target: self, at: 1)
  408. #endif
  409. if let items = PDFOfficeMenu?.items {
  410. for menu in items {
  411. let ranges = menu.title.ranges(of: "PDF Reader Pro")
  412. if let _range = ranges.range.first {
  413. menu.title.replaceSubrange(_range, with: KMTools.getAppName())
  414. }
  415. }
  416. }
  417. let fileMenu = mainMenu?.item(at: 1)?.submenu
  418. var shareItem: NSMenuItem?
  419. if let item = fileMenu?.item(withTitle: NSLocalizedString("Save Archive…", comment: "")) {
  420. shareItem = NSMenuItem(title: NSLocalizedString("Share", comment: ""), action: nil, target: nil)
  421. fileMenu?.insertItem(shareItem!, at: item.index)
  422. fileMenu?.insertItem(.separator(), at: item.index)
  423. } else {
  424. shareItem = NSMenuItem(title: NSLocalizedString("Share", comment: ""), action: nil, target: nil)
  425. fileMenu?.insertItem(shareItem!, at: (fileMenu?.items.count)!-1)
  426. }
  427. shareItem?.submenu = NSSharingServicePicker.menu(forSharingItems: [""], subjectContext: "", withTarget: self, selector: #selector(sharePageItemAction), serviceDelegate: nil)
  428. let deviceCameraMenuItem = NSMenuItem(title: NSLocalizedString("Import From Camera", comment: ""), action: #selector(deviceCameraMenuItemAciton), target: self)
  429. let deviceScannerMenuItem = NSMenuItem(title: NSLocalizedString("Import From Scanner", comment: ""), action: #selector(deviceScannerMenuItemAciton), target: self)
  430. fileMenu?.insertItem(deviceCameraMenuItem, at: (fileMenu?.items.count)!-1)
  431. fileMenu?.insertItem(deviceScannerMenuItem, at: (fileMenu?.items.count)!-1)
  432. fileMenu?.insertItem(.separator(), at: (fileMenu?.items.count)!-1)
  433. }
  434. @objc func sharePageItemAction(sender: NSMenuItem) {
  435. if ((NSApp.mainWindow?.windowController is KMBrowserWindowController) == false) {
  436. return
  437. }
  438. let windowControler = NSApp.mainWindow?.windowController as! KMBrowserWindowController
  439. let model = windowControler.browser?.tabStripModel
  440. if let cnt = model?.count(), cnt <= 0 {
  441. return
  442. }
  443. if let data = model?.activeTabContents()?.isHome, data {
  444. return
  445. }
  446. let document: KMMainDocument = model?.activeTabContents() as! KMMainDocument
  447. if let data = document.mainViewController?.saveWatermarkFlag, !data {
  448. let represent : NSSharingService = sender.representedObject as! NSSharingService
  449. represent.perform(withItems: [document.fileURL as Any])
  450. return
  451. }
  452. let represent : NSSharingService = sender.representedObject as! NSSharingService
  453. represent.perform(withItems: [document.fileURL as Any])
  454. }
  455. @objc func deviceCameraMenuItemAciton(sender: NSMenuItem) {
  456. KMPrint("deviceCameraMenuItemAciton")
  457. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "kDeviceCameraMenuItemNotification"), object: nil)
  458. }
  459. @objc func deviceScannerMenuItemAciton(sender: NSMenuItem) {
  460. KMPrint("deviceScannerMenuItemAciton")
  461. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "kDeviceScannerMenuItemNotification"), object: nil)
  462. }
  463. // MARK: PDF Reader Pro Menu
  464. @IBAction func openPreferenceWindow(_ sender: Any) {
  465. KMPreferenceController.shared.showWindow(self)
  466. }
  467. @objc @IBAction func manageAcctounMenuAction(_ sender: Any) {
  468. if KMLightMemberManager.manager.isLogin() {
  469. _ = KMAccountInfoWindowController.show(window: NSApp.mainWindow!)
  470. }
  471. }
  472. @IBAction func loginMenuItemAction(_ sender: Any) {
  473. // Login & Logout
  474. if KMLightMemberManager.manager.isLogin() {
  475. } else {
  476. _ = KMLoginWindowController.show(window: NSApp.mainWindow!)
  477. }
  478. }
  479. @IBAction func logoutMenuItemAction(_ sender: Any) {
  480. // Login & Logout
  481. if KMLightMemberManager.manager.isLogin() {
  482. KMRequestServerManager.manager.logout { success, result in
  483. if success {
  484. KMPrint("登出成功")
  485. }
  486. }
  487. }
  488. }
  489. @IBAction func restoreMenuItemAction(_ sender: Any) {
  490. KMPurchaseManager.manager.restorePurchases { isSuccess, error in
  491. if isSuccess {
  492. } else {
  493. if error != .restoreSuccess {
  494. KMComparativeTableViewController.purchasefailed(view: NSApp.mainWindow?.contentView, state: error)
  495. }
  496. }
  497. }
  498. }
  499. @objc func accountRefreshAction() {
  500. KMLightMemberManager.manager.updateNetworkingUserInfo { isDidLogout in
  501. }
  502. }
  503. @objc func showAccount() {
  504. }
  505. @objc func resumePurchase() {
  506. }
  507. // MARK: help Menu
  508. @IBAction func menuItemAction_quickStudy(_ sender: NSMenuItem) -> Void {
  509. KMTools.openQuickStartStudy()
  510. }
  511. @IBAction func menuItemAction_onlineHelp(_ sender: NSMenuItem) -> Void {
  512. KMTools.openFAQWebsite()
  513. }
  514. @IBAction func menuItemAction_morePudact(_ sender: NSMenuItem) -> Void {
  515. KMTools.openMoreProductWebsite()
  516. }
  517. @IBAction func menuItemAction_freePDFTemplate(_ sender: NSMenuItem) -> Void {
  518. KMTools.openFreePDFTemplatesWebsite()
  519. }
  520. @IBAction func menuItemAction_payEmail(_ sender: NSMenuItem) -> Void {
  521. KMEmailSubWindowController().showWindow(nil)
  522. }
  523. @IBAction func menuItemAction_poweredByComPDFKit(_ sender: NSMenuItem) -> Void {
  524. KMTools.openComPDFKitPowerWebsite()
  525. }
  526. @IBAction func menuItemAction_feekback(_ sender: NSMenuItem) -> Void {
  527. KMTools.proposeNewFeature()
  528. }
  529. @IBAction func menuItemAction_giveFiveStar(_ sender: NSMenuItem) -> Void {
  530. KMTools.rateUs()
  531. }
  532. @objc func restoreSubscriptions(_ sender: NSMenuItem) {
  533. #if VERSION_FREE
  534. KMPrint("restoreSubscriptions ...")
  535. let compareWindowVC: KMPurchaseCompareWindowController = KMPurchaseCompareWindowController.sharedInstance() as! KMPurchaseCompareWindowController
  536. compareWindowVC.showWindowRestore(nil)
  537. #else
  538. var vc: KMToolCompareWindowController? = nil
  539. vc = KMToolCompareWindowController.toolCompare(toolType: .Convert, selectNum: 0)
  540. vc!.showWindowRestore(sender: (Any).self)
  541. #endif
  542. }
  543. // MARK:- DMG
  544. @objc func checkForUpdates(_ sender: NSMenuItem) {
  545. #if VERSION_DMG
  546. SUUpdater.shared().checkForUpdates(sender)
  547. #endif
  548. }
  549. @objc func enterLicense(_ sender: NSMenuItem) {
  550. #if VERSION_DMG
  551. if let tManager = VerificationManager.default() {
  552. let status = tManager.status
  553. if status == ActivityStatusVerifExpire {
  554. let vc = KMVerificationWindowController.verification(with: .activateExpired)
  555. vc?.showWindow(nil)
  556. } else if status == ActivityStatusVerification {
  557. let vc = KMVerificationWindowController.verification(with: .info)
  558. vc?.showWindow(nil)
  559. } else {
  560. let vc = KMVerificationWindowController.verification(with: .activate)
  561. vc?.showWindow(nil)
  562. }
  563. }
  564. #endif
  565. }
  566. @objc func pdftoOfficeMenuItemAction(_ sender: NSMenuItem) {
  567. #if VERSION_DMG
  568. var url = URL(string: "https://www.pdfreaderpro.com/store?product_code=product_2")
  569. if SKInspectPublicTool.currentisLanguageHans() {
  570. url = URL(string: "https://www.pdfreaderpro.com/zh-cn/store?product_code=product_2")
  571. }
  572. let tWorkSpace = NSWorkspace.shared
  573. if tWorkSpace.open(url!) == false {
  574. tWorkSpace.open(url!)
  575. }
  576. #endif
  577. }
  578. @IBAction func volumeDiscount(_ sender: NSMenuItem) {
  579. var tStrHttpUrl = "https://www.pdfreaderpro.com/vpp-purchase-program"
  580. #if VERSION_DMG
  581. tStrHttpUrl = "https://www.pdfreaderpro.com/vpp-purchase-program?utm_source=pdfdmg&utm_campaign=menubar_vpp"
  582. if SKInspectPublicTool.currentisLanguageHans() {
  583. tStrHttpUrl = "https://www.pdfreaderpro.com/vpp-purchase-program?utm_source=pdfdmg&utm_campaign=menubar_vpp_zh"
  584. }
  585. #else
  586. tStrHttpUrl = "https://www.pdfreaderpro.com/vpp-purchase-program?utm_source=pdfmacstore&utm_campaign=menubar_vpp"
  587. if SKInspectPublicTool.currentisLanguageHans() {
  588. tStrHttpUrl = "https://www.pdfreaderpro.com/vpp-purchase-program?utm_source=pdfmacstore&utm_campaign=menubar_vpp_zh"
  589. }
  590. #endif
  591. guard let url = URL(string: tStrHttpUrl) else {
  592. NSSound.beep()
  593. return
  594. }
  595. let tWorkSpace = NSWorkspace.shared
  596. if tWorkSpace.open(url) == false {
  597. tWorkSpace.open(url)
  598. }
  599. }
  600. @IBAction func crossPlatformAction(_ sender: NSMenuItem) {
  601. 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"
  602. if SKInspectPublicTool.currentisLanguageHans() {
  603. 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"
  604. }
  605. guard let url = URL(string: tStrHttpUrl) else {
  606. return
  607. }
  608. let tWorkSpace = NSWorkspace.shared
  609. if tWorkSpace.open(url) == false {
  610. tWorkSpace.open(url)
  611. }
  612. #if VERSION_DMG
  613. FMTrackEventManager.defaultManager.trackEvent(event: "Menubar", withProperties: ["Menubar_Btn" : "Menubar_Btn_Help_CrossPlatform"])
  614. #endif
  615. }
  616. @IBAction func EducationDiscountAction(_ sender: NSMenuItem) {
  617. 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)
  618. guard let url = URL(string: tStrHttpUrl) else {
  619. return
  620. }
  621. let tWorkSpace = NSWorkspace.shared
  622. if tWorkSpace.open(url) == false {
  623. tWorkSpace.open(url)
  624. }
  625. #if VERSION_DMG
  626. FMTrackEventManager.defaultManager.trackEvent(event: "Menubar", withProperties: ["Menubar_Btn" : "Menubar_Btn_Help_EduDiscount"])
  627. #endif
  628. }
  629. @IBAction func aiToolsAction(_ sender: NSMenuItem) {
  630. #if VERSION_DMG
  631. KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
  632. #else
  633. AIPurchaseWindowController.currentWC().showWindow(nil)
  634. #endif
  635. }
  636. @IBAction func orderFrontLineInspector(_ sender: Any?) {
  637. if let win = KMLineInspector.shared.window {
  638. if win.isVisible {
  639. win.orderOut(sender)
  640. } else {
  641. win.orderFront(sender)
  642. }
  643. }
  644. }
  645. @IBAction func showDownloads(_ sender: NSMenuItem) -> Void {
  646. KMPrint("showDownloads ...")
  647. }
  648. @IBAction func showWelcomeWindow(_ sender: NSMenuItem) -> Void {
  649. self.reopenDocument(forPaths: [])
  650. }
  651. @IBAction func newsletter(_ sender: NSMenuItem) -> Void {
  652. KMEmailSubWindowController().showWindow(nil)
  653. }
  654. @IBAction func feedback(_ sender: NSMenuItem) -> Void {
  655. KMTools.feekback()
  656. }
  657. @IBAction func reportBug(_ sender: NSMenuItem) -> Void {
  658. KMTools.reportBug()
  659. }
  660. @IBAction func reportGeneralQuestions(_ sender: NSMenuItem) -> Void {
  661. KMTools.reportGeneralQuestions()
  662. }
  663. }
  664. extension AppDelegate : NSMenuDelegate,NSMenuItemValidation {
  665. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  666. let action = menuItem.action
  667. if action == #selector(manageAcctounMenuAction) {
  668. self.updateLoginMenuItem()
  669. return KMLightMemberManager.manager.isLogin()
  670. }
  671. if action == #selector(loginMenuItemAction) {
  672. self.updateLoginMenuItem()
  673. return !KMLightMemberManager.manager.isLogin()
  674. }
  675. if action == #selector(logoutMenuItemAction) {
  676. self.updateLoginMenuItem()
  677. return KMLightMemberManager.manager.isLogin()
  678. }
  679. if (action == #selector(sharePageItemAction)) {
  680. guard let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController else {
  681. return false
  682. }
  683. let isHome = _windowC.browser?.activeTabContents()?.isHome ?? false
  684. return !isHome
  685. }
  686. if action == #selector(closeDocument) {
  687. guard let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController else {
  688. if NSApp.mainWindow?.windowController != nil {
  689. return true
  690. }
  691. return false
  692. }
  693. let isNewTab = _windowC.browser?.activeTabContents()?.isNewTab ?? false
  694. if isNewTab {
  695. return true
  696. }
  697. // let isHome = _windowC.browser?.activeTabContents()?.isHome ?? false
  698. // return !isHome
  699. }
  700. return true
  701. }
  702. func updateLoginMenuItem() {
  703. let firstItem = NSApp.mainMenu?.item(at: 0)?.submenu
  704. if firstItem != nil {
  705. let item1 = firstItem?.item(withTag: 11)
  706. let item2 = firstItem?.item(withTag: 12)
  707. let item3 = firstItem?.item(withTag: 13)
  708. let item4 = firstItem?.item(withTag: 14)
  709. // let item5 = firstItem?.item(withTag: 15)
  710. let item6 = firstItem?.item(withTag: kKMMainMenuAccountRefreshItemTag)
  711. // if KMLightMemberManager.manager.isLogin() {
  712. // item1?.title = KMLightMemberManager.manager.info.email
  713. // item1?.isHidden = false
  714. // item2?.isHidden = true
  715. // item3?.isHidden = false
  716. // item4?.isHidden = false
  717. //// item5?.isHidden = false
  718. // item6?.isHidden = false
  719. // } else {
  720. // item1?.isHidden = true
  721. // item2?.isHidden = false
  722. // item3?.isHidden = true
  723. // item4?.isHidden = true
  724. //// item5?.isHidden = true
  725. // item6?.isHidden = true
  726. // }
  727. item1?.isHidden = true
  728. item2?.isHidden = true
  729. item3?.isHidden = true
  730. item4?.isHidden = true
  731. // item5?.isHidden = true
  732. item6?.isHidden = true
  733. }
  734. }
  735. @objc func clickOutline(menuItem: NSMenuItem) {
  736. KMPrint("更新菜单栏")
  737. }
  738. func menu(_ menu: NSMenu, update item: NSMenuItem, at index: Int, shouldCancel: Bool) -> Bool {
  739. return true
  740. }
  741. }
  742. #if VERSION_DMG
  743. extension AppDelegate : SUUpdaterDelegate {
  744. func updaterWillRelaunchApplication(_ updater: SUUpdater) {
  745. }
  746. func feedURLString(for updater: SUUpdater) -> String? {
  747. #if DEBUG
  748. return "http://test-pdf-pro.kdan.cn:3021/downloads/pdfmasterprocast.xml"
  749. #else
  750. return "https://www.pdfreaderpro.com/downloads/pdfmasterprocast.xml"
  751. #endif
  752. }
  753. func updaterShouldPromptForPermissionToCheck(forUpdates updater: SUUpdater) -> Bool {
  754. return false
  755. }
  756. func upgradeAPP(with updater: SUUpdater) {
  757. let string = "macappstore://apps.apple.com/cn/app/pdf-master-ai-pdf/id6446781258?mt=12"
  758. let url: URL = URL(string: string)!
  759. NSWorkspace.shared.open(url)
  760. }
  761. func upgradeButtonString(for updater: SUUpdater) -> String {
  762. return NSLocalizedString("PDF Reader Pro", comment: "")
  763. }
  764. }
  765. #endif
  766. extension AppDelegate {
  767. // MARK: - Services Support
  768. func openDocumentFromURLOnPboard(_ pboard: NSPasteboard, userData: String?, error errorString: inout String?) {
  769. var error: NSError?
  770. if let document = NSDocumentController.shared.openDocumentWithURLFromPasteboard(pboard, showNotes: false, outError: &error) {
  771. // Document opened successfully
  772. } else if let error = error {
  773. errorString = error.localizedDescription
  774. }
  775. }
  776. func openDocumentFromDataOnPboard(_ pboard: NSPasteboard, userData: String?, error errorString: inout String?) {
  777. var error: NSError?
  778. if let document = NSDocumentController.shared.openDocumentWithImageFromPasteboard(pboard, error: &error) {
  779. // Document opened successfully
  780. } else if let error = error {
  781. errorString = error.localizedDescription
  782. }
  783. }
  784. func openNotesDocumentFromURLOnPboard(_ pboard: NSPasteboard, userData: String?, error errorString: inout String?) {
  785. var error: NSError?
  786. if let document = NSDocumentController.shared.openDocumentWithURLFromPasteboard(pboard, showNotes: true, outError: &error) {
  787. // Document opened successfully
  788. } else if let error = error {
  789. errorString = error.localizedDescription
  790. }
  791. }
  792. }
  793. extension AppDelegate: UNUserNotificationCenterDelegate {
  794. func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
  795. // 处理用户点击推送通知的操作
  796. completionHandler()
  797. }
  798. }