GitXplorerGitXplorer
n

streamdeck-kotlin-sdk

public
5 stars
1 forks
0 issues

Commits

List of commits on branch main.
Unverified
e5a793f682b555d6412edacacea3bb8ceb619055

oups

nnathanfallet committed 7 months ago
Unverified
42a2ced59ebf2ec62cad6cd6b3d891ebf93d5467

upgrade to kaccelero

nnathanfallet committed 7 months ago
Unverified
82e8f4ed812a0d4946b26c23deb9ee6ec6a6bf4f

oups

nnathanfallet committed 8 months ago
Unverified
b2420ed607bc6ebb148a89e24dd8c01c92350c64

upgrade to kotlin 2

nnathanfallet committed 8 months ago
Verified
60961e49ac6af4d92554bc8c58f4147dadb10b98

Merge pull request #5 from TheGeekMax/main

committed 9 months ago
Unverified
b535992d0dd3bc67b6b4cccece279ed31c8f7e2e

feat: adding sent events to plugin interface

TTheGeekMax committed 9 months ago

README

The README file for this repository.

streamdeck-kotlin-sdk

License Issues Pull Requests Code Size codecov

A Kotlin SDK to create Stream Deck plugins.

Install the SDK and the Gradle plugin

Add the gradle plugin and the dependency to your build.gradle(.kts):

plugins {
    id("me.nathanfallet.streamdeck") version "1.2.0"
}

dependencies {
    implementation("me.nathanfallet.streamdeck:streamdeck-kotlin-sdk:1.2.0")
}

Usage

Create a plugin

Create a plugin is really simple, you just need to extend the Plugin class:

class MyAwesomePlugin : Plugin() {

    override fun onEnable() {
        // Setup your plugin here
    }

}

And add a main function to your application to start it:

fun main(args: Array<String>) = MyAwesomePlugin().main(args)

Update your build.gradle(.kts) to register your plugin id and main class:

application {
    mainClass = "me.nathanfallet.myawesomeplugin.MyAwesomePluginKt"
}

streamDeckPlugin {
    pluginId = "me.nathanfallet.myawesomeplugin"
}

Handle events

To handle events, create a usecase that implements IHandleEventUseCase.

There are two ways to handle events:

  • Have one usecase per event type
  • Have one usecase that routes events to other usecases

One usecase per event type

class HandleKeyDownUseCase : IHandleEventUseCase {

    override suspend fun invoke(input1: IEvent, input2: IPlugin) {
        if (input1 !is KeyDownEvent) return

        println("Key down event received for key ${input1.payload.coordinates.column}x${input1.payload.coordinates.row}")
    }

}

And register it in your plugin:

class MyAwesomePlugin : Plugin() {

    override fun onEnable() {
        // Setup your plugin here

        registerUseCase(HandleKeyDownUseCase()) // Add this
    }

}

One usecase that routes events to other usecases

class HandleEventsUseCase(
    private val handleKeyDownUseCase: HandleKeyDownUseCase,
    // Add other usecases here
) : IHandleEventUseCase {

    override suspend fun invoke(input1: IEvent, input2: IPlugin) {
        when (input1) {
            is KeyDownEvent -> handleKeyDownUseCase(input1, input2)
            else -> return // Ignore other events
        }
    }

}
class HandleKeyDownUseCase : IPairSuspendUseCase<KeyDownEvent, IPlugin> {

    override suspend fun invoke(input1: KeyDownEvent, input2: IPlugin) {
        println("Key down event received for key ${input1.payload.coordinates.column}x${input1.payload.coordinates.row}")
    }

}

And register it in your plugin:

class MyAwesomePlugin : Plugin() {

    override fun onEnable() {
        // Setup your plugin here

        registerUseCase(
            HandleEventsUseCase(
                HandleKeyDownUseCase(),
                // Add other usecases here
            )
        )
    }

}

Build the plugin

Create a manifest.json file in your src/main/resources folder (along with any other assets you want to include in the plugin, like action icons).

Thanks to the gradle plugin, you can use the ./gradlew buildStreamDeckPlugin command (or the buildStreamDeckPlugin task from your IDE) to build the build/<pluginId>.sdPlugin folder containing the plugin.

You might also need to adjust the manifest file first for it to match with your gradle project name:

{
  "CodePathMac": "bin/my-awesome-plugin",
  "CodePathWin": "bin/my-awesome-plugin.bat"
}