Skip to content

Commit

Permalink
Merge pull request #8 from dim-stream-deck/crash-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fcannizzaro authored Jan 14, 2023
2 parents 6360217 + 8725249 commit 27dbb1c
Show file tree
Hide file tree
Showing 21 changed files with 352 additions and 270 deletions.
2 changes: 1 addition & 1 deletion plugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"Author": "fcannizzaro",
"Description": "Use Destiny Item Manager from your Stream Deck! Equip Loadouts, Pull Items, Search and much more",
"Icon": "icons/pluginIcon",
"Version": "2.0.3",
"Version": "2.0.4",
"SDKVersion": 2,
"URL": "https://dimstreamdeck.vercel.app",
"uuid": "com.dim.streamdeck",
Expand Down
64 changes: 27 additions & 37 deletions property-inspector/src/actions/pull-item.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
Box,
Button,
Divider,
Group,
Expand All @@ -19,7 +20,7 @@ export default () => {
setGlobalSettings,
} = useStreamDeck();
if (!settings.altActionTrigger) {
setSettings({ altActionTrigger: "double" });
setSettings({ altActionTrigger: "long" });
}
if (!settings.altAction) {
setSettings({ altAction: "equip" });
Expand Down Expand Up @@ -52,44 +53,33 @@ export default () => {
</Button>
)}
</Group>
{/* alt action settings */}
{settings.item && (
<Paper withBorder mt={12} p={8}>
</Paper>
{/* alt action settings */}
{settings.item && (
<Box p="sm">
<Divider labelPosition="center" label="Gestures" mb="sm" />
<Group spacing="xs" mb="xs">
<Title ml={2} color="white" order={5}>
{"Equip"}
Equip
</Title>
<Tabs
variant="pills"
value={settings.altActionTrigger}
onTabChange={(altActionTrigger) =>
setSettings({ altActionTrigger })
}
>
<Tabs.List grow mt={8}>
<Tabs.Tab value="double">Double Press</Tabs.Tab>
<Tabs.Tab value="hold">Hold</Tabs.Tab>
</Tabs.List>
</Tabs>
{/* this section will be useful when theres desire for alternate actions than equip
<Divider mt={2}/>
<SegmentedControl
fullWidth
color="primary"
orientation="vertical"
value={settings.altAction}
onChange={(altAction) => setSettings({ altAction })}
data={resources.map((it) => ({
value: it.value,
label: (
<Group>
<Text ml="sm">{it.label}</Text>
</Group>
),
}))}
/> */}
</Paper>
)}
</Paper>
<Text size="sm" color="dimmed">
(Alternative Action)
</Text>
</Group>
<Tabs
variant="pills"
value={settings.altActionTrigger}
onTabChange={(altActionTrigger) =>
setSettings({ altActionTrigger })
}
>
<Tabs.List grow mt={8}>
<Tabs.Tab value="double">Double Press</Tabs.Tab>
<Tabs.Tab value="hold">Hold</Tabs.Tab>
</Tabs.List>
</Tabs>
</Box>
)}
<Divider labelPosition="center" label="Accessibility" my="sm" />
<Switch
label="(Global) Grayscale filter for not-equipped items"
Expand Down
4 changes: 2 additions & 2 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dim-stream-deck"
version = "2.0.3"
version = "2.0.4"
edition = "2021"

[dependencies]
Expand All @@ -12,7 +12,7 @@ futures = "0.3"
futures-util = "0.3"
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1.21.2", features = ["full"] }
stream_deck_sdk = { version="1.0.2", features = ["download", "images"] } # path="../../../rust/sdk"
stream_deck_sdk = { version="1.0.3", features = ["download", "images"] } # path="../../../rust/sdk"
warp = "0.3.3"
skia-safe = "0.57.0"
tokio-stream = "0.1.11"
Expand Down
8 changes: 4 additions & 4 deletions rust/src/actions/authorization.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::collections::HashMap;

use async_trait::async_trait;
use serde::Serialize;
use serde_json::{Map, Value};
use std::collections::HashMap;
use serde_json::Value;
use stream_deck_sdk::action::Action;
use stream_deck_sdk::events::events::SendToPluginEvent;
use stream_deck_sdk::stream_deck::StreamDeck;
Expand All @@ -26,7 +27,6 @@ impl Action for AuthorizationAction {
async fn on_send_to_plugin(&self, e: SendToPluginEvent, sd: StreamDeck) {
if e.payload.contains_key("resetAll") {
let mut changes: HashMap<String, Value> = HashMap::default();
changes.insert("tokens".to_string(), Value::Object(Map::new()));
changes.insert("missing".to_string(), Value::Array(vec![]));
sd.update_global_settings(changes, Some(true)).await;
return;
Expand All @@ -49,6 +49,6 @@ impl Action for AuthorizationAction {
code: e.payload.get("code").unwrap().as_str().unwrap().to_string()
}),
))
.await;
.await;
}
}
17 changes: 7 additions & 10 deletions rust/src/actions/farming_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ impl Action for FarmingModeAction {
}

async fn on_appear(&self, e: AppearEvent, sd: StreamDeck) {
let settings = sd
.global_settings::<PartialPluginSettings>()
.await
.farming_mode;
self.update(e.context, sd, settings).await;
let settings: Option<PartialPluginSettings> = sd.global_settings().await;
let farming_mode = settings.and_then(|s| s.farming_mode);

self.update(e.context, sd, farming_mode).await;
}

async fn on_key_up(&self, _e: KeyEvent, sd: StreamDeck) {
Expand All @@ -46,11 +45,9 @@ impl Action for FarmingModeAction {
async fn on_global_settings_changed(&self, _e: DidReceiveGlobalSettingsEvent, sd: StreamDeck) {
let contexts = sd.contexts_of(self.uuid()).await;
for ctx in contexts {
let settings = sd
.global_settings::<PartialPluginSettings>()
.await
.farming_mode;
self.update(ctx.clone(), sd.clone(), settings).await;
let settings: Option<PartialPluginSettings> = sd.global_settings().await;
let farming_mode = settings.and_then(|s| s.farming_mode);
self.update(ctx.clone(), sd.clone(), farming_mode).await;
}
}
}
29 changes: 19 additions & 10 deletions rust/src/actions/loadout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,32 @@ impl Action for LoadoutAction {

async fn on_appear(&self, e: AppearEvent, sd: StreamDeck) {
let settings = get_settings(e.payload.settings);
self.update(e.context, settings, sd).await;
if settings.is_some() {
self.update(e.context, settings.unwrap(), sd).await;
}
}

async fn on_key_up(&self, e: KeyEvent, sd: StreamDeck) {
let settings: LoadoutSettings = get_settings(e.payload.settings);
self.equip_loadout(sd, e.context, settings, e.is_double_tap)
.await;
let settings: Option<LoadoutSettings> = get_settings(e.payload.settings);
if settings.is_some() {
self.equip_loadout(sd, e.context, settings.unwrap(), e.is_double_tap)
.await;
}
}

async fn on_settings_changed(&self, e: DidReceiveSettingsEvent, sd: StreamDeck) {
let settings = get_settings(e.payload.settings);
self.update(e.context, settings, sd).await;
async fn on_long_press(&self, e: KeyEvent, _timeout: f32, sd: StreamDeck) {
let settings: Option<LoadoutSettings> = get_settings(e.payload.settings);
if settings.is_some() {
self.equip_loadout(sd, e.context, settings.unwrap(), true)
.await
}
}

async fn on_long_press(&self, e: KeyEvent, _timeout: f32, sd: StreamDeck) {
let settings: LoadoutSettings = get_settings(e.payload.settings);
self.equip_loadout(sd, e.context, settings, true).await;
async fn on_settings_changed(&self, e: DidReceiveSettingsEvent, sd: StreamDeck) {
let settings = get_settings(e.payload.settings);
if settings.is_some() {
self.update(e.context, settings.unwrap(), sd).await;
}
}

async fn on_send_to_plugin(&self, e: SendToPluginEvent, sd: StreamDeck) {
Expand Down
53 changes: 28 additions & 25 deletions rust/src/actions/max_power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,23 @@ struct PartialPluginSettings {
pub(crate) max_power: Option<MaxPower>,
}

fn render_action(power_type: PowerType, max_power: MaxPower) -> String {
fn render_action(power_type: PowerType, max_power: MaxPower) -> Option<String> {
let file_image = format!("./images/max-power/{:?}.png", power_type);
let (mut surface, mut paint, typeface) = prepare_render(file_image, 144);

if max_power.total.is_none() || max_power.base.is_none() || max_power.artifact.is_none() {
return None;
}

let total = max_power.total.unwrap();
let base = max_power.base.unwrap();
let artifact = max_power.artifact.unwrap();

match power_type {
PowerType::All => {
let (base, _) = prepare_text(&max_power.base, &typeface, 26.0);
let (artifact, _) = prepare_text(&max_power.artifact.to_string(), &typeface, 26.0);
let (total, (w, _)) = prepare_text(&max_power.total, &typeface, 31.0);
let (base, _) = prepare_text(&base, &typeface, 26.0);
let (artifact, _) = prepare_text(&artifact.to_string(), &typeface, 26.0);
let (total, (w, _)) = prepare_text(&total, &typeface, 31.0);

surface
.canvas()
Expand All @@ -58,9 +66,9 @@ fn render_action(power_type: PowerType, max_power: MaxPower) -> String {
}
_ => {
let (level, y) = match power_type {
PowerType::Total => (max_power.total, 126.0),
PowerType::Base => (max_power.base, 128.0),
PowerType::Artifact => (max_power.artifact.to_string(), 128.0),
PowerType::Total => (total, 126.0),
PowerType::Base => (base, 128.0),
PowerType::Artifact => (artifact.to_string(), 128.0),
_ => unreachable!(),
};
let (label, (w, _)) = prepare_text(&level, &typeface, 28.0);
Expand All @@ -70,25 +78,20 @@ fn render_action(power_type: PowerType, max_power: MaxPower) -> String {
}
}

surface_to_b64(surface)
Some(surface_to_b64(surface))
}

impl MaxPowerAction {
async fn update(&self, context: String, sd: StreamDeck, settings: Option<MaxPowerSettings>) {
let max_power = sd
.global_settings::<PartialPluginSettings>()
.await
.max_power;

if settings.is_none() || max_power.is_none() {
return;
let global = sd.global_settings::<PartialPluginSettings>().await;
if let Some(global) = global {
if let Some(max_power) = global.max_power {
let settings = settings.unwrap();
let power_type = settings.power_type.unwrap_or(PowerType::All);
let image = render_action(power_type, max_power);
sd.set_image_b64(context, image).await;
}
}

let settings = settings.unwrap();
let power_type = settings.power_type.unwrap_or(PowerType::All);

let image = render_action(power_type, max_power.unwrap());
sd.set_image_b64(context, Some(image)).await;
}
}

Expand All @@ -99,8 +102,8 @@ impl Action for MaxPowerAction {
}

async fn on_appear(&self, e: AppearEvent, sd: StreamDeck) {
let settings: MaxPowerSettings = get_settings(e.payload.settings);
self.update(e.context, sd, Some(settings)).await;
let settings: Option<MaxPowerSettings> = get_settings(e.payload.settings);
self.update(e.context, sd, settings).await;
}

async fn on_key_down(&self, e: KeyEvent, sd: StreamDeck) {
Expand All @@ -109,8 +112,8 @@ impl Action for MaxPowerAction {
}

async fn on_settings_changed(&self, e: DidReceiveSettingsEvent, sd: StreamDeck) {
let settings: MaxPowerSettings = get_settings(e.payload.settings);
self.update(e.context, sd, Some(settings)).await;
let settings: Option<MaxPowerSettings> = get_settings(e.payload.settings);
self.update(e.context, sd, settings).await;
}

async fn on_global_settings_changed(&self, _e: DidReceiveGlobalSettingsEvent, sd: StreamDeck) {
Expand Down
Loading

0 comments on commit 27dbb1c

Please sign in to comment.