feat(startup): get environment
This commit is contained in:
@@ -14,6 +14,7 @@ use self::core::eventloop::EventLoop;
|
||||
use clap::Parser;
|
||||
use color_eyre::eyre::Result;
|
||||
use directories::ProjectDirs;
|
||||
use once_cell::sync::OnceCell;
|
||||
use stardust_xr::server;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
@@ -52,6 +53,8 @@ struct CliArgs {
|
||||
startup_script: Option<PathBuf>,
|
||||
}
|
||||
|
||||
static STARDUST_INSTANCE: OnceCell<String> = OnceCell::new();
|
||||
|
||||
struct EventLoopInfo {
|
||||
tokio_handle: Handle,
|
||||
socket_path: PathBuf,
|
||||
@@ -259,6 +262,7 @@ async fn event_loop(
|
||||
) -> color_eyre::eyre::Result<()> {
|
||||
let socket_path =
|
||||
server::get_free_socket_path().expect("Unable to find a free stardust socket path");
|
||||
STARDUST_INSTANCE.set(socket_path.file_name().unwrap().to_string_lossy().into_owned()).expect("Someone hasn't done their job, yell at Nova because how is this set multiple times what the hell");
|
||||
let _event_loop = EventLoop::new(socket_path.clone()).expect("Couldn't create server socket");
|
||||
info!("Init event loop");
|
||||
info!(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::core::client::Client;
|
||||
use crate::{core::client::Client, wayland::WAYLAND_DISPLAY, STARDUST_INSTANCE};
|
||||
|
||||
use super::{
|
||||
items::{ItemAcceptor, TypeInfo},
|
||||
@@ -9,7 +9,7 @@ use color_eyre::eyre::Result;
|
||||
use glam::Mat4;
|
||||
use parking_lot::Mutex;
|
||||
use rustc_hash::FxHashMap;
|
||||
use stardust_xr::schemas::flex::{deserialize, flexbuffers, serialize};
|
||||
use stardust_xr::schemas::flex::{deserialize, serialize};
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
sync::{Arc, Weak},
|
||||
@@ -86,6 +86,10 @@ impl Debug for StartupSettings {
|
||||
pub fn create_interface(client: &Arc<Client>) -> Result<()> {
|
||||
let node = Node::create(client, "", "startup", false);
|
||||
node.add_local_signal("create_startup_settings", create_startup_settings_flex);
|
||||
node.add_local_method(
|
||||
"get_connection_environment",
|
||||
get_connection_environment_flex,
|
||||
);
|
||||
node.add_to_scenegraph().map(|_| ())
|
||||
}
|
||||
|
||||
@@ -94,9 +98,13 @@ pub fn create_startup_settings_flex(
|
||||
calling_client: Arc<Client>,
|
||||
data: &[u8],
|
||||
) -> Result<()> {
|
||||
let name = flexbuffers::Reader::get_root(data)?.get_str()?;
|
||||
let node =
|
||||
Node::create(&calling_client, "/startup/settings", name, true).add_to_scenegraph()?;
|
||||
let node = Node::create(
|
||||
&calling_client,
|
||||
"/startup/settings",
|
||||
deserialize(data)?,
|
||||
true,
|
||||
)
|
||||
.add_to_scenegraph()?;
|
||||
StartupSettings::add_to(&node);
|
||||
|
||||
node.add_local_signal("set_root", StartupSettings::set_root_flex);
|
||||
@@ -111,3 +119,21 @@ pub fn create_startup_settings_flex(
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
macro_rules! env_insert {
|
||||
($env:ident, $name:ident) => {
|
||||
$env.insert(stringify!($name).to_string(), $name.get().unwrap().clone());
|
||||
};
|
||||
}
|
||||
pub fn get_connection_environment_flex(
|
||||
_node: &Node,
|
||||
_calling_client: Arc<Client>,
|
||||
_data: &[u8],
|
||||
) -> Result<Vec<u8>> {
|
||||
let mut env: FxHashMap<String, String> = FxHashMap::default();
|
||||
env_insert!(env, STARDUST_INSTANCE);
|
||||
#[cfg(feature = "wayland")]
|
||||
env_insert!(env, WAYLAND_DISPLAY);
|
||||
|
||||
Ok(serialize(env)?)
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ use tokio::{
|
||||
};
|
||||
use tracing::{debug, debug_span, info, instrument};
|
||||
|
||||
pub static WAYLAND_DISPLAY: OnceCell<String> = OnceCell::new();
|
||||
|
||||
pub static SERIAL_COUNTER: CounterU32 = CounterU32::new(0);
|
||||
|
||||
struct EGLRawHandles {
|
||||
@@ -85,6 +87,9 @@ impl Wayland {
|
||||
|
||||
let socket = ListeningSocket::bind_auto("wayland", 0..33)?;
|
||||
let socket_name = socket.socket_name().unwrap().to_str().unwrap().to_string();
|
||||
WAYLAND_DISPLAY
|
||||
.set(socket_name.clone())
|
||||
.expect("seriously message nova this time they screwed up big time");
|
||||
info!(socket_name, "Wayland active");
|
||||
|
||||
let join_handle =
|
||||
|
||||
Reference in New Issue
Block a user