fix: remove useless optimizations
This commit is contained in:
parent
a17362437a
commit
e72ad1f030
@ -1,7 +1,5 @@
|
|||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
import { useTheme } from "@mui/material";
|
import { useTheme } from "@mui/material";
|
||||||
import { listen } from "@tauri-apps/api/event";
|
|
||||||
import { appWindow } from "@tauri-apps/api/window";
|
|
||||||
|
|
||||||
const maxPoint = 30;
|
const maxPoint = 30;
|
||||||
|
|
||||||
@ -72,28 +70,7 @@ const TrafficGraph = (props: Props) => {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// reduce the GPU usage when hidden
|
|
||||||
const [enablePaint, setEnablePaint] = useState(true);
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
appWindow.isVisible().then(setEnablePaint);
|
|
||||||
|
|
||||||
const unlistenBlur = listen("tauri://blur", async () => {
|
|
||||||
setEnablePaint(await appWindow.isVisible());
|
|
||||||
});
|
|
||||||
|
|
||||||
const unlistenFocus = listen("tauri://focus", async () => {
|
|
||||||
setEnablePaint(await appWindow.isVisible());
|
|
||||||
});
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
unlistenBlur.then((fn) => fn());
|
|
||||||
unlistenFocus.then((fn) => fn());
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!enablePaint) return;
|
|
||||||
|
|
||||||
let raf = 0;
|
let raf = 0;
|
||||||
const canvas = canvasRef.current!;
|
const canvas = canvasRef.current!;
|
||||||
|
|
||||||
@ -216,7 +193,7 @@ const TrafficGraph = (props: Props) => {
|
|||||||
return () => {
|
return () => {
|
||||||
cancelAnimationFrame(raf);
|
cancelAnimationFrame(raf);
|
||||||
};
|
};
|
||||||
}, [enablePaint, palette]);
|
}, [palette]);
|
||||||
|
|
||||||
return <canvas ref={canvasRef} style={{ width: "100%", height: "100%" }} />;
|
return <canvas ref={canvasRef} style={{ width: "100%", height: "100%" }} />;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user