Fix store display

This commit is contained in:
NGnius (Graham) 2024-02-24 22:00:09 -05:00
parent af8e8f5258
commit a5e4ce29a6
6 changed files with 177 additions and 44 deletions

63
backend/Cargo.lock generated
View file

@ -1170,7 +1170,7 @@ checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
[[package]] [[package]]
name = "powertools" name = "powertools"
version = "2.0.0-alpha3" version = "2.0.0-alpha4"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"chrono", "chrono",
@ -1295,6 +1295,20 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
[[package]]
name = "ring"
version = "0.17.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb0205304757e5d899b9c2e448b867ffd03ae7f988002e47cd24954391394d0b"
dependencies = [
"cc",
"getrandom",
"libc",
"spin",
"untrusted",
"windows-sys 0.48.0",
]
[[package]] [[package]]
name = "ron" name = "ron"
version = "0.8.1" version = "0.8.1"
@ -1332,6 +1346,18 @@ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]]
name = "rustls"
version = "0.21.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "629648aced5775d558af50b2b4c7b02983a04b312126d45eeead26e7caa498b9"
dependencies = [
"log",
"ring",
"rustls-webpki",
"sct",
]
[[package]] [[package]]
name = "rustls-pemfile" name = "rustls-pemfile"
version = "1.0.4" version = "1.0.4"
@ -1341,6 +1367,16 @@ dependencies = [
"base64 0.21.5", "base64 0.21.5",
] ]
[[package]]
name = "rustls-webpki"
version = "0.101.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765"
dependencies = [
"ring",
"untrusted",
]
[[package]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.16" version = "1.0.16"
@ -1353,6 +1389,16 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294"
[[package]]
name = "sct"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414"
dependencies = [
"ring",
"untrusted",
]
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.193" version = "1.0.193"
@ -1738,6 +1784,12 @@ dependencies = [
"subtle", "subtle",
] ]
[[package]]
name = "untrusted"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
[[package]] [[package]]
name = "ureq" name = "ureq"
version = "2.9.1" version = "2.9.1"
@ -1750,9 +1802,12 @@ dependencies = [
"flate2", "flate2",
"log", "log",
"once_cell", "once_cell",
"rustls",
"rustls-webpki",
"serde", "serde",
"serde_json", "serde_json",
"url", "url",
"webpki-roots",
] ]
[[package]] [[package]]
@ -1912,6 +1967,12 @@ version = "0.2.89"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f"
[[package]]
name = "webpki-roots"
version = "0.25.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14247bb57be4f377dfb94c72830b8ce8fc6beac03cf4bf7b9732eadd414123fc"
[[package]] [[package]]
name = "which" name = "which"
version = "4.4.2" version = "4.4.2"

View file

@ -1,6 +1,6 @@
[package] [package]
name = "powertools" name = "powertools"
version = "2.0.0-alpha3" version = "2.0.0-alpha4"
edition = "2021" edition = "2021"
authors = ["NGnius (Graham) <ngniusness@gmail.com>"] authors = ["NGnius (Graham) <ngniusness@gmail.com>"]
description = "Backend (superuser) functionality for PowerTools" description = "Backend (superuser) functionality for PowerTools"
@ -43,7 +43,7 @@ chrono = { version = "0.4", features = [ "serde" ] }
libryzenadj = { version = "0.13" } libryzenadj = { version = "0.13" }
# ureq's tls feature does not like musl targets # ureq's tls feature does not like musl targets
ureq = { version = "2", features = ["json", "gzip", "brotli", "charset"], default-features = false, optional = true } ureq = { version = "2", features = ["json", "gzip", "brotli", "charset", "tls"], default-features = false, optional = true }
clap = { version = "4.4", features = [ "derive" ] } clap = { version = "4.4", features = [ "derive" ] }

View file

@ -91,7 +91,7 @@ fn save_cache(cache: &StoreCache) {
fn get_maybe_cached(steam_app_id: u32) -> Vec<community_settings_core::v1::Metadata> { fn get_maybe_cached(steam_app_id: u32) -> Vec<community_settings_core::v1::Metadata> {
let mut cache = load_cache(); let mut cache = load_cache();
if let Some(cached_result) = cache.get(&steam_app_id) { let data = if let Some(cached_result) = cache.get(&steam_app_id) {
if cached_result.updated < (Utc::now() - MAX_CACHE_DURATION) { if cached_result.updated < (Utc::now() - MAX_CACHE_DURATION) {
// cache needs update // cache needs update
if let Ok(result) = search_by_app_id_online(steam_app_id) { if let Ok(result) = search_by_app_id_online(steam_app_id) {
@ -126,6 +126,14 @@ fn get_maybe_cached(steam_app_id: u32) -> Vec<community_settings_core::v1::Metad
} else { } else {
Vec::with_capacity(0) Vec::with_capacity(0)
} }
};
#[cfg(debug_assertions)]
{
data
}
#[cfg(not(debug_assertions))]
{
data.into_iter().filter(|meta| meta.id != "0").collect()
} }
} }

View file

@ -1,6 +1,6 @@
{ {
"name": "PowerTools", "name": "PowerTools",
"version": "2.0.0-alpha3", "version": "2.0.0-alpha4",
"description": "Power tweaks for power users", "description": "Power tweaks for power users",
"scripts": { "scripts": {
"build": "shx rm -rf dist && rollup -c", "build": "shx rm -rf dist && rollup -c",

View file

@ -355,7 +355,6 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({}) => {
backend.resolve( backend.resolve(
backend.loadGeneralSettingsVariant("please give me a new ID k thx bye" /* anything that cannot be parsed as a u64 will be set to u64::MAX, which will cause the back-end to auto-generate an ID */, name), backend.loadGeneralSettingsVariant("please give me a new ID k thx bye" /* anything that cannot be parsed as a u64 will be set to u64::MAX, which will cause the back-end to auto-generate an ID */, name),
(ok: boolean) => { (ok: boolean) => {
isVariantLoading = false;
backend.log(backend.LogLevel.Debug, "New settings variant ok? " + ok); backend.log(backend.LogLevel.Debug, "New settings variant ok? " + ok);
reload(); reload();
backend.resolve(backend.waitForComplete(), (_) => { backend.resolve(backend.waitForComplete(), (_) => {
@ -539,7 +538,7 @@ export default definePlugin((serverApi: ServerAPI) => {
ico = <span><GiFireExtinguisher /><GiFireBomb /><GiMineExplosion /></span>; ico = <span><GiFireExtinguisher /><GiFireBomb /><GiMineExplosion /></span>;
} }
//registerCallbacks(false); //registerCallbacks(false);
serverApi.routerHook.addRoute(STORE_RESULTS_URI, StoreResultsPage); serverApi.routerHook.addRoute(STORE_RESULTS_URI, () => <StoreResultsPage onNewVariant={tryNotifyProfileChange}/>);
return { return {
title: <div className={staticClasses.Title}>PowerTools</div>, title: <div className={staticClasses.Title}>PowerTools</div>,
content: <Content serverAPI={serverApi} />, content: <Content serverAPI={serverApi} />,
@ -548,7 +547,7 @@ export default definePlugin((serverApi: ServerAPI) => {
tryNotifyProfileChange = function() {}; tryNotifyProfileChange = function() {};
backend.log(backend.LogLevel.Debug, "PowerTools shutting down"); backend.log(backend.LogLevel.Debug, "PowerTools shutting down");
clearHooks(); clearHooks();
//serverApi.routerHook.removeRoute("/decky-plugin-test"); serverApi.routerHook.removeRoute(STORE_RESULTS_URI);
}, },
}; };
}); });

View file

@ -1,19 +1,20 @@
import { Component } from "react"; import { Component } from "react";
import { HiDownload } from "react-icons/hi"; import { HiDownload } from "react-icons/hi";
import { PanelSectionRow, PanelSection, Focusable, staticClasses, DialogButton } from "decky-frontend-lib"; import { PanelSectionRow, Focusable, staticClasses, DialogButton } from "decky-frontend-lib";
import * as backend from "../backend"; import * as backend from "../backend";
import { tr } from "usdpl-front"; import { tr } from "usdpl-front";
import { get_value} from "usdpl-front"; import { get_value, set_value } from "usdpl-front";
import { import {
STORE_RESULTS, STORE_RESULTS,
VARIANTS_GEN,
} from "../consts"; } from "../consts";
export class StoreResultsPage extends Component { export class StoreResultsPage extends Component<{onNewVariant: () => void}> {
constructor() { constructor(props: {onNewVariant: () => void}) {
super({}); super(props);
this.state = { this.state = {
reloadThingy: "/shrug", reloadThingy: "/shrug",
}; };
@ -25,49 +26,60 @@ export class StoreResultsPage extends Component {
if (storeItems) { if (storeItems) {
if (storeItems.length == 0) { if (storeItems.length == 0) {
backend.log(backend.LogLevel.Warn, "No store results; got array with length 0 from cache"); backend.log(backend.LogLevel.Warn, "No store results; got array with length 0 from cache");
return (<PanelSection> return (<Focusable
style={{
display: "flex",
flexWrap: "wrap",
justifyContent: "center",
rowGap: "5px",
columnGap: "5px",
maxWidth: "100%",
margin: "auto",
}}
>
{ tr("No results") /* TODO translate */ } { tr("No results") /* TODO translate */ }
</PanelSection>); </Focusable>);
} else { } else {
// TODO // TODO
return (<PanelSection> return (<Focusable
style={{
display: "flex",
flexWrap: "wrap",
justifyContent: "center",
rowGap: "5px",
columnGap: "5px",
maxWidth: "100%",
margin: "2em 0.5em",
}}
>
{ {
storeItems.map((meta: backend.StoreMetadata) => { storeItems.map((meta: backend.StoreMetadata) => (<PanelSectionRow>
<PanelSectionRow>
<Focusable style={{ <Focusable style={{
display: "flex", display: "flex",
flexDirection: "row", flexDirection: "row",
borderRadius: "2px", borderRadius: "1em",
maxWidth: "100%",
padding: "1em",
//borderColor: "#93b3c8", // light blue bg colour
//borderWidth: "0.1em",
//borderStyle: "solid",
margin: "0.5em",
}}> }}>
<DialogButton
//layout="below"
style={{
width: "56px",
display: "flex",
flexShrink: "0",
alignSelf: "center",
}}
onClick={(_: MouseEvent) => {
backend.log(backend.LogLevel.Info, "Downloading settings " + meta.name + " (" + meta.id + ")");
backend.storeDownloadById(meta.id);
}}
>
{ /* TODO make this responsive when clicked */}
<HiDownload/>
</DialogButton>
<div style={{ <div style={{
flexGrow: "1", flexGrow: "1",
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
minWidth: "0", minWidth: "0",
marginBottom: "2px", marginBottom: "2px",
padding: "0.25em",
}} }}
className={staticClasses.Text}> className={staticClasses.Text}>
<div style={{ <div style={{
display: "flex", display: "flex",
flexDirection: "row", flexDirection: "row",
minWidth: "0", minWidth: "0",
fontSize: "16px", fontSize: "24px",
padding: "0.25em",
}} }}
className={staticClasses.Text}> className={staticClasses.Text}>
{ meta.name } { meta.name }
@ -76,33 +88,86 @@ export class StoreResultsPage extends Component {
display: "flex", display: "flex",
flexDirection: "row", flexDirection: "row",
minWidth: "0", minWidth: "0",
fontSize: "12px", fontSize: "20px",
padding: "0.25em",
}} }}
className={staticClasses.Text}> className={staticClasses.Text}>
{ tr("Created by") /* TODO translate */} { meta.steam_username } { tr("Created by") /* TODO translate */} { meta.steam_username }
</div> </div>
<div> <div style={{
display: "flex",
flexDirection: "row",
minWidth: "0",
fontSize: "16px",
padding: "0.25em",
}}>
{ meta.tags.map((tag: string) => (<span style={{ { meta.tags.map((tag: string) => (<span style={{
borderRadius: "10px", borderRadius: "1em",
borderColor: "#dbe2e6", // main text colour
backgroundColor: "#dbe2e6",
color: "#1f2126", // main top image bg colour
padding: "0.25em",
margin: "0.25em",
display: "flex",
minWidth: "0",
justifyContent: "center",
fontSize: "12px",
flexGrow: "1",
}}> }}>
{tag} {tag}
</span>) </span>)
) } ) }
</div> </div>
</div> </div>
</Focusable> <DialogButton
</PanelSectionRow> //layout="below"
}) style={{
minWidth: "56px",
maxWidth: "56px",
display: "flex",
flexShrink: "0",
alignSelf: "center",
padding: "1em",
margin: "0.5em",
}}
onClick={(_: MouseEvent) => {
backend.log(backend.LogLevel.Info, "Downloading settings " + meta.name + " (" + meta.id + ")");
backend.resolve(backend.storeDownloadById(meta.id),
(variants: backend.VariantInfo[]) => {
set_value(VARIANTS_GEN, variants)
this.props.onNewVariant();
} }
</PanelSection>); );
}}
>
{ /* TODO make this responsive when clicked */}
<HiDownload style={{
height: "100%",
width: "100%",
}}/>
</DialogButton>
</Focusable>
</PanelSectionRow>))
}
</Focusable>);
} }
} else { } else {
backend.log(backend.LogLevel.Warn, "Store failed to load; got null from cache"); backend.log(backend.LogLevel.Warn, "Store failed to load; got null from cache");
// store did not pre-load when the game started // store did not pre-load when the game started
return (<PanelSection> return (<Focusable
style={{
display: "flex",
flexWrap: "wrap",
justifyContent: "center",
rowGap: "5px",
columnGap: "5px",
maxWidth: "100%",
margin: "auto",
}}
>
{ tr("Store failed to load") /* TODO translate */ } { tr("Store failed to load") /* TODO translate */ }
</PanelSection>); </Focusable>);
} }
} }
} }