AppDelegate.swift 43 KB

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