Minor license handling tweaks

This commit is contained in:
Gregory Schier
2025-11-09 06:01:03 -08:00
parent 054916b7af
commit 554e632c19
4 changed files with 15 additions and 24 deletions

View File

@@ -1,22 +1,18 @@
use crate::error::Result;
use crate::{LicenseCheckStatus, activate_license, check_license, deactivate_license};
use log::{debug, info};
use tauri::{Runtime, WebviewWindow, command};
#[command]
pub async fn check<R: Runtime>(window: WebviewWindow<R>) -> Result<LicenseCheckStatus> {
debug!("Checking license");
check_license(&window).await
}
#[command]
pub async fn activate<R: Runtime>(license_key: &str, window: WebviewWindow<R>) -> Result<()> {
info!("Activating license {}", license_key);
activate_license(&window, license_key).await
}
#[command]
pub async fn deactivate<R: Runtime>(window: WebviewWindow<R>) -> Result<()> {
info!("Deactivating activation");
deactivate_license(&window).await
}

View File

@@ -67,6 +67,7 @@ pub async fn activate_license<R: Runtime>(
window: &WebviewWindow<R>,
license_key: &str,
) -> Result<()> {
info!("Activating license {}", license_key);
let client = reqwest::Client::new();
let payload = ActivateLicenseRequestPayload {
license_key: license_key.to_string(),
@@ -103,6 +104,7 @@ pub async fn activate_license<R: Runtime>(
}
pub async fn deactivate_license<R: Runtime>(window: &WebviewWindow<R>) -> Result<()> {
info!("Deactivating activation");
let app_handle = window.app_handle();
let activation_id = get_activation_id(app_handle).await;
@@ -159,8 +161,6 @@ pub async fn check_license<R: Runtime>(window: &WebviewWindow<R>) -> Result<Lice
let settings = window.db().get_settings();
let trial_end = settings.created_at.add(Duration::from_secs(TRIAL_SECONDS));
debug!("Trial ending at {trial_end:?}");
let has_activation_id = !activation_id.is_empty();
let trial_period_active = Utc::now().naive_utc() < trial_end;
@@ -185,11 +185,13 @@ pub async fn check_license<R: Runtime>(window: &WebviewWindow<R>) -> Result<Lice
}
if response.status().is_server_error() {
warn!("Failed to check license {}", response.status());
return Err(ServerError);
}
let body: CheckActivationResponsePayload = response.json().await?;
if !body.active {
info!("Inactive License {:?}", body);
return Ok(LicenseCheckStatus::InvalidLicense);
}