Add log uploading

This commit is contained in:
marios8543
2024-02-23 22:22:10 +02:00
parent 6b5f7c8642
commit 6b7f842233
4 changed files with 30 additions and 7 deletions
@@ -24,7 +24,7 @@ const LogList: FC<{ plugin: string }> = ({ plugin }) => {
{logList.map((log_file) => (
<DialogButton
style={{ marginBottom: "0.5rem" }}
onOKActionDescription={t("LogViewer.viewLog", "View Log")}
onOKActionDescription={t("LogViewer.viewLog")}
onOKButton={() =>
showModal(
<LogViewModal name={log_file} plugin={plugin}></LogViewModal>,
@@ -1,6 +1,7 @@
import { Focusable } from "decky-frontend-lib";
import { ConfirmModal, Focusable, showModal } from "decky-frontend-lib";
import { VFC, useEffect, useState } from "react";
import { ScrollableWindowRelative } from "./ScrollableWindow";
import { t } from "i18next";
interface LogFileProps {
plugin: string;
@@ -8,14 +9,24 @@ interface LogFileProps {
closeModal?: () => void;
}
const uploadConfirmation = (name: string, plugin: string) => {
const confirmModal = <ConfirmModal onOK={() => {
window.DeckyPluginLoader.callServerMethod("upload_log", { plugin_name: plugin, log_name: name }).then((res) => {
console.log(res)
showModal(<ConfirmModal><h2>{res.result}</h2></ConfirmModal>)
})
}} strTitle={t("LogViewer.uploadConfirm")}>{t("LogViewer.uploadDisclaimer")}</ConfirmModal>
showModal(confirmModal);
}
const LogViewModal: VFC<LogFileProps> = ({ name, plugin, closeModal }) => {
const [logText, setLogText] = useState("Loading text....");
const [logText, setLogText] = useState("");
useEffect(() => {
window.DeckyPluginLoader.callServerMethod("get_plugin_log_text", {
plugin_name: plugin,
log_name: name,
}).then((text) => {
setLogText(text.result || "Error loading text");
setLogText(text.result || t("LogViewer.textError"));
});
}, []);
@@ -30,8 +41,8 @@ const LogViewModal: VFC<LogFileProps> = ({ name, plugin, closeModal }) => {
left: 0,
right: 0,
}}
onSecondaryActionDescription={"Upload Log"}
onSecondaryButton={() => console.log("Uploading...")}
onSecondaryActionDescription={t("LogViewer.uploadLog")}
onSecondaryButton={() => uploadConfirmation(name, plugin)}
>
<ScrollableWindowRelative alwaysFocus={true} onCancel={closeModal}>
<div style={{ whiteSpace: "pre-wrap", padding: "12px 0" }}>