LAUNCHER-6 fix: Errors when reading game logs
This commit is contained in:
parent
b435206799
commit
54e9b505dc
4 changed files with 24 additions and 9 deletions
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
|
|
@ -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": {},
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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.',
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue