From 0af071aede5e99b55a98916c7d921c99dc4493c4 Mon Sep 17 00:00:00 2001 From: Beingpax Date: Mon, 29 Sep 2025 10:11:04 +0545 Subject: [PATCH] fix license logic --- VoiceInk/Models/LicenseViewModel.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/VoiceInk/Models/LicenseViewModel.swift b/VoiceInk/Models/LicenseViewModel.swift index 57a5bd5..fdef606 100644 --- a/VoiceInk/Models/LicenseViewModel.swift +++ b/VoiceInk/Models/LicenseViewModel.swift @@ -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") } + } }