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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ parking_lot = "0.12.5"
postcard = { version = "1.0.8", features = ["use-std"] }
replace_with = "0.1.8"
serde = { version = "1.0.164", features = ["derive"] }
serde_json = "1.0.116"
serde_json = "1.0.149"
serde_tuple = "1.1.2"
smallbox = "0.8.8"
static_assertions = "1.1.0"
Expand Down
1 change: 1 addition & 0 deletions applications/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ massive-input.workspace = true
anyhow.workspace = true
derive_more.workspace = true
log.workspace = true
serde_json.workspace = true
tokio.workspace = true
uuid.workspace = true
# Architecture: We should get rid of the winit dependency here. Current ViewEvent depends on it,
Expand Down
17 changes: 12 additions & 5 deletions applications/src/instance_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ use massive_renderer::FontManager;
use massive_util::{CoalescingKey, CoalescingReceiver};

use crate::{
InstanceEnvironment, InstanceId, Scene, ViewEvent, ViewExtent, ViewId,
InstanceEnvironment, InstanceId, InstanceParameters, Scene, ViewEvent, ViewExtent, ViewId,
view::{ViewCommand, ViewCreationInfo},
view_builder::ViewBuilder,
};

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CreationMode {
New,
New(InstanceParameters),
Restore,
}

Expand Down Expand Up @@ -57,8 +57,15 @@ impl InstanceContext {
self.id
}

pub fn creation_mode(&self) -> CreationMode {
self.creation_mode
pub fn creation_mode(&self) -> &CreationMode {
&self.creation_mode
}

pub fn parameters(&self) -> Option<&InstanceParameters> {
match &self.creation_mode {
CreationMode::New(map) => Some(map),
CreationMode::Restore => None,
}
}

pub fn primary_monitor_scale_factor(&self) -> f64 {
Expand Down
10 changes: 10 additions & 0 deletions applications/src/instance_environment.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use massive_renderer::FontManager;
use serde_json::{Map, Value};
use tokio::sync::mpsc::UnboundedSender;

use crate::{InstanceCommand, InstanceId};
Expand All @@ -9,8 +10,11 @@ pub struct InstanceEnvironment {
// Robustness: This might change on runtime.
pub(crate) primary_monitor_scale_factor: f64,
pub(crate) font_manager: FontManager,
pub(crate) parameters: Map<String, Value>,
}

pub type InstanceParameters = Map<String, Value>;

impl InstanceEnvironment {
pub fn new(
requests_tx: UnboundedSender<(InstanceId, InstanceCommand)>,
Expand All @@ -21,6 +25,12 @@ impl InstanceEnvironment {
command_sender: requests_tx,
primary_monitor_scale_factor,
font_manager,
parameters: Default::default(),
}
}

pub fn with_parameters(mut self, parameters: InstanceParameters) -> Self {
self.parameters = parameters;
self
}
}
1 change: 1 addition & 0 deletions desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ derive_more.workspace = true
euclid.workspace = true
futures.workspace = true
log.workspace = true
serde_json.workspace = true
serde.workspace = true
tokio = { workspace = true, features = ["time"] }
toml.workspace = true
Expand Down
12 changes: 8 additions & 4 deletions desktop/src/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use tokio::sync::mpsc::{UnboundedReceiver, unbounded_channel};
use uuid::Uuid;

use massive_applications::{
CreationMode, InstanceCommand, InstanceEnvironment, InstanceEvent, InstanceId, ViewCommand,
ViewEvent, ViewId, ViewRole,
CreationMode, InstanceCommand, InstanceEnvironment, InstanceEvent, InstanceId,
InstanceParameters, ViewCommand, ViewEvent, ViewId, ViewRole,
};
use massive_input::{EventManager, ExternalEvent};
use massive_renderer::RenderPacing;
Expand Down Expand Up @@ -72,7 +72,10 @@ impl Desktop {
.get_named(&env.primary_application)
.expect("No primary application");

instance_manager.spawn(primary_application, CreationMode::New)?;
instance_manager.spawn(
primary_application,
CreationMode::New(InstanceParameters::new()),
)?;

// First wait for the initial view that's being created.

Expand Down Expand Up @@ -201,6 +204,7 @@ impl Desktop {
}
UserIntent::StartInstance {
originating_instance,
parameters,
} => {
// Feature: Support starting non-primary applications.
let application = self
Expand All @@ -211,7 +215,7 @@ impl Desktop {

let instance = self
.instance_manager
.spawn(application, CreationMode::New)?;
.spawn(application, CreationMode::New(parameters))?;

// Simplify: Use the currently focused instance for determining the originating one.
let band_location = self
Expand Down
4 changes: 3 additions & 1 deletion desktop/src/desktop_interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use winit::{
};

use massive_animation::{Animated, Interpolation};
use massive_applications::{InstanceId, ViewEvent, ViewRole};
use massive_applications::{InstanceId, InstanceParameters, ViewEvent, ViewRole};
use massive_geometry::PixelCamera;
use massive_input::Event;
use massive_renderer::RenderGeometry;
Expand All @@ -31,6 +31,7 @@ pub enum UserIntent {
//
// Idea: What about looking for which presenter has the focus currently?
originating_instance: Option<InstanceId>,
parameters: InstanceParameters,
},
StopInstance {
instance: InstanceId,
Expand Down Expand Up @@ -175,6 +176,7 @@ impl DesktopInteraction {
Key::Character(c) if c.as_str() == "t" => {
return Ok(UserIntent::StartInstance {
originating_instance: Some(instance),
parameters: Default::default(),
});
}
Key::Character(c) if c.as_str() == "w" => {
Expand Down
3 changes: 0 additions & 3 deletions desktop/src/instance_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ pub struct InstanceManager {
#[derive(Debug)]
struct RunningInstance {
application_name: String,
#[allow(dead_code)]
creation_mode: CreationMode,
events_tx: UnboundedSender<InstanceEvent>,
views: HashMap<ViewId, ViewInfo>,
}
Expand Down Expand Up @@ -107,7 +105,6 @@ impl InstanceManager {
instance_id,
RunningInstance {
application_name: application.name.clone(),
creation_mode,
events_tx,
views: HashMap::new(),
},
Expand Down
1 change: 1 addition & 0 deletions desktop/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub use desktop_interaction::*;
pub use desktop_presenter::DesktopPresenter;
pub use event_router::{EventRouter, EventTransition, HitTester};


// A layout helper.
// Robustness: Can't we implement ToPixels somewhere?

Expand Down
32 changes: 13 additions & 19 deletions desktop/src/projects/configuration/toml_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ use std::collections::HashMap;
use anyhow::Result;
use indexmap::IndexMap;
use serde::Deserialize;
use serde_json::Map;
use toml::Value;

use super::types::{
GroupContents, LaunchGroup, LaunchProfile, LayoutDirection, Parameter, Parameters, ScopedTag,
};
use super::types::{GroupContents, LaunchGroup, LaunchProfile, LayoutDirection, ScopedTag};

/// Intermediate representation for deserializing TOML configuration files.
#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -71,23 +70,18 @@ fn build_launch_profile(
groups: &[String],
) -> Result<LaunchProfile> {
let mut tags = Vec::new();
let mut params = Vec::new();
let mut params = Map::new();

for (key, value) in section {
let value = toml_value_to_string(&value)?;

if groups.contains(&key) {
let value = toml_value_to_string(&value)?;
tags.push(ScopedTag::new(key, value));
} else {
params.push(Parameter::new(key, value));
params.insert(key, serde_json::to_value(&value)?);
}
}

Ok(LaunchProfile {
name,
params: Parameters(params),
tags,
})
Ok(LaunchProfile { name, params, tags })
}

/// Build a cross-product hierarchy of groups at the given depth level.
Expand Down Expand Up @@ -224,7 +218,7 @@ datacenter = "ber"

assert_eq!(app_ref.name, "host-1");
assert_eq!(app_ref.params.len(), 1);
assert_eq!(app_ref.params[0].name, "command");
assert!(app_ref.params.contains_key("command"));
assert_eq!(app_ref.tags.len(), 2);
assert!(app_ref.tags.iter().any(|t| t.scope == "datacenter"));
assert!(app_ref.tags.iter().any(|t| t.scope == "type"));
Expand Down Expand Up @@ -323,14 +317,14 @@ datacenter = "ber"
}

fn app(name: &str, params: &[(&str, &str)], tags: &[(&str, &str)]) -> LaunchProfile {
let mut param_map = Map::new();
for (k, v) in params {
param_map.insert(k.to_string(), serde_json::Value::String(v.to_string()));
}

LaunchProfile {
name: name.to_string(),
params: Parameters(
params
.iter()
.map(|(k, v)| Parameter::new(k.to_string(), v.to_string()))
.collect(),
),
params: param_map,
tags: tags
.iter()
.map(|(scope, tag)| ScopedTag::new(scope.to_string(), tag.to_string()))
Expand Down
19 changes: 3 additions & 16 deletions desktop/src/projects/configuration/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use derive_more::Deref;
use serde_json::{Map, Value};

use massive_layout::LayoutAxis;

#[derive(Debug)]
Expand Down Expand Up @@ -34,7 +35,7 @@ pub enum GroupContents {
#[derive(Debug, Clone)]
pub struct LaunchProfile {
pub name: String,
pub params: Parameters,
pub params: Map<String, Value>,
pub tags: Vec<ScopedTag>,
}

Expand All @@ -52,17 +53,3 @@ impl ScopedTag {
}
}
}

#[derive(Debug, Deref, Clone, Default)]
pub struct Parameters(pub Vec<Parameter>);

#[derive(Debug, Clone)]
pub struct Parameter {
pub name: String,
pub value: String,
}
impl Parameter {
pub fn new(name: String, value: String) -> Self {
Self { name, value }
}
}
1 change: 1 addition & 0 deletions desktop/src/projects/launcher_presenter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ impl LauncherPresenter {
// Usability: Should pass this rect?
return Ok(UserIntent::StartInstance {
originating_instance: None,
parameters: self.profile.params.clone(),
});
}
ViewEvent::CursorEntered { .. } => {
Expand Down
6 changes: 2 additions & 4 deletions desktop/src/projects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use log::warn;

use crate::{
band_presenter::BandTarget,
projects::configuration::{
GroupContents, LaunchProfile, LayoutDirection, Parameters, ScopedTag,
},
projects::configuration::{GroupContents, LaunchProfile, LayoutDirection, ScopedTag},
};

mod configuration;
Expand Down Expand Up @@ -72,7 +70,7 @@ impl Default for ProjectConfiguration {
content: GroupContents::Profiles(
[LaunchProfile {
name: DEFAULT_PROFILE.into(),
params: Parameters::default(),
params: Default::default(),
tags: Vec::new(),
}]
.into(),
Expand Down
Loading