Merge branch 'main' into decky

This commit is contained in:
NGnius (Graham) 2023-01-12 19:50:47 -05:00
commit bdf622dbb1
5 changed files with 67 additions and 37 deletions

2
backend/Cargo.lock generated
View file

@ -106,7 +106,7 @@ dependencies = [
[[package]] [[package]]
name = "fantastic-rs" name = "fantastic-rs"
version = "0.3.5" version = "0.4.0"
dependencies = [ dependencies = [
"log", "log",
"serde", "serde",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "fantastic-rs" name = "fantastic-rs"
version = "0.3.5" version = "0.4.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View file

@ -1,6 +1,6 @@
{ {
"name": "Fantastic", "name": "Fantastic",
"version": "0.3.5", "version": "0.4.0",
"description": "A template to quickly create decky plugins from scratch, based on TypeScript and webpack", "description": "A template to quickly create decky plugins from scratch, based on TypeScript and webpack",
"scripts": { "scripts": {
"build": "shx rm -rf dist && rollup -c", "build": "shx rm -rf dist && rollup -c",

View file

@ -53,6 +53,10 @@ export async function getVersion(): Promise<string> {
return (await call_backend("version", []))[0]; return (await call_backend("version", []))[0];
} }
export async function getName(): Promise<string> {
return (await call_backend("name", []))[0];
}
export async function getCurve(): Promise<{"x": number, "y": number}[]> { export async function getCurve(): Promise<{"x": number, "y": number}[]> {
return (await call_backend("get_curve", []))[0]; return (await call_backend("get_curve", []))[0];
} }

View file

@ -3,11 +3,10 @@ import {
DialogButton, DialogButton,
PanelSection, PanelSection,
PanelSectionRow, PanelSectionRow,
Field,
ServerAPI, ServerAPI,
ToggleField, ToggleField,
staticClasses, staticClasses,
gamepadDialogClasses,
joinClassNames,
} from "decky-frontend-lib"; } from "decky-frontend-lib";
import { VFC, useState } from "react"; import { VFC, useState } from "react";
import { FaFan } from "react-icons/fa"; import { FaFan } from "react-icons/fa";
@ -21,6 +20,10 @@ const POINT_SIZE = 32;
var periodicHook: any = null; var periodicHook: any = null;
var usdplReady: boolean = false; var usdplReady: boolean = false;
var name: string = "";
var version: string = "";
var egg = 0;
var curve_backup: {x: number, y: number}[] = []; var curve_backup: {x: number, y: number}[] = [];
const Content: VFC<{ serverAPI: ServerAPI }> = ({serverAPI}) => { const Content: VFC<{ serverAPI: ServerAPI }> = ({serverAPI}) => {
@ -90,7 +93,6 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({serverAPI}) => {
} }
const width: number = ctx.canvas.width; const width: number = ctx.canvas.width;
const height: number = ctx.canvas.height; const height: number = ctx.canvas.height;
ctx.strokeStyle = "#1a9fff"; ctx.strokeStyle = "#1a9fff";
ctx.fillStyle = "#1a9fff"; ctx.fillStyle = "#1a9fff";
ctx.lineWidth = 2; ctx.lineWidth = 2;
@ -106,9 +108,42 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({serverAPI}) => {
ctx.arc(90, 65, 5, 0, Math.PI * 2, true); // Right eye*/ ctx.arc(90, 65, 5, 0, Math.PI * 2, true); // Right eye*/
//ctx.beginPath(); //ctx.beginPath();
//ctx.moveTo(0, height); //ctx.moveTo(0, height);
if (interpolGlobal) {
// graph helper lines
ctx.beginPath(); ctx.beginPath();
ctx.strokeStyle = "#093455";
//ctx.fillStyle = "#093455";
const totalLines = 7;
const lineDistance = 1 / (totalLines + 1);
for (let i = 1; i <= totalLines; i++) {
ctx.moveTo(lineDistance * i * width, 0);
ctx.lineTo(lineDistance * i * width, height);
ctx.moveTo(0, lineDistance * i * height);
ctx.lineTo(width, lineDistance * i * height);
}
ctx.stroke();
//ctx.fill();
ctx.beginPath();
ctx.strokeStyle = "#1a9fff";
ctx.fillStyle = "#1a9fff";
// axis labels
ctx.textAlign = "center";
ctx.rotate(- Math.PI / 2);
ctx.fillText("Fan RPM", - height / 2, 12); // Y axis is rotated 90 degrees
ctx.rotate(Math.PI / 2);
ctx.fillText("Temperature", width / 2, height - 4);
// graph data labels
ctx.textAlign = "start"; // default
ctx.fillText("0", 2, height - 2);
ctx.fillText("100%", 2, 9);
ctx.textAlign = "right";
ctx.fillText("100°C", width - 2, height - 2);
ctx.moveTo(0, height); ctx.moveTo(0, height);
if (interpolGlobal) {
//ctx.beginPath();
for (let i = 0; i < curveGlobal.length; i++) { for (let i = 0; i < curveGlobal.length; i++) {
const canvasHeight = (1 - curveGlobal[i].y) * height; const canvasHeight = (1 - curveGlobal[i].y) * height;
const canvasWidth = curveGlobal[i].x * width; const canvasWidth = curveGlobal[i].x * width;
@ -119,11 +154,8 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({serverAPI}) => {
} }
ctx.lineTo(width, 0); ctx.lineTo(width, 0);
//ctx.moveTo(width, 0); //ctx.moveTo(width, 0);
ctx.stroke();
ctx.fill();
} else { } else {
ctx.beginPath(); //ctx.beginPath();
ctx.moveTo(0, height);
for (let i = 0; i < curveGlobal.length - 1; i++) { for (let i = 0; i < curveGlobal.length - 1; i++) {
const canvasHeight = (1 - curveGlobal[i].y) * height; const canvasHeight = (1 - curveGlobal[i].y) * height;
const canvasWidth = curveGlobal[i].x * width; const canvasWidth = curveGlobal[i].x * width;
@ -153,11 +185,10 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({serverAPI}) => {
ctx.moveTo(canvasWidth2, canvasHeight2); ctx.moveTo(canvasWidth2, canvasHeight2);
ctx.lineTo(canvasWidth2, height); ctx.lineTo(canvasWidth2, height);
} }
//ctx.moveTo(width, 0); //ctx.moveTo(width, 0);
}
ctx.stroke(); ctx.stroke();
ctx.fill(); ctx.fill();
}
console.debug("Rendered fan graph canvas frame", frameCount); console.debug("Rendered fan graph canvas frame", frameCount);
//console.debug("Drew canvas with " + curveGlobal.length.toString() + " points; " + width.toString() + "x" + height.toString()); //console.debug("Drew canvas with " + curveGlobal.length.toString() + " points; " + width.toString() + "x" + height.toString());
//ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); //ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
@ -194,35 +225,21 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({serverAPI}) => {
); );
} }
const FieldWithSeparator = joinClassNames(gamepadDialogClasses.Field, gamepadDialogClasses.WithBottomSeparatorStandard);
// TODO handle clicking on fan curve nodes // TODO handle clicking on fan curve nodes
return ( return (
<PanelSection> <PanelSection>
<PanelSectionRow> <PanelSectionRow>
<div className={FieldWithSeparator}> <Field
<div className={gamepadDialogClasses.FieldLabelRow}> label="Current Fan Speed">
<div className={gamepadDialogClasses.FieldLabel}>
Current Fan Speed
</div>
<div className={gamepadDialogClasses.FieldChildren}>
{fanRpmGlobal.toFixed(0) + " RPM"} {fanRpmGlobal.toFixed(0) + " RPM"}
</div> </Field>
</div>
</div>
</PanelSectionRow> </PanelSectionRow>
<PanelSectionRow> <PanelSectionRow>
<div className={FieldWithSeparator}> <Field
<div className={gamepadDialogClasses.FieldLabelRow}> label="Current Temperature">
<div className={gamepadDialogClasses.FieldLabel}>
Current Temperature
</div>
<div className={gamepadDialogClasses.FieldChildren}>
{temperatureGlobal.toFixed(1) + " °C"} {temperatureGlobal.toFixed(1) + " °C"}
</div> </Field>
</div>
</div>
</PanelSectionRow> </PanelSectionRow>
<PanelSectionRow> <PanelSectionRow>
<ToggleField <ToggleField
@ -265,6 +282,13 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({serverAPI}) => {
/> />
</PanelSectionRow> </PanelSectionRow>
} }
<PanelSectionRow>
<Field
label={name}
onClick={()=> { egg++; }}>
{egg % 10 == 9 ? "by NGnius" : "v" + version}
</Field>
</PanelSectionRow>
</PanelSection> </PanelSection>
); );
}; };
@ -289,6 +313,8 @@ export default definePlugin((serverApi: ServerAPI) => {
await backend.initBackend(); await backend.initBackend();
usdplReady = true; usdplReady = true;
backend.getEnabled(); backend.getEnabled();
name = await backend.getName();
version = await backend.getVersion();
})(); })();
let ico = <FaFan />; let ico = <FaFan />;