Skip to content

Commit

Permalink
Run cargo fmt. Add github workflow to validate
Browse files Browse the repository at this point in the history
  • Loading branch information
Exidex committed Feb 2, 2025
1 parent 478c72f commit 2d08307
Show file tree
Hide file tree
Showing 122 changed files with 10,062 additions and 6,543 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/format.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Format
on: [push, pull_request]
jobs:
all:
runs-on: ubuntu-latest
steps:
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
- uses: actions/checkout@v4
- name: Check format
run: cargo +nightly fmt --all -- --check --verbose
2 changes: 0 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ jobs:
github-release-id: ${{ steps.init-step.outputs.github-release-id }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-node@v4
with:
node-version: 22
Expand Down
12 changes: 5 additions & 7 deletions rust/cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::{anyhow, Context};
use anyhow::anyhow;
use anyhow::Context;
use clap::Parser;
use gauntlet_client::open_window;
use gauntlet_management_client::start_management_client;
Expand Down Expand Up @@ -52,8 +53,7 @@ pub fn init() {

#[cfg(target_os = "macos")]
fn setup_auto_launch_macos() -> anyhow::Result<()> {
let app_path = std::env::current_exe()
.context("Unable to get current_exe from env")?;
let app_path = std::env::current_exe().context("Unable to get current_exe from env")?;

// expect Gauntlet.app in path according to macos app bundle structure
let app_path_fn = || {
Expand All @@ -66,13 +66,11 @@ fn setup_auto_launch_macos() -> anyhow::Result<()> {
}
};

let app_path = app_path_fn()
.ok_or(anyhow!("Unexpected executable path: {:?}", &app_path))?;
let app_path = app_path_fn().ok_or(anyhow!("Unexpected executable path: {:?}", &app_path))?;

setup_auto_launch(app_path)
}


#[cfg(target_os = "windows")]
fn setup_auto_launch_windows() -> anyhow::Result<()> {
let app_path = std::env::current_exe()
Expand All @@ -95,4 +93,4 @@ fn setup_auto_launch(app_path: String) -> anyhow::Result<()> {
.and_then(|auto| auto.enable())?;

Ok(())
}
}
57 changes: 42 additions & 15 deletions rust/client/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ use std::fs::File;
use std::io::Write;
use std::path::Path;

use convert_case::{Case, Casing};

use gauntlet_component_model::{create_component_model, Component, ComponentName, Property, PropertyType};
use convert_case::Case;
use convert_case::Casing;
use gauntlet_component_model::create_component_model;
use gauntlet_component_model::Component;
use gauntlet_component_model::ComponentName;
use gauntlet_component_model::Property;
use gauntlet_component_model::PropertyType;

fn main() -> anyhow::Result<()> {
let out_dir = env::var("OUT_DIR")?;
Expand All @@ -20,10 +24,14 @@ fn main() -> anyhow::Result<()> {
Component::Standard { name, props, .. } => {
for prop in props {
let PropertyType::Function { arguments } = &prop.property_type else {
continue
continue;
};

output.push_str(&format!("fn create_{}_{}_event(\n", name.to_string().to_case(Case::Snake), prop.name.to_case(Case::Snake)));
output.push_str(&format!(
"fn create_{}_{}_event(\n",
name.to_string().to_case(Case::Snake),
prop.name.to_case(Case::Snake)
));
output.push_str(" widget_id: UiWidgetId,\n");

for arg in arguments {
Expand All @@ -34,29 +42,38 @@ fn main() -> anyhow::Result<()> {
output.push_str(" crate::model::UiViewEvent::View {\n");
output.push_str(" widget_id,\n");
output.push_str(&format!(" event_name: \"{}\".to_owned(),\n", prop.name));
output.push_str(" event_arguments: vec![\n",);
output.push_str(" event_arguments: vec![\n");

for arg in arguments {
match arg.property_type {
PropertyType::String => {
if arg.optional {
output.push_str(&format!(" {}.map(|{}| gauntlet_common::model::UiPropertyValue::String({})).unwrap_or_else(|| gauntlet_common::model::UiPropertyValue::Undefined),\n", arg.name, arg.name, arg.name));
} else {
output.push_str(&format!(" gauntlet_common::model::UiPropertyValue::String({}),\n", arg.name));
output.push_str(&format!(
" gauntlet_common::model::UiPropertyValue::String({}),\n",
arg.name
));
}
}
PropertyType::Number => {
if arg.optional {
output.push_str(&format!(" {}.map(|{}| gauntlet_common::model::UiPropertyValue::Number({})).unwrap_or_else(|| gauntlet_common::model::UiPropertyValue::Undefined),\n", arg.name, arg.name, arg.name));
} else {
output.push_str(&format!(" gauntlet_common::model::UiPropertyValue::Number({}),\n", arg.name));
output.push_str(&format!(
" gauntlet_common::model::UiPropertyValue::Number({}),\n",
arg.name
));
}
}
PropertyType::Boolean => {
if arg.optional {
output.push_str(&format!(" {}.map(|{}| gauntlet_common::model::UiPropertyValue::Bool({})).unwrap_or_else(|| gauntlet_common::model::UiPropertyValue::Undefined),\n", arg.name, arg.name, arg.name));
} else {
output.push_str(&format!(" gauntlet_common::model::UiPropertyValue::Bool({}),\n", arg.name));
output.push_str(&format!(
" gauntlet_common::model::UiPropertyValue::Bool({}),\n",
arg.name
));
}
}
_ => {
Expand Down Expand Up @@ -87,8 +104,18 @@ fn generate_file<P: AsRef<Path>>(path: P, text: &str) -> std::io::Result<()> {

fn generate_type(property: &Property, name: &ComponentName) -> String {
match property.optional {
true => generate_optional_type(&property.property_type, format!("{}{}", name, &property.name.to_case(Case::Pascal))),
false => generate_required_type(&property.property_type, Some(format!("{}{}", name, &property.name.to_case(Case::Pascal))))
true => {
generate_optional_type(
&property.property_type,
format!("{}{}", name, &property.name.to_case(Case::Pascal)),
)
}
false => {
generate_required_type(
&property.property_type,
Some(format!("{}{}", name, &property.name.to_case(Case::Pascal))),
)
}
}
}

Expand All @@ -107,9 +134,9 @@ fn generate_required_type(property_type: &PropertyType, union_name: Option<Strin
PropertyType::Union { .. } => {
match union_name {
None => panic!("should not be used"),
Some(union_name) => union_name
Some(union_name) => union_name,
}
},
PropertyType::Array { item } => format!("Vec<{}>", generate_required_type(item, union_name))
}
PropertyType::Array { item } => format!("Vec<{}>", generate_required_type(item, union_name)),
}
}
}
11 changes: 7 additions & 4 deletions rust/client/src/global_shortcut.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use global_hotkey::hotkey::{Code, HotKey, Modifiers};
use gauntlet_common::model::PhysicalKey;
use gauntlet_common::model::PhysicalShortcut;
use global_hotkey::hotkey::Code;
use global_hotkey::hotkey::HotKey;
use global_hotkey::hotkey::Modifiers;
use iced::futures::channel::mpsc::Sender;
use iced::futures::SinkExt;
use tokio::runtime::Handle;
use gauntlet_common::model::{PhysicalKey, PhysicalShortcut};

use crate::ui::AppMsg;

pub fn register_listener(msg_sender: Sender<AppMsg>) {
Expand All @@ -22,7 +26,6 @@ pub fn register_listener(msg_sender: Sender<AppMsg>) {
}

pub fn convert_physical_shortcut_to_hotkey(shortcut: PhysicalShortcut) -> HotKey {

let modifiers: Modifiers = {
let mut modifiers = Modifiers::empty();

Expand Down Expand Up @@ -232,4 +235,4 @@ pub fn convert_physical_shortcut_to_hotkey(shortcut: PhysicalShortcut) -> HotKey
};

HotKey::new(Some(modifiers), code)
}
}
24 changes: 11 additions & 13 deletions rust/client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
use gauntlet_common::dirs::Dirs;
use gauntlet_common::model::{BackendRequestData, BackendResponseData, UiRequestData, UiResponseData};
use gauntlet_common::model::BackendRequestData;
use gauntlet_common::model::BackendResponseData;
use gauntlet_common::model::UiRequestData;
use gauntlet_common::model::UiResponseData;
use gauntlet_common::rpc::backend_api::BackendApi;
use gauntlet_utils::channel::{RequestReceiver, RequestSender};
use gauntlet_utils::channel::RequestReceiver;
use gauntlet_utils::channel::RequestSender;

use crate::ui::GauntletComplexTheme;

pub(in crate) mod ui;
pub(in crate) mod model;
pub mod global_shortcut;
pub(crate) mod model;
pub(crate) mod ui;

pub fn start_client(
minimized: bool,
Expand All @@ -28,9 +33,7 @@ pub fn open_window() {
Ok(mut backend_api) => {
tracing::info!("Server is already running, opening window...");

backend_api.show_window()
.await
.expect("Unknown error")
backend_api.show_window().await.expect("Unknown error")
}
Err(_) => {
tracing::error!("Unable to connect to server. Please check if you have Gauntlet running on your PC")
Expand All @@ -48,15 +51,10 @@ pub fn open_settings_window() {
let result = BackendApi::new().await;

match result {
Ok(mut backend_api) => {
backend_api.show_settings_window()
.await
.expect("Unknown error")
}
Ok(mut backend_api) => backend_api.show_settings_window().await.expect("Unknown error"),
Err(_) => {
tracing::error!("Unable to connect to server. Please check if you have Gauntlet running on your PC")
}
}
})
}

8 changes: 5 additions & 3 deletions rust/client/src/model.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use gauntlet_common::model::{UiPropertyValue, UiWidgetId};
use gauntlet_common::model::UiPropertyValue;
use gauntlet_common::model::UiWidgetId;

use crate::ui::AppMsg;

#[derive(Debug, Clone)]
Expand All @@ -9,9 +11,9 @@ pub enum UiViewEvent {
event_arguments: Vec<UiPropertyValue>,
},
Open {
href: String
href: String,
},
AppEvent {
event: AppMsg
event: AppMsg,
},
}
67 changes: 51 additions & 16 deletions rust/client/src/ui/client_context.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
use std::collections::HashMap;
use std::sync::Arc;

use gauntlet_common::model::EntrypointId;
use gauntlet_common::model::PhysicalShortcut;
use gauntlet_common::model::PluginId;
use gauntlet_common::model::RootWidget;
use gauntlet_common::model::UiRenderLocation;
use gauntlet_common::model::UiWidgetId;
use iced::Task;

use crate::model::UiViewEvent;
use crate::ui::widget::{ActionPanel, ComponentWidgetEvent};
use crate::ui::widget::ActionPanel;
use crate::ui::widget::ComponentWidgetEvent;
use crate::ui::widget_container::PluginWidgetContainer;
use crate::ui::AppMsg;
use gauntlet_common::model::{EntrypointId, PhysicalShortcut, PluginId, RootWidget, UiRenderLocation, UiWidgetId};
use iced::Task;
use std::collections::HashMap;
use std::sync::Arc;

pub struct ClientContext {
inline_views: Vec<(PluginId, PluginWidgetContainer)>, // Vec to have stable ordering
Expand All @@ -27,8 +35,7 @@ impl ClientContext {
}

pub fn get_first_inline_view_container(&self) -> Option<&PluginWidgetContainer> {
self.inline_views.first()
.map(|(_, container)| container)
self.inline_views.first().map(|(_, container)| container)
}

pub fn get_first_inline_view_action_panel(&self) -> Option<ActionPanel> {
Expand All @@ -43,7 +50,8 @@ impl ClientContext {
}

pub fn get_inline_view_container(&self, plugin_id: &PluginId) -> &PluginWidgetContainer {
self.inline_views.iter()
self.inline_views
.iter()
.find(|(id, _)| id == plugin_id)
.map(|(_, container)| container)
.expect("there should always be container for plugin at this point")
Expand All @@ -54,7 +62,8 @@ impl ClientContext {
let (_, container) = &mut self.inline_views[index];
container
} else {
self.inline_views.push((plugin_id.clone(), PluginWidgetContainer::new()));
self.inline_views
.push((plugin_id.clone(), PluginWidgetContainer::new()));
let (_, container) = self.inline_views.last_mut().expect("getting just pushed item");
container
}
Expand Down Expand Up @@ -84,19 +93,37 @@ impl ClientContext {
plugin_id: &PluginId,
plugin_name: &str,
entrypoint_id: &EntrypointId,
entrypoint_name: &str
entrypoint_name: &str,
) -> AppMsg {
match render_location {
UiRenderLocation::InlineView => self.get_mut_inline_view_container(plugin_id).replace_view(container, images, plugin_id, plugin_name, entrypoint_id, entrypoint_name),
UiRenderLocation::View => self.get_mut_view_container().replace_view(container, images, plugin_id, plugin_name, entrypoint_id, entrypoint_name)
UiRenderLocation::InlineView => {
self.get_mut_inline_view_container(plugin_id).replace_view(
container,
images,
plugin_id,
plugin_name,
entrypoint_id,
entrypoint_name,
)
}
UiRenderLocation::View => {
self.get_mut_view_container().replace_view(
container,
images,
plugin_id,
plugin_name,
entrypoint_id,
entrypoint_name,
)
}
}
}

pub fn set_inline_view_shortcuts(&mut self, shortcuts: HashMap<PluginId, HashMap<String, PhysicalShortcut>>) {
self.inline_view_shortcuts = shortcuts;
}

pub fn clear_all_inline_views(&mut self) {
pub fn clear_all_inline_views(&mut self) {
self.inline_views.clear()
}

Expand All @@ -106,10 +133,18 @@ impl ClientContext {
}
}

pub fn handle_event(&mut self, render_location: UiRenderLocation, plugin_id: &PluginId, event: ComponentWidgetEvent) -> Option<UiViewEvent> {
pub fn handle_event(
&mut self,
render_location: UiRenderLocation,
plugin_id: &PluginId,
event: ComponentWidgetEvent,
) -> Option<UiViewEvent> {
match render_location {
UiRenderLocation::InlineView => self.get_mut_inline_view_container(&plugin_id).handle_event(plugin_id.clone(), event),
UiRenderLocation::View => self.get_mut_view_container().handle_event(plugin_id.clone(), event)
UiRenderLocation::InlineView => {
self.get_mut_inline_view_container(&plugin_id)
.handle_event(plugin_id.clone(), event)
}
UiRenderLocation::View => self.get_mut_view_container().handle_event(plugin_id.clone(), event),
}
}

Expand Down
Loading

0 comments on commit 2d08307

Please sign in to comment.