123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441 |
- import Cocoa
- import KMAdvertisement
- @main
- class AppDelegate: NSObject, NSApplicationDelegate {
-
- func applicationDidBecomeActive(_ notification: Notification) {
-
- }
- func applicationWillFinishLaunching(_ notification: Notification) {
-
- CPDFKit.setLicenseKey("dgtev+v8ZBzllfSsfeXK1lPMh3JgNGs+Kg7lCqvmwo/sE0ZkT05iJx02yR9udvC8JztTWdi+6XuuVrAgKaBeXPfM6M3KdqihXikerzGW/lOgNN6IEA2w+U0z94MwjwV00Jw//KZrTIA5cikmxCG5c3WWlZ7KwohsXpz5CjL9GZ0=", secret: "mG0c3O3Mzeu5dkZJW3gpqh188cTuhYlGRPrbR/gfX4qvEHOmPIqbfhpDnKKj+7YmZYmbELOmlC/T06UnUm6GVQ4kKHeI5gp+IshiDDfImK1hrp9sGpqfp0B228KI+IMTu4aGVjtYuk+Uxs/kosIBwyVLBY93oKLBB8UJg4t07605BGbaBKUlDopA0iGq1HSncic5RdoSGMQ2mYUuV1oxpwnky4YgYJhGWR5TM3YzBCpiTBw1ZUzJi+CA9XatMW99rCikYgLTfhDOO2GaHDBf3Q==")
-
- CPDFConvertKit.setLicenseKey("tur8T617A7J3w3qcOIP9jKaYVpALoUNwKypy6gVwBA/PxkH51D/Ygdvv2o7zPWrWx1Z2sDrXQ3FEklZX8MXPxWxLg2I5jOkrBsqbr4+Go9jXqEo2NnJPnWWu74CDuyHcfBqJNL33iA03ejgabcG/aBTYhpoBhf5keDLRpw7gMAw=", secret: "mG0c3O3Mzeu5dkZJW3gpqh188cTuhYlGRPrbR/gfX4o3S5AixMY+3TX1FpQaugG9sTsnCq4QxIEDzyAI3s3dWjNe3wDsMrmFq51HtjPa2tSFAoV6NtcUJC8skonXVk7kMv7C2jvq4o0q6sQtN3jR4/O0KyLBwAUtFVoCfhic6aFGCBFYi5JVW6AhRY7eYhL/GmmM2OPfZmckrGW/KP13rb8TdeaHIEX2khN2RJTdbnY=")
-
-
- ComPDFUIConfig.initializeUIConfig();
-
- KMDesignToken.shared.parserExcel(withPath: "")
- }
- func applicationDidFinishLaunching(_ aNotification: Notification) {
-
- KMAdvertisementManager.manager.initConfig(appName: .PDFReaderProMac,
- subscribeType: .unsubscribed,
- platform: .Mac)
- KMAdvertisementManager.manager.debug = true
-
-
- NSApp.appearance = NSAppearance(named: .aqua)
-
-
- var info = UserDefaults.standard.value(forKey: "kFirstOpenAppCount")
- var count = 0
- if info != nil {
- count = info as? Int ?? 0
- }
- count += 1
- UserDefaults.standard.set(count, forKey: "kFirstOpenAppCount")
- UserDefaults.standard.synchronize()
-
- self.initMainMenu()
-
- DBClientsManager.setup(withAppKeyDesktop: "jxjlqfm1cfp2mjj")
-
- reopenDocument(forPaths: [])
-
- KMPreferenceManager.shared.author = NSFullUserName()
- }
-
- func application(_ application: NSApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
-
- }
-
- func application(_ application: NSApplication, didReceiveRemoteNotification userInfo: [String : Any]) {
-
- }
-
- func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
- if !flag {
- let browser: KMBrowser = KMBrowser.init()
- browser.windowController = KMBrowserWindowController.init(browser: browser)
- browser.addHomeTabContents()
- browser.windowController.showWindow(self)
- }
- return flag
- }
-
- func applicationShouldOpenUntitledFile(_ sender: NSApplication) -> Bool {
- if (KMPreferenceManager.shared.openLastUnclosedDocumentWhenAppStart == false) {
- return false
- }
-
- let filepaths = KMPreferenceManager.shared.lastOpenFilepaths
- if (filepaths == nil || filepaths!.count == 0) {
- return false
- }
-
- DispatchQueue.main.async {
- for filepath in filepaths! {
- if filepath.isPDFValid() {
- NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: filepath), display: true) { document, result, error in
- }
- } else {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
- alert.runModal()
- }
- }
- }
- return false
- }
- func applicationWillTerminate(_ aNotification: Notification) {
- if (NSApp.orderedDocuments.count > 0) {
- var filepaths: [String] = []
- for document in NSApp.orderedDocuments {
- if (document.fileURL?.path != nil) {
- filepaths.append((document.fileURL?.path)!)
- }
- }
- KMPreferenceManager.shared.lastOpenFilepaths = filepaths
- } else {
- KMPreferenceManager.shared.lastOpenFilepaths = nil
- }
- }
- func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
- return true
- }
-
-
-
- func reopenDocument(forPaths paths: [String]) -> Void {
- let browser = KMBrowser.init() as KMBrowser
- browser.windowController = KMBrowserWindowController.init(browser: browser)
- browser.addHomeTabContents()
- browser.windowController.showWindow(self)
- }
-
-
- func initMainMenu() {
-
- let mainMenu = NSApp.mainMenu
- if (mainMenu == nil) {
- return
- }
- for menu in mainMenu!.items {
- let subMenu = menu.submenu
- for item in subMenu!.items {
- item.title = NSLocalizedString(item.title, comment: "")
- let itemSubMenu = item.submenu
- if (itemSubMenu == nil) {
- continue
- }
-
- for item in itemSubMenu!.items {
- item.title = NSLocalizedString(item.title, comment: "")
- }
- }
- }
-
- let PDFOfficeMenu = mainMenu?.item(at: 0)?.submenu
-
-
-
- #if VERSION_DMG
- PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Check for Updates", comment: ""), action: #selector(checkForUpdates), target: self, at: 1)
- #endif
-
- let fileMenu = mainMenu?.item(at: 1)?.submenu
- let shareItem: NSMenuItem = NSMenuItem(title: NSLocalizedString("Share", comment: ""), action: nil, target: nil)
- fileMenu!.insertItem(shareItem, at: (fileMenu?.items.count)!-1)
-
- shareItem.submenu = NSSharingServicePicker.menu(forSharingItems: [""], subjectContext: "", withTarget: self, selector: #selector(sharePageItemAction), serviceDelegate: nil)
-
- let viewMenu = mainMenu?.item(at: 3)?.submenu
- var zoomMenu: NSMenu?
- for item in viewMenu!.items {
- if (item.title == NSLocalizedString("Zoom", comment: "")) {
- zoomMenu = item.submenu
- break
- }
- }
- if (zoomMenu != nil) {
- for item in zoomMenu!.items {
- if (item.title == NSLocalizedString("Zoom In", comment: "")) {
- item.keyEquivalent = "+"
- item.keyEquivalentModifierMask = [.command]
- break
- }
- }
- }
- }
-
- @objc func sharePageItemAction(sender: NSMenuItem) {
- if ((NSApp.mainWindow?.windowController is KMBrowserWindowController) == false) {
- return
- }
-
- let windowControler = NSApp.mainWindow?.windowController as! KMBrowserWindowController
- let model: CTTabStripModel = windowControler.browser.tabStripModel
- if (model.count() <= 0) {
- return
- }
-
- if (model.activeTabContents().isHome) {
- return
- }
-
- let document: KMMainDocument = model.activeTabContents() as! KMMainDocument
- let represent : NSSharingService = sender.representedObject as! NSSharingService
- represent.perform(withItems: [document.fileURL as Any])
- }
-
- func updateAccountMenus() {
- let mainMenu = NSApp.mainMenu
- let PDFOfficeMenu: NSMenu = (mainMenu?.item(at: 0)?.submenu)!
-
- var index: Int = 4
- #if VERSION_DMG
- index = 5
- #endif
-
- let isLogin = false
- if (isLogin) {
- PDFOfficeMenu.insertItem(withTitle: NSLocalizedString("user@mobile.com", comment: ""), action: #selector(showAccount), target: self, at: index)
- let manageAcctounItem = PDFOfficeMenu.item(at: index+1)
- manageAcctounItem?.title = NSLocalizedString("View my account", comment: "")
-
- PDFOfficeMenu.insertItem(withTitle: NSLocalizedString("Resume purchase", comment: ""), action: #selector(resumePurchase), target: self, at: index+2)
- let loginItem = PDFOfficeMenu.item(at: index+3)
- loginItem?.title = NSLocalizedString("Logout", comment: "")
- } else {
- var hasLoginItems = false
- for item in PDFOfficeMenu.items {
- if (item.action == #selector(showAccount) ||
- item.action == #selector(resumePurchase)) {
- hasLoginItems = true
- break
- }
- }
-
- if (hasLoginItems) {
- let loginItem = PDFOfficeMenu.item(at: index+3)
- loginItem?.title = NSLocalizedString("Log In", comment: "")
- PDFOfficeMenu.removeItem(at: index+2)
-
- let manageAcctounItem = PDFOfficeMenu.item(at: index+1)
- manageAcctounItem?.title = NSLocalizedString("Manage my account", comment: "")
- PDFOfficeMenu.removeItem(at: index)
- } else {
- let manageAcctounItem = PDFOfficeMenu.item(at: index+1)
- manageAcctounItem?.title = NSLocalizedString("Manage my account", comment: "")
- let loginItem = PDFOfficeMenu.item(at: index+2)
- loginItem?.title = NSLocalizedString("Log In", comment: "")
- }
- }
- }
-
-
- @IBAction func openPreferenceWindow(_ sender: Any) {
- KMPreferenceWindowController.shared.showWindow(nil)
- }
-
- @objc @IBAction func manageAcctounMenuAction(_ sender: Any) {
- if KMLightMemberManager.manager.isLogin() {
- KMAccountInfoWindowController.show(window: NSApp.mainWindow!)
- }
- }
-
- @IBAction func loginMenuItemAction(_ sender: Any) {
-
- if KMLightMemberManager.manager.isLogin() {
-
- } else {
- KMLoginWindowController.show(window: NSApp.mainWindow!)
- }
- }
-
- @IBAction func logoutMenuItemAction(_ sender: Any) {
-
- if KMLightMemberManager.manager.isLogin() {
- KMRequestServerManager.manager.logout { success, result in
- if success {
- print("登出成功")
- }
- }
- }
- }
-
- @objc func showAccount() {
-
- }
-
- @objc func resumePurchase() {
-
- }
-
-
-
- @IBAction func menuItemAction_quickStudy(_ sender: NSMenuItem) -> Void {
- KMTools.openQuickStartStudy()
- }
-
- @IBAction func menuItemAction_onlineHelp(_ sender: NSMenuItem) -> Void {
- KMTools.openFAQWebsite()
- }
-
- @IBAction func menuItemAction_morePudact(_ sender: NSMenuItem) -> Void {
- KMTools.openMoreProductWebsite()
- }
-
- @IBAction func menuItemAction_freePDFTemplate(_ sender: NSMenuItem) -> Void {
- KMTools.openFreePDFTemplatesWebsite()
- }
-
- @IBAction func menuItemAction_payEmail(_ sender: NSMenuItem) -> Void {
- KMEmailSubWindowController().showWindow(nil)
- }
-
- @IBAction func menuItemAction_poweredByComPDFKit(_ sender: NSMenuItem) -> Void {
- KMTools.openComPDFKitPowerWebsite()
- }
-
- @IBAction func menuItemAction_feekback(_ sender: NSMenuItem) -> Void {
- KMTools.feekback()
- }
-
- @IBAction func menuItemAction_giveFiveStar(_ sender: NSMenuItem) -> Void {
-
- }
-
-
- #if VERSION_DMG
- @objc func checkForUpdates(_ sender: NSMenuItem) {
-
- }
-
- #endif
- }
- extension AppDelegate : NSMenuDelegate,NSMenuItemValidation {
- func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
- let action = menuItem.action
- if action == #selector(manageAcctounMenuAction) {
- self.updateLoginMenuItem()
- return KMLightMemberManager.manager.isLogin()
- }
- if action == #selector(loginMenuItemAction) {
- self.updateLoginMenuItem()
- return !KMLightMemberManager.manager.isLogin()
- }
-
- if action == #selector(logoutMenuItemAction) {
- self.updateLoginMenuItem()
- return KMLightMemberManager.manager.isLogin()
- }
- return true
- }
-
- func updateLoginMenuItem() {
-
- let firstItem = NSApp.mainMenu?.item(at: 0)?.submenu
- if firstItem != nil {
- let item1 = firstItem?.item(withTag: 11)
- let item2 = firstItem?.item(withTag: 12)
- let item3 = firstItem?.item(withTag: 13)
- let item4 = firstItem?.item(withTag: 14)
- if KMLightMemberManager.manager.isLogin() {
- item1?.title = KMLightMemberManager.manager.info.email
- item1?.isHidden = false
- item2?.isHidden = true
- item3?.isHidden = false
- item4?.isHidden = false
- } else {
- item1?.isHidden = true
- item2?.isHidden = false
- item3?.isHidden = true
- item4?.isHidden = true
- }
- }
- }
-
- @objc func clickOutline(menuItem: NSMenuItem) {
- print("更新菜单栏")
- }
-
- func menuNeedsUpdate(_ menu: NSMenu) {
- print("menuNeedsUpdate")
-
- }
-
- func menu(_ menu: NSMenu, update item: NSMenuItem, at index: Int, shouldCancel: Bool) -> Bool {
- return true
- }
- }
|