123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- //
- // KMNewUserGiftWindowController.swift
- // PDF Reader Pro
- //
- // Created by User-Tangchao on 2024/12/25.
- //
- import Cocoa
- @objcMembers class KMNewUserGiftWindowController: KMBaseWindowController {
- @IBOutlet weak var contentBox: NSBox!
- @IBOutlet weak var backgroundIv: NSImageView!
- @IBOutlet weak var titleLabel: NSTextField!
- @IBOutlet weak var subTitleLabel: NSTextField!
- @IBOutlet weak var listBox: NSBox!
- @IBOutlet weak var listBos2: NSBox!
- @IBOutlet weak var buttonBox: NSBox!
-
- private lazy var listBackgroundIv: NSImageView = {
- let view = NSImageView()
- return view
- }()
-
- private lazy var listBackgroundIv2: NSImageView = {
- let view = NSImageView()
- return view
- }()
-
- private lazy var giftItemView_: KMNewUserGiftItemView = {
- let view = KMNewUserGiftItemView()
- return view
- }()
-
- private lazy var giftItemView2_: KMNewUserGiftItemView = {
- let view = KMNewUserGiftItemView()
- return view
- }()
-
- private lazy var submitButton_: NSButton = {
- let view = NSButton()
- view.isBordered = false
- return view
- }()
-
- private lazy var buttonIv_: NSImageView = {
- let view = NSImageView()
- return view
- }()
-
- static let shared = KMNewUserGiftWindowController(windowNibName: "KMNewUserGiftWindowController")
-
- private let hasVaildShowKey_ = "hasVaildShow"
-
- override func windowDidLoad() {
- super.windowDidLoad()
-
- let closeButton = window?.standardWindowButton(.closeButton)
- closeButton?.target = self
- closeButton?.action = #selector(closeAction)
- window?.standardWindowButton(.zoomButton)?.isHidden = true
- window?.standardWindowButton(.miniaturizeButton)?.isHidden = true
- window?.delegate = self
-
- backgroundIv.image = NSImage(named: "KMImageNewUserGiftBg")
- backgroundIv.image?.size = window?.frame.size ?? NSMakeSize(660, 490)
-
- titleLabel.stringValue = NSLocalizedString("Welcome Gift For New Users!", comment: "")
- subTitleLabel.stringValue = NSLocalizedString("Hi! We’re delighted to meet you. Dive in and enjoy your PDF journey with us!", comment: "")
- titleLabel.font = .UbuntuMediumFontWithSize(30)
- titleLabel.alignment = .center
- subTitleLabel.font = .UbuntuMediumFontWithSize(16)
-
- contentBox.contentView?.addSubview(listBackgroundIv, positioned: .below, relativeTo: listBox)
- listBackgroundIv.mas_makeConstraints { make in
- make?.centerX.equalTo()(listBox)?.offset()(-3)
- make?.centerY.equalTo()(listBox)?.offset()(3)
- }
- listBackgroundIv.image = NSImage(named: "KMImageNewUserGiftItemBg")
-
- contentBox.contentView?.addSubview(listBackgroundIv2, positioned: .below, relativeTo: listBos2)
- listBackgroundIv2.mas_makeConstraints { make in
- make?.centerX.equalTo()(listBos2)?.offset()(-3)
- make?.centerY.equalTo()(listBos2)?.offset()(3)
- }
- listBackgroundIv2.image = NSImage(named: "KMImageNewUserGiftItemBg2")
-
- listBox.borderWidth = 0
- listBos2.borderWidth = 0
- listBox.contentView = giftItemView_
- listBos2.contentView = giftItemView2_
- giftItemView_.titleLabel.stringValue = String(format: NSLocalizedString("%d-day VIP Free Trial", comment: ""), 7)
- giftItemView_.titleLabel.font = .SFProTextRegularFont(20)
- giftItemView_.subTitleLabel.stringValue = NSLocalizedString("Enjoy the full functions of PDF Reader Pro.\nEdit, convert, annotate, and combine PDFs.", comment: "")
- giftItemView_.subTitleLabel.font = .SFProTextRegularFont(14)
- giftItemView2_.titleLabel.font = .SFProTextRegularFont(20)
-
- if KMIsDMGVersion() {
- if NSLocalizedString("USD", comment: "") == "USD" {
- giftItemView2_.titleLabel.stringValue = String(format: NSLocalizedString("%@ Coupons in Total", comment: ""), "$60")
- giftItemView2_.subTitleLabel.stringValue = String(format: NSLocalizedString("New users can get %@ Coupons to upgrade the plan.", comment: ""), "$60")
- } else {
- giftItemView2_.titleLabel.stringValue = String(format: NSLocalizedString("%@ Coupons in Total", comment: ""), "360元")
- giftItemView2_.subTitleLabel.stringValue = String(format: NSLocalizedString("New users can get %@ Coupons to upgrade the plan.", comment: ""), "360元")
- }
- } else {
- var showCNY = false
- #if VERSION_DMG
- #else
- if let localeId = IAPProductsManager.default()?.allAccessPackPermanent_lite?.product?.priceLocale.identifier {
- showCNY = localeId.contains("zh_CN") || localeId.contains("zh_TW")
- }
- #endif
- if showCNY == false {
- // if NSLocalizedString("USD", comment: "") == "USD" {
- giftItemView2_.titleLabel.stringValue = String(format: NSLocalizedString("%@ Coupons in Total", comment: ""), "USD 30")
- giftItemView2_.subTitleLabel.stringValue = String(format: NSLocalizedString("New users can get %@ Coupons to upgrade the plan.", comment: ""), "USD 30")
- } else {
- giftItemView2_.titleLabel.stringValue = String(format: NSLocalizedString("%@ Coupons in Total", comment: ""), "180元")
- giftItemView2_.subTitleLabel.stringValue = String(format: NSLocalizedString("New users can get %@ Coupons to upgrade the plan.", comment: ""), "180元")
- }
- }
- giftItemView2_.subTitleLabel.font = .SFProTextRegularFont(14)
-
- buttonBox.borderWidth = 0
- contentBox.contentView?.addSubview(buttonIv_, positioned: .below, relativeTo: buttonBox)
- buttonIv_.image = NSImage(named: "KMImageNameCancelSubscribeSuccessButton")
- buttonIv_.mas_makeConstraints { make in
- make?.centerX.mas_equalTo()
- make?.centerY.equalTo()(buttonBox)?.offset()(6)
- }
-
- buttonBox.contentView?.addSubview(submitButton_)
- submitButton_.frame = buttonBox.contentView?.frame ?? .zero
- submitButton_.autoresizingMask = [.width, .height]
- submitButton_.title = NSLocalizedString("Sign in to Get Gift", comment: "")
- submitButton_.font = .UbuntuMediumFontWithSize(16)
- submitButton_.target = self
- submitButton_.action = #selector(submitAction)
- interfaceThemeDidChanged(self.window?.appearance?.name ?? .aqua)
- }
-
- override func interfaceThemeDidChanged(_ appearance: NSAppearance.Name) {
- super.interfaceThemeDidChanged(appearance)
-
- KMMainThreadExecute {
- if KMAppearance.isDarkMode() {
- self.titleLabel.textColor = .white
- self.subTitleLabel.textColor = .white
- self.submitButton_.setTitleColor(NSColor(hex: "#050022"))
- } else {
- self.titleLabel.textColor = NSColor(hex: "#000150")
- self.subTitleLabel.textColor = NSColor(hex: "#000150")
- self.submitButton_.setTitleColor(.white)
- }
-
- self.giftItemView_.titleLabel.textColor = .white
- self.giftItemView_.subTitleLabel.textColor = .white
- self.giftItemView2_.titleLabel.textColor = .white
- self.giftItemView2_.subTitleLabel.textColor = .white
- }
- }
-
- // MARK: - Actions
-
- @objc func submitAction() {
- trackEvent(eventName: "PUW", params: ["PUW_Btn" : "Welcom_Signin"], platform: .AppCenter)
-
- saveShowRecord()
-
- closeWindow()
- _showLoginWindow()
- }
-
- @objc func closeAction() {
- trackEvent(eventName: "PUW", params: ["PUW_Btn" : "Welcom_Cancel"], platform: .AppCenter)
-
- saveShowRecord()
-
- closeWindow()
-
- _showLoginWindow()
- }
-
- // MARK: - Private Methods
-
- private func _showNewGuideWindow() {
- if KMMemberInfo.shared.isMemberAllFunction { // 有权益(本地 或 账号)
- return
- }
-
- KMNewUserGuideWindowController.shared.openWindow()
- }
-
- private func _showLoginWindow() {
- if KMMemberInfo.shared.isLogin {
- _showNewGuideWindow()
- return
- }
- KMLoginWindowsController.shared.openWindow { [unowned self] success in
- if success == false {
- return
- }
- _showNewGuideWindow()
- }
- }
-
- private func _showCenter(animate: Bool){
- guard let screenFrame = NSScreen.main?.frame else {
- return
- }
- guard let win = self.window else {
- return
- }
-
- var frame = win.frame
- frame.origin.y = (screenFrame.size.height-frame.size.height)*0.5
- frame.origin.x = (screenFrame.size.width-frame.size.width)*0.5
- win.setFrame(frame, display: true, animate: animate)
- }
-
- // MARK: - Public Methods
-
- public func needShowForlocalCheck() -> Bool {
- if KMDataManager.ud_bool(forKey: hasVaildShowKey_) { // 不重复显示
- #if DEBUG
- #else
- return false
- #endif
- }
- let appFirstLaunch = KMDataManager.default.appFirstLaunch
- let appFirstLaunchForUpdate = KMDataManager.default.appFirstLaunchForUpdate
- if appFirstLaunch == false && appFirstLaunchForUpdate == false {
- #if DEBUG
- #else
- // return false
- #endif
- }
- return true
- }
-
- public func needShow() -> Bool {
- if needShowForlocalCheck() == false {
- return false
- }
-
- if KMNewUserGiftManager.default.needShow() == false {
- return false
- }
-
- if KMMemberInfo.shared.isLogin { // 登陆
- return false
- }
- return true
- }
-
- public func saveShowRecord() {
- KMDataManager.ud_set(true, forKey: hasVaildShowKey_)
- }
-
- public func openWindow() {
- showWindow(nil)
-
- _showCenter(animate: false)
- window?.makeKeyAndOrderFront(nil)
-
- trackEvent(eventName: "PUW", params: ["PUW_Exposure" : "PUW_WelcomGift"], platform: .AppCenter)
- }
-
- public func closeWindow() {
- window?.close()
- }
- }
- // MARK: - NSWindowDelegate
- extension KMNewUserGiftWindowController: NSWindowDelegate {
- func windowDidResize(_ notification: Notification) {
- guard let data = window?.isEqual(to: notification.object), data == true else {
- return
- }
- backgroundIv.image?.size = window?.frame.size ?? NSMakeSize(660, 490)
- }
- }
|