Skip to content

Commit

Permalink
update types/packages
Browse files Browse the repository at this point in the history
  • Loading branch information
fcannizzaro committed Oct 1, 2024
1 parent 4ea862b commit e9247cf
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 185 deletions.
2 changes: 1 addition & 1 deletion plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@types/node": "22.7.4",
"@types/ws": "^8.5.12",
"property-inspector": "workspace:*",
"rollup": "^4.22.5",
"rollup": "^4.23.0",
"rollup-plugin-copy": "^3.5.0",
"rollup-plugin-swc3": "^0.11.2",
"typescript": "^5.6.2"
Expand Down
16 changes: 10 additions & 6 deletions plugin/src/actions/character/character.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Watcher } from "@/util/watcher";
import {
action, SingletonAction,
WillAppearEvent,
WillDisappearEvent
action,
KeyAction,
SingletonAction,
WillAppearEvent,
WillDisappearEvent,
} from "@elgato/streamdeck";
import { CharacterIcon } from "./character-icon";
import { State } from "@/state";
import { Action } from "@/settings";

/**
* Show character character
Expand All @@ -15,14 +16,17 @@ import { Action } from "@/settings";
export class Character extends SingletonAction {
private watcher = Watcher("state");

private async update(e: Action) {
private async update(e: KeyAction) {
const character = State.get("character");
if (!character) return;
e.setImage(await CharacterIcon(character));
}

onWillAppear(e: WillAppearEvent) {
this.watcher.start(e.action.id, () => this.update(e.action));
if (e.action.isKey()) {
this.update(e.action);
this.watcher.start(e.action.id, () => this.update(e.action as KeyAction));
}
}

onWillDisappear(e: WillDisappearEvent) {
Expand Down
20 changes: 10 additions & 10 deletions plugin/src/actions/farming-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ import { ev } from "@/util/ev";
import { State } from "@/state";
import { log } from "@/util/logger";
import {
action,
KeyUpEvent,
SingletonAction,
WillAppearEvent,
action,
KeyAction,
SingletonAction,
WillAppearEvent,
} from "@elgato/streamdeck";

type Action = KeyUpEvent["action"];

/**
* Toggle the farming mode on DIM.
*/
@action({ UUID: "com.dim.streamdeck.farming-mode" })
export class FarmingMode extends SingletonAction {
private listener: any;

private update(e: Action) {
private update(e: KeyAction) {
const farmingMode = State.get("farmingMode");
e.setState(farmingMode ? 1 : 0);
}

onWillAppear(e: WillAppearEvent) {
this.update(e.action as Action);
this.listener = () => this.update(e.action as Action);
ev.on("farmingMode", this.listener);
if (e.action.isKey()) {
this.update(e.action);
this.listener = () => this.update(e.action as KeyAction);
ev.on("farmingMode", this.listener);
}
}

onWillDisappear() {
Expand Down
25 changes: 14 additions & 11 deletions plugin/src/actions/postmaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@ import { State } from "@/state";
import { log } from "@/util/logger";
import { Watcher } from "@/util/watcher";
import {
action,
DidReceiveSettingsEvent,
KeyDownEvent,
SingletonAction,
WillAppearEvent,
WillDisappearEvent,
action,
DidReceiveSettingsEvent,
KeyAction,
KeyDownEvent,
SingletonAction,
WillAppearEvent,
WillDisappearEvent,
} from "@elgato/streamdeck";
import { PostmasterSettings, Schemas } from "@plugin/types";

type Action = KeyDownEvent["action"];

/**
* Show postmaster contents.
*/
@action({ UUID: "com.dim.streamdeck.postmaster" })
export class Postmaster extends SingletonAction {
private watcher = Watcher("state");

private async update(e: Action, settings?: PostmasterSettings) {
private async update(e: KeyAction, settings?: PostmasterSettings) {
const { type, style } =
settings ?? Schemas.postmaster(await e.getSettings());
const postmaster = State.get("postmaster");
Expand All @@ -40,11 +39,15 @@ export class Postmaster extends SingletonAction {
}

onDidReceiveSettings(e: DidReceiveSettingsEvent<PostmasterSettings>) {
this.update(e.action as Action, e.payload.settings);
if (e.action.isKey()) {
this.update(e.action, e.payload.settings);
}
}

onWillAppear(e: WillAppearEvent) {
this.watcher.start(e.action.id, () => this.update(e.action as Action));
if (e.action.isKey()) {
this.watcher.start(e.action.id, () => this.update(e.action as KeyAction));
}
}

onWillDisappear(e: WillDisappearEvent) {
Expand Down
Loading

0 comments on commit e9247cf

Please sign in to comment.