improve start-minimized and start-on-login behavior
Previously, when Creddy was configured to start minimized, it would always start minimized, regardless of how it was launched. Really, though, when you use this setting what you probably want is for it to start minimized only when it's being launched automatically, i.e. on login. This update changes its behavior so that it will only start minimized when auto-launching. Additionally, if Creddy detects on startup that its start-on-login configuration doesn't match the system, it will modify its own settings to match the system (unless it's the very first launch, of course.) That way if you disable Creddy's start-on-login behavior from your system dialog, it will respect your change.
This commit is contained in:
@ -65,7 +65,7 @@ pub struct GlobalArgs {
|
||||
#[derive(Debug, Subcommand)]
|
||||
pub enum Action {
|
||||
/// Launch Creddy
|
||||
Run,
|
||||
Run(RunArgs),
|
||||
/// Request credentials from Creddy and output to stdout
|
||||
Get(GetArgs),
|
||||
/// Inject credentials into the environment of another command
|
||||
@ -78,6 +78,14 @@ pub enum Action {
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
pub struct RunArgs {
|
||||
/// Minimize to system tray on launch
|
||||
#[arg(long, default_value_t = false)]
|
||||
pub minimized: bool,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
pub struct GetArgs {
|
||||
/// If unspecified, use default credentials
|
||||
|
@ -6,6 +6,7 @@ pub use cli::{
|
||||
exec,
|
||||
get,
|
||||
GlobalArgs,
|
||||
RunArgs,
|
||||
invoke_shortcut,
|
||||
};
|
||||
|
||||
|
@ -1,13 +1,17 @@
|
||||
use std::env;
|
||||
use std::process::{self, Command};
|
||||
|
||||
use creddy_cli::{Action, Cli};
|
||||
|
||||
use creddy_cli::{
|
||||
Action,
|
||||
Cli,
|
||||
RunArgs,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
let res = match cli.action {
|
||||
None | Some(Action::Run)=> launch_gui(),
|
||||
None => launch_gui(RunArgs { minimized: false }),
|
||||
Some(Action::Run(run_args)) => launch_gui(run_args),
|
||||
Some(Action::Get(args)) => creddy_cli::get(args, cli.global_args),
|
||||
Some(Action::Exec(args)) => creddy_cli::exec(args, cli.global_args),
|
||||
Some(Action::Shortcut(args)) => creddy_cli::invoke_shortcut(args, cli.global_args),
|
||||
@ -21,7 +25,7 @@ fn main() {
|
||||
}
|
||||
|
||||
|
||||
fn launch_gui() -> anyhow::Result<()> {
|
||||
fn launch_gui(run_args: RunArgs) -> anyhow::Result<()> {
|
||||
let mut path = env::current_exe()?;
|
||||
path.pop(); // bin dir
|
||||
|
||||
@ -31,6 +35,10 @@ fn launch_gui() -> anyhow::Result<()> {
|
||||
|
||||
path.push("creddy.exe"); // exe in main install dir (aka gui exe)
|
||||
|
||||
Command::new(path).spawn()?;
|
||||
let mut cmd = Command::new(path);
|
||||
if run_args.minimized {
|
||||
cmd.arg("--minimized");
|
||||
}
|
||||
cmd.spawn()?;
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user