AppDelegate.swift 41 KB

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