diff --git a/komorebi/src/process_event.rs b/komorebi/src/process_event.rs index d11fa85f..d16c2db9 100644 --- a/komorebi/src/process_event.rs +++ b/komorebi/src/process_event.rs @@ -49,7 +49,7 @@ pub fn listen_for_events(wm: Arc>) { 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); diff --git a/komorebi/src/splash.rs b/komorebi/src/splash.rs index 517a1384..e8a07d22 100644 --- a/komorebi/src/splash.rs +++ b/komorebi/src/splash.rs @@ -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)> { @@ -91,13 +92,32 @@ fn is_valid_payload(raw: &str, fresh: bool) -> eyre::Result { Ok(validation_successful) } -pub fn should() -> eyre::Result { +pub enum ValidationFeedback { + Successful(PathBuf), + Unsuccessful(String), + NoEmail, + NoConnectivity, +} + +impl From for bool { + fn from(value: ValidationFeedback) -> Self { + match value { + ValidationFeedback::Successful(_) => false, + + ValidationFeedback::Unsuccessful(_) + | ValidationFeedback::NoEmail + | ValidationFeedback::NoConnectivity => true, + } + } +} + +pub fn should() -> eyre::Result { 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 { 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 { 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)) } } diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 90ab605a..f8946ca1 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -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(