AppDelegate.swift 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  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+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szTXi8P1RGbs2t6D//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 = NSAppearance(named: .darkAqua)
  353. } else {
  354. NSApp.appearance = NSAppearance(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. if let item = PDFOfficeMenu?.item(withTitle: NSLocalizedString("Volume Discount", comment: "")) {
  468. item.isHidden = true
  469. }
  470. if let item = PDFOfficeMenu?.item(withTitle: NSLocalizedString("One License for Mac and Windows", comment: "")) {
  471. item.isHidden = true
  472. }
  473. if let item = PDFOfficeMenu?.item(withTitle: NSLocalizedString("Education Discount", comment: "")) {
  474. item.isHidden = true
  475. }
  476. let fileMenu = mainMenu?.item(at: 1)?.submenu
  477. var shareItem: NSMenuItem?
  478. if let item = fileMenu?.item(withTitle: NSLocalizedString("Save Archive…", comment: "")) {
  479. shareItem = NSMenuItem(title: NSLocalizedString("Share", comment: ""), action: nil, target: nil)
  480. fileMenu?.insertItem(shareItem!, at: item.index)
  481. fileMenu?.insertItem(.separator(), at: item.index)
  482. } else {
  483. shareItem = NSMenuItem(title: NSLocalizedString("Share", comment: ""), action: nil, target: nil)
  484. fileMenu?.insertItem(shareItem!, at: (fileMenu?.items.count)!-1)
  485. }
  486. shareItem?.submenu = NSSharingServicePicker.menu(forSharingItems: [""], subjectContext: "", withTarget: self, selector: #selector(sharePageItemAction), serviceDelegate: nil)
  487. let deviceCameraMenuItem = NSMenuItem(title: NSLocalizedString("Import From Camera", comment: ""), action: #selector(deviceCameraMenuItemAciton), target: self)
  488. let deviceScannerMenuItem = NSMenuItem(title: NSLocalizedString("Import From Scanner", comment: ""), action: #selector(deviceScannerMenuItemAciton), target: self)
  489. fileMenu?.insertItem(deviceCameraMenuItem, at: (fileMenu?.items.count)!-1)
  490. fileMenu?.insertItem(deviceScannerMenuItem, at: (fileMenu?.items.count)!-1)
  491. fileMenu?.insertItem(.separator(), at: (fileMenu?.items.count)!-1)
  492. }
  493. @objc func sharePageItemAction(sender: NSMenuItem) {
  494. if ((NSApp.mainWindow?.windowController is KMBrowserWindowController) == false) {
  495. return
  496. }
  497. let windowControler = NSApp.mainWindow?.windowController as! KMBrowserWindowController
  498. let model = windowControler.browser?.tabStripModel
  499. if let cnt = model?.count(), cnt <= 0 {
  500. return
  501. }
  502. if let data = model?.activeTabContents()?.isHome, data {
  503. return
  504. }
  505. let document: KMMainDocument = model?.activeTabContents() as! KMMainDocument
  506. if let data = document.mainViewController?.saveWatermarkFlag, !data {
  507. let represent : NSSharingService = sender.representedObject as! NSSharingService
  508. represent.perform(withItems: [document.fileURL as Any])
  509. return
  510. }
  511. let represent : NSSharingService = sender.representedObject as! NSSharingService
  512. represent.perform(withItems: [document.fileURL as Any])
  513. }
  514. @objc func deviceCameraMenuItemAciton(sender: NSMenuItem) {
  515. KMPrint("deviceCameraMenuItemAciton")
  516. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "kDeviceCameraMenuItemNotification"), object: nil)
  517. }
  518. @objc func deviceScannerMenuItemAciton(sender: NSMenuItem) {
  519. KMPrint("deviceScannerMenuItemAciton")
  520. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "kDeviceScannerMenuItemNotification"), object: nil)
  521. }
  522. // MARK: PDF Reader Pro Menu
  523. @IBAction func openPreferenceWindow(_ sender: Any) {
  524. KMPreferenceController.shared.showWindow(self)
  525. }
  526. @objc @IBAction func manageAcctounMenuAction(_ sender: Any) {
  527. if KMLightMemberManager.manager.isLogin() {
  528. _ = KMAccountInfoWindowController.show(window: NSApp.mainWindow!)
  529. }
  530. }
  531. @IBAction func loginMenuItemAction(_ sender: Any) {
  532. // Login & Logout
  533. if KMLightMemberManager.manager.isLogin() {
  534. } else {
  535. _ = KMLoginWindowController.show(window: NSApp.mainWindow!)
  536. }
  537. }
  538. @IBAction func logoutMenuItemAction(_ sender: Any) {
  539. // Login & Logout
  540. if KMLightMemberManager.manager.isLogin() {
  541. KMRequestServerManager.manager.logout { success, result in
  542. if success {
  543. KMPrint("登出成功")
  544. }
  545. }
  546. }
  547. }
  548. @IBAction func restoreMenuItemAction(_ sender: Any) {
  549. KMPurchaseManager.manager.restorePurchases { isSuccess, error in
  550. if isSuccess {
  551. } else {
  552. if error != .restoreSuccess {
  553. KMComparativeTableViewController.purchasefailed(view: NSApp.mainWindow?.contentView, state: error)
  554. }
  555. }
  556. }
  557. }
  558. @objc func accountRefreshAction() {
  559. KMLightMemberManager.manager.updateNetworkingUserInfo { isDidLogout in
  560. }
  561. }
  562. @objc func showAccount() {
  563. }
  564. @objc func resumePurchase() {
  565. }
  566. // MARK: help Menu
  567. @IBAction func menuItemAction_quickStudy(_ sender: NSMenuItem) -> Void {
  568. KMTools.openQuickStartStudy()
  569. }
  570. @IBAction func menuItemAction_onlineHelp(_ sender: NSMenuItem) -> Void {
  571. KMTools.openFAQWebsite()
  572. }
  573. @IBAction func menuItemAction_morePudact(_ sender: NSMenuItem) -> Void {
  574. KMTools.openMoreProductWebsite()
  575. }
  576. @IBAction func menuItemAction_freePDFTemplate(_ sender: NSMenuItem) -> Void {
  577. KMTools.openFreePDFTemplatesWebsite()
  578. }
  579. @IBAction func menuItemAction_payEmail(_ sender: NSMenuItem) -> Void {
  580. KMEmailSubWindowController().showWindow(nil)
  581. }
  582. @IBAction func menuItemAction_poweredByComPDFKit(_ sender: NSMenuItem) -> Void {
  583. KMTools.openComPDFKitPowerWebsite()
  584. }
  585. @IBAction func menuItemAction_feekback(_ sender: NSMenuItem) -> Void {
  586. KMTools.proposeNewFeature()
  587. }
  588. @IBAction func menuItemAction_giveFiveStar(_ sender: NSMenuItem) -> Void {
  589. KMTools.rateUs()
  590. }
  591. @objc func restoreSubscriptions(_ sender: NSMenuItem) {
  592. #if VERSION_FREE
  593. KMPrint("restoreSubscriptions ...")
  594. let compareWindowVC: KMPurchaseCompareWindowController = KMPurchaseCompareWindowController.sharedInstance() as! KMPurchaseCompareWindowController
  595. compareWindowVC.showWindowRestore(nil)
  596. #else
  597. var vc: KMToolCompareWindowController? = nil
  598. vc = KMToolCompareWindowController.toolCompare(toolType: .Convert, selectNum: 0)
  599. vc!.showWindowRestore(sender: (Any).self)
  600. #endif
  601. }
  602. // MARK:- DMG
  603. @objc func checkForUpdates(_ sender: NSMenuItem) {
  604. #if VERSION_DMG
  605. SUUpdater.shared().checkForUpdates(sender)
  606. #endif
  607. }
  608. @objc func enterLicense(_ sender: NSMenuItem) {
  609. #if VERSION_DMG
  610. if let tManager = VerificationManager.default() {
  611. let status = tManager.status
  612. if status == ActivityStatusVerifExpire {
  613. let vc = KMVerificationWindowController.verification(with: .activateExpired)
  614. vc?.showWindow(nil)
  615. } else if status == ActivityStatusVerification {
  616. let vc = KMVerificationWindowController.verification(with: .info)
  617. vc?.showWindow(nil)
  618. } else {
  619. let vc = KMVerificationWindowController.verification(with: .activate)
  620. vc?.showWindow(nil)
  621. }
  622. }
  623. #endif
  624. }
  625. @objc func pdftoOfficeMenuItemAction(_ sender: NSMenuItem) {
  626. #if VERSION_DMG
  627. // var url = URL(string: Store_Link + "?product_code=product_2")
  628. // let tWorkSpace = NSWorkspace.shared
  629. // if tWorkSpace.open(url!) == false {
  630. // tWorkSpace.open(url!)
  631. // }
  632. let embeddedWC = KMPurchaseEmbeddedWindowController.currentFirstTrialWC("com.brother.pdfreaderpro.mac.product_2")
  633. embeddedWC.showWindow(nil)
  634. embeddedWC.window?.center()
  635. #endif
  636. }
  637. @IBAction func volumeDiscount(_ sender: NSMenuItem) {
  638. var tStrHttpUrl = "https://www.pdfreaderpro.com/vpp-purchase-program"
  639. #if VERSION_DMG
  640. tStrHttpUrl = APPMain_Link + "/vpp-purchase-program?utm_source=pdfdmg&utm_campaign=menubar_vpp"
  641. #else
  642. tStrHttpUrl = APPMain_Link + "/vpp-purchase-program?utm_source=pdfmacstore&utm_campaign=menubar_vpp"
  643. #endif
  644. guard let url = URL(string: tStrHttpUrl) else {
  645. NSSound.beep()
  646. return
  647. }
  648. let tWorkSpace = NSWorkspace.shared
  649. if tWorkSpace.open(url) == false {
  650. tWorkSpace.open(url)
  651. }
  652. }
  653. @IBAction func crossPlatformAction(_ sender: NSMenuItem) {
  654. var tStrHttpUrl = CrossPlatform_Link
  655. guard let url = URL(string: tStrHttpUrl) else {
  656. return
  657. }
  658. let tWorkSpace = NSWorkspace.shared
  659. if tWorkSpace.open(url) == false {
  660. tWorkSpace.open(url)
  661. }
  662. #if VERSION_DMG
  663. FMTrackEventManager.defaultManager.trackEvent(event: "Menubar", withProperties: ["Menubar_Btn" : "Menubar_Btn_Help_CrossPlatform"])
  664. #endif
  665. }
  666. @IBAction func EducationDiscountAction(_ sender: NSMenuItem) {
  667. let tStrHttpUrl = KMLocalizedString("https://www.pdfreaderpro.com/store?mode=edu#utm_source=mac_app&utm_medium=pdf_pro_dmg&utm_content=menu_bar_click")
  668. // let tStrHttpUrl = Store_Edu_Link
  669. guard let url = URL(string: tStrHttpUrl) else {
  670. return
  671. }
  672. let tWorkSpace = NSWorkspace.shared
  673. if tWorkSpace.open(url) == false {
  674. tWorkSpace.open(url)
  675. }
  676. #if VERSION_DMG
  677. FMTrackEventManager.defaultManager.trackEvent(event: "Menubar", withProperties: ["Menubar_Btn" : "Menubar_Btn_Help_EduDiscount"])
  678. #endif
  679. }
  680. @IBAction func aiToolsAction(_ sender: NSMenuItem) {
  681. #if VERSION_DMG
  682. KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
  683. #else
  684. AIPurchaseWindowController.currentWC().showWindow(nil)
  685. #endif
  686. }
  687. @IBAction func orderFrontLineInspector(_ sender: Any?) {
  688. if let win = KMLineInspector.shared.window {
  689. if win.isVisible {
  690. win.orderOut(sender)
  691. } else {
  692. win.orderFront(sender)
  693. }
  694. }
  695. }
  696. @IBAction func showDownloads(_ sender: NSMenuItem) -> Void {
  697. KMPrint("showDownloads ...")
  698. }
  699. @IBAction func showWelcomeWindow(_ sender: NSMenuItem) -> Void {
  700. self.reopenDocument(forPaths: [])
  701. }
  702. @IBAction func newsletter(_ sender: NSMenuItem) -> Void {
  703. KMEmailSubWindowController().showWindow(nil)
  704. }
  705. @IBAction func feedback(_ sender: NSMenuItem) -> Void {
  706. KMTools.feekback()
  707. }
  708. @IBAction func reportBug(_ sender: NSMenuItem) -> Void {
  709. KMTools.reportBug()
  710. }
  711. @IBAction func reportGeneralQuestions(_ sender: NSMenuItem) -> Void {
  712. KMTools.reportGeneralQuestions()
  713. }
  714. }
  715. extension AppDelegate : NSMenuDelegate,NSMenuItemValidation {
  716. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  717. let action = menuItem.action
  718. if action == #selector(manageAcctounMenuAction) {
  719. self.updateLoginMenuItem()
  720. return KMLightMemberManager.manager.isLogin()
  721. }
  722. if action == #selector(loginMenuItemAction) {
  723. self.updateLoginMenuItem()
  724. return !KMLightMemberManager.manager.isLogin()
  725. }
  726. if action == #selector(logoutMenuItemAction) {
  727. self.updateLoginMenuItem()
  728. return KMLightMemberManager.manager.isLogin()
  729. }
  730. if (action == #selector(sharePageItemAction)) {
  731. guard let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController else {
  732. return false
  733. }
  734. let isHome = _windowC.browser?.activeTabContents()?.isHome ?? false
  735. return !isHome
  736. }
  737. if action == #selector(closeDocument) {
  738. guard let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController else {
  739. if NSApp.mainWindow?.windowController != nil {
  740. return true
  741. }
  742. return false
  743. }
  744. let isNewTab = _windowC.browser?.activeTabContents()?.isNewTab ?? false
  745. if isNewTab {
  746. return true
  747. }
  748. // let isHome = _windowC.browser?.activeTabContents()?.isHome ?? false
  749. // return !isHome
  750. }
  751. return true
  752. }
  753. func updateLoginMenuItem() {
  754. let firstItem = NSApp.mainMenu?.item(at: 0)?.submenu
  755. if firstItem != nil {
  756. let item1 = firstItem?.item(withTag: 11)
  757. let item2 = firstItem?.item(withTag: 12)
  758. let item3 = firstItem?.item(withTag: 13)
  759. let item4 = firstItem?.item(withTag: 14)
  760. // let item5 = firstItem?.item(withTag: 15)
  761. let item6 = firstItem?.item(withTag: kKMMainMenuAccountRefreshItemTag)
  762. // if KMLightMemberManager.manager.isLogin() {
  763. // item1?.title = KMLightMemberManager.manager.info.email
  764. // item1?.isHidden = false
  765. // item2?.isHidden = true
  766. // item3?.isHidden = false
  767. // item4?.isHidden = false
  768. //// item5?.isHidden = false
  769. // item6?.isHidden = false
  770. // } else {
  771. // item1?.isHidden = true
  772. // item2?.isHidden = false
  773. // item3?.isHidden = true
  774. // item4?.isHidden = true
  775. //// item5?.isHidden = true
  776. // item6?.isHidden = true
  777. // }
  778. item1?.isHidden = true
  779. item2?.isHidden = true
  780. item3?.isHidden = true
  781. item4?.isHidden = true
  782. // item5?.isHidden = true
  783. item6?.isHidden = true
  784. }
  785. }
  786. @objc func clickOutline(menuItem: NSMenuItem) {
  787. KMPrint("更新菜单栏")
  788. }
  789. func menu(_ menu: NSMenu, update item: NSMenuItem, at index: Int, shouldCancel: Bool) -> Bool {
  790. return true
  791. }
  792. }
  793. #if VERSION_DMG
  794. extension AppDelegate : SUUpdaterDelegate {
  795. func updaterWillRelaunchApplication(_ updater: SUUpdater) {
  796. }
  797. func feedURLString(for updater: SUUpdater) -> String? {
  798. var hostURL = "https://www.pdfreaderpro.com/downloads/"
  799. #if DEBUG
  800. hostURL = "http://test-pdf-pro.kdan.cn:3021/downloads/"
  801. #else
  802. hostURL = "https://www.pdfreaderpro.com/downloads/"
  803. #endif
  804. return hostURL+NSLocalizedString("pdfreaderprocast.xml", comment: "")
  805. }
  806. func updaterShouldPromptForPermissionToCheck(forUpdates updater: SUUpdater) -> Bool {
  807. return false
  808. }
  809. func upgradeAPP(with updater: SUUpdater) {
  810. let string = "macappstore://apps.apple.com/app/id825459243?mt=12"
  811. let url: URL = URL(string: string)!
  812. NSWorkspace.shared.open(url)
  813. }
  814. func upgradeButtonString(for updater: SUUpdater) -> String {
  815. return NSLocalizedString("PDF Reader Pro", comment: "")
  816. }
  817. }
  818. #endif
  819. extension AppDelegate {
  820. // MARK: - Services Support
  821. func openDocumentFromURLOnPboard(_ pboard: NSPasteboard, userData: String?, error errorString: inout String?) {
  822. var error: NSError?
  823. if let document = NSDocumentController.shared.openDocumentWithURLFromPasteboard(pboard, showNotes: false, outError: &error) {
  824. // Document opened successfully
  825. } else if let error = error {
  826. errorString = error.localizedDescription
  827. }
  828. }
  829. func openDocumentFromDataOnPboard(_ pboard: NSPasteboard, userData: String?, error errorString: inout String?) {
  830. var error: NSError?
  831. if let document = NSDocumentController.shared.openDocumentWithImageFromPasteboard(pboard, error: &error) {
  832. // Document opened successfully
  833. } else if let error = error {
  834. errorString = error.localizedDescription
  835. }
  836. }
  837. func openNotesDocumentFromURLOnPboard(_ pboard: NSPasteboard, userData: String?, error errorString: inout String?) {
  838. var error: NSError?
  839. if let document = NSDocumentController.shared.openDocumentWithURLFromPasteboard(pboard, showNotes: true, outError: &error) {
  840. // Document opened successfully
  841. } else if let error = error {
  842. errorString = error.localizedDescription
  843. }
  844. }
  845. }
  846. extension AppDelegate: UNUserNotificationCenterDelegate {
  847. func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
  848. // 处理用户点击推送通知的操作
  849. completionHandler()
  850. }
  851. }