mirror of
https://github.com/Stremio/stremio-shell-ng.git
synced 2026-03-11 17:15:49 +00:00
refactor(app): make updater thread blocking
This commit is contained in:
parent
520971b841
commit
9364538e41
1 changed files with 12 additions and 18 deletions
|
|
@ -10,8 +10,7 @@ use std::{
|
||||||
process::{self, Command},
|
process::{self, Command},
|
||||||
str,
|
str,
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
thread,
|
thread, time,
|
||||||
time::{self, Duration},
|
|
||||||
};
|
};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use winapi::um::{winbase::CREATE_BREAKAWAY_FROM_JOB, winuser::WS_EX_TOPMOST};
|
use winapi::um::{winbase::CREATE_BREAKAWAY_FROM_JOB, winuser::WS_EX_TOPMOST};
|
||||||
|
|
@ -151,10 +150,17 @@ impl MainWindow {
|
||||||
let force_update = self.force_update;
|
let force_update = self.force_update;
|
||||||
let release_candidate = self.release_candidate;
|
let release_candidate = self.release_candidate;
|
||||||
let autoupdater_setup_file = self.autoupdater_setup_file.clone();
|
let autoupdater_setup_file = self.autoupdater_setup_file.clone();
|
||||||
let mut last_update_check = time::Instant::now();
|
|
||||||
|
|
||||||
thread::spawn(move || loop {
|
thread::spawn(move || {
|
||||||
let check_for_update = || {
|
loop {
|
||||||
|
if let Ok(msg) = updater_rx.recv() {
|
||||||
|
if msg == "check_for_update" {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
loop {
|
||||||
let current_version = env!("CARGO_PKG_VERSION")
|
let current_version = env!("CARGO_PKG_VERSION")
|
||||||
.parse()
|
.parse()
|
||||||
.expect("Should always be valid");
|
.expect("Should always be valid");
|
||||||
|
|
@ -183,21 +189,9 @@ impl MainWindow {
|
||||||
Ok(None) => println!("No new updates found"),
|
Ok(None) => println!("No new updates found"),
|
||||||
Err(e) => eprintln!("Failed to fetch updates: {e}"),
|
Err(e) => eprintln!("Failed to fetch updates: {e}"),
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
updater_rx.try_iter().for_each(|message| {
|
thread::sleep(time::Duration::from_secs(UPDATE_INTERVAL));
|
||||||
if message.as_str() == "check_for_update" {
|
|
||||||
check_for_update();
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
let now = time::Instant::now();
|
|
||||||
if now > (last_update_check + time::Duration::from_secs(UPDATE_INTERVAL)) {
|
|
||||||
last_update_check = now;
|
|
||||||
check_for_update();
|
|
||||||
}
|
|
||||||
|
|
||||||
thread::sleep(Duration::from_millis(10));
|
|
||||||
}); // thread
|
}); // thread
|
||||||
|
|
||||||
if let Ok(mut listener) = PipeServer::bind(socket_path) {
|
if let Ok(mut listener) = PipeServer::bind(socket_path) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue