From dfb8edd0696a5f106740e5edec060a5dbb7ab3f4 Mon Sep 17 00:00:00 2001 From: LynithDev <61880709+LynithDev@users.noreply.github.com> Date: Thu, 8 Aug 2024 19:12:28 +0200 Subject: [PATCH] fix: Force image rendering with GPU on WebKitGTK fix: Pluralisation of function secondsToWords feat: Screenshot list works (needs better functionality though) --- apps/desktop/src/api/commands/cluster.rs | 13 +++ apps/desktop/src/api/commands/mod.rs | 1 + apps/desktop/tauri.conf.json | 3 +- apps/frontend/src/globals.css | 8 ++ apps/frontend/src/index.tsx | 6 +- .../ui/pages/cluster/ClusterScreenshots.tsx | 79 +++++++++++++------ apps/frontend/src/utils/index.ts | 16 ++-- 7 files changed, 90 insertions(+), 36 deletions(-) diff --git a/apps/desktop/src/api/commands/cluster.rs b/apps/desktop/src/api/commands/cluster.rs index 73ee8c25..f11a1f02 100644 --- a/apps/desktop/src/api/commands/cluster.rs +++ b/apps/desktop/src/api/commands/cluster.rs @@ -182,3 +182,16 @@ pub async fn upload_log(uuid: Uuid, log_name: String) -> Result let id = logger::upload_log(&cluster.cluster_path(), log).await?; Ok(id) } + +#[specta::specta] +#[tauri::command] +pub async fn get_screenshots(uuid: Uuid) -> Result, String> { + let cluster = onelauncher::cluster::get_by_uuid(uuid, None) + .await? + .ok_or("cluster not found")?; + + let screenshots = cluster::content::screenshots::get_screenshots(&cluster.cluster_path()) + .await?; + + Ok(screenshots) +} diff --git a/apps/desktop/src/api/commands/mod.rs b/apps/desktop/src/api/commands/mod.rs index f5ecda31..2cb9d778 100644 --- a/apps/desktop/src/api/commands/mod.rs +++ b/apps/desktop/src/api/commands/mod.rs @@ -39,6 +39,7 @@ macro_rules! collect_commands { get_cluster_logs, get_cluster_log, upload_log, + get_screenshots, // Processor get_running_clusters, get_processes_by_path, diff --git a/apps/desktop/tauri.conf.json b/apps/desktop/tauri.conf.json index c9bf4014..ab93a66c 100644 --- a/apps/desktop/tauri.conf.json +++ b/apps/desktop/tauri.conf.json @@ -58,8 +58,7 @@ "enable": true, "scope": { "allow": [ - "$DATA/OneLauncher/metadata/caches/icons/*", - "$DATA/OneLauncher/db/**", + "$DATA/OneLauncher/**", "$RESOURCE/**" ], "deny": ["$DATA/OneLauncher/db/*.stronghold"] diff --git a/apps/frontend/src/globals.css b/apps/frontend/src/globals.css index 37bb0326..d77bb742 100644 --- a/apps/frontend/src/globals.css +++ b/apps/frontend/src/globals.css @@ -24,6 +24,14 @@ img { } /* end lynith's native experience (tm) */ +/* lynith's epic webkit gtk <=2.44 fixer */ +body[data-platform="linux"] img { + /* Forces webkit gtk to use the GPU for image rendering, should speed up loading of some pages. Temporary until Tauri updates to at least 2.45 + 2.45 is the first version to use Skia for rendering, which prioritises the GPU over the CPU unlike Cairo */ + @apply transform-gpu; +} +/* end lynith's epic webkit gtk <=2.44 fixer */ + h1 { @apply text-2xl font-semibold; line-height: 1.5 !important; } h2 { @apply text-xxl font-semibold; line-height: 1.25 !important; } h3 { @apply text-xl font-medium; } diff --git a/apps/frontend/src/index.tsx b/apps/frontend/src/index.tsx index 6dcd7670..afd4411d 100644 --- a/apps/frontend/src/index.tsx +++ b/apps/frontend/src/index.tsx @@ -1,9 +1,9 @@ /* @refresh reload */ import { render } from 'solid-js/web'; -import './imports'; - import { Route, Router } from '@solidjs/router'; +import { bridge } from './imports'; + import App from './ui/App'; import HomePage from './ui/pages/Home'; import UpdatesPage from './ui/pages/Updates'; @@ -11,6 +11,8 @@ import ClusterRoot from '~ui/pages/cluster/ClusterRoot'; import SettingsRoot from '~ui/pages/settings/SettingsRoot'; import BrowserRoot from '~ui/pages/browser/BrowserRoot'; +document.body.setAttribute('data-platform', bridge.PROGRAM_INFO.platform); + render(() => ( diff --git a/apps/frontend/src/ui/pages/cluster/ClusterScreenshots.tsx b/apps/frontend/src/ui/pages/cluster/ClusterScreenshots.tsx index e8e8159d..28fb8e10 100644 --- a/apps/frontend/src/ui/pages/cluster/ClusterScreenshots.tsx +++ b/apps/frontend/src/ui/pages/cluster/ClusterScreenshots.tsx @@ -1,43 +1,74 @@ -import { For } from 'solid-js'; +import { convertFileSrc } from '@tauri-apps/api/core'; +import { open } from '@tauri-apps/plugin-shell'; +import { LinkExternal01Icon } from '@untitled-theme/icons-solid'; +import { join } from 'pathe'; +import { For, Show } from 'solid-js'; +import { bridge } from '~imports'; +import Button from '~ui/components/base/Button'; import ScrollableContainer from '~ui/components/ScrollableContainer'; import Sidebar from '~ui/components/Sidebar'; - -const list = Array(19).fill({ - date_taken: Math.floor(Date.now() / 1000), - path: 'https://www.researchgate.net/publication/301648368/figure/fig2/AS:667842240315400@1536237406360/A-screenshot-from-Minecraft-a-popular-video-game-which-poses-a-challenging-lifelong.ppm', -}); - -// TODO: Make sure the screenshots in the list are downscaled, grid / container can get laggy on low end devices -interface Screenshot { - path: string; - date_taken: number; -}; +import useClusterContext from '~ui/hooks/useCluster'; +import useCommand from '~ui/hooks/useCommand'; +import useSettingsContext from '~ui/hooks/useSettings'; function ClusterScreenshots() { + const { settings } = useSettingsContext(); + const [cluster] = useClusterContext(); + const [list] = useCommand(bridge.commands.getScreenshots, cluster()!.uuid!); + + function openFolder() { + open(join(settings().config_dir || '', 'clusters', cluster()?.path || '', 'screenshots')); + } + return (

Screenshots

-
- - {screenshot => ( - - )} - -
+ No screenshots found. Press F2 in game to take a screenshot!} + when={list() !== undefined && list()!.length > 0} + > +
+ + {screenshot => ( + + )} + +
+
+ +
+
); } export default ClusterScreenshots; -function ScreenshotEntry(props: Screenshot) { +function ScreenshotEntry(props: { path: string; cluster_path: string }) { + const { settings } = useSettingsContext(); + + const dir = () => join(settings().config_dir || '', 'clusters', props.cluster_path, 'screenshots'); + const pathSrc = () => convertFileSrc(join(dir(), props.path)); + + function onClick() { + // TODO: Probably make a cool image viewer or something + open(dir()); + } + return ( -
- {/*
*/} - {props.path} - {/*
*/} +
+ {props.path}
); } diff --git a/apps/frontend/src/utils/index.ts b/apps/frontend/src/utils/index.ts index 0f2cb4a3..998811b1 100644 --- a/apps/frontend/src/utils/index.ts +++ b/apps/frontend/src/utils/index.ts @@ -54,21 +54,21 @@ export function secondsToWords(seconds: number | bigint, plural: boolean = true) const func = (n: number) => { if (n < 60) - return `${n} seconds`; + return `${n} second`; else if (n < (60 * 60)) - return `${Math.floor(n / 60)} minutes`; + return `${Math.floor(n / 60)} minute`; else if (n < (60 * 60 * 24)) - return `${Math.floor(n / (60 * 60))} hours`; + return `${Math.floor(n / (60 * 60))} hour`; else if (n < (60 * 60 * 24 * 7)) - return `${Math.floor(n / (60 * 60 * 24))} days`; + return `${Math.floor(n / (60 * 60 * 24))} day`; else if (n < (60 * 60 * 24 * 30)) - return `${Math.floor(n / (60 * 60 * 24 * 7))} weeks`; + return `${Math.floor(n / (60 * 60 * 24 * 7))} week`; else if (n < (60 * 60 * 24 * 365)) - return `${Math.floor(n / (60 * 60 * 24 * 30))} months`; + return `${Math.floor(n / (60 * 60 * 24 * 30))} month`; else if (n < (60 * 60 * 24 * 365 * 10)) - return `${Math.floor(n / (60 * 60 * 24 * 365))} years`; + return `${Math.floor(n / (60 * 60 * 24 * 365))} year`; - return `${n} seconds`; // Hmmmmmm + return `${n} second`; // Hmmmmmm }; const str = func(n);