LAUNCHER-6 fix: Errors when reading game logs

This commit is contained in:
LynithDev 2025-01-28 11:16:46 +01:00
parent b435206799
commit 54e9b505dc
4 changed files with 24 additions and 9 deletions

View file

@ -41,7 +41,9 @@
".rustup",
".crates"
],
"rust-analyzer.procMacro.enable": true,
"rust-analyzer.procMacro.enable": false,
"rust-analyzer.procMacro.attributes.enable": false,
"rust-analyzer.check.command": "check",
"rust-analyzer.diagnostics.experimental.enable": false,
"rust-analyzer.linkedProjects": [],
"rust-analyzer.cargo.extraEnv": {},

View file

@ -10,9 +10,9 @@ import { TimeAgo } from '~ui/components/DynamicTime';
import Modal, { createModal } from '~ui/components/overlay/Modal';
import Sidebar from '~ui/components/Sidebar';
import useClusterContext from '~ui/hooks/useCluster';
import useCommand from '~ui/hooks/useCommand';
import { tryResult } from '~ui/hooks/useCommand';
import useNotifications from '~ui/hooks/useNotifications';
import { createSignal, onCleanup, onMount } from 'solid-js';
import { createResource, createSignal, onCleanup, onMount } from 'solid-js';
import { render } from 'solid-js/web';
interface ClusterGameParams extends Params {
@ -25,7 +25,14 @@ interface ClusterGameParams extends Params {
function ClusterGame() {
const [cluster] = useClusterContext();
const [params] = useSearchParams<ClusterGameParams>();
const [log] = useCommand(() => bridge.commands.getClusterLog(cluster()!.uuid, 'latest.log'));
const [log] = createResource(() => {
return tryResult(() => bridge.commands.getClusterLog(cluster()!.uuid, 'latest.log'))
.then(res => res)
.catch((err) => {
console.error(err);
return '';
});
});
const [isRunning, setIsRunning] = createSignal(true);
const notifications = useNotifications();

View file

@ -6,10 +6,10 @@ import Dropdown from '~ui/components/base/Dropdown';
import FormattedLog from '~ui/components/content/FormattedLog';
import useClusterContext from '~ui/hooks/useCluster';
import useCommand, { tryResult } from '~ui/hooks/useCommand';
import useNotifications from '~ui/hooks/useNotifications.tsx';
import useSettings from '~ui/hooks/useSettings';
import { join } from 'pathe';
import { createEffect, createSignal, For, Show, untrack } from 'solid-js';
import useNotifications from "~ui/hooks/useNotifications.tsx";
function ClusterLogs() {
const [cluster] = useClusterContext();
@ -49,9 +49,9 @@ function ClusterLogs() {
const id = await tryResult(() => bridge.commands.uploadLog(cluster()!.uuid, log));
open(`https://mclo.gs/${id}`).then(() => notifications.set("logs", {
title: "Log Uploaded",
message: "Opening in your browser."
open(`https://mclo.gs/${id}`).then(() => notifications.set('logs', {
title: 'Log Uploaded',
message: 'Opening in your browser.',
}));
}

View file

@ -247,7 +247,13 @@ pub async fn read_log_to_string(path: &std::path::PathBuf) -> crate::Result<Stri
if ext == "gz" {
result = io::read_gz_to_string(path).await?;
} else if ext == "log" || ext == "txt" {
result = io::read_to_string(path).await?;
// On Java 17 and older, UTF-8 is not the default charset (https://openjdk.org/jeps/400)
// Minecraft on Windows on older versions sometimes likes to output the log
// in an encoding other than UTF-8, which would make OneLauncher throw an error
// when attempting to read it into a String (Rust Strings are UTF-8)
// TODO: Potentially explore a better solution for non UTF-8 log reading?
let bytes = io::read(path).await?;
result = String::from_utf8_lossy(&bytes).to_string();
}
return Ok(result);