Skip to content
This repository has been archived by the owner on Mar 2, 2023. It is now read-only.

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Colucci committed Feb 28, 2019
0 parents commit e66f0f1
Show file tree
Hide file tree
Showing 23 changed files with 3,871 additions and 0 deletions.
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License

Copyright 2018 Corsair Memory, Inc

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
60 changes: 60 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

# Stream Deck Plugin Template

The `Stream Deck Plugin Template` is a boilerplate template to let you get started quickly when writing a Javascript plugin for [Stream Deck](https://developer.elgato.com/documentation/stream-deck/).

`Stream Deck Plugin Template` requires Stream Deck 4.1 or later.

# Description

`Stream Deck Plugin Template` is a complete plugin that shows you how to
- load and save settings using Stream Deck's persistent store
- setup and communicate with the Property Inspector
- pass messages directly from Property Inspector to the plugin (and vice versa)
- localize your Property Inspector's UI to another language


If you think about creating a Stream Deck plugin, it's a good idea to start with this template, because it already implements all code required to communicate from your plugin to the `Property Inspector` and to your `Stream Deck`.

There are also a bunch of utility helpers included, which makes it easy to process messages sent and received via Websockets.

Together with the [`PISamples` library](https://github.com/elgatosf/streamdeck-pisamples/) it helps you create your full-fledges Stream Deck plugin fast.

## Features:

Features:

- code written in Javascript
- cross-platform (macOS, Windows)
- localization support
- styled [Property Inspector](https://developer.elgato.com/documentation/stream-deck/sdk/property-inspector/) included
- Property Inspector contains all required boilerplate code to let you instantly work on your plugin's code.

----

# Quickstart: From Template to Plugin in under a minute

A short guide to help you getting started quickly.

### Pre-requisites

- Download or clone the template plugin.

### Do a search/replace on strings in the template's files:

Use a your utility of choice (or your terminal) to do a full string replace using:

Replace all occurences of:

`com.elgato.template` with `your.identifier.plugin`

and

`Stream Deck Template` with`Your Plugin Name`


Fire up your preferred code-editor and open `app.js`.

Remove what you don't need and start coding (e.g. in the `onKeyDown` method)

Happy coding...
Binary file added Release/com.elgato.template.streamDeckPlugin
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
143 changes: 143 additions & 0 deletions Sources/com.elgato.template.sdPlugin/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/* global $CC, Utils, $SD */

/**
* Here are a couple of wrappers we created to help ypu quickly setup
* your plugin and subscribe to events sent by Stream Deck to your plugin.
*/

/**
* The 'connected' event is sent to your plugin, after the plugin's instance
* is registered with Stream Deck software. It carries the current websocket
* and other information about the current environmet in a JSON object
* You can use it to subscribe to events you want to use in your plugin.
*/

$SD.on('connected', (jsonObj) => connected(jsonObj));

function connected(jsn) {
/** subscribe to the willAppear and other events */
$SD.on('com.elgato.template.action.willAppear', (jsonObj) => action.onWillAppear(jsonObj));
$SD.on('com.elgato.template.action.keyUp', (jsonObj) => action.onKeyUp(jsonObj));
$SD.on('com.elgato.template.action.sendToPlugin', (jsonObj) => action.onSendToPlugin(jsonObj));
$SD.on('com.elgato.template.action.didReceiveSettings', (jsonObj) => action.onDidReceiveSettings(jsonObj));
$SD.on('com.elgato.template.action.propertyInspectorDidAppear', (jsonObj) => {
console.log('%c%s', 'color: white; background: black; font-size: 13px;', '[app.js]propertyInspectorDidAppear:');
});
$SD.on('com.elgato.template.action.propertyInspectorDidDisappear', (jsonObj) => {
console.log('%c%s', 'color: white; background: red; font-size: 13px;', '[app.js]propertyInspectorDidDisappear:');
});
};

/** ACTIONS */

const action = {
settings:{},
onDidReceiveSettings: function(jsn) {
console.log('%c%s', 'color: white; background: red; font-size: 15px;', '[app.js]onDidReceiveSettings:');

this.settings = Utils.getProp(jsn, 'payload.settings', {});
this.doSomeThing(this.settings, 'onDidReceiveSettings', 'orange');

/**
* In this example we put a HTML-input element with id='mynameinput'
* into the Property Inspector's DOM. If you enter some data into that
* input-field it get's saved to Stream Deck persistently and the plugin
* will receice the updated 'didReceiveSettings' event.
* Here we look for this setting and use it to change the title of
* the key.
*/

this.setTitle(jsn);
},

/**
* The 'willAppear' event is the first event a key will receive, right before it gets
* showed on your Stream Deck and/or in Stream Deck software.
* This event is a good place to setup your plugin and look at current settings (if any),
* which are embedded in the events payload.
*/

onWillAppear: function (jsn) {
console.log("You can cache your settings in 'onWillAppear'", jsn.payload.settings);
/**
* "The willAppear event carries your saved settings (if any). You can use these settings
* to setup your plugin or save the settings for later use.
* If you want to request settings at a later time, you can do so using the
* 'getSettings' event, which will tell Stream Deck to send your data
* (in the 'didReceiceSettings above)
*
* $SD.api.getSettings(jsn.context);
*/
this.settings = jsn.payload.settings;

// nothing in the settings pre-fill something just for demonstration purposes
if (!this.settings || Object.keys(this.settings).length === 0) {
this.settings.mynameinput = 'TEMPLATE';
}
this.setTitle(jsn);
},

onKeyUp: function (jsn) {
this.doSomeThing(jsn, 'onKeyUp', 'green');
},

onSendToPlugin: function (jsn) {
/**
* this is a message sent directly from the Property Inspector
* (e.g. some value, which is not saved to settings)
* You can send this event from Property Inspector (see there for an example)
*/

const sdpi_collection = Utils.getProp(jsn, 'payload.sdpi_collection', {});
if (sdpi_collection.value && sdpi_collection.value !== undefined) {
this.doSomeThing({ [sdpi_collection.key] : sdpi_collection.value }, 'onSendToPlugin', 'fuchsia');
}
},

/**
* This snippet shows, how you could save settings persistantly to Stream Deck software
* It is not used in this example plugin.
*/

saveSettings: function (jsn, sdpi_collection) {
console.log('saveSettings:', jsn);
if (sdpi_collection.hasOwnProperty('key') && sdpi_collection.key != '') {
if (sdpi_collection.value && sdpi_collection.value !== undefined) {
this.settings[sdpi_collection.key] = sdpi_collection.value;
console.log('setSettings....', this.settings);
$SD.api.setSettings(jsn.context, this.settings);
}
}
},

/**
* Here's a quick demo-wrapper to show how you could change a key's title based on what you
* stored in settings.
* If you enter something into Property Inspector's name field (in this demo),
* it will get the title of your key.
*
* @param {JSON} jsn // the JSON object passed from Stream Deck to the plugin, which contains the plugin's context
*
*/

setTitle: function(jsn) {
if (this.settings && this.settings.hasOwnProperty('mynameinput')) {
console.log("watch the key on your StreamDeck - it got a new title...", this.settings.mynameinput);
$SD.api.setTitle(jsn.context, this.settings.mynameinput);
}
},

/**
* Finally here's a methood which gets called from various events above.
* This is just an idea how you can act on receiving some interesting message
* from Stream Deck.
*/

doSomeThing: function(inJsonData, caller, tagColor) {
console.log('%c%s', `color: white; background: ${tagColor || 'grey'}; font-size: 15px;`, `[app.js]doSomeThing from: ${caller}`);
// console.log(inJsonData);
},


};

16 changes: 16 additions & 0 deletions Sources/com.elgato.template.sdPlugin/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"Description": "Nimm diese Vorlage für dein erstes Plugin",
"Name": "Stream Deck Template",
"Category": "Templates",
"com.elgato.template.action": {
"Name": "Action",
"Tooltip": "Dies ist die einzige 'Action' in diesem Template"
},
"Localization": {
"More info": "Mehr Infos",
"Message": "Nachricht",
"Click Me": "Klicke mich",
"Button": "Taste"

}
}
15 changes: 15 additions & 0 deletions Sources/com.elgato.template.sdPlugin/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"Description": "Use this to create your own plugin",
"Name": "Stream Deck Template",
"Category": "Templates",
"com.elgato.template.action": {
"Name": "Action",
"Tooltip": "This is the only action in this plugin"
},
"Localization": {
"More info": "More info",
"Message": "Message",
"Click Me": "Click Me",
"Button": "Button"
}
}
19 changes: 19 additions & 0 deletions Sources/com.elgato.template.sdPlugin/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE HTML>
<html>

<head>
<title>com.elgato.template</title>
<meta charset="utf-8" />
<style>
canvas {
background-color:transparent;
}
</style>
</head>

<body>
<script src="propertyinspector/js/common.js"></script>
<script src="app.js"></script>
</body>

</html>
38 changes: 38 additions & 0 deletions Sources/com.elgato.template.sdPlugin/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"Actions": [
{
"Icon": "action/images/actionimage",
"Name": "Example Action",
"States": [
{
"Image": "action/images/action"
}
],
"Tooltip": "This is an example tooltip",
"UUID": "com.elgato.template.action"
}
],
"SDKVersion": 2,
"Author": "Elgato Systems",
"CodePath": "index.html",
"PropertyInspectorPath": "propertyinspector/index.html",
"Description": "Example description",
"Name": "Stream Deck Template",
"Icon": "action/images/action",
"URL": "https://www.elgato.com/en/gaming/stream-deck",
"Version": "1.0.0",
"OS": [
{
"Platform": "mac",
"MinimumVersion" : "10.11"
},
{
"Platform": "windows",
"MinimumVersion" : "10"
}
],
"Software":
{
"MinimumVersion" : "4.1"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e66f0f1

Please sign in to comment.