mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 07:33:12 +09:00
Merge pull request #956 from bbassie/feature/plugin-change-refresh
Reload the web interface when the controller's plugins change
This commit is contained in:
5 files changed
+72
-7
No files matched your search
@@ -9,8 +9,9 @@ import ErrorBoundary from "./ErrorBoundary";
|
||||
import SiteLayout from "./SiteLayout";
|
||||
import ControlContext from "./ControlContext";
|
||||
import LoginForm from "./LoginForm";
|
||||
import { pluginSetKey } from "../util/pluginSet";
|
||||
|
||||
import { Card, ConfigProvider, Spin, Typography, theme } from "antd";
|
||||
import { Button, Card, ConfigProvider, Spin, Typography, theme } from "antd";
|
||||
|
||||
const { Paragraph } = Typography;
|
||||
|
||||
@@ -28,11 +29,26 @@ function ErrorCard(props: ErrorProps) {
|
||||
}
|
||||
|
||||
|
||||
function PluginsChangedCard() {
|
||||
return <div className="login-container">
|
||||
<Card>
|
||||
<h1>Reload required</h1>
|
||||
<Paragraph>
|
||||
The plugins the controller is running have changed since this page was opened.
|
||||
So the page has been closed and must be reloaded to continue functioning as expected.
|
||||
</Paragraph>
|
||||
<Button type="primary" onClick={() => window.location.reload()}>Reload</Button>
|
||||
</Card>
|
||||
</div>;
|
||||
}
|
||||
|
||||
|
||||
type AppProps = {
|
||||
control: Control;
|
||||
};
|
||||
export default function App(props: AppProps) {
|
||||
let [connected, setConnected] = useState(false);
|
||||
let [pluginsChanged, setPluginsChanged] = useState(false);
|
||||
let [token, setToken] = useState(localStorage.getItem("controller_token") || null);
|
||||
let connector = props.control.connector;
|
||||
|
||||
@@ -73,6 +89,21 @@ export default function App(props: AppProps) {
|
||||
};
|
||||
}, [token, props.control]);
|
||||
|
||||
// The controller reports the plugins it is running in the handshake
|
||||
// This is used to detect when plugins change and a restart is required
|
||||
useEffect(() => {
|
||||
function onHello(data: any) {
|
||||
if (pluginSetKey(data.plugins) !== props.control.pluginSetKey) {
|
||||
setPluginsChanged(true);
|
||||
}
|
||||
}
|
||||
|
||||
connector.on("hello", onHello);
|
||||
return () => {
|
||||
connector.off("hello", onHello);
|
||||
};
|
||||
}, [props.control]);
|
||||
|
||||
useEffect(() => {
|
||||
if (token && !connected) {
|
||||
if (props.control.loggingOut) {
|
||||
@@ -86,7 +117,10 @@ export default function App(props: AppProps) {
|
||||
}, [token, connected]);
|
||||
|
||||
let page;
|
||||
if (connected) {
|
||||
if (pluginsChanged) {
|
||||
page = <PluginsChangedCard />;
|
||||
|
||||
} else if (connected) {
|
||||
page = <SiteLayout/>;
|
||||
|
||||
} else if (token) {
|
||||
|
||||
@@ -88,11 +88,14 @@ export default function PluginsPage() {
|
||||
if (!plugin.meta.enabled) {
|
||||
return <><InfoCircleFilled style={{ color: "#1668dc" }} /> Disabled on controller</>;
|
||||
}
|
||||
if (!plugin.meta.web.error && !control.pluginInfos.has(plugin.meta.name)) {
|
||||
return <><InfoCircleFilled style={{ color: "#1668dc" }} /> Reload page to load</>;
|
||||
}
|
||||
if (!plugin.package) {
|
||||
return <><CloseCircleFilled style={{ color: "#dc4446" }} /> Error loading module</>;
|
||||
}
|
||||
if (plugin.package.version !== plugin.meta.version) {
|
||||
return "Version missmatched";
|
||||
return <><CloseCircleFilled style={{ color: "#dc4446" }} /> Version mis-matched</>;
|
||||
}
|
||||
return plugin.package.version;
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user