mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-16 05:41:16 +01:00
feat(cli): add feedback to the license cmd
This commit is contained in:
1 parent
9dbae50909
commit
9711a00cd0
3 files changed
+57
-10
No files matched your search
@@ -51,7 +51,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);
|
||||
|
||||
+26
-7
@@ -20,6 +20,7 @@ use objc2_app_kit::NSFloatingWindowLevel;
|
||||
use objc2_app_kit::NSWorkspace;
|
||||
use objc2_foundation::NSString;
|
||||
use objc2_foundation::NSURL;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
pub fn mdm_enrollment() -> eyre::Result<(bool, Option<String>)> {
|
||||
@@ -100,13 +101,31 @@ 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)?;
|
||||
}
|
||||
@@ -114,7 +133,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)?;
|
||||
@@ -129,16 +148,16 @@ 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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+30
-2
@@ -23,6 +23,7 @@ use komorebi_client::replace_env_in_path;
|
||||
use komorebi_client::send_message;
|
||||
use komorebi_client::send_query;
|
||||
use komorebi_client::splash;
|
||||
use komorebi_client::splash::ValidationFeedback;
|
||||
use lazy_static::lazy_static;
|
||||
use std::fs::File;
|
||||
use std::fs::OpenOptions;
|
||||
@@ -1254,8 +1255,35 @@ fn main() -> eyre::Result<()> {
|
||||
clap_complete::generate(arg.shell, &mut cli, "komorebic", &mut std::io::stdout());
|
||||
}
|
||||
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(
|
||||
|
||||
Reference in new issue
Block a user