Skip to content

Commit

Permalink
add MOTD
Browse files Browse the repository at this point in the history
  • Loading branch information
beebls committed Nov 17, 2023
1 parent 79daa4b commit 0025c9d
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 24 deletions.
3 changes: 2 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ export async function genericGET(
fetchPath: string,
requiresAuth: boolean = false,
customAuthToken: string | undefined = undefined,
onError: () => void = () => {}
onError: () => void = () => {},
failSilently: boolean = false
) {
const { apiUrl } = globalState!.getPublicState();
function doTheFetching(authToken: string | undefined = undefined) {
Expand Down
7 changes: 7 additions & 0 deletions src/apiTypes/Motd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface Motd {
id: string;
name: string;
description: string;
date: string;
severity: "High" | "Medium" | "Low";
}
51 changes: 51 additions & 0 deletions src/components/QAMTab/MOTDDisplay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Focusable, PanelSection } from "decky-frontend-lib";
import { useEffect, useState } from "react";
import { Motd } from "../../apiTypes/Motd";
import { genericGET } from "../../api";

export function MOTDDisplay() {
const [motd, setMotd] = useState<Motd | undefined>();
useEffect(() => {
async function getMotd() {
const res = await genericGET("/motd", false);
setMotd(res);
}
getMotd();
}, []);

function getColors() {
switch (motd?.severity) {
case "High":
return { bg: "#c3010155", border: "#560d0d", text: "#fff" };
case "Medium":
return { bg: "rgba(255, 255, 0, 0.067)", border: "rgba(255, 255, 0, 0.467)", text: "#fff" };
default:
return { bg: "#3e72b055", border: "#6680a8", text: "#fff" };
}
}

if (motd && motd?.name) {
return (
<PanelSection>
<Focusable
onActivate={() => {}}
style={{
backgroundColor: getColors().bg,
color: getColors().text,
borderColor: getColors().border,
borderWidth: "0.25em",
borderStyle: "solid",
padding: "0.25em",
display: "flex",
flexDirection: "column",
}}
focusWithinClassName="gpfocuswithin"
>
<span style={{ fontWeight: "bold" }}>{motd?.name}</span>
<span style={{ fontSize: "0.75em" }}>{motd?.description}</span>
</Focusable>
</PanelSection>
);
}
return null;
}
1 change: 1 addition & 0 deletions src/components/QAMTab/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./QAMThemeToggleList";
export * from "./PresetSelectionDropdown";
export * from "./MOTDDisplay";
49 changes: 26 additions & 23 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { RiPaintFill } from "react-icons/ri";

import { ThemeManagerRouter } from "./pages/theme-manager";
import { CssLoaderContextProvider, CssLoaderState, useCssLoaderState } from "./state";
import { PresetSelectionDropdown, QAMThemeToggleList, TitleView } from "./components";
import { MOTDDisplay, PresetSelectionDropdown, QAMThemeToggleList, TitleView } from "./components";
import { ExpandedViewPage } from "./pages/theme-manager/ExpandedView";
import { Flags, Theme } from "./ThemeTypes";
import { dummyFunction, getInstalledThemes, reloadBackend } from "./python";
Expand Down Expand Up @@ -58,11 +58,13 @@ function Content() {
}, []);

return (
<PanelSection title="Themes">
{dummyFuncResult ? (
<>
<style>
{`
<>
<MOTDDisplay />
<PanelSection title="Themes">
{dummyFuncResult ? (
<>
<style>
{`
.CSSLoader_QAMTab_NavButton {
height: 2em !important;
width: 1.5em !important;
Expand All @@ -84,25 +86,26 @@ function Content() {
transform: translate(-50%, -50%);
}
`}
</style>
{localThemeList.length > 0 && <PresetSelectionDropdown />}
<QAMThemeToggleList />
</>
) : (
</style>
{localThemeList.length > 0 && <PresetSelectionDropdown />}
<QAMThemeToggleList />
</>
) : (
<PanelSectionRow>
<span>
CssLoader failed to initialize, try reloading, and if that doesn't work, try
restarting your deck.
</span>
</PanelSectionRow>
)}

<PanelSectionRow>
<span>
CssLoader failed to initialize, try reloading, and if that doesn't work, try restarting
your deck.
</span>
<ButtonItem layout="below" onClick={() => reload()}>
Refresh
</ButtonItem>
</PanelSectionRow>
)}

<PanelSectionRow>
<ButtonItem layout="below" onClick={() => reload()}>
Refresh
</ButtonItem>
</PanelSectionRow>
</PanelSection>
</PanelSection>
</>
);
}

Expand Down

0 comments on commit 0025c9d

Please sign in to comment.