ChristopheCVB / TouchPortalPluginSDK

This Project is an SDK to create a Touch Portal Plugin using Java or Kotlin and Gradle
GNU General Public License v3.0
37 stars 6 forks source link

Modularization #54

Closed ChristopheCVB closed 12 months ago

ChristopheCVB commented 1 year ago

The current way of handling actions works great for small plugins, however, for larger ones, it gets a bit messy.

Add the possibility for Actions and Connectors to be classes that extend something from the SDK.

Basically an abstract class such as:

abstract class TPInvokable<T extends TouchPortalPlugin> {
  protected final T touchPortalPlugin;

  public TPInvokable(T touchPortalPlugin) {
    this.touchPortalPlugin = touchPortalPlugin;
  }

  public abstract void onInvoke();

  public abstract void onListChanged(TPListChangeMessage tpListChangeMessage);
}

Developers would then have to register those to the TouchPortalPlugin before connecting

// Plugin class
public class MyTPPlugin extends TouchPortalPlugin {}
// TPAction class
@Action(name = "Action One", categoryId = "BaseCategory")
public class ActionOne extends TPAction<MyTPPlugin> {
  @Data
  private String param1;

  public ActionOne(MyTPPlugin myTPPlugin) {
    super(myTPPlugin);
  }

  @Override
  public void onListChanged(TPListChangeMessage tpListChangeMessage) {
    // Update Specific Choices
  }

  @Override
  public void onInvoke() {
    // Do stuff
  }
}
// Later when the plugin starts
MyTPPlugin myTPPlugin = new MyTPPlugin();
myTPPlugin.register(ActionOne.class);
myTPPlugin.connectThenPairAndListen(myTPPlugin);
Pjiesco commented 1 year ago

I think this would be a really nice addition to the SDK!