mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00

- Launcher can now be accessed via Tools>Upgrade/Downgrade - Anki closes automatically on update - When launcher not available, show update link like in the past - It appears that access to the modern console host requires an app to be built with the windows console subsystem, so we introduce an extra anki-console.exe binary to relaunch ourselves with. Solves https://forums.ankiweb.net/t/new-online-installer-launcher/62745/50 - Windows now requires you to close the terminal like on a Mac, as I couldn't figure out how to have it automatically close. Suggestions welcome! - Reduce the amount of duplicate/near-duplicate code in the various platform files, and improve readability - Add a helper to install the current code into the launcher env - Fix cargo test failing to build on ARM64 Windows
54 lines
1.6 KiB
Rust
54 lines
1.6 KiB
Rust
// Copyright: Ankitects Pty Ltd and contributors
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
use std::io;
|
|
use std::io::Write;
|
|
use std::process::Command;
|
|
use std::sync::atomic::AtomicBool;
|
|
use std::sync::atomic::Ordering;
|
|
use std::sync::Arc;
|
|
use std::thread;
|
|
use std::time::Duration;
|
|
|
|
use anki_process::CommandExt as AnkiCommandExt;
|
|
use anyhow::Context;
|
|
use anyhow::Result;
|
|
|
|
pub fn prepare_for_launch_after_update(mut cmd: Command) -> Result<()> {
|
|
// Pre-validate by running --version to trigger any Gatekeeper checks
|
|
print!("\n\x1B[1mThis may take a few minutes. Please wait\x1B[0m");
|
|
io::stdout().flush().unwrap();
|
|
|
|
// Start progress indicator
|
|
let running = Arc::new(AtomicBool::new(true));
|
|
let running_clone = running.clone();
|
|
let progress_thread = thread::spawn(move || {
|
|
while running_clone.load(Ordering::Relaxed) {
|
|
print!(".");
|
|
io::stdout().flush().unwrap();
|
|
thread::sleep(Duration::from_secs(1));
|
|
}
|
|
});
|
|
|
|
let _ = cmd
|
|
.env("ANKI_FIRST_RUN", "1")
|
|
.arg("--version")
|
|
.stdout(std::process::Stdio::null())
|
|
.stderr(std::process::Stdio::null())
|
|
.ensure_success();
|
|
|
|
// Stop progress indicator
|
|
running.store(false, Ordering::Relaxed);
|
|
progress_thread.join().unwrap();
|
|
println!(); // New line after dots
|
|
Ok(())
|
|
}
|
|
|
|
pub fn relaunch_in_terminal() -> Result<()> {
|
|
let current_exe = std::env::current_exe().context("Failed to get current executable path")?;
|
|
Command::new("open")
|
|
.args(["-a", "Terminal"])
|
|
.arg(current_exe)
|
|
.ensure_spawn()?;
|
|
std::process::exit(0);
|
|
}
|