Improve persistence of state between plugin openings
This commit is contained in:
parent
2ef35ba832
commit
616f73d08c
1 changed files with 23 additions and 11 deletions
|
@ -18,6 +18,9 @@ import {Canvas} from "./canvas";
|
||||||
const POINT_SIZE = 32;
|
const POINT_SIZE = 32;
|
||||||
|
|
||||||
var periodicHook: any = null;
|
var periodicHook: any = null;
|
||||||
|
var usdplReady: boolean = false;
|
||||||
|
|
||||||
|
var curve_backup: {x: number, y: number}[] = [];
|
||||||
|
|
||||||
const Content: VFC<{ serverAPI: ServerAPI }> = ({serverAPI}) => {
|
const Content: VFC<{ serverAPI: ServerAPI }> = ({serverAPI}) => {
|
||||||
// const [result, setResult] = useState<number | undefined>();
|
// const [result, setResult] = useState<number | undefined>();
|
||||||
|
@ -39,8 +42,12 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({serverAPI}) => {
|
||||||
const [interpolGlobal, setInterpol] = useState<boolean>(false);
|
const [interpolGlobal, setInterpol] = useState<boolean>(false);
|
||||||
const [serverApiGlobal, setServerApi] = useState<ServerAPI>(serverAPI);
|
const [serverApiGlobal, setServerApi] = useState<ServerAPI>(serverAPI);
|
||||||
const [firstTime, setFirstTime] = useState<boolean>(true);
|
const [firstTime, setFirstTime] = useState<boolean>(true);
|
||||||
const [usdplReady, setUsdplReady] = useState<boolean>(false);
|
const [curveGlobal, setCurve_internal] = useState<{x: number, y: number}[]>(curve_backup);
|
||||||
const [curveGlobal, setCurve] = useState<{x: number, y: number}[]>([]);
|
|
||||||
|
const setCurve = (value: {x: number, y: number}[]) => {
|
||||||
|
setCurve_internal(value);
|
||||||
|
curve_backup = value;
|
||||||
|
}
|
||||||
|
|
||||||
const [temperatureGlobal, setTemperature] = useState<number>(-273.15);
|
const [temperatureGlobal, setTemperature] = useState<number>(-273.15);
|
||||||
const [fanRpmGlobal, setFanRpm] = useState<number>(-1337);
|
const [fanRpmGlobal, setFanRpm] = useState<number>(-1337);
|
||||||
|
@ -161,15 +168,15 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({serverAPI}) => {
|
||||||
if (firstTime) {
|
if (firstTime) {
|
||||||
setFirstTime(false);
|
setFirstTime(false);
|
||||||
setServerApi(serverAPI);
|
setServerApi(serverAPI);
|
||||||
(async function(){
|
|
||||||
await backend.initBackend();
|
|
||||||
setUsdplReady(true);
|
|
||||||
backend.resolve(backend.getEnabled(), setEnable);
|
backend.resolve(backend.getEnabled(), setEnable);
|
||||||
backend.resolve(backend.getInterpolate(), setInterpol);
|
backend.resolve(backend.getInterpolate(), setInterpol);
|
||||||
backend.resolve(backend.getCurve(), setCurve);
|
backend.resolve(backend.getCurve(), setCurve);
|
||||||
backend.resolve(backend.getTemperature(), setTemperature);
|
backend.resolve(backend.getTemperature(), setTemperature);
|
||||||
backend.resolve(backend.getFanRpm(), setFanRpm);
|
backend.resolve(backend.getFanRpm(), setFanRpm);
|
||||||
})();
|
|
||||||
|
if (periodicHook != null) {
|
||||||
|
clearInterval(periodicHook);
|
||||||
|
}
|
||||||
|
|
||||||
periodicHook = setInterval(function() {
|
periodicHook = setInterval(function() {
|
||||||
backend.resolve(backend.getTemperature(), setTemperature);
|
backend.resolve(backend.getTemperature(), setTemperature);
|
||||||
|
@ -275,6 +282,11 @@ export default definePlugin((serverApi: ServerAPI) => {
|
||||||
exact: true,
|
exact: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
(async function(){
|
||||||
|
await backend.initBackend();
|
||||||
|
usdplReady = true;
|
||||||
|
})();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: <div className={staticClasses.Title}>Fantastic</div>,
|
title: <div className={staticClasses.Title}>Fantastic</div>,
|
||||||
content: <Content serverAPI={serverApi} />,
|
content: <Content serverAPI={serverApi} />,
|
||||||
|
|
Loading…
Reference in a new issue