Skip to content

Commit

Permalink
refactor: file structure for PI support (#26)
Browse files Browse the repository at this point in the history
* refactor: relocate target (API)

* refactor: relocate device (API)

* fix: export DeviceType enum

* refactor: relocate layout (API)

* refactor: relocate command (API)

* refactor: relocate events (API)

* refactor: relocate registration info (API)

* refactor: relocate manifest (API)

* refactor: relocate plugin files (Node.js)

* fix: remove rogue console log

* refactor: streamline accessing API types

* fix: missing exports

---------

Co-authored-by: Richard Herman <[email protected]>
  • Loading branch information
GeekyEggo and GeekyEggo authored Jan 29, 2024
1 parent ea2c3f7 commit 7ef4e8b
Show file tree
Hide file tree
Showing 86 changed files with 555 additions and 516 deletions.
4 changes: 2 additions & 2 deletions rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const banner = `/**!

const config: RollupOptions[] = [
{
input: "src/index.ts",
input: "src/plugin/index.ts",
output: {
file: "dist/index.js",
banner,
Expand All @@ -34,7 +34,7 @@ const config: RollupOptions[] = [
external: ["ws"]
},
{
input: "src/index.ts",
input: "src/plugin/index.ts",
output: {
file: "dist/index.d.ts"
},
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Schema, createGenerator } from "ts-json-schema-generator";
// Create a generator so we're able to produce multiple schemas.
const generator = createGenerator({
extraTags: ["errorMessage", "imageDimensions", "filePath"],
path: join(__dirname, "../src/index.ts"),
path: join(__dirname, "../src/plugin/index.ts"),
skipTypeCheck: true,
tsconfig: join(__dirname, "../tsconfig.json")
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeviceType } from "../device-info";
import { DeviceType } from "../device";
import type * as events from "../events";

const action = "com.elgato.test.one";
Expand Down
11 changes: 5 additions & 6 deletions src/connectivity/commands.ts → src/api/command.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { DidReceiveGlobalSettings, DidReceiveSettings } from "./events";
import { State } from "./events";
import type { FeedbackPayload } from "./layouts";
import { Target } from "./target";
import type { DidReceiveGlobalSettings, DidReceiveSettings, State } from "./events";
import type { FeedbackPayload } from "./layout";
import type { Target } from "./target";

/**
* Command sent to Stream Deck.
Expand All @@ -28,7 +27,7 @@ type CommandBase<TCommand, TPayload = void> = TPayload extends void
/**
* A {@link CommandBase} that is associated with a specific context, e.g. action.
*/
export type ContextualizedCommand<TCommand, TPayload = void> = CommandBase<TCommand, TPayload> & {
type ContextualizedCommand<TCommand, TPayload = void> = CommandBase<TCommand, TPayload> & {
/**
* Defines the context of the command, e.g. which action instance the command is intended for.
*/
Expand Down Expand Up @@ -227,7 +226,7 @@ export type SwitchToProfile = ContextualizedCommand<
export type SendToPropertyInspector = ContextualizedCommand<"sendToPropertyInspector", unknown>;

/**
* Command sent to Stream Deck.
* Command sent to Stream Deck, from the plugin.
*/
export type Command =
| GetGlobalSettings
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DeviceType } from "../device-info";
import type { DeviceType } from "../device";
import type { DeviceIdentifier } from "./device";
import type { EventIdentifier, PayloadObject } from "./index";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DeviceInfo } from "../device-info";
import type { DeviceInfo } from "../device";
import type { EventIdentifier } from "./index";

/**
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Manifest } from "../../manifest";
import type { Manifest } from "../manifest";
import type { EventIdentifier, PayloadObject } from "./index";

/**
Expand Down
9 changes: 9 additions & 0 deletions src/api/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Languages supported by Stream Deck.
*/
export const supportedLanguages = ["de", "en", "es", "fr", "ja", "zh_CN"] as const;

/**
* Language supported by Stream Deck
*/
export type Language = (typeof supportedLanguages)[number];
8 changes: 8 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export * from "./command";
export { DeviceType } from "./device";
export * from "./events";
export { Language, supportedLanguages } from "./i18n";
export * from "./layout";
export { Manifest } from "./manifest";
export { RegistrationInfo, RegistrationParameter } from "./registration";
export { Target } from "./target";
3 changes: 1 addition & 2 deletions src/connectivity/layouts.ts → src/api/layout.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint-disable jsdoc/check-tag-names */
import type { ActionClient } from "../actions/client";

/**
* Payload object, used in conjunction with {@link ActionClient.setLayout}, that enables updating items within a layout.
* Payload object used to update a Stream Deck encoder's (touchscreen) layout.
*/
export type FeedbackPayload = Record<string, Partial<Bar> | Partial<GBar> | Partial<Pixmap> | Partial<Text> | number | string>;

Expand Down
45 changes: 2 additions & 43 deletions src/manifest.ts → src/api/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
/* eslint-disable jsdoc/check-tag-names */
import { existsSync, readFileSync } from "node:fs";
import { join } from "node:path";

import { Version } from "./common/version";
import { DeviceType } from "./connectivity/device-info";
import { Controller } from "./connectivity/events";
import type { DeviceType } from "./device";
import type { Controller } from "./events";

/**
* Defines the plugin and available actions, and all information associated with them, including the plugin's entry point, all iconography, action default behavior, etc.
Expand Down Expand Up @@ -669,40 +665,3 @@ type ActionState = {
*/
TitleColor?: HexColorString;
};

let manifest: Omit<Manifest, "$schema">;
let softwareMinimumVersion: Version;

/**
* Gets the minimum version that this plugin required, as defined within the manifest.
* @returns Minimum required version.
*/
export function getSoftwareMinimumVersion(): Version {
return (softwareMinimumVersion ??= new Version(getManifest().Software.MinimumVersion));
}

/**
* Gets the manifest associated with the plugin.
* @returns The manifest.
*/
export function getManifest(): Omit<Manifest, "$schema"> {
return (manifest ??= readManifest());
}

/**
* Reads the manifest associated with the plugin from the `manifest.json` file.
* @returns The manifest.
*/
function readManifest(): Omit<Manifest, "$schema"> {
const path = join(process.cwd(), "manifest.json");
if (!existsSync(path)) {
throw new Error("Failed to read manifest.json as the file does not exist.");
}

return JSON.parse(
readFileSync(path, {
encoding: "utf-8",
flag: "r"
}).toString()
);
}
124 changes: 124 additions & 0 deletions src/api/registration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import type { DeviceInfo } from "./device";
import type { Language } from "./i18n";

/**
* Defines the type of argument supplied by Stream Deck.
*/
export enum RegistrationParameter {
/**
* Identifies the argument that specifies the web socket port that Stream Deck is listening on.
*/
Port = "-port",

/**
* Identifies the argument that supplies information about the Stream Deck and the plugin.
*/
Info = "-info",

/**
* Identifies the argument that specifies the unique identifier that can be used when registering the plugin.
*/
PluginUUID = "-pluginUUID",

/**
* Identifies the argument that specifies the event to be sent to Stream Deck as part of the registration procedure.
*/
RegisterEvent = "-registerEvent"
}

/**
* Object containing information about the Stream Deck application, the plugin, the user's operating system, user's Stream Deck devices, etc.
*/
export type RegistrationInfo = {
/**
* Stream Deck application specific information.
*/
readonly application: {
/**
* Font being used by the Stream Deck application.
*/
readonly font: string;

/**
* Users preferred language; this is used by the Stream Deck application for localization.
*/
readonly language: Language;

/**
* Operating system.
*/
readonly platform: "mac" | "windows";

/**
* Operating system version, e.g. "10" for Windows 10.
*/
readonly platformVersion: string;

/**
* Stream Deck application version.
*/
readonly version: string;
};

/**
* Collection of preferred colors used by the Stream Deck.
*/
readonly colors: {
/**
* Color that denotes the background of a button that is being moused over.
*/
readonly buttonMouseOverBackgroundColor: string;

/**
* Color that denotes the background of a pressed button.
*/
readonly buttonPressedBackgroundColor: string;

/**
* Color that denotes the border of a press button.
*/
readonly buttonPressedBorderColor: string;

/**
* Color that denotes the text of a pressed button.
*/
readonly buttonPressedTextColor: string;

/**
* Color of highlighted text.
*/
readonly highlightColor: string;
};

/**
* Pixel ratio, used to identify if the Stream Deck application is running on a high DPI screen.
*/
readonly devicePixelRatio: number;

/**
* Devices associated with the Stream Deck application; this may include devices that are not currently connected. Use `"deviceDidConnect"` event to determine which devices are active.
*/
readonly devices: [
DeviceInfo & {
/**
* Unique identifier of the Stream Deck device.
*/
readonly id: string;
}
];

/**
* Information about the plugin.
*/
readonly plugin: {
/**
* Unique identifier of the plugin, as defined by the plugin.
*/
readonly uuid: string;

/**
* Version of the plugin.
*/
readonly version: string;
};
};
File renamed without changes.
Loading

0 comments on commit 7ef4e8b

Please sign in to comment.