Skip to content

Commit

Permalink
Add option for opening/closing SteamVR with dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
zmerp committed Apr 3, 2023
1 parent ae15044 commit 183d629
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 18 deletions.
7 changes: 2 additions & 5 deletions alvr/dashboard/src/dashboard/components/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ use eframe::{
emath::{Align, Align2},
epaint::Color32,
};
use std::{
net::{IpAddr, Ipv4Addr},
thread,
};
use std::net::{IpAddr, Ipv4Addr};

struct EditPopupState {
new_client: bool,
Expand Down Expand Up @@ -56,7 +53,7 @@ impl ConnectionsTab {
});
ui.with_layout(Layout::right_to_left(eframe::emath::Align::Center), |ui| {
if ui.button("Launch SteamVR").clicked() {
thread::spawn(|| LAUNCHER.lock().launch_steamvr());
LAUNCHER.lock().launch_steamvr();
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion alvr/dashboard/src/dashboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl eframe::App for Dashboard {
requests.push(DashboardRequest::RestartSteamvr);
}
} else if ui.button("Launch SteamVR").clicked() {
thread::spawn(|| LAUNCHER.lock().launch_steamvr());
LAUNCHER.lock().launch_steamvr();
}

ui.horizontal(|ui| {
Expand Down
30 changes: 27 additions & 3 deletions alvr/dashboard/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod steamvr_launcher;
mod theme;

use alvr_common::{parking_lot::Mutex, ALVR_VERSION};
use alvr_sockets::GpuVendor;
use alvr_sockets::{DashboardRequest, GpuVendor};
use dashboard::Dashboard;
use data_sources::ServerEvent;
use eframe::{egui, IconData, NativeOptions};
Expand All @@ -18,10 +18,12 @@ use std::{
sync::{mpsc, Arc},
thread,
};
use steamvr_launcher::LAUNCHER;

fn main() {
let (server_events_sender, server_events_receiver) = mpsc::channel();
logging_backend::init_logging(server_events_sender.clone());
let (dashboard_requests_sender, dashboard_requests_receiver) = mpsc::channel();

{
let mut data_manager = data_sources::get_local_data_source();
Expand All @@ -43,6 +45,14 @@ fn main() {
session_ref.server_version = ALVR_VERSION.clone();
session_ref.client_connections.clear();
}

if data_manager
.settings()
.extra
.open_close_steamvr_with_dashboard
{
LAUNCHER.lock().launch_steamvr()
}
}

let ico = IconDir::read(Cursor::new(include_bytes!("../resources/dashboard.ico"))).unwrap();
Expand All @@ -64,9 +74,8 @@ fn main() {
},
{
let data_thread = Arc::clone(&data_thread);
let dashboard_requests_sender = dashboard_requests_sender.clone();
Box::new(move |creation_context| {
let (dashboard_requests_sender, dashboard_requests_receiver) = mpsc::channel();

let context = creation_context.egui_ctx.clone();
*data_thread.lock() = Some(thread::spawn(|| {
data_sources::data_interop_thread(
Expand All @@ -86,5 +95,20 @@ fn main() {
)
.unwrap();

if data_sources::get_local_data_source()
.settings()
.extra
.open_close_steamvr_with_dashboard
{
dashboard_requests_sender
.send(DashboardRequest::ShutdownSteamvr)
.ok();

LAUNCHER.lock().ensure_steamvr_shutdown()
}

// This is the signal to shutdown the data thread.
drop(dashboard_requests_sender);

data_thread.lock().take().unwrap().join().unwrap();
}
5 changes: 4 additions & 1 deletion alvr/dashboard/src/steamvr_launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,18 @@ impl Launcher {
}
}

pub fn restart_steamvr(&self) {
pub fn ensure_steamvr_shutdown(&self) {
debug!("Waiting for SteamVR to shutdown...");
let start_time = Instant::now();
while start_time.elapsed() < SHUTDOWN_TIMEOUT && is_steamvr_running() {
thread::sleep(Duration::from_millis(500));
}

maybe_kill_steamvr();
}

pub fn restart_steamvr(&self) {
self.ensure_steamvr_shutdown();
self.launch_steamvr();
}

Expand Down
11 changes: 11 additions & 0 deletions alvr/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ static VIDEO_RECORDING_FILE: Lazy<Mutex<Option<File>>> = Lazy::new(|| Mutex::new

static DISCONNECT_CLIENT_NOTIFIER: Lazy<Notify> = Lazy::new(Notify::new);
static RESTART_NOTIFIER: Lazy<Notify> = Lazy::new(Notify::new);
static SHUTDOWN_NOTIFIER: Lazy<Notify> = Lazy::new(Notify::new);

static FRAME_RENDER_VS_CSO: &[u8] = include_bytes!("../cpp/platform/win32/FrameRenderVS.cso");
static FRAME_RENDER_PS_CSO: &[u8] = include_bytes!("../cpp/platform/win32/FrameRenderPS.cso");
Expand Down Expand Up @@ -166,6 +167,16 @@ pub fn shutdown_tasks() {
WEBSERVER_RUNTIME.lock().take();
}

pub fn notify_shutdown_driver() {
thread::spawn(|| {
SHUTDOWN_NOTIFIER.notify_waiters();

shutdown_tasks();

unsafe { ShutdownSteamvr() };
});
}

pub fn notify_restart_driver() {
alvr_events::send_event(EventType::ServerRequestsSelfRestart);

Expand Down
11 changes: 6 additions & 5 deletions alvr/server/src/web_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ async fn http_api(
if let Ok(request) = from_request_body::<DashboardRequest>(request).await {
match request {
DashboardRequest::Ping => (),
DashboardRequest::Log(event) => {
let level = event.severity.into_log_level();
log::log!(level, "{}", event.content);
}
DashboardRequest::GetSession => {
alvr_events::send_event(alvr_events::EventType::Session(Box::new(
SERVER_DATA_MANAGER.read().session().clone(),
Expand All @@ -128,15 +132,12 @@ async fn http_api(
return reply_json(&ServerResponse::AudioDevices(list));
}
}
DashboardRequest::RestartSteamvr => crate::notify_restart_driver(),
DashboardRequest::Log(event) => {
let level = event.severity.into_log_level();
log::log!(level, "{}", event.content);
}
DashboardRequest::CaptureFrame => unsafe { crate::CaptureFrame() },
DashboardRequest::InsertIdr => unsafe { crate::RequestIDR() },
DashboardRequest::StartRecording => crate::create_recording_file(),
DashboardRequest::StopRecording => *VIDEO_RECORDING_FILE.lock() = None,
DashboardRequest::RestartSteamvr => crate::notify_restart_driver(),
DashboardRequest::ShutdownSteamvr => crate::notify_shutdown_driver(),
}

reply(StatusCode::OK)?
Expand Down
6 changes: 5 additions & 1 deletion alvr/session/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,10 +741,13 @@ pub struct ExtraDesc {
help = r#"This controls the driver registration operations while launching SteamVR.
Unregister other drivers at startup: This is the recommended option and will handle most interferences from other installed drivers.
Unregister ALVR at shutdown: This should be used when you want to load other drivers like for full body tracking. Other VR streaming drivers like Virtual Desktop must be manually unregistered or uninstalled.
No action: All driver registration actions should be performed mnually, ALVR included. This allows to launch SteamVR without launching the dashboard first."#
No action: All driver registration actions should be performed manually, ALVR included. This allows to launch SteamVR without launching the dashboard first."#
))]
pub driver_launch_action: DriverLaunchAction,

#[schema(strings(display_name = "Open and close SteamVR with dashboard"))]
pub open_close_steamvr_with_dashboard: bool,

pub notification_level: LogSeverity,
pub show_raw_events: bool,

Expand Down Expand Up @@ -1069,6 +1072,7 @@ pub fn session_settings_default() -> SettingsDefault {
driver_launch_action: DriverLaunchActionDefault {
variant: DriverLaunchActionDefaultVariant::UnregisterOtherDriversAtStartup,
},
open_close_steamvr_with_dashboard: false,
notification_level: LogSeverityDefault {
variant: if cfg!(debug_assertions) {
LogSeverityDefaultVariant::Info
Expand Down
5 changes: 3 additions & 2 deletions alvr/sockets/src/packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ pub struct PathValuePair {
#[derive(Serialize, Deserialize, Debug)]
pub enum DashboardRequest {
Ping,
Log(LogEvent),
GetSession,
UpdateSession(Box<SessionDesc>),
SetValues(Vec<PathValuePair>),
Expand All @@ -203,12 +204,12 @@ pub enum DashboardRequest {
action: ClientListAction,
},
GetAudioDevices,
RestartSteamvr,
CaptureFrame,
InsertIdr,
StartRecording,
StopRecording,
Log(LogEvent),
RestartSteamvr,
ShutdownSteamvr,
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down

0 comments on commit 183d629

Please sign in to comment.