feat(cli): add feedback to the license cmd

This commit is contained in:
LGUG2Z
2025-10-29 08:48:25 -07:00
parent b613986474
commit 1a42c64620
3 changed files with 58 additions and 10 deletions

View File

@@ -49,7 +49,7 @@ pub fn listen_for_events(wm: Arc<Mutex<WindowManager>>) {
loop {
if let Ok((mdm, server)) = mdm_enrollment() {
#[allow(clippy::collapsible_if)]
if mdm && splash::should().unwrap_or(true) {
if mdm && splash::should().map(|f| f.into()).unwrap_or(true) {
let mut args = vec!["splash".to_string()];
if let Some(server) = server {
args.push(server);

View File

@@ -10,6 +10,7 @@ use color_eyre::eyre;
use color_eyre::eyre::OptionExt;
use ed25519_dalek::Verifier;
use ed25519_dalek::VerifyingKey;
use std::path::PathBuf;
use std::process::Command;
pub fn mdm_enrollment() -> eyre::Result<(bool, Option<String>)> {
@@ -91,13 +92,32 @@ fn is_valid_payload(raw: &str, fresh: bool) -> eyre::Result<bool> {
Ok(validation_successful)
}
pub fn should() -> eyre::Result<bool> {
pub enum ValidationFeedback {
Successful(PathBuf),
Unsuccessful(String),
NoEmail,
NoConnectivity,
}
impl From<ValidationFeedback> for bool {
fn from(value: ValidationFeedback) -> Self {
match value {
ValidationFeedback::Successful(_) => false,
ValidationFeedback::Unsuccessful(_)
| ValidationFeedback::NoEmail
| ValidationFeedback::NoConnectivity => true,
}
}
}
pub fn should() -> eyre::Result<ValidationFeedback> {
let icul_validation = DATA_DIR.join("icul.validation");
if icul_validation.exists() {
tracing::debug!("found local individual commercial use license validation payload");
let raw_payload = std::fs::read_to_string(&icul_validation)?;
if is_valid_payload(&raw_payload, false)? {
return Ok(false);
return Ok(ValidationFeedback::Successful(icul_validation));
} else {
std::fs::remove_file(&icul_validation)?;
}
@@ -105,7 +125,7 @@ pub fn should() -> eyre::Result<bool> {
let icul = DATA_DIR.join("icul");
if !icul.exists() {
return Ok(true);
return Ok(ValidationFeedback::NoEmail);
}
let email = std::fs::read_to_string(icul)?;
@@ -120,15 +140,15 @@ pub fn should() -> eyre::Result<bool> {
Ok(response) => response,
Err(error) => {
tracing::error!("{error}");
return Ok(true);
return Ok(ValidationFeedback::NoConnectivity);
}
};
let raw_payload = response.text()?;
if is_valid_payload(&raw_payload, true)? {
std::fs::write(icul_validation, &raw_payload)?;
Ok(false)
std::fs::write(&icul_validation, &raw_payload)?;
Ok(ValidationFeedback::Successful(icul_validation))
} else {
Ok(true)
Ok(ValidationFeedback::Unsuccessful(raw_payload))
}
}

View File

@@ -61,6 +61,7 @@ use komorebi_client::SocketMessage;
use komorebi_client::StateQuery;
use komorebi_client::StaticConfig;
use komorebi_client::WindowKind;
use komorebi_client::splash::ValidationFeedback;
lazy_static! {
static ref HAS_CUSTOM_CONFIG_HOME: AtomicBool = AtomicBool::new(false);
@@ -1639,8 +1640,35 @@ fn main() -> eyre::Result<()> {
}
}
SubCommand::License(arg) => {
std::fs::write(DATA_DIR.join("icul"), arg.email)?;
splash::should()?;
let _ = std::fs::remove_file(DATA_DIR.join("icul.validation"));
std::fs::write(DATA_DIR.join("icul"), &arg.email)?;
match splash::should()? {
ValidationFeedback::Successful(icul_validation) => {
println!("Individual commercial use license validation successful");
println!(
"Local validation file saved to {}",
icul_validation.display()
);
println!("\n{}", std::fs::read_to_string(&icul_validation)?);
}
ValidationFeedback::Unsuccessful(invalid_payload) => {
println!(
"No active individual commercial use license found for {}",
arg.email
);
println!("\n{invalid_payload}");
println!(
"\nYou can purchase an individual commercial use license at https://lgug2z.com/software/komorebi"
);
}
ValidationFeedback::NoEmail => {}
ValidationFeedback::NoConnectivity => {
println!(
"Could not make a connection to validate an individual commercial use license for {}",
arg.email
);
}
}
}
SubCommand::Quickstart => {
fn write_file_with_prompt(