AppDelegate.swift 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  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. import KMComponentLibrary
  10. @main
  11. class AppDelegate: NSObject, NSApplicationDelegate, iRateDelegate{
  12. var rateWindowVC: KMRateWindowController!
  13. func applicationWillFinishLaunching(_ notification: Notification) {
  14. #if VERSION_FREE
  15. #if VERSION_DMG
  16. CPDFConvertKit.setLicenseKey("d/nxJMNuCxxkHSwLM0ZdNce/rfLLR/Zd4rIX5WYwyfDcsm6dSdNtSUiv13bO8R4ETaEAX5s0Zv9RWOhjgXdRzHAduf7IP6TApYIwvbc/4Wbhm7GLSWUo2vOXw2G5jlkAokntq5+SKv5430RX0ZrxQ9x2VTUBxdUy36Pugm8nUhxilBbDnuicJIN6FWAsq6WLAMc/w2WIlAQ5BjepEYuMs1Vg6D8GBhrSoVMEa86Hg59j9TlN3HVIvLfUp+9q3cBR8A3t2RE3IXoSi3liVfegl03jN17hspcQnTjYRJGarPQ+mAN8tVXV8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  22. #endif
  23. CPDFKit.verify(withKey: "gMFiX0z5iLRx4DWXB1YzzszTXi8P1RGbs2t6D//Sowj62gyYAbZ2QqbLiIvwPt6N9mO4+kppY6mjsHQYLJIM4qyVkdOLyrRoET55leUlys2xv/vAuxkQ8RqQJYgFv0WhmC+IpenDmk3/XrKPcvGsERUyEuLO4FifqOncSuh6GHy4bbo0PkSWJhKZASN8hmzTMkKtI79ppkJ6CgjxZewhelUbJM07e0wdmJR9DF1x0EIntYoXxZ6z1fc6cjsRblPhDGEcUBTvbF6DMGXXRzJxlUFMzG7ka5InMav4dBW5CFLNpSEpGnzWO99DFwA9L4XZdGV2vKMNLXBhmYQF1PibTWu0lH1oY17eVN2TRW5amzrZsD0yy20WxEXrssgDJq7xPzi1sOZ56C+jdE/8p9tNUW4KYJ5GoqCVh5w0Ajkc3xRqWrpmJXUollqL+u9K6VDPiGAwpSBmox6oux68kbF7jkiCZDxHK7wfU3XrdhO8pmKn37TM/hBROJ3ufWlCiyNQy5AlRqzN1AAIKVmJzmOQCOcohtAQS/ULdkM2FO7GcxWLAf1YhWUmCAiDfm1c1lrdjqG0V0XpnGga69npgRspIG1y9kaZz89k1E7lWRj5bPVsGo+cInV8gEE9jyu1d/w+z+IoMv/64lho9GX2iJoq9a2ZlLQs3Nchtt3ztkLOIrL83eqpD+OFl7xBMsabCVNViM2vieVHPpj+ryaMGUv809szrKYrmDEsg4RKbxuXysKB3jpAHRMF+rSFAwQSTXQlmZfbxpitFoKX83UBkha60z3+yyZvjzxnVmPLWTnX0u13CDIXEvC3V6mR2aaKvVJnE5h5fVw9F2s3H5Q55YkTYg==")
  24. ComPDFUIConfig.initializeUIConfig()
  25. ComponentLibrary.shared.parserExcel(withPath: "")
  26. }
  27. func applicationDidFinishLaunching(_ aNotification: Notification) {
  28. // Insert code here to initialize your application
  29. KMNThumbnailManager.clearCacheThumImage() //清除页面缩图缓存
  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. DispatchQueue.main.async {
  39. NSApplication.shared.registerForRemoteNotifications()
  40. }
  41. #if VERSION_DMG
  42. let updater = SUUpdater.shared()
  43. updater?.delegate = self
  44. updater?.automaticallyChecksForUpdates = true
  45. #else
  46. #endif
  47. //Firebase RemoteConfig
  48. #if VERSION_FREE
  49. KMKdanRemoteConfig.remoteConfig.fetch { _status, error in
  50. }
  51. #endif
  52. let versionString = MainBundle.infoDictionary?[kCFBundleVersionKey as String] as? String ?? ""
  53. let lastVersionString = KMDataManager.ud_string(forKey: SKLastVersionLaunchedKey)
  54. if lastVersionString == nil || SKVersionNumber.compareVersionString(lastVersionString, toVersionString: versionString) == .orderedAscending {
  55. let sud = UserDefaults.standard
  56. if versionString.isEmpty == false {
  57. sud.set(versionString, forKey: SKLastVersionLaunchedKey)
  58. }
  59. // [sud setBool:NO forKey:@"kShowRecentGuideKey"];
  60. // [sud removeObjectForKey:@"kToolbarTipIsShow"];
  61. // [sud removeObjectForKey:@"kShowNoPermissionAlertKey"];
  62. // [sud removeObjectForKey:@"KMTabbingHintShowFlag"];
  63. // [sud removeObjectForKey:@"KMConverthHaveOpenConvertDetails"];
  64. sud.synchronize()
  65. }
  66. UserDefaults.standard.register(defaults: ["NSApplicationCrashOnExceptions" : true])
  67. NSApp.servicesProvider = self
  68. KMStatusBar.system()
  69. // MARK: 广告数据初始化
  70. var appName: KMAdvertisementAppNameType = .PDFReaderProMac
  71. #if VERSION_FREE
  72. #if VERSION_DMG
  73. appName = .PDFReaderProMacDMG
  74. #else
  75. #endif
  76. #else
  77. appName = .PDFReaderProMacPro
  78. #endif
  79. KMAdvertisementManager.manager.initConfig(appName: appName,
  80. subscribeType: .unknow,
  81. platform: .Mac)
  82. // 测试模式,默认false
  83. KMAdvertisementManager.manager.debug = true
  84. NSApp.appearance = NSAppearance.current
  85. KMAnalytics.configure()
  86. //第一次开启app
  87. let info = UserDefaults.standard.value(forKey: "kFirstOpenAppCount")
  88. var count = 0
  89. if info != nil {
  90. count = info as? Int ?? 0
  91. }
  92. count += 1
  93. UserDefaults.standard.set(count, forKey: "kFirstOpenAppCount")
  94. UserDefaults.standard.synchronize()
  95. self.initMainMenu()
  96. reopenDocument(forPaths: [])
  97. self.initiRateData()
  98. let appleEventManager = NSAppleEventManager.shared()
  99. appleEventManager.setEventHandler(self,
  100. andSelector: #selector(handleGetURLEvent(_:withReplyEvent:)),
  101. forEventClass: AEEventClass(kInternetEventClass),
  102. andEventID: AEEventID(kAEGetURL))
  103. DistributedNotificationCenter.default().addObserver(self, selector: #selector(_themeChanged), name: NSApplication.interfaceThemeChangedNotification, object: nil)
  104. #if VERSION_DMG
  105. VerificationManager.default()
  106. KMDMGProductsManager.shareInstance.getProductDatas()
  107. #else
  108. self.initiVersionData()
  109. IAPProductsManager.default().initIAP()
  110. #endif
  111. //AI相关
  112. AIInfoManager.default()
  113. NotificationCenter.default.addObserver(self, selector: #selector(AIDeviceStatusChangeNotification), name: NSNotification.Name(rawValue: "kDeviceAIStatusChangeNotification"), object: nil)
  114. for string in ["Ubuntu-Bold","Ubuntu-Medium"] {
  115. let fontURL = Bundle.main.url(forResource: string, withExtension: "ttf")
  116. var error: Unmanaged<CFError>?
  117. if !CTFontManagerRegisterFontsForURL(fontURL! as CFURL, .process, &error) {
  118. print("Failed to register font!")
  119. } else {
  120. print("Font registered successfully!")
  121. }
  122. }
  123. NotificationCenter.default.addObserver(self, selector: #selector(deviceActivateStatusChangeNotification), name: NSNotification.Name(rawValue: "kDeviceActivateNotification"), object: nil)
  124. }
  125. func initiRateData() {
  126. iRate.sharedInstance().delegate = self
  127. #if VERSION_FREE
  128. iRate.sharedInstance().appStoreID = 919472673
  129. #else
  130. iRate.sharedInstance().appStoreID = 825459243
  131. #endif
  132. iRate.sharedInstance().onlyPromptIfLatestVersion = false
  133. iRate.sharedInstance().onlyPromptIfMainWindowIsAvailable = true
  134. }
  135. //MARK: iRateDelegate
  136. func iRateUserDidDeclineToRateApp() {
  137. KMVerificationWindowController.verificationFeedback()
  138. }
  139. func iRateShouldPromptForRating() -> Bool {
  140. let notShow: Bool = UserDefaults.standard.bool(forKey: "kUserHaveClickRateUsKey")
  141. if !notShow {
  142. UserDefaults.standard.setValue(true, forKey: "kUserHaveClickRateUsKey")
  143. UserDefaults.standard.synchronize()
  144. NotificationCenter.default.post(name: Notification.Name(rawValue: "kUserHaveClickRateUsNotification"), object: self)
  145. }
  146. self.rateWindowVC = KMRateWindowController.init(windowNibName: "KMRateWindowController")
  147. self.rateWindowVC.closeBlock = { wc in
  148. }
  149. self.rateWindowVC.closeBlock = { wc in
  150. }
  151. self.rateWindowVC.showWindow(nil)
  152. return false
  153. }
  154. @objc func handleGetURLEvent(_ event: NSAppleEventDescriptor, withReplyEvent replyEvent: NSAppleEventDescriptor) {
  155. if let urlString = event.paramDescriptor(forKeyword: AEKeyword(keyDirectObject))?.stringValue,
  156. let url = URL(string: urlString) {
  157. // 在这里处理收到的 URL Scheme
  158. KMPrint("Received URL Scheme: \(url.scheme ?? "")")
  159. KMPrint("Path: \(url.path)")
  160. if NSApp.mainWindow == nil {
  161. let bundleIdentifier: String = Bundle.main.bundleIdentifier ?? ""
  162. launchApp(bundleIdentifier: bundleIdentifier)
  163. }
  164. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  165. #if VERSION_DMG
  166. // 执行相应的操作
  167. if url.scheme == "subscriptiondmgschemes" {
  168. }
  169. #endif
  170. #if VERSION_FREE
  171. // 执行相应的操作
  172. if url.scheme == "subscriptionSchemes" {
  173. if url.path == "/open" {
  174. // 执行打开操作
  175. } else if url.path == "/close" {
  176. // 执行关闭操作
  177. }
  178. }
  179. #endif
  180. }
  181. }
  182. }
  183. func launchApp(bundleIdentifier: String) {
  184. let workspace = NSWorkspace.shared
  185. // Launch the application with the specified bundle identifier
  186. if let appURL = NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleIdentifier) {
  187. do {
  188. try workspace.launchApplication(at: appURL, options: .default, configuration: [:])
  189. } catch {
  190. print("Error launching the application: \(error)")
  191. }
  192. } else {
  193. print("Application with bundle identifier '\(bundleIdentifier)' not found.")
  194. }
  195. }
  196. func application(_ application: NSApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  197. let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
  198. print("Device token:", token)
  199. }
  200. func application(_ application: NSApplication, didReceiveRemoteNotification userInfo: [String : Any]) {
  201. }
  202. func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
  203. if !flag {
  204. let browser: KMBrowser = KMBrowser.init()
  205. browser.windowController = KMBrowserWindowController.init(browser: browser)
  206. browser.addHomeTabContents()
  207. browser.windowController.window?.center()
  208. browser.windowController.showWindow(self)
  209. }
  210. return flag
  211. }
  212. func applicationShouldOpenUntitledFile(_ sender: NSApplication) -> Bool {
  213. if (SettingsManager.sharedInstance.reopenFileWhenAppStart == false) {
  214. return false
  215. }
  216. let filepaths = KMPreferenceManager.shared.lastOpenFilepaths
  217. if (filepaths == nil || filepaths!.count == 0) {
  218. return false
  219. }
  220. DispatchQueue.main.async {
  221. for filepath in filepaths! {
  222. NSDocumentController.shared.km_safe_openDocument(withContentsOf: URL(fileURLWithPath: filepath), display: true) { _, _, _ in
  223. }
  224. }
  225. }
  226. return false
  227. }
  228. func applicationWillTerminate(_ aNotification: Notification) {
  229. if (NSDocumentController.shared.documents.count > 0) {
  230. var filepaths: [String] = []
  231. for document in NSDocumentController.shared.documents {
  232. // KMPrint(document.fileURL as Any)
  233. if (document.fileURL?.path != nil) {
  234. filepaths.append((document.fileURL?.path)!)
  235. }
  236. }
  237. KMPreferenceManager.shared.lastOpenFilepaths = filepaths
  238. } else {
  239. KMPreferenceManager.shared.lastOpenFilepaths = nil
  240. }
  241. }
  242. func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
  243. return true
  244. }
  245. // MARK: private
  246. func reopenDocument(forPaths paths: [String]) -> Void {
  247. let browser = KMBrowser.init() as KMBrowser
  248. browser.windowController = KMBrowserWindowController.init(browser: browser)
  249. var frame = browser.windowController?.window?.frame ?? CGRectZero
  250. frame.size.width = 1280
  251. frame.size.height = 800
  252. browser.windowController?.window?.setFrame(frame, display: true)
  253. browser.addHomeTabContents()
  254. browser.windowController.showWindow(self)
  255. }
  256. //MARK: - iVersion
  257. func initiVersionData() -> Void{
  258. #if VERSION_DMG
  259. #else
  260. let tVersion = iVersion.sharedInstance()
  261. tVersion?.applicationBundleID = Bundle.main.bundleIdentifier
  262. var tStr = "New Update Available"
  263. tVersion?.updateAvailableTitle = (tVersion?.localizedString(forKey: tStr, withDefault: tStr) ?? "") + "\n"
  264. tVersion?.versionLabelFormat = ""
  265. tVersion?.groupNotesByVersion = true
  266. tVersion?.showOnFirstLaunch = false
  267. tVersion?.checkPeriod = 2
  268. tVersion?.remindPeriod = 5
  269. let infoDictionary = Bundle .main.infoDictionary!
  270. var appName: String = infoDictionary["CFBundleDisplayName"] as! String
  271. if appName.count < 1 {
  272. appName = infoDictionary["CFBundleName"] as! String
  273. }
  274. tStr = "The new version of %@ is available now. Go update for new features.";
  275. tStr = (tVersion?.localizedString(forKey: tStr, withDefault: tStr))!
  276. tStr = String(format: tStr, appName)
  277. tVersion?.inThisVersionTitle = tStr
  278. tStr = "UPDATE NOW";
  279. tVersion!.downloadButtonLabel = tVersion?.localizedString(forKey: tStr, withDefault: tStr)
  280. tStr = "LATER";
  281. tVersion!.remindButtonLabel = tVersion?.localizedString(forKey: tStr, withDefault: tStr)
  282. tVersion!.ignoreButtonLabel = ""
  283. #endif
  284. }
  285. func mainViewController() -> KMMainViewController? {
  286. guard let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController else {
  287. return nil
  288. }
  289. let isHome: Bool = _windowC.browser?.activeTabContents()?.isHome ?? true
  290. if isHome {
  291. return nil
  292. }
  293. guard let document: KMMainDocument = _windowC.activeTabContents() as? KMMainDocument else {
  294. return nil
  295. }
  296. if let data = document.mainViewController {
  297. return data
  298. }
  299. return nil
  300. }
  301. func homeViewController() -> KMNHomeViewController? {
  302. guard let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController else {
  303. return nil
  304. }
  305. let isHome: Bool = _windowC.browser?.activeTabContents()?.isHome ?? true
  306. if isHome == false {
  307. return nil
  308. }
  309. guard let document: KMMainDocument = _windowC.activeTabContents() as? KMMainDocument else {
  310. return nil
  311. }
  312. if let data = document.homeViewController {
  313. return data
  314. }
  315. return nil
  316. }
  317. }
  318. // MARK: - SUUpdaterDelegate
  319. #if VERSION_DMG
  320. extension AppDelegate : SUUpdaterDelegate {
  321. func updaterWillRelaunchApplication(_ updater: SUUpdater) {
  322. }
  323. func feedURLString(for updater: SUUpdater) -> String? {
  324. var hostURL = "https://www.pdfreaderpro.com/downloads/"
  325. #if DEBUG
  326. hostURL = "http://test-pdf-pro.kdan.cn:3021/downloads/"
  327. #else
  328. hostURL = "https://www.pdfreaderpro.com/downloads/"
  329. #endif
  330. return hostURL+NSLocalizedString("pdfreaderprocast.xml", comment: "")
  331. }
  332. func updaterShouldPromptForPermissionToCheck(forUpdates updater: SUUpdater) -> Bool {
  333. return false
  334. }
  335. func upgradeAPP(with updater: SUUpdater) {
  336. let string = "macappstore://apps.apple.com/app/id825459243?mt=12"
  337. let url: URL = URL(string: string)!
  338. NSWorkspace.shared.open(url)
  339. }
  340. func upgradeButtonString(for updater: SUUpdater) -> String {
  341. return NSLocalizedString("PDF Reader Pro", comment: "")
  342. }
  343. }
  344. #endif
  345. // MARK: - Services Support
  346. extension AppDelegate {
  347. func openDocumentFromURLOnPboard(_ pboard: NSPasteboard, userData: String?, error errorString: inout String?) {
  348. var error: NSError?
  349. if let _ = NSDocumentController.shared.openDocumentWithURLFromPasteboard(pboard, showNotes: false, outError: &error) {
  350. // Document opened successfully
  351. } else if let error = error {
  352. errorString = error.localizedDescription
  353. }
  354. }
  355. func openDocumentFromDataOnPboard(_ pboard: NSPasteboard, userData: String?, error errorString: inout String?) {
  356. var error: NSError?
  357. if let _ = NSDocumentController.shared.openDocumentWithImageFromPasteboard(pboard, error: &error) {
  358. // Document opened successfully
  359. } else if let error = error {
  360. errorString = error.localizedDescription
  361. }
  362. }
  363. func openNotesDocumentFromURLOnPboard(_ pboard: NSPasteboard, userData: String?, error errorString: inout String?) {
  364. var error: NSError?
  365. if let _ = NSDocumentController.shared.openDocumentWithURLFromPasteboard(pboard, showNotes: true, outError: &error) {
  366. // Document opened successfully
  367. } else if let error = error {
  368. errorString = error.localizedDescription
  369. }
  370. }
  371. }
  372. //MARK: - UNUserNotificationCenterDelegate
  373. extension AppDelegate: UNUserNotificationCenterDelegate {
  374. func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
  375. // 处理用户点击推送通知的操作
  376. completionHandler()
  377. }
  378. }
  379. //MARK: - Notification
  380. extension AppDelegate {
  381. @objc private func _themeChanged(_ sender: Notification) {
  382. let isDarkModel = KMAdvertisementConfig.isDarkModel()
  383. if isDarkModel {
  384. NSApp.appearance = NSAppearance(named: .darkAqua)
  385. } else {
  386. NSApp.appearance = NSAppearance(named: .aqua)
  387. }
  388. NotificationCenter.default.post(name: Notification.Name(rawValue: "kEffectiveAppearance"), object: nil)
  389. }
  390. @objc func AIDeviceStatusChangeNotification() {
  391. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  392. }
  393. }
  394. @objc func deviceActivateStatusChangeNotification() {
  395. }
  396. }