Fix autoupdater

This commit is contained in:
Vladimir Borisov 2024-04-19 18:44:33 +03:00
parent a4bf9e4a55
commit e88653974b
4 changed files with 38 additions and 49 deletions

41
Cargo.lock generated
View file

@ -1381,7 +1381,6 @@ dependencies = [
"webview2",
"webview2-sys",
"whoami",
"win32job",
"winapi",
"winres",
]
@ -1486,26 +1485,6 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "thiserror"
version = "1.0.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.52",
]
[[package]]
name = "tinyvec"
version = "1.6.0"
@ -1858,16 +1837,6 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17882f045410753661207383517a6f62ec3dbeb6a4ed2acce01f0728238d1983"
[[package]]
name = "win32job"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b2b1bf557d947847a30eb73f79aa6cdb3eaf3ce02f5e9599438f77896a62b3c"
dependencies = [
"thiserror",
"windows",
]
[[package]]
name = "winapi"
version = "0.3.9"
@ -1896,16 +1865,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be"
dependencies = [
"windows-core",
"windows-targets 0.52.4",
]
[[package]]
name = "windows-core"
version = "0.52.0"

View file

@ -15,6 +15,7 @@ native-windows-derive = "1"
winapi = { version = "0.3.9", features = [
"libloaderapi",
"handleapi",
"jobapi2",
"wincon",
"winuser",
"namedpipeapi"
@ -29,7 +30,6 @@ clap = { version = "4", features = ["derive", "unicode"] }
open = "5"
urlencoding = "2"
bitflags = "2"
win32job = "2"
parse-display = "0.9"
flume = "0.11"
whoami = "1.5"

View file

@ -5,6 +5,7 @@ use serde_json;
use std::{
cell::RefCell,
io::Read,
os::windows::process::CommandExt,
path::{Path, PathBuf},
process::{self, Command},
str,
@ -12,7 +13,7 @@ use std::{
thread, time,
};
use url::Url;
use winapi::um::winuser::WS_EX_TOPMOST;
use winapi::um::{winbase::CREATE_BREAKAWAY_FROM_JOB, winuser::WS_EX_TOPMOST};
use crate::stremio_app::{
constants::{APP_NAME, UPDATE_ENDPOINT, UPDATE_INTERVAL, WINDOW_MIN_HEIGHT, WINDOW_MIN_WIDTH},
@ -273,6 +274,8 @@ impl MainWindow {
"/FORCECLOSEAPPLICATIONS",
"/TASKS=runapp",
])
.creation_flags(CREATE_BREAKAWAY_FROM_JOB)
.stdin(process::Stdio::null())
.stdout(process::Stdio::null())
.stderr(process::Stdio::null())
.spawn();

View file

@ -3,7 +3,15 @@ use std::os::windows::process::CommandExt;
use std::process::Command;
use std::thread;
use std::time::Duration;
use win32job::Job;
use winapi::um::{
processthreadsapi::GetCurrentProcess,
winbase::CreateJobObjectA,
winnt::{
JobObjectExtendedLimitInformation, JOBOBJECT_BASIC_LIMIT_INFORMATION,
JOBOBJECT_EXTENDED_LIMIT_INFORMATION, JOB_OBJECT_LIMIT_BREAKAWAY_OK,
JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION, JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE,
},
};
const CREATE_NO_WINDOW: u32 = 0x08000000;
@ -12,11 +20,30 @@ pub struct StremioServer {}
impl StremioServer {
pub fn new() -> StremioServer {
thread::spawn(move || {
let job = Job::create().expect("Cannont create job");
let mut info = job.query_extended_limit_info().expect("Cannont get info");
info.limit_kill_on_job_close();
job.set_extended_limit_info(&info).ok();
job.assign_current_process().ok();
// Use Win32JobObject to kill the child process when the parent process is killed
// With the JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK and JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE flags
unsafe {
let job_main_process = CreateJobObjectA(std::ptr::null_mut(), std::ptr::null_mut());
let jeli = JOBOBJECT_EXTENDED_LIMIT_INFORMATION {
BasicLimitInformation: JOBOBJECT_BASIC_LIMIT_INFORMATION {
LimitFlags: JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE
| JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION
| JOB_OBJECT_LIMIT_BREAKAWAY_OK,
..std::mem::zeroed()
},
..std::mem::zeroed()
};
winapi::um::jobapi2::SetInformationJobObject(
job_main_process,
JobObjectExtendedLimitInformation,
&jeli as *const _ as *mut _,
std::mem::size_of::<JOBOBJECT_EXTENDED_LIMIT_INFORMATION>() as u32,
);
winapi::um::jobapi2::AssignProcessToJobObject(
job_main_process,
GetCurrentProcess(),
);
}
loop {
let child = Command::new("./stremio-runtime")
.arg("server.js")