fix license logic
This commit is contained in:
parent
2663096eb2
commit
0af071aede
@ -41,6 +41,7 @@ class LicenseViewModel: ObservableObject {
|
||||
// Skip server validation on startup
|
||||
if userDefaults.activationId != nil || !userDefaults.bool(forKey: "VoiceInkLicenseRequiresActivation") {
|
||||
licenseState = .licensed
|
||||
activationsLimit = userDefaults.activationsLimit
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -127,12 +128,14 @@ class LicenseViewModel: ObservableObject {
|
||||
userDefaults.activationId = activationId
|
||||
userDefaults.set(true, forKey: "VoiceInkLicenseRequiresActivation")
|
||||
self.activationsLimit = limit
|
||||
userDefaults.activationsLimit = limit
|
||||
|
||||
} else {
|
||||
// This license doesn't require activation (unlimited devices)
|
||||
userDefaults.activationId = nil
|
||||
userDefaults.set(false, forKey: "VoiceInkLicenseRequiresActivation")
|
||||
self.activationsLimit = licenseCheck.activationsLimit ?? 0
|
||||
userDefaults.activationsLimit = licenseCheck.activationsLimit ?? 0
|
||||
|
||||
// Update the license state for unlimited license
|
||||
licenseState = .licensed
|
||||
@ -155,6 +158,7 @@ class LicenseViewModel: ObservableObject {
|
||||
userDefaults.activationId = nil
|
||||
userDefaults.set(false, forKey: "VoiceInkLicenseRequiresActivation")
|
||||
self.activationsLimit = 0
|
||||
userDefaults.activationsLimit = 0
|
||||
|
||||
licenseState = .licensed
|
||||
validationMessage = "License activated successfully!"
|
||||
@ -174,9 +178,12 @@ class LicenseViewModel: ObservableObject {
|
||||
userDefaults.trialStartDate = nil
|
||||
userDefaults.set(false, forKey: "VoiceInkHasLaunchedBefore") // Allow trial to restart
|
||||
|
||||
userDefaults.activationsLimit = 0
|
||||
|
||||
licenseState = .trial(daysRemaining: trialPeriodDays) // Reset to trial state
|
||||
licenseKey = ""
|
||||
validationMessage = nil
|
||||
activationsLimit = 0
|
||||
NotificationCenter.default.post(name: .licenseStatusChanged, object: nil)
|
||||
loadLicenseState()
|
||||
}
|
||||
@ -189,4 +196,9 @@ extension UserDefaults {
|
||||
get { string(forKey: "VoiceInkActivationId") }
|
||||
set { set(newValue, forKey: "VoiceInkActivationId") }
|
||||
}
|
||||
|
||||
var activationsLimit: Int {
|
||||
get { integer(forKey: "VoiceInkActivationsLimit") }
|
||||
set { set(newValue, forKey: "VoiceInkActivationsLimit") }
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user