BROKEN: aaaaa

This commit is contained in:
Aode (Lion) 2022-03-16 19:13:56 -05:00
parent 7bb1073fd9
commit 0c59291170
10 changed files with 177 additions and 1244 deletions

62
Cargo.lock generated
View file

@ -184,23 +184,18 @@ dependencies = [
"system-deps",
]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "base16ct"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce"
[[package]]
name = "base64"
version = "0.13.0"
@ -481,19 +476,6 @@ dependencies = [
"syn",
]
[[package]]
name = "env_logger"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3"
dependencies = [
"atty",
"humantime",
"log",
"regex",
"termcolor",
]
[[package]]
name = "event-listener"
version = "2.5.2"
@ -917,12 +899,6 @@ version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9100414882e15fb7feccb4897e5f0ff0ff1ca7d1a86a23208ada4d7a18e6c6c4"
[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "ident_case"
version = "1.0.1"
@ -1746,7 +1722,6 @@ dependencies = [
"anyhow",
"async-io",
"async-stream",
"env_logger",
"event-listener",
"futures-channel",
"futures-core",
@ -1758,12 +1733,15 @@ dependencies = [
"glib-sys",
"gtk",
"libhandy",
"log",
"marble",
"once_cell",
"pango",
"serde_json",
"streamdeck-common",
"tracing",
"tracing-error 0.2.0",
"tracing-log",
"tracing-subscriber 0.3.9",
"zbus",
]
@ -1791,7 +1769,7 @@ name = "streamdeck-daemon"
version = "0.1.0"
dependencies = [
"anyhow",
"base64",
"base16ct",
"directories",
"either",
"futures-util",
@ -1855,15 +1833,6 @@ dependencies = [
"version-compare",
]
[[package]]
name = "termcolor"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
dependencies = [
"winapi-util",
]
[[package]]
name = "thiserror"
version = "1.0.30"
@ -2213,15 +2182,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"

View file

@ -31,6 +31,7 @@ pub(crate) fn button_path(serial_number: &str, input: &Input) -> String {
}
struct Daemon {
discovery_enabled: bool,
manager: Sender<ManagerMessage>,
decks: BTreeSet<String>,
}
@ -41,20 +42,23 @@ fn fail(e: impl std::fmt::Display) -> zbus::fdo::Error {
#[zbus::dbus_interface(name = "dog.asonix.git.asonix.StreamdeckDaemon")]
impl Daemon {
async fn enable_discovery(&self) -> zbus::fdo::Result<()> {
tracing::debug!("enable_discovery");
self.manager
.send(ManagerMessage::EnableDiscovery)
.await
.map_err(fail)
#[dbus_interface(property)]
async fn discovery_enabled(&self) -> bool {
self.discovery_enabled
}
async fn disable_discovery(&self) -> zbus::fdo::Result<()> {
tracing::debug!("disable_discovery");
self.manager
.send(ManagerMessage::DisableDiscovery)
.await
.map_err(fail)
#[dbus_interface(property)]
async fn set_discovery_enabled(&mut self, enabled: bool) {
tracing::debug!("set_discovery_enabled, {}", enabled);
let cmd = if enabled {
ManagerMessage::EnableDiscovery
} else {
ManagerMessage::DisableDiscovery
};
if self.manager.send(cmd).await.is_ok() {
self.discovery_enabled = enabled;
}
}
async fn get_decks(&self) -> Vec<String> {
@ -63,10 +67,10 @@ impl Daemon {
}
#[dbus_interface(signal)]
async fn deck_added(ctx: &SignalContext<'_>, serial_number: &str) -> zbus::Result<()>;
async fn deck_added(ctx: &SignalContext<'_>, path: &str) -> zbus::Result<()>;
#[dbus_interface(signal)]
async fn deck_removed(ctx: &SignalContext<'_>, serial_number: &str) -> zbus::Result<()>;
async fn deck_removed(ctx: &SignalContext<'_>, path: &str) -> zbus::Result<()>;
}
#[tracing::instrument(skip_all)]
@ -78,6 +82,7 @@ pub(crate) async fn spawn(
manager: Sender<ManagerMessage>,
) -> anyhow::Result<zbus::Connection> {
let state = Daemon {
discovery_enabled: true,
manager: manager.clone(),
decks: BTreeSet::new(),
};
@ -115,9 +120,9 @@ pub(crate) async fn spawn(
continue;
}
daemon.decks.insert(config.serial_number.clone());
daemon.decks.insert(deck_path(&config.serial_number));
let ctx = daemon_ref.signal_context();
let _ = Daemon::deck_added(ctx, &config.serial_number).await;
let _ = Daemon::deck_added(ctx, &deck_path(&config.serial_number)).await;
}
}
DeckMessage::Close(serial_number) => {
@ -131,9 +136,9 @@ pub(crate) async fn spawn(
.await
{
let mut daemon = daemon_ref.get_mut().await;
daemon.decks.remove(&serial_number);
daemon.decks.remove(&deck_path(&serial_number));
let ctx = daemon_ref.signal_context();
let _ = Daemon::deck_removed(ctx, &serial_number).await;
let _ = Daemon::deck_removed(ctx, &deck_path(&serial_number)).await;
}
}
}

View file

@ -11,7 +11,6 @@ anyhow = "1"
async-io = "1.4.1"
async-stream = "0.3.1"
streamdeck-common = { path = "../streamdeck-common", features = ["ipc-dbus"] }
env_logger = "0.9.0"
event-listener = "2.5.1"
futures-channel = { version = "0.3.14", features = ["sink"] }
futures-core = "0.3.14"
@ -23,9 +22,16 @@ gio = "0.15.1"
glib = "0.15.3"
glib-sys = "0.15.1"
libhandy = "0.9.0"
log = "0.4"
marble = { path = "../marble" }
once_cell = "1.7.2"
pango = "0.15.2"
serde_json = "1"
tracing = "0.1.15"
tracing-error = "0.2.0"
tracing-log = "0.1.2"
tracing-subscriber = { version = "0.3.0", features = [
"env-filter",
"fmt",
"tracing-log",
] }
zbus = "2.1.1"

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,76 @@
use streamdeck_common::Input;
#[zbus::dbus_proxy(
interface = "dog.asonix.git.asonix.StreamdeckDaemon",
default_service = "dog.asonix.git.asonix.StreamdeckDaemon",
default_path = "/dog/asonix/git/asonix/StreamdeckDaemon"
)]
trait Daemon {
#[dbus_proxy(property)]
fn discovery_enabled(&self) -> zbus::fdo::Result<bool>;
#[dbus_proxy(property)]
fn set_discovery_enabled(&self, enabled: bool) -> zbus::fdo::Result<()>;
fn get_decks(&self) -> zbus::fdo::Result<Vec<String>>;
#[dbus_proxy(signal)]
fn deck_added(&self, path: &str) -> zbus::fdo::Result<()>;
#[dbus_proxy(signal)]
fn deck_removed(&self, path: &str) -> zbus::fdo::Result<()>;
}
#[zbus::dbus_proxy(
interface = "dog.asonix.git.asonix.StreamdeckDaemon.Deck",
default_service = "dog.asonix.git.asonix.StreamdeckDaemon.Deck"
)]
trait Deck {
#[dbus_proxy(property)]
fn name(&self) -> zbus::fdo::Result<String>;
#[dbus_proxy(property)]
fn set_name(&self, name: String) -> zbus::fdo::Result<()>;
#[dbus_proxy(property)]
fn product_name(&self) -> zbus::fdo::Result<String>;
#[dbus_proxy(property)]
fn port_name(&self) -> zbus::fdo::Result<String>;
fn get_buttons(&self) -> zbus::fdo::Result<Vec<String>>;
fn create_button(&self, input: Input, command: String) -> zbus::fdo::Result<String>;
fn remove_button(&self, input: Input) -> zbus::fdo::Result<()>;
#[dbus_proxy(signal)]
fn button_pushed(&self, input: Input) -> zbus::fdo::Result<()>;
#[dbus_proxy(signal)]
fn button_added(&self, input: Input) -> zbus::fdo::Result<()>;
#[dbus_proxy(signal)]
fn button_removed(&self, input: Input) -> zbus::fdo::Result<()>;
}
#[zbus::dbus_proxy(
interface = "dog.asonix.git.asonix.StreamdeckDaemon.Deck.Button",
default_service = "dog.asonix.git.asonix.StreamdeckDaemon.Deck.Button"
)]
trait Button {
#[dbus_proxy(property)]
fn name(&self) -> zbus::fdo::Result<String>;
#[dbus_proxy(property)]
fn set_name(&self, name: String) -> zbus::fdo::Result<()>;
#[dbus_proxy(property)]
fn command(&self) -> zbus::fdo::Result<String>;
#[dbus_proxy(property)]
fn set_command(&self, command: String) -> zbus::fdo::Result<()>;
#[dbus_proxy(signal)]
fn pushed(&self) -> zbus::fdo::Result<()>;
}

View file

@ -97,7 +97,7 @@ fn read_input(
for keypress in keypresses {
if keypress.serial_number == *serial_number {
should_break = true;
command_page.set_input_key(keypress.key);
command_page.set_input_keys(keypress.keys);
stack.set_visible_child_name("command");
}
}

View file

@ -4,7 +4,7 @@ use once_cell::unsync::Lazy;
mod application;
mod command;
mod config;
mod daemon;
mod dbus;
mod dialogs;
mod main_window;
mod views;
@ -28,12 +28,9 @@ fn saved_state() -> Settings {
SAVED_STATE.with(|settings| (*settings).clone())
}
fn main() {
if std::env::var("RUST_LOG").is_err() {
std::env::set_var("RUST_LOG", "info");
}
env_logger::init();
gtk::init().expect("Failed to initialize gtk");
fn main() -> anyhow::Result<()> {
init_tracing()?;
gtk::init()?;
libhandy::functions::init();
let handle = daemon::Handle::current();
@ -41,4 +38,32 @@ fn main() {
application::App::new().run_with_args(&std::env::args().collect::<Vec<_>>());
drop(handle);
Ok(())
}
fn init_tracing() -> anyhow::Result<()> {
use tracing::subscriber::set_global_default;
use tracing_error::ErrorLayer;
use tracing_log::LogTracer;
use tracing_subscriber::{
filter::Targets, fmt::format::FmtSpan, layer::SubscriberExt, Layer, Registry,
};
LogTracer::init()?;
let targets = std::env::var("RUST_LOG")
.unwrap_or_else(|_| "streamdeck_daemon=debug,streamdeck_handshake=debug,info".into())
.parse::<Targets>()?;
let format_layer = tracing_subscriber::fmt::layer()
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
.with_filter(targets);
let subscriber = Registry::default()
.with(format_layer)
.with(ErrorLayer::default());
set_global_default(subscriber)?;
Ok(())
}

View file

@ -1,7 +1,7 @@
use crate::daemon::{CommandState, Handle};
use futures_util::stream::StreamExt;
use gtk::{prelude::*, subclass::prelude::*};
use streamdeck_common::{Command, CommandVariant, StateOperation, VisibilityOperation};
use streamdeck_common::{Command, CommandVariant, Input, StateOperation, VisibilityOperation};
glib::wrapper! {
pub struct CommandConfig(ObjectSubclass<imp::CommandConfig>)
@ -17,7 +17,7 @@ impl CommandConfig {
this
}
pub(crate) fn set_input_key(&self, key: u8) {
pub(crate) fn set_input_keys(&self, key: Input) {
{
let this = imp::CommandConfig::from_instance(self);
this.input_key.set(key).unwrap();
@ -29,7 +29,7 @@ impl CommandConfig {
pub(crate) fn register_command(&self, command_state: CommandState) {
self.set_command(command_state.command());
self.set_name(command_state.name());
self.set_input_key(command_state.key());
self.set_input_keys(command_state.keys());
let stream = command_state.command_stream();
let weak = self.downgrade();
@ -384,7 +384,7 @@ mod imp {
use gtk::{prelude::*, subclass::prelude::*};
use once_cell::unsync::OnceCell;
use std::cell::RefCell;
use streamdeck_common::{Command, CommandVariant, StateOperation, VisibilityOperation};
use streamdeck_common::{Command, CommandVariant, Input, StateOperation, VisibilityOperation};
#[derive(Debug)]
pub(super) struct SwitchSceneState {
@ -411,7 +411,7 @@ mod imp {
#[derive(Debug, Default)]
pub struct CommandConfig {
pub(super) serial_number: OnceCell<String>,
pub(super) input_key: OnceCell<u8>,
pub(super) input_key: OnceCell<Input>,
pub(super) command: RefCell<Option<Command>>,
pub(super) command_stack: OnceCell<gtk::Stack>,
pub(super) command_name: OnceCell<gtk::Entry>,

View file

@ -5,6 +5,7 @@ use crate::{
use futures_util::stream::StreamExt;
use gtk::{prelude::*, subclass::prelude::*};
use marble::widgets::Dialog;
use streamdeck_common::Input;
glib::wrapper! {
pub struct CommandList(ObjectSubclass<imp::CommandList>)
@ -42,9 +43,9 @@ impl CommandList {
glib::MainContext::default().spawn_local(async move {
futures_util::pin_mut!(stream);
while let Some(key) = stream.next().await {
while let Some(keys) = stream.next().await {
if let Some(this) = weak.upgrade() {
this.remove_command(key);
this.remove_command(keys);
} else {
break;
}
@ -60,22 +61,22 @@ impl CommandList {
let serial_number = inner.serial_number.get().unwrap();
let mut rows = inner.rows.borrow_mut();
if rows.contains_key(&command.key()) {
if rows.contains_key(&command.keys()) {
return;
}
let key = command.key();
let keys = command.keys();
let row = CommandRow::new(serial_number, command);
list_box.add(&row);
rows.insert(key, row);
rows.insert(keys, row);
}
fn remove_command(&self, key: u8) {
fn remove_command(&self, keys: Input) {
let inner = imp::CommandList::from_instance(self);
let mut rows = inner.rows.borrow_mut();
if let Some(row) = rows.remove(&key) {
if let Some(row) = rows.remove(&keys) {
let list_box = inner.list_box.get().unwrap();
list_box.remove(&row);
}
@ -89,16 +90,16 @@ impl CommandList {
let command_row = row.downcast::<CommandRow>().ok()?;
let serial_number = command_row.serial_number();
let input_key = command_row.input_key();
let input_keys = command_row.input_keys();
glib::MainContext::default().spawn_local(
glib::clone!(@weak self as obj, @weak command_row => async move {
let this = imp::CommandList::from_instance(&obj);
let list_box = this.list_box.get().unwrap();
if Handle::current().unset_input(serial_number, input_key).await.is_ok() {
if Handle::current().unset_input(serial_number, input_keys.clone()).await.is_ok() {
list_box.remove(&command_row);
this.rows.borrow_mut().remove(&input_key);
this.rows.borrow_mut().remove(&input_keys);
}
obj.show_all();
@ -154,12 +155,13 @@ mod imp {
use marble::widgets::{AlertView, Dialog};
use once_cell::unsync::OnceCell;
use std::{cell::RefCell, collections::HashMap};
use streamdeck_common::Input;
#[derive(Debug, Default)]
pub struct CommandList {
pub(super) serial_number: OnceCell<String>,
pub(super) list_box: OnceCell<gtk::ListBox>,
pub(super) rows: RefCell<HashMap<u8, CommandRow>>,
pub(super) rows: RefCell<HashMap<Input, CommandRow>>,
pub(super) dialog: RefCell<Option<Dialog>>,
}

View file

@ -6,7 +6,7 @@ use futures_util::stream::StreamExt;
use gtk::{prelude::*, subclass::prelude::*};
use marble::widgets::Dialog;
use std::{cell::RefCell, rc::Rc};
use streamdeck_common::Command;
use streamdeck_common::{Command, Input};
glib::wrapper! {
pub struct CommandRow(ObjectSubclass<imp::CommandRow>)
@ -30,7 +30,7 @@ impl CommandRow {
let row_state = CommandRowState::build(&command_state.command(), command_grid);
inner.row_state.set(row_state).unwrap();
inner.input_key.set(command_state.key()).unwrap();
inner.input_key.set(command_state.keys()).unwrap();
inner
.command
.set(Rc::new(RefCell::new(command_state.command())))
@ -86,10 +86,10 @@ impl CommandRow {
serial_number.clone()
}
pub(crate) fn input_key(&self) -> u8 {
pub(crate) fn input_keys(&self) -> Input {
let this = imp::CommandRow::from_instance(self);
let input_key = this.input_key.get().unwrap();
*input_key
let input_keys = this.input_key.get().unwrap();
input_keys.clone()
}
fn present_dialog(&self) {
@ -102,7 +102,7 @@ impl CommandRow {
let command_state = if let Some(deck_state) =
Handle::current().state().deck_state(&self.serial_number())
{
if let Some(command_state) = deck_state.command_state(self.input_key()) {
if let Some(command_state) = deck_state.command_state(self.input_keys()) {
command_state
} else {
return;
@ -149,14 +149,14 @@ mod imp {
use marble::widgets::Dialog;
use once_cell::unsync::OnceCell;
use std::{cell::RefCell, rc::Rc};
use streamdeck_common::Command;
use streamdeck_common::{Command, Input};
#[derive(Debug, Default)]
pub struct CommandRow {
pub(super) row_title: OnceCell<gtk::Label>,
pub(super) command_grid: OnceCell<gtk::Grid>,
pub(super) serial_number: OnceCell<String>,
pub(super) input_key: OnceCell<u8>,
pub(super) input_key: OnceCell<Input>,
pub(super) command: OnceCell<Rc<RefCell<Command>>>,
pub(super) row_state: OnceCell<CommandRowState>,
pub(super) dialog: RefCell<Option<Dialog>>,