Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 23 additions & 29 deletions src/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,41 +114,35 @@ pub fn run(
ev.run();
})?;

// Main event loop thread to poll for foreground/system etc. events
let ev_thread = {
let config = config.clone();
let session = session.clone();
let web_state = web_state.clone();
thread::Builder::new()
.name("event_loop_thread".to_string())
.spawn(move || {
event_loop(EventLoopArgs {
config,
web_state,
event_tx,
alert_tx,
web_change_tx,
session,
start,
})
.context("event loop")
.expect("event loop failed");
})?
};

rt.clone().block_on(processor(ProcessorArgs {
let processor_handle = rt.clone().spawn(processor(ProcessorArgs {
desktop_state,
web_state,
web_state: web_state.clone(),
config: config.clone(),
rt,
session,
rt: rt.clone(),
session: session.clone(),
start,
event_rx,
alert_rx,
web_change_rx,
}))?;
// can't turn these to [util::error::Result]s :/
ev_thread.join().expect("event loop thread");
}));

// Main event loop thread to poll for foreground/system etc. events
event_loop(EventLoopArgs {
config: config.clone(),
web_state,
event_tx,
alert_tx,
web_change_tx,
session,
start,
})
.context("event loop")
.expect("event loop failed");

rt.block_on(processor_handle)
.expect("processor loop join")
.context("processor loop")
.expect("processor loop");
it_ev_thread.join().expect("interaction event loop thread");
Ok(())
}
Expand Down
26 changes: 21 additions & 5 deletions src/platform/src/events/system.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use util::error::{Context, Result};
use util::tracing::{ResultTraceExt, info};
use windows::Win32::Foundation::HANDLE;
use windows::Win32::Foundation::{HANDLE, LRESULT};
use windows::Win32::System::Power::{
HPOWERNOTIFY, POWERBROADCAST_SETTING, RegisterPowerSettingNotification,
UnregisterPowerSettingNotification,
Expand All @@ -10,9 +10,9 @@ use windows::Win32::System::RemoteDesktop::{
};
use windows::Win32::System::SystemServices::GUID_MONITOR_POWER_ON;
use windows::Win32::UI::WindowsAndMessaging::{
DEVICE_NOTIFY_WINDOW_HANDLE, ENDSESSION_LOGOFF, PBT_APMRESUMESUSPEND, PBT_APMSUSPEND,
PBT_POWERSETTINGCHANGE, WM_ENDSESSION, WM_POWERBROADCAST, WM_WTSSESSION_CHANGE,
WTS_SESSION_LOCK, WTS_SESSION_UNLOCK,
DEVICE_NOTIFY_WINDOW_HANDLE, ENDSESSION_CLOSEAPP, ENDSESSION_LOGOFF, PBT_APMRESUMESUSPEND,
PBT_APMSUSPEND, PBT_POWERSETTINGCHANGE, WM_ENDSESSION, WM_POWERBROADCAST, WM_QUERYENDSESSION,
WM_WTSSESSION_CHANGE, WTS_SESSION_LOCK, WTS_SESSION_UNLOCK,
};

use crate::objects::{Duration, MessageWindow, Timestamp};
Expand Down Expand Up @@ -144,7 +144,23 @@ impl<'a> SystemEventWatcher<'a> {

message_window.add_callback(Box::new(move |_, msg, wparam, lparam| {
let timestamp = Timestamp::now();
if msg == WM_ENDSESSION {
if msg == WM_QUERYENDSESSION {
// This is for MSI updates (Restart Manager). We need to
// indicate that we can handle the end session request.
// https://learn.microsoft.com/en-us/windows/win32/rstmgr/guidelines-for-applications
if lparam.0 as u32 == ENDSESSION_CLOSEAPP {
return Some(LRESULT(1));
}
} else if msg == WM_ENDSESSION {
// End session request received by Restart Manager (MSI Update).
// We test the whole lparam to see if it is ENDSESSION_CLOSEAPP instead of bitmask
// so that we don't catch logoff / shutdown / restart instead.
// https://learn.microsoft.com/en-us/windows/win32/rstmgr/guidelines-for-applications
if lparam.0 as u32 == ENDSESSION_CLOSEAPP && wparam.0 as u32 == 1 {
info!("end session request received, exiting");
std::process::exit(0);
}

if lparam.0 as u32 & ENDSESSION_LOGOFF != 0 {
state.is_logoff = true;
callback(SystemStateEvent {
Expand Down
7 changes: 0 additions & 7 deletions src/ui/src-tauri/installer/main.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@
InstallScope="perMachine"
SummaryCodepage="!(loc.TauriCodepage)"/>

<!-- Force terminate application during uninstall/upgrade.
None of our bins use Restart Manager, so we force kill them
after Restart Manager fails to gracefully kill them -->
<Property Id="MSIRMSHUTDOWN" Value="1" />
<Property Id="MSIRESTARTMANAGERCONTROL" Value="DisableShutdown" />
<!-- <Property Id="MSIFASTINSTALL" Value="1" /> -->

<!-- https://docs.microsoft.com/en-us/windows/win32/msi/reinstallmode -->
<!-- reinstall all files; rewrite all registry entries; reinstall all shortcuts -->
<Property Id="REINSTALLMODE" Value="amus" />
Expand Down