AppDelegate.swift 42 KB

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