mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-07-11 07:32:51 +02:00
feat(cli): add feedback to the license cmd
This commit is contained in:
@@ -49,7 +49,7 @@ pub fn listen_for_events(wm: Arc<Mutex<WindowManager>>) {
|
|||||||
loop {
|
loop {
|
||||||
if let Ok((mdm, server)) = mdm_enrollment() {
|
if let Ok((mdm, server)) = mdm_enrollment() {
|
||||||
#[allow(clippy::collapsible_if)]
|
#[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()];
|
let mut args = vec!["splash".to_string()];
|
||||||
if let Some(server) = server {
|
if let Some(server) = server {
|
||||||
args.push(server);
|
args.push(server);
|
||||||
|
|||||||
+27
-7
@@ -10,6 +10,7 @@ use color_eyre::eyre;
|
|||||||
use color_eyre::eyre::OptionExt;
|
use color_eyre::eyre::OptionExt;
|
||||||
use ed25519_dalek::Verifier;
|
use ed25519_dalek::Verifier;
|
||||||
use ed25519_dalek::VerifyingKey;
|
use ed25519_dalek::VerifyingKey;
|
||||||
|
use std::path::PathBuf;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
pub fn mdm_enrollment() -> eyre::Result<(bool, Option<String>)> {
|
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)
|
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");
|
let icul_validation = DATA_DIR.join("icul.validation");
|
||||||
if icul_validation.exists() {
|
if icul_validation.exists() {
|
||||||
tracing::debug!("found local individual commercial use license validation payload");
|
tracing::debug!("found local individual commercial use license validation payload");
|
||||||
let raw_payload = std::fs::read_to_string(&icul_validation)?;
|
let raw_payload = std::fs::read_to_string(&icul_validation)?;
|
||||||
if is_valid_payload(&raw_payload, false)? {
|
if is_valid_payload(&raw_payload, false)? {
|
||||||
return Ok(false);
|
return Ok(ValidationFeedback::Successful(icul_validation));
|
||||||
} else {
|
} else {
|
||||||
std::fs::remove_file(&icul_validation)?;
|
std::fs::remove_file(&icul_validation)?;
|
||||||
}
|
}
|
||||||
@@ -105,7 +125,7 @@ pub fn should() -> eyre::Result<bool> {
|
|||||||
|
|
||||||
let icul = DATA_DIR.join("icul");
|
let icul = DATA_DIR.join("icul");
|
||||||
if !icul.exists() {
|
if !icul.exists() {
|
||||||
return Ok(true);
|
return Ok(ValidationFeedback::NoEmail);
|
||||||
}
|
}
|
||||||
|
|
||||||
let email = std::fs::read_to_string(icul)?;
|
let email = std::fs::read_to_string(icul)?;
|
||||||
@@ -120,15 +140,15 @@ pub fn should() -> eyre::Result<bool> {
|
|||||||
Ok(response) => response,
|
Ok(response) => response,
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
tracing::error!("{error}");
|
tracing::error!("{error}");
|
||||||
return Ok(true);
|
return Ok(ValidationFeedback::NoConnectivity);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let raw_payload = response.text()?;
|
let raw_payload = response.text()?;
|
||||||
if is_valid_payload(&raw_payload, true)? {
|
if is_valid_payload(&raw_payload, true)? {
|
||||||
std::fs::write(icul_validation, &raw_payload)?;
|
std::fs::write(&icul_validation, &raw_payload)?;
|
||||||
Ok(false)
|
Ok(ValidationFeedback::Successful(icul_validation))
|
||||||
} else {
|
} else {
|
||||||
Ok(true)
|
Ok(ValidationFeedback::Unsuccessful(raw_payload))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-2
@@ -61,6 +61,7 @@ use komorebi_client::SocketMessage;
|
|||||||
use komorebi_client::StateQuery;
|
use komorebi_client::StateQuery;
|
||||||
use komorebi_client::StaticConfig;
|
use komorebi_client::StaticConfig;
|
||||||
use komorebi_client::WindowKind;
|
use komorebi_client::WindowKind;
|
||||||
|
use komorebi_client::splash::ValidationFeedback;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref HAS_CUSTOM_CONFIG_HOME: AtomicBool = AtomicBool::new(false);
|
static ref HAS_CUSTOM_CONFIG_HOME: AtomicBool = AtomicBool::new(false);
|
||||||
@@ -1639,8 +1640,35 @@ fn main() -> eyre::Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
SubCommand::License(arg) => {
|
SubCommand::License(arg) => {
|
||||||
std::fs::write(DATA_DIR.join("icul"), arg.email)?;
|
let _ = std::fs::remove_file(DATA_DIR.join("icul.validation"));
|
||||||
splash::should()?;
|
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 => {
|
SubCommand::Quickstart => {
|
||||||
fn write_file_with_prompt(
|
fn write_file_with_prompt(
|
||||||
|
|||||||
Reference in New Issue
Block a user