Skip to content

Commit 6f32bbe

Browse files
committed
restart application fix
1 parent a2086b9 commit 6f32bbe

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/settings_window.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,24 @@ pub fn settings_window(
5555
ui.disable();
5656
let _ = ui.button("Update");
5757
});
58-
ui.label("No new update");
58+
ui.label("You have the latest version");
5959
}
6060
});
6161
ui.label(update_text.clone());
6262

6363
ui.horizontal(|ui| {
64-
if ui.button("Exit Settings").clicked() {
65-
*settings_window_open = false;
66-
*update_text = "".to_string();
67-
}
64+
ui.horizontal(|ui| {
65+
if !update_text.is_empty() {
66+
ui.disable();
67+
};
68+
if ui.button("Exit Settings").clicked() {
69+
*settings_window_open = false;
70+
*update_text = "".to_string();
71+
}
72+
});
6873

6974
if !update_text.is_empty() && ui.button("Restart").clicked() {
70-
let _ = restart_application();
75+
restart_application();
7176
ctx.request_repaint(); // Optional: Request repaint for immediate feedback
7277
ui.ctx().send_viewport_cmd(egui::ViewportCommand::Close);
7378
}

src/update.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,20 @@ use self_update::update::Release;
33
use semver::Version;
44
use std::fs::File;
55
use std::path::Path;
6-
use std::process::{Command, ExitStatus};
6+
use std::process::Command;
77
use std::{env, fs, io};
88
use zip::ZipArchive;
99

1010
const REPO_OWNER: &str = "hacknus";
1111
const REPO_NAME: &str = "serial-monitor-rust";
12-
1312
const MACOS_APP_NAME: &str = "Serial Monitor.app";
1413

15-
pub fn restart_application() -> std::io::Result<ExitStatus> {
14+
pub fn restart_application() {
1615
// Get the current executable path
1716
let current_exe = std::env::current_exe().expect("Failed to get current executable path");
1817

1918
// Launch a new instance of the application
20-
Command::new(current_exe)
21-
.spawn()
22-
.expect("Failed to restart application")
23-
.wait()
19+
let _ = Command::new(current_exe).spawn();
2420
}
2521

2622
fn extract_zip(tmp_archive_path: &Path, tmp_archive_dir: &Path) -> io::Result<()> {
@@ -173,6 +169,10 @@ pub fn update(release: Release) -> Result<(), Box<dyn std::error::Error>> {
173169

174170
let _ = copy_dir(&tmp_archive_dir.path().join(&app_name), &app_dir, &binary);
175171

172+
// MACOS_APP_NAME either needs to be hardcoded or extracted from the downloaded and
173+
// extracted archive, but we cannot just assume that the parent directory of the
174+
// currently running executable is equal to the app name - this is especially not
175+
// the case if we run the code with `cargo run`.
176176
tmp_archive_dir
177177
.path()
178178
.join(format!("{}/Contents/MacOS/{}", MACOS_APP_NAME, binary))

0 commit comments

Comments
 (0)