123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- //
- // AccountTools.swift
- // PDF Reader Pro
- //
- // Created by User-Tangchao on 2024/11/5.
- //
- import Cocoa
- @objcMembers class AccountTools: NSObject {
- @available(macOS 10.15.0, iOS 13.0, *)
- public class func canUseAdvance() async -> Bool {
- return await withCheckedContinuation({ continuation in
- self.canUseAdvance { success, err in
- continuation.resume(returning: success)
- }
- })
- }
-
- public class func canUseAdvance(callback: @escaping ((Bool, String?)->Void)) {
- if AccountManager.manager.isTrialing {
- callback(true, nil)
- return
- }
-
- guard let token = KMDataManager.ud_string(forKey: kAccountTokenKey), token.isEmpty == false else {
- return callback(false, nil)
- }
- let state = Self._isConnectionAvailable()
- if !state {
- // self._showHud(msg: NSLocalizedString("Unable to connect to server, please check your connection.", comment: ""))
- return callback(false, nil)
- }
-
- let header = ["Token" : token]
-
- let uuid = GetHardwareUUID()
- let params = ["device_code" : uuid]
- // 绑定设备
- KMHTTP.OEM_POST(urlString: kURLAPI_oemBind, parameter: params, headers: header) { success, dataModel, err in
- callback(success, "")
-
- if dataModel?.code == KMHttpReponseCode.passwordChanged.rawValue {
- DispatchQueue.main.async {
- self._showHud(msg: NSLocalizedString("Your password has been changed. Please login again.", comment: ""))
- }
- }
- }
- }
-
- public class func canUseAdvance_success(callback: @escaping ((Bool)->Void)) {
- if AccountManager.manager.isTrialing {
- callback(true)
- return
- }
-
- guard let token = KMDataManager.ud_string(forKey: kAccountTokenKey), token.isEmpty == false else {
- self.gotoCompare()
- return callback(false)
- }
- let state = Self._isConnectionAvailable()
- if !state {
- // self._showHud(msg: NSLocalizedString("Unable to connect to server, please check your connection.", comment: ""))
- self.gotoCompare()
- return callback(false)
- }
-
- let header = ["Token" : token]
-
- let uuid = GetHardwareUUID()
- let params = ["device_code" : uuid]
- // 绑定设备
- KMHTTP.OEM_POST(urlString: kURLAPI_oemBind, parameter: params, headers: header) { success, dataModel, err in
- if success == false {
- self.gotoCompare()
-
- if dataModel?.code == KMHttpReponseCode.passwordChanged.rawValue {
- DispatchQueue.main.async {
- self._showHud(msg: NSLocalizedString("Your password has been changed. Please login again.", comment: ""))
- }
- }
- }
- callback(success)
- }
- }
-
- class func gotoCompare() {
- KMMainThreadExecute {
- let winC = KMPurchaseCompareWindowController.sharedInstance()
- winC?.showWindow(nil)
- }
- }
- private class func _isConnectionAvailable() -> Bool {
- if Reachability.forInternetConnection().currentReachabilityStatus().rawValue == 0 {
- return false
- }
- return true
- }
-
- private class func _showHud(msg: String) {
- if let data = NSApp.mainWindow?.contentView {
- _ = CustomAlertView.alertView(message: msg, fromView: data, withStyle: .black)
- }
- }
- }
|