// // KMToolCompareWindowController.swift // PDF Master // // Created by liujiajie on 2023/11/9. // import Cocoa var currentWindowController: KMToolCompareWindowController? = nil class KMToolCompareWindowController: NSWindowController{ var type: KMCompareWithToolType? var selectIndex: Int = 0 @IBOutlet var box: NSBox! var modalSession: NSApplication.ModalSession? deinit { NotificationCenter.default.removeObserver(self) } convenience init(toolType: KMCompareWithToolType, selectNum: Int) { self.init(windowNibName: "KMToolCompareWindowController") self.type = toolType self.selectIndex = selectNum } func toolCompareWith(toolType:KMCompareWithToolType, selectNum:Int) -> KMToolCompareWindowController { if (currentWindowController != nil) { return currentWindowController! } let vc = KMToolCompareWindowController(toolType: toolType, selectNum: selectNum) currentWindowController = vc return vc } override func windowDidLoad() { super.windowDidLoad() #if VERSION_DMG // IAPProductsManager.defaultManager().loadProducts() NotificationCenter.default.addObserver(self, selector: #selector(IAPProductLoadedNotification(notification:)), name: NSNotification.Name("KMIAPProductLoadedNotification"), object: nil) NotificationCenter.default.addObserver(self, selector: #selector(IAPSubscriptionLoadedNotification(notification:)), name: NSNotification.Name("KMIAPSubscriptionLoadedNotification"), object: nil) NotificationCenter.default.addObserver(self, selector: #selector(IAPProductPurchasedNotification(notification:)), name: NSNotification.Name("KMIAPProductPurchasedNotification"), object: nil) NotificationCenter.default.addObserver(self, selector: #selector(IAPProductFailedNotification(notification:)), name: NSNotification.Name("KMIAPProductFailedNotification"), object: nil) NotificationCenter.default.addObserver(self, selector: #selector(IAPProductRestoreFinishedNotification(notification:)), name: NSNotification.Name("KMIAPProductRestoreFinishedNotification"), object: nil) NotificationCenter.default.addObserver(self, selector: #selector(IAPProductRestoreFailedNotification(notification:)), name: NSNotification.Name("KMIAPProductRestoreFailedNotification"), object: nil) #endif } func removeWaitingView(view: NSView) { for subview in view.subviews { if subview is WaitingView { subview.removeFromSuperview() break } } } func reloadData() { // if IAPProductsManager.defaultManager().isAvailableAllFunction { // self.payConvertCompareViewController.reloadData() // } else { // self.convertCompareViewController.reloadData() // } } @objc func IAPProductFailedNotification(notification: NSNotification) { self.removeWaitingView(view: (self.window?.contentView)!) } @objc func IAPProductPurchasedNotification(notification: NSNotification) { self.removeWaitingView(view: (self.window?.contentView)!) self.reloadData() } @objc func IAPProductLoadedNotification(notification: NSNotification) { self.reloadData() } @objc func IAPProductRestoreFinishedNotification(notification: NSNotification) { self.removeWaitingView(view: (self.window?.contentView)!) self.reloadData() } @objc func IAPProductRestoreFailedNotification(notification: NSNotification) { self.removeWaitingView(view: (self.window?.contentView)!) } @objc func IAPSubscriptionLoadedNotification(notification: NSNotification) { self.removeWaitingView(view: (self.window?.contentView)!) self.reloadData() } }