Provide control at init time for web plugins

The control interface is required for adding handlers for message types
a plugin defines, but the plugins were loaded before the Control
instance was created. This meant there was no sensible way for web
plugins to register handlers for their own message types.

Move the creating of the Control instance to before plugins are loaded
and set this.control for web plugins before init is called.
This commit is contained in:
Hornwitser committed 2023-11-28 15:35:40 +01:00
1 parent 70d2b319b3
commit 8c724e3bc5
4 files changed
+17 -16

No files matched your search

+8 -6
View File
@@ -1,5 +1,6 @@
import type React from "react";
import type { AccountRole, Link, Logger, PluginWebpackEnvInfo } from "@clusterio/lib";
import type { AccountRole, Logger, PluginWebpackEnvInfo } from "@clusterio/lib";
import type { Control } from "./util/websocket";
/**
* Plugin supplied login form
@@ -77,11 +78,6 @@ export default class BaseWebPlugin {
* Contents of the plugin's package.json file
*/
package: any;
/**
* Control link to the controller, not available until the
* connect event in onControllerConnectionEvent is signaled.
*/
control?: Link;
/**
* Logger for this plugin
*
@@ -152,6 +148,12 @@ export default class BaseWebPlugin {
* The plugin's own info module
*/
public info: PluginWebpackEnvInfo,
/**
* Control link to the controller
*
* Not connected at the time init is invoked.
*/
public control: Control,
logger: Logger,
) {
this.package = packageData;