Skip to content

Commit

Permalink
Fix autoupdater
Browse files Browse the repository at this point in the history
  • Loading branch information
core1024 committed Apr 19, 2024
1 parent 4fc97a9 commit 7983724
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 49 deletions.
41 changes: 0 additions & 41 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ native-windows-derive = "1"
winapi = { version = "0.3.9", features = [
"libloaderapi",
"handleapi",
"jobapi2",
"wincon",
"winuser",
"namedpipeapi"
Expand All @@ -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"
Expand Down
5 changes: 4 additions & 1 deletion src/stremio_app/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ use serde_json;
use std::{
cell::RefCell,
io::Read,
os::windows::process::CommandExt,
path::{Path, PathBuf},
process::{self, Command},
str,
sync::{Arc, Mutex},
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},
Expand Down Expand Up @@ -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();
Expand Down
39 changes: 33 additions & 6 deletions src/stremio_app/stremio_server/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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")
Expand Down

0 comments on commit 7983724

Please sign in to comment.