Skip to content

Commit

Permalink
add a property inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonoughe committed Mar 10, 2019
1 parent 105259c commit 07ae274
Show file tree
Hide file tree
Showing 35 changed files with 3,159 additions and 238 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"rust.target": "i686-pc-windows-msvc"
"rust.target": "i686-pc-windows-msvc",
"[html]": {
"editor.formatOnSave": false
}
}
11 changes: 6 additions & 5 deletions Build-Plugin.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
$dist = New-Item -ItemType 'Directory' -Path (Join-Path $PSScriptRoot 'dist/io.github.mdonoughe.sbzdeck.sdPlugin') -Force

cargo build --release --manifest-path (Join-Path $PSScriptRoot 'Cargo.toml' | Resolve-Path).ProviderPath
Join-Path $PSScriptRoot 'target\i686-pc-windows-msvc\release\sbzdeck.exe' | Copy-Item -Destination $dist.PSPath

# temporary
Join-Path $PSScriptRoot 'examples\sbzdeck.json' | Copy-Item -Destination $dist.PSPath
Push-Location $PSScriptRoot
cargo build --release -p plugin
Get-Item target/i686-pc-windows-msvc/release/plugin.exe | Copy-Item -Destination (Join-Path $dist.PSPath 'sbzdeck.exe')
cargo web deploy --release -o dist/io.github.mdonoughe.sbzdeck.sdPlugin/inspector -p inspector
Pop-Location

$manifest = Join-Path $PSScriptRoot 'manifest.json' | Get-Item | Get-Content | ConvertFrom-Json
$manifest.CodePathWin = 'sbzdeck.exe'
$manifest.PropertyInspectorPath = 'inspector/index.html'
$manifest | ConvertTo-Json -Depth 100 | Set-Content -LiteralPath ($dist | Join-Path -ChildPath 'manifest.json')

$images = @(
Expand Down
184 changes: 165 additions & 19 deletions Cargo.lock

Large diffs are not rendered by default.

30 changes: 6 additions & 24 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
[package]
name = "sbzdeck"
version = "0.1.0"
authors = ["Matthew Donoughe <mdonoughe@gmail.com>"]
description = "Steam Deck plugin for Sound Blaster devices"
repository = "https://github.com/mdonoughe/sbzdeck/"
readme = "README.md"
keywords = ["stream-deck", "sound-blaster"]
license = "MIT/Apache-2.0"
edition = "2018"
[workspace]

[badges]
travis-ci = { repository = "mdonoughe/sbzdeck" }

[dependencies]
futures = "0.1.25"
indexmap = "1.0"
sbz-switch = "3.1"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
slog = { version = "2.4", features = ["max_level_trace", "release_max_level_info"] }
sloggers = "0.3"
streamdeck-rs = { git = "https://github.com/mdonoughe/streamdeck-rs", branch = "sdk2" }
tokio = "0.1.14"
members = [
"common",
"inspector",
"plugin"
]
11 changes: 11 additions & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "common"
version = "0.1.0"
authors = ["Matthew Donoughe <mdonoughe@gmail.com>"]
edition = "2018"

[dependencies]
indexmap = { version = "1", features = ["serde-1"] }
serde = "1"
serde_derive = "1"
serde_json = "1"
48 changes: 48 additions & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use indexmap::{IndexMap, IndexSet};
use serde_derive::{Deserialize, Serialize};
use std::collections::{BTreeMap, BTreeSet};

#[derive(Debug, Deserialize, Serialize)]
#[serde(tag = "event", rename_all = "camelCase")]
pub enum FromInspector {
GetFeatures,
#[serde(rename_all = "camelCase")]
SetFeatures {
selected_parameters: BTreeMap<String, BTreeSet<String>>,
},
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(tag = "event", rename_all = "camelCase")]
pub enum ToInspector {
#[serde(rename_all = "camelCase")]
SetFeatures {
selected_parameters: IndexMap<String, IndexMap<String, bool>>,
},
}

#[derive(Debug, Default, Deserialize, Serialize)]
pub struct SerdeProfile {
pub volume: Option<f32>,
#[serde(default)]
pub parameters: BTreeMap<String, BTreeMap<String, serde_json::Value>>,
}

#[derive(Debug, Default, Deserialize, Serialize)]
pub struct SerdeProfiles {
#[serde(default)]
pub headphones: SerdeProfile,
#[serde(default)]
pub speakers: SerdeProfile,
}

#[derive(Debug, Default, Deserialize, Serialize)]
pub struct SerdeCardSettings {
#[serde(default)]
pub selected_parameters: IndexMap<String, IndexSet<String>>,
#[serde(default)]
pub profiles: SerdeProfiles,
}

#[derive(Debug, Default, Deserialize, Serialize)]
pub struct Empty {}
17 changes: 17 additions & 0 deletions inspector/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "inspector"
version = "0.1.0"
authors = ["Matthew Donoughe <mdonoughe@gmail.com>"]
edition = "2018"

[lib]
crate-type = ["cdylib"]

[dependencies]
common = { path = "../common" }
indexmap = "1.0"
serde = "1"
serde_derive = "1"
serde_json = "1"
stdweb = "0.4"
yew = "0.6"
97 changes: 97 additions & 0 deletions inspector/src/feature.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
use super::parameter::Parameter;
use indexmap::IndexMap;
use stdweb::traits::IEvent;
use yew::prelude::*;
use yew::virtual_dom::VNode;

#[derive(Clone, Default, PartialEq)]
pub struct Properties {
pub name: String,
pub is_expanded: bool,
pub parameters: IndexMap<String, bool>,
pub onexpandchange: Option<Callback<bool>>,
pub onchange: Option<Callback<(String, bool)>>,
}

pub struct Feature {
name: String,
is_expanded: bool,
parameters: IndexMap<String, bool>,
onexpandchange: Option<Callback<bool>>,
onchange: Option<Callback<(String, bool)>>,
}

pub enum Message {
Toggle,
SetParameter { name: String, is_selected: bool },
}

impl Component for Feature {
type Message = Message;
type Properties = Properties;

fn create(properties: Self::Properties, _link: ComponentLink<Self>) -> Self {
Self {
name: properties.name,
is_expanded: properties.is_expanded,
parameters: properties.parameters,
onexpandchange: properties.onexpandchange,
onchange: properties.onchange,
}
}

fn update(&mut self, message: Self::Message) -> ShouldRender {
match message {
Message::Toggle => {
if let Some(ref mut callback) = self.onexpandchange {
callback.emit(!self.is_expanded);
}
}
Message::SetParameter { name, is_selected } => {
if let Some(ref mut callback) = self.onchange {
callback.emit((name, is_selected));
}
}
}
false
}

fn change(&mut self, properties: Self::Properties) -> ShouldRender {
let changed = self.name != properties.name
|| self.is_expanded != properties.is_expanded
|| self.parameters != properties.parameters;
self.name = properties.name;
self.is_expanded = properties.is_expanded;
self.parameters = properties.parameters;
self.onchange = properties.onchange;
self.onexpandchange = properties.onexpandchange;
changed
}
}

impl Renderable<Feature> for Feature {
fn view(&self) -> Html<Self> {
let mut tag = html! {
<details>
<summary onclick=|e| { e.prevent_default(); Message::Toggle },>{ &self.name }</summary>
// capitalize `type` because otherwise yew eats it
<div Type="checkbox", class="sdpi-item",>
<div class="sdpi-item-value min100",>
{ for self.parameters.iter().map(|(name, is_selected)| {
let cb_name = name.clone();
html! {
<Parameter: name=name, is_selected=is_selected, onchange=move |is_selected| { Message::SetParameter { name: cb_name.clone(), is_selected } }, />
}
}) }
</div>
</div>
</details>
};
if self.is_expanded {
if let VNode::VTag(ref mut vtag) = tag {
vtag.add_attribute("open", &"");
}
}
tag
}
}
Loading

0 comments on commit 07ae274

Please sign in to comment.