refactor: session state save data as bin file
This commit is contained in:
@@ -33,7 +33,8 @@ impl LaunchInfo {
|
|||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct ClientStateParsed {
|
pub struct ClientStateParsed {
|
||||||
pub launch_info: Option<LaunchInfo>,
|
pub launch_info: Option<LaunchInfo>,
|
||||||
pub data: Vec<u8>,
|
#[serde(skip)]
|
||||||
|
pub data: Option<Vec<u8>>,
|
||||||
pub root: Mat4,
|
pub root: Mat4,
|
||||||
pub spatial_anchors: FxHashMap<String, Mat4>,
|
pub spatial_anchors: FxHashMap<String, Mat4>,
|
||||||
}
|
}
|
||||||
@@ -41,7 +42,7 @@ impl ClientStateParsed {
|
|||||||
pub fn from_deserialized(client: &Client, state: ClientState) -> Self {
|
pub fn from_deserialized(client: &Client, state: ClientState) -> Self {
|
||||||
ClientStateParsed {
|
ClientStateParsed {
|
||||||
launch_info: LaunchInfo::from_client(client),
|
launch_info: LaunchInfo::from_client(client),
|
||||||
data: state.data.unwrap_or_default(),
|
data: state.data,
|
||||||
root: Self::spatial_transform(client, state.root).unwrap_or_default(),
|
root: Self::spatial_transform(client, state.root).unwrap_or_default(),
|
||||||
spatial_anchors: state
|
spatial_anchors: state
|
||||||
.spatial_anchors
|
.spatial_anchors
|
||||||
@@ -63,7 +64,9 @@ impl ClientStateParsed {
|
|||||||
}
|
}
|
||||||
pub fn from_file(file: &Path) -> Option<Self> {
|
pub fn from_file(file: &Path) -> Option<Self> {
|
||||||
let file_string = std::fs::read_to_string(file).ok()?;
|
let file_string = std::fs::read_to_string(file).ok()?;
|
||||||
toml::from_str(&file_string).ok()
|
let mut client_state: Self = toml::from_str(&file_string).ok()?;
|
||||||
|
client_state.data = std::fs::read(file.with_extension("bin")).ok();
|
||||||
|
Some(client_state)
|
||||||
}
|
}
|
||||||
pub fn to_file(&self, directory: &Path) {
|
pub fn to_file(&self, directory: &Path) {
|
||||||
let app_name = self
|
let app_name = self
|
||||||
@@ -71,11 +74,14 @@ impl ClientStateParsed {
|
|||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|l| l.cmdline.first().unwrap().split('/').next_back().unwrap())
|
.map(|l| l.cmdline.first().unwrap().split('/').next_back().unwrap())
|
||||||
.unwrap_or("unknown");
|
.unwrap_or("unknown");
|
||||||
let state_file_path = directory
|
let state_file_prefix = directory.join(format!("{app_name}-{}", nanoid::nanoid!()));
|
||||||
.join(format!("{app_name}-{}", nanoid::nanoid!()))
|
let state_metadata_path = state_file_prefix.with_extension("toml");
|
||||||
.with_extension("toml");
|
let state_data_path = state_file_prefix.with_extension("bin");
|
||||||
|
|
||||||
std::fs::write(state_file_path, toml::to_string(&self).unwrap()).unwrap();
|
std::fs::write(state_metadata_path, toml::to_string(&self).unwrap()).unwrap();
|
||||||
|
if let Some(data) = self.data.as_deref() {
|
||||||
|
std::fs::write(state_data_path, data).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_to(&self, client: &Arc<Client>) -> ClientState {
|
pub fn apply_to(&self, client: &Arc<Client>) -> ClientState {
|
||||||
@@ -83,7 +89,7 @@ impl ClientStateParsed {
|
|||||||
root.set_transform(self.root)
|
root.set_transform(self.root)
|
||||||
}
|
}
|
||||||
ClientState {
|
ClientState {
|
||||||
data: Some(self.data.clone()),
|
data: self.data.clone(),
|
||||||
root: 0,
|
root: 0,
|
||||||
spatial_anchors: self
|
spatial_anchors: self
|
||||||
.spatial_anchors
|
.spatial_anchors
|
||||||
@@ -111,7 +117,7 @@ impl Default for ClientStateParsed {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
launch_info: None,
|
launch_info: None,
|
||||||
data: Default::default(),
|
data: None,
|
||||||
root: Mat4::IDENTITY,
|
root: Mat4::IDENTITY,
|
||||||
spatial_anchors: Default::default(),
|
spatial_anchors: Default::default(),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ fn build_line_mesh(
|
|||||||
perceptual_roughness: 1.0,
|
perceptual_roughness: 1.0,
|
||||||
// TODO: this should be Blend
|
// TODO: this should be Blend
|
||||||
alpha_mode: AlphaMode::Opaque,
|
alpha_mode: AlphaMode::Opaque,
|
||||||
unlit: true,
|
emissive: Color::srgba_u8(128, 128, 128, 255).into(),
|
||||||
..default()
|
..default()
|
||||||
})),
|
})),
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use crate::wayland::WAYLAND_DISPLAY;
|
|||||||
use crate::{CliArgs, STARDUST_INSTANCE};
|
use crate::{CliArgs, STARDUST_INSTANCE};
|
||||||
use directories::ProjectDirs;
|
use directories::ProjectDirs;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
use std::ffi::OsStr;
|
||||||
use std::os::unix::fs::PermissionsExt;
|
use std::os::unix::fs::PermissionsExt;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::{Child, Command, Stdio};
|
use std::process::{Child, Command, Stdio};
|
||||||
@@ -58,6 +59,7 @@ pub fn restore_session(session_dir: &Path, debug_launched_clients: bool) -> Vec<
|
|||||||
};
|
};
|
||||||
clients
|
clients
|
||||||
.filter_map(Result::ok)
|
.filter_map(Result::ok)
|
||||||
|
.filter(|c| c.path().extension() == Some(OsStr::new("toml")))
|
||||||
.filter_map(|c| ClientStateParsed::from_file(&c.path()))
|
.filter_map(|c| ClientStateParsed::from_file(&c.path()))
|
||||||
.filter_map(ClientStateParsed::launch_command)
|
.filter_map(ClientStateParsed::launch_command)
|
||||||
.filter_map(|c| run_client(c, debug_launched_clients))
|
.filter_map(|c| run_client(c, debug_launched_clients))
|
||||||
|
|||||||
Reference in New Issue
Block a user