Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Mar 19, 2024
1 parent 4086fad commit ea2f62f
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- if: ${{ matrix.os == 'ubuntu-20.04' }}
run: sudo apt-get update && sudo apt-get install -y gcc libxcb-composite0-dev
- run: cargo build --release
- uses: actions/upload-artifact@v1 # Windows Defender gave a false positive with v1
- uses: actions/upload-artifact@v4
with:
name: ludusavi-v${{ env.LUDUSAVI_VERSION }}-${{ matrix.artifact-name }}
path: target/release/${{ matrix.artifact-file }}
Expand Down
20 changes: 0 additions & 20 deletions src/cli/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,26 +566,6 @@ pub struct Cli {
pub sub: Option<Subcommand>,
}

impl Cli {
pub fn relaunch_gui_args(&self) -> Vec<String> {
let mut args = vec![];

if let Some(config) = self.config.as_ref() {
args.push("--config".into());
args.push(config.to_string_lossy().to_string());
}

if self.no_manifest_update {
args.push("--no-manifest-update".into());
}
if self.try_manifest_update {
args.push("--try-manifest-update".into());
}

args
}
}

#[cfg(test)]
mod tests {
use clap::Parser;
Expand Down
37 changes: 1 addition & 36 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod testing;
use crate::{
gui::Flags,
lang::TRANSLATOR,
prelude::{app_dir, CONFIG_DIR, ENV_DEBUG, ENV_RELAUNCHED, VERSION},
prelude::{app_dir, CONFIG_DIR, VERSION},
};

/// The logger must be assigned to a variable because we're using async logging.
Expand Down Expand Up @@ -47,48 +47,13 @@ fn prepare_logging() -> Result<flexi_logger::LoggerHandle, flexi_logger::FlexiLo
.start()
}

fn has_env(key: &str) -> bool {
std::env::var(key).is_ok()
}

fn relaunch_detached(args: Vec<String>) -> ! {
let exe = match std::env::current_exe() {
Ok(x) => x,
Err(e) => {
eprintln!("Unable to relaunch in detached mode: {e:?}");
std::process::exit(1);
}
};

let mut command = std::process::Command::new(exe);
command.args(args).env(ENV_RELAUNCHED, "1");

#[cfg(target_os = "windows")]
{
use std::os::windows::process::CommandExt;
command.creation_flags(winapi::um::winbase::CREATE_NO_WINDOW);
}

match command.spawn() {
Ok(_) => std::process::exit(0),
Err(e) => {
eprintln!("Unable to relaunch in detached mode: {e:?}");
std::process::exit(1);
}
}
}

fn main() {
let args = cli::parse();
if let Some(config_dir) = args.config.as_deref() {
*CONFIG_DIR.lock().unwrap() = Some(config_dir.to_path_buf());
}
match args.sub {
None => {
if cfg!(target_os = "windows") && !has_env(ENV_DEBUG) && !has_env(ENV_RELAUNCHED) {
relaunch_detached(args.relaunch_gui_args());
}

#[allow(unused)]
let logger = prepare_logging();

Expand Down
1 change: 0 additions & 1 deletion src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ static HANDLER_SIGINT: Mutex<Option<signal_hook::SigId>> = Mutex::new(None);

pub const ENV_DEBUG: &str = "LUDUSAVI_DEBUG";
const ENV_THREADS: &str = "LUDUSAVI_THREADS";
pub const ENV_RELAUNCHED: &str = "LUDUSAVI_INTERNAL_RELAUNCHED";

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum Finality {
Expand Down

0 comments on commit ea2f62f

Please sign in to comment.