mirror of
https://github.com/mountain-loop/yaak.git
synced 2025-12-23 22:48:55 -05:00
Minor license handling tweaks
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use log::debug;
|
||||
use mime_guess::{Mime, mime};
|
||||
use mime_guess::{mime, Mime};
|
||||
use std::path::Path;
|
||||
use std::str::FromStr;
|
||||
use tokio::fs;
|
||||
@@ -7,14 +6,8 @@ use tokio::fs;
|
||||
pub async fn read_response_body(body_path: impl AsRef<Path>, content_type: &str) -> Option<String> {
|
||||
let body = fs::read(body_path).await.ok()?;
|
||||
let body_charset = parse_charset(content_type).unwrap_or("utf-8".to_string());
|
||||
debug!("body_charset: {}", body_charset);
|
||||
if let Some(decoder) = charset::Charset::for_label(body_charset.as_bytes()) {
|
||||
debug!("Using decoder for charset: {}", body_charset);
|
||||
let (cow, real_encoding, exist_replace) = decoder.decode(&body);
|
||||
debug!(
|
||||
"Decoded body with charset: {}, real_encoding: {:?}, exist_replace: {}",
|
||||
body_charset, real_encoding, exist_replace
|
||||
);
|
||||
let (cow, _real_encoding, _exist_replace) = decoder.decode(&body);
|
||||
return cow.into_owned().into();
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,16 +75,16 @@ function SettingsLicenseCmp() {
|
||||
{check.error && <Banner color="danger">{check.error}</Banner>}
|
||||
{activate.error && <Banner color="danger">{activate.error}</Banner>}
|
||||
|
||||
{check.data?.type === 'invalid_license' && (
|
||||
<Banner color="danger">
|
||||
Your license is invalid. Please <Link href="https://yaak.app/dashboard">Sign In</Link> for
|
||||
more details
|
||||
</Banner>
|
||||
)}
|
||||
|
||||
{check.data?.type === 'commercial_use' ? (
|
||||
<HStack space={2}>
|
||||
<Button
|
||||
variant="border"
|
||||
color="secondary"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
deactivate.mutate();
|
||||
}}
|
||||
>
|
||||
<Button variant="border" color="secondary" size="sm" onClick={() => deactivate.mutate()}>
|
||||
Deactivate License
|
||||
</Button>
|
||||
<Button
|
||||
@@ -104,12 +104,12 @@ function SettingsLicenseCmp() {
|
||||
<Button
|
||||
size="sm"
|
||||
color="primary"
|
||||
rightSlot={<Icon icon="external_link" />}
|
||||
onClick={() =>
|
||||
openUrl(
|
||||
`https://yaak.app/pricing?s=purchase&ref=app.yaak.desktop&t=${check.data?.type ?? ''}`,
|
||||
)
|
||||
}
|
||||
rightSlot={<Icon icon="external_link" />}
|
||||
>
|
||||
Purchase License
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user