AppDelegate.swift 44 KB

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