AppDelegate.swift 39 KB

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