-
-
Notifications
You must be signed in to change notification settings - Fork 8
Creating a New Plugin
The recommended way to create a plugin is with SwiftPM. It's up to you whether you'll want to separate your project into a library and executable or not, but for now we'll just be using a single executable.
mkdir counter-plugin
cd counter-plugin
swift package init --type executable
To use the StreamDeck library in a SwiftPM project,
add the following line to the dependencies in your Package.swift file:
.package(name: "StreamDeck", url: "https://github.com/emorydunn/StreamDeckPlugin.git", .branch("main"))Finally, include "StreamDeck" as a dependency for your executable target:
let package = Package(
// name, products, etc.
platforms: [.macOS(.v10_15)],
dependencies: [
.package(name: "StreamDeck", url: "https://github.com/emorydunn/StreamDeckPlugin.git", .branch("main")),
// other dependencies
],
targets: [
.target(name: "<command-line-tool>", dependencies: [
"StreamDeck"
]),
// other targets
]
)Add a new file to your project, we'll call it "Counter.swift", and then add our StreamDeckPlugin subclass:
import Foundation
import StreamDeck
class CounterPlugin: StreamDeckPlugin {
var counter: Int = 0
override func keyDown(action: String, context: String, device: String, payload: KeyEvent) {
counter += 1
setTitle(in: context, to: "\(counter)")
}
}In your main.swift file you'll need to register the plugin's type and call the main function to read the command line arguments from the Steam Deck application. Using the convenience method below lets the PluginManager handle the lifecycle of the plugin and keep the program running.
import Foundation
import StreamDeck
PluginManager.main(plugin: CounterPlugin.self)