AppDelegate.swift 44 KB

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