123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- //
- // KMTabbingHintWindowController.swift
- // PDF Reader Pro
- //
- // Created by liujiajie on 2/28/24.
- //
- import Cocoa
- typealias homeClickedTabbingShowBlock = (_ continueOrNot: Bool) -> Void
- let KMTabbingHintShowFlag = "KMTabbingHintShowFlag"
- class KMTabbingHintWindowController: NSWindowController{
- @IBOutlet var hintLabel: NSTextField!
- @IBOutlet var newTabInWindowButton: NSButton!
- @IBOutlet var newWindowButton: NSButton!
- @IBOutlet var notShowAgainButton: NSButton!
- @IBOutlet var gapView: NSView!
- @IBOutlet var cancelButton: NSButton!
- @IBOutlet var doneButton: NSButton!
-
- @IBOutlet weak var lockIv: NSImageView!
-
- var selectCallBack: homeClickedTabbingShowBlock?
-
- convenience init() {
- self.init(windowNibName: "KMTabbingHintWindowController")
- }
-
- override func windowDidLoad() {
- super.windowDidLoad()
- localiedLanguage()
- configuViewsUI()
-
- #if VERSION_DMG
- NotificationCenter.default.addObserver(self, selector: #selector(deviceActivateStatusChangeNotification), name: NSNotification.Name.deviceActivateStatusChange, object: nil)
- #else
- NotificationCenter.default.addObserver(self, selector: #selector(IAPResultReceived), name: NSNotification.Name.KMIAPSubscriptionLoaded, object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(IAPPurchaseSuccess), name: NSNotification.Name.KMIAPProductPurchased, object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(IAPRestoreFinish), name: NSNotification.Name.KMIAPProductRestoreFinished, object: nil)
-
- #endif
- }
-
- func localiedLanguage() {
- hintLabel.stringValue = String(format: "%@:", NSLocalizedString("Open a document in", comment: ""))
- newTabInWindowButton.title = NSLocalizedString("a new tab in the same window", comment: "")
- newWindowButton.title = NSLocalizedString("a new window", comment: "")
- notShowAgainButton.title = NSLocalizedString("No longer prompt", comment: "")
- cancelButton.title = NSLocalizedString("Cancel", comment: "")
- doneButton.title = NSLocalizedString("Done", comment: "")
- }
- func configuViewsUI() {
- hintLabel.font = NSFont.boldSystemFont(ofSize: 16)
-
- newTabInWindowButton.state = .off
- newWindowButton.state = .on
- notShowAgainButton.state = .off
-
- gapView.wantsLayer = true
- gapView.layer?.backgroundColor = NSColor(red: 218/255.0, green: 218/255.0, blue: 218/255.0, alpha: 1).cgColor
- window?.contentView?.wantsLayer = true
- var color = NSColor.white
- if #available(macOS 10.14, *) {
- if let appearanceName = NSApp.effectiveAppearance.bestMatch(from: [.aqua, .darkAqua]),
- appearanceName == .darkAqua {
- color = KMAppearance.viewBackgroundColor()
- }
- }
- color = NSColor(deviceRed: 74.0/255.0, green: 74.0/255.0, blue: 74.0/255.0, alpha: 1.0)
- if #available(macOS 10.14, *) {
- if let appearanceName = NSApp.effectiveAppearance.bestMatch(from: [.aqua, .darkAqua]),
- appearanceName == .darkAqua {
- color = NSColor(deviceRed: 1.0, green: 1.0, blue: 1.0, alpha: 0.7)
- }
- }
- hintLabel.textColor = color
- newTabInWindowButton?.setTitleColor(color)
- newWindowButton?.setTitleColor(color)
- notShowAgainButton?.setTitleColor(color)
-
- self.reloadData()
- }
- @IBAction func buttonClicked_NewTabInWindowButton(_ sender: NSButton) {
- if IAPProductsManager.default().isAvailableAllFunction() == false {
- sender.state = NSControl.StateValue.off
- let winC = KMPurchaseCompareWindowController.sharedInstance()
- winC?.kEventName = "Reading_MultiTab_BuyNow"
- winC?.showWindow(nil)
- return
- }
- sender.state = NSControl.StateValue.on
- self.newWindowButton.state = .off
- }
-
- @IBAction func buttonClicked_NewWindow(_ sender: NSButton) {
- sender.state = NSControl.StateValue.on
- self.newTabInWindowButton.state = .off
- }
- @IBAction func buttonClicked_DonotHintAgain(_ sender: NSButton) {
-
- }
- @IBAction func buttonClicked_Cancel(_ sender: NSButton) {
- self.km_quick_endSheet()
- if let callback = self.selectCallBack {
- callback(false)
- }
- }
- @IBAction func buttonClicked_Done(_ sender: NSButton) {
- UserDefaults.standard.set(self.notShowAgainButton.state, forKey: KMTabbingHintShowFlag)
- UserDefaults.standard.synchronize()
- if let callback = self.selectCallBack {
- callback(true)
- }
- self.km_quick_endSheet()
- }
-
- func reloadData() {
- KMMainThreadExecute {
- self.lockIv.isHidden = IAPProductsManager.default().isAvailableAllFunction()
- }
- }
-
- // MARK: - Noti Methods
-
- @objc func deviceActivateStatusChangeNotification(sender: Notification) {
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
- self.reloadData()
- }
- }
- @objc func IAPResultReceived(sender: Notification) {
- DispatchQueue.main.async {
- self.reloadData()
- }
- }
- @objc func IAPPurchaseSuccess(sender: Notification) {
- DispatchQueue.main.async {
- self.reloadData()
- }
- }
- @objc func IAPRestoreFinish(sender: Notification) {
- DispatchQueue.main.async {
- self.reloadData()
- }
- }
- }
|