123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- //
- // KMSubscribeWaterMarkWindowController.swift
- // PDF Reader Pro
- //
- // Created by lizhe on 2023/6/12.
- //
- import Cocoa
- var subscribeWaterMarkController: KMSubscribeWaterMarkWindowController?
- var subscribeWaterMarkMainWindow: NSWindow?
- @objc enum KMSubscribeWaterMarkType: Int {
- case none = 0
- case stamp = 1
- case link
- case sign
- case editText
- case editImage
- case insert
- case extract
- case replace
- case split
- case delete
- case rotate
- case copy
- case toWord
- case toExcel
- case toPPT
- case toRTF
- case toCSV
- case toHTML
- case toText
- case toImage
- case compress
- case merge
- case setPassword
- case removePassword
- case crop
- case aiTranslate
- case aiRewrite
- case aiCorrect
- case save
-
- func isConvertType() -> Bool {
- if (self == .toWord || self == .toExcel || self == .toPPT || self == .toRTF || self == .toCSV || self == .toHTML || self == .toText || self == .toImage) {
- return true
- }
- return false
- }
- }
- typealias KMSubscribeWaterMarkWindowControllerCloseAction = (_ controller: KMSubscribeWaterMarkWindowController) -> Void
- typealias KMSubscribeWaterMarkWindowControllerWatermarkExportAction = (_ controller: KMSubscribeWaterMarkWindowController) -> Void
- typealias KMSubscribeWaterMarkWindowControllerSubscribeAction = (_ controller: KMSubscribeWaterMarkWindowController) -> Void
- var tempType: KMSubscribeWaterMarkType = .none
- var tempLimit: Bool = false
- var tempContinue: Bool = false
- class KMSubscribeWaterMarkWindowController: NSWindowController {
- @IBOutlet weak var waterMarkView: KMSubscribeWaterMarkView!
- @IBOutlet weak var waterViewHeightConstrain: NSLayoutConstraint!
-
- var closeAction: KMSubscribeWaterMarkWindowControllerCloseAction?
- var subscribeAction: KMSubscribeWaterMarkWindowControllerSubscribeAction?
- var watermarkExportAction: KMSubscribeWaterMarkWindowControllerWatermarkExportAction?
-
- var isContinue: Bool?
- var isAI: Bool?
- var isLimit: Bool?
- var type: KMSubscribeWaterMarkType? {
- didSet {
- self.waterMarkView?.type = type
- }
- }
-
- deinit {
- KMPrint("KMSubscribeWaterMarkWindowController 释放")
- }
-
- override func windowDidLoad() {
- super.windowDidLoad()
-
- self.waterMarkView.subscribeLabel.stringValue = ""
- self.setup()
- self.reloadData()
- // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
- }
-
- override func awakeFromNib() {
- super.awakeFromNib()
-
- // self.waterMarkView.subscribeLabel.stringValue = ""
- }
-
- //MARK: 打开文件
- @objc static func show(window: NSWindow, isContinue: Bool = false, limit: Bool = false, type: KMSubscribeWaterMarkType = .none, subscribeDidClick: (()->Void)? = nil, completion: @escaping (_ isSubscribeSuccess: Bool, _ isWaterMarkExport: Bool, _ isClose: Bool) -> Void) -> KMSubscribeWaterMarkWindowController {
- #if VERSION_DMG
- if type != .save && !KMLightMemberManager.manager.isLogin() {
- KMLoginWindowController.show(window: window)
- return KMSubscribeWaterMarkWindowController()
- }
- #endif
- tempLimit = limit
- tempType = type
- tempContinue = isContinue
-
- var isAI = false
- if type == .aiCorrect ||
- type == .aiRewrite ||
- type == .aiTranslate {
- isAI = true
- } else {
- isAI = false
- }
-
- if isAI && KMLightMemberManager.manager.purchaseState != .subscription {
- if KMLightMemberManager.manager.isLogin() {
- KMComparativeTableViewController.show(window: NSApp.mainWindow!, .equity)
- } else {
- let controller = KMLoginWindowController.show(window: NSApp.mainWindow!,.equity)
- if isAI {
- let alert = NSAlert()
- alert.messageText = NSLocalizedString("Please Login or Sign up to proceed to the next step.", comment: "")
- alert.informativeText = NSLocalizedString("On upgrading your account, you can enjoy all AI features in PDF Reader Pro.", comment: "")
- alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
- alert.beginSheetModal(for: (controller?.window)!) { result in
- }
- }
- }
- return KMSubscribeWaterMarkWindowController.init()
- } else {
- let subscribeWaterMarkWindowController: KMSubscribeWaterMarkWindowController = KMSubscribeWaterMarkWindowController.init(windowNibName: "KMSubscribeWaterMarkWindowController")
- subscribeWaterMarkWindowController.isContinue = isContinue
- subscribeWaterMarkWindowController.isAI = isAI
- subscribeWaterMarkWindowController.isLimit = limit
-
- window.beginSheet(subscribeWaterMarkWindowController.window!)
- subscribeWaterMarkWindowController.window?.center()
- subscribeWaterMarkWindowController.type = type
- subscribeWaterMarkWindowController.reloadData()
-
- subscribeWaterMarkWindowController.closeAction = { controller in
- completion(false, false, true)
- subscribeWaterMarkMainWindow?.endSheet(controller.window!)
- controller.window?.close()
-
- subscribeWaterMarkController = nil
- subscribeWaterMarkMainWindow = nil
- }
-
- subscribeWaterMarkWindowController.watermarkExportAction = { controller in
- completion(false, true, false)
- subscribeWaterMarkMainWindow?.endSheet(controller.window!)
- controller.window?.close()
- subscribeWaterMarkController = nil
- subscribeWaterMarkMainWindow = nil
- }
-
- subscribeWaterMarkWindowController.subscribeAction = { controller in
- if let callback = subscribeDidClick {
- callback()
- }
-
- subscribeWaterMarkMainWindow?.endSheet(controller.window!)
- controller.window?.close()
- subscribeWaterMarkController = nil
-
- if KMLightMemberManager.manager.isLogin() ||
- type == .save ||
- ((type.isConvertType() || type == .merge) && !limit) {
- _ = KMComparativeTableViewController.show(window: subscribeWaterMarkMainWindow ?? NSWindow(), .equity, inputType: type)
- } else {
- _ = KMLoginWindowController.show(window: subscribeWaterMarkMainWindow ?? NSWindow())
- }
- subscribeWaterMarkMainWindow = nil
- }
-
- subscribeWaterMarkController = subscribeWaterMarkWindowController
- subscribeWaterMarkMainWindow = window
- return subscribeWaterMarkWindowController
- }
- }
-
- func setup() {
- self.window?.contentView?.backgroundColor(NSColor.km_init(hex: "#FFFFFF"))
- self.waterMarkView.waterExportButton.title = ""
- self.waterMarkView.subscribeLabel.stringValue = ""
- self.waterMarkView.closeAction = { [weak self] view in
- guard let callBack = self?.closeAction else { return }
-
- callBack((self!))
- }
-
- self.waterMarkView.waterMarkExportAction = { [weak self] view in
- self?.trackEvent(eventName: "PUW_Sub_SaveWatermark")
-
- guard let callBack = self?.watermarkExportAction else { return }
-
- callBack((self!))
- }
-
- self.waterMarkView.subscribeAction = { [weak self] view in
- guard let callBack = self?.subscribeAction else { return }
-
- callBack((self!))
- }
- }
-
- func closeWindow() {
- if subscribeWaterMarkMainWindow != nil {
- subscribeWaterMarkMainWindow?.endSheet((subscribeWaterMarkController?.window)!)
- }
-
- if subscribeWaterMarkController != nil {
- subscribeWaterMarkController?.window?.close()
- }
- subscribeWaterMarkController = nil
- subscribeWaterMarkMainWindow = nil
- }
-
- func reloadData() {
- if KMSubscribeWaterMarkWindowController.canShowSubscripBenefits() {
- self.waterViewHeightConstrain.constant = 462
- } else {
- self.waterViewHeightConstrain.constant = 563
- }
- self.waterMarkView.type = tempType
- self.waterMarkView.updateConstraints()
-
- self.updateLanguage()
- }
-
- func updateLanguage() {
- if self.waterMarkView != nil {
- if tempContinue {
- self.waterMarkView.waterExportButton.title = NSLocalizedString("Save with Watermark", comment: "")
- } else {
- if tempType == .merge {
- if (tempLimit) {
- self.waterMarkView.waterExportButton.title = NSLocalizedString("Exceed Times Limit", comment: "")
- self.waterMarkView.isSecondEnable = false
-
- self.waterMarkView.subscribeLabel.stringValue = NSLocalizedString("Upgrade Now", comment: "")
- } else {
- self.waterMarkView.isSecondEnable = true
- self.waterMarkView.waterExportButton.title = NSLocalizedString("Delete Files from List", comment: "")
- }
- } else if tempType.isConvertType() {
- if (tempLimit) {
- self.waterMarkView.waterExportButton.title = NSLocalizedString("Exceed Times Limit", comment: "")
- self.waterMarkView.isSecondEnable = false
-
- self.waterMarkView.subscribeLabel.stringValue = NSLocalizedString("Upgrade Now", comment: "")
- } else {
- self.waterMarkView.isSecondEnable = true
- // if KMLightMemberManager.manager.isLogin() {
- self.waterMarkView.waterExportButton.title = NSLocalizedString("Convert First 10 Pages", comment: "")
- // } else {
- // subscribeWaterMarkWindowController.waterMarkView.waterExportButton.title = NSLocalizedString("Later", comment: "")
- // }
- }
- } else if (type == .save) {
- self.waterMarkView.subscribeLabel.stringValue = NSLocalizedString("Upgrade Now", comment: "")
- self.waterMarkView.waterExportButton.title = NSLocalizedString("Save with Watermark", comment: "")
- } else {
- self.waterMarkView.waterExportButton.title = NSLocalizedString("Save with Watermark", comment: "")
- }
- }
- }
- }
-
- static func isSampleController() -> KMSubscribeWaterMarkWindowController {
- for window in NSApp.windows {
- let controller = window.windowController
- if controller is KMSubscribeWaterMarkWindowController {
- return controller as! KMSubscribeWaterMarkWindowController
- }
- }
- return KMSubscribeWaterMarkWindowController()
- }
-
- static func canShowSubscripBenefits() -> Bool {
- #if VERSION_DMG
- return KMLightMemberManager.manager.isLogin() || tempType == .save || ((tempType.isConvertType() || tempType == .merge) && tempLimit)
- #else
- return KMLightMemberManager.manager.isLogin() || tempType == .save || ((tempType.isConvertType() || tempType == .merge) && !tempLimit)
- #endif
- }
- }
- // MARK: - Analytics (埋点)
- extension KMSubscribeWaterMarkWindowController {
- func trackEvent(eventName: String) -> Void {
- KMAnalytics.trackEvent(eventName: eventName, parameters: [
- KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.puw,
- KMAnalytics.Parameter.labelKey : KMAnalytics.Label.sub_PUW], platform: .AppCenter, appTarget: .all)
- }
-
- func trackEvent(type: KMSubscribeWaterMarkType) -> Void {
- KMTools.trackEvent(type: type)
- }
- }
|