From 6c2ff06a96ff4bdc3298a0cc88c220835c2ec32d Mon Sep 17 00:00:00 2001
From: OrigamingWasTaken <74014262+OrigamingWasTaken@users.noreply.github.com>
Date: Wed, 3 Jul 2024 18:08:26 +0200
Subject: [PATCH] Added a clear logs button
---
frontend/src/windows/main/pages/Misc.svelte | 48 +++++++++++++--
.../windows/main/pages/Settings/Panel.svelte | 21 +++++--
frontend/src/windows/main/ts/debugging.ts | 60 ++++++++++++-------
package.json | 2 +-
4 files changed, 97 insertions(+), 34 deletions(-)
diff --git a/frontend/src/windows/main/pages/Misc.svelte b/frontend/src/windows/main/pages/Misc.svelte
index ff67b16..140a9f9 100644
--- a/frontend/src/windows/main/pages/Misc.svelte
+++ b/frontend/src/windows/main/pages/Misc.svelte
@@ -4,13 +4,15 @@
import { dataPath, saveSettings } from "../ts/settings";
import { toast } from "svelte-sonner";
import { enableMultiInstance, parseFFlags } from "../ts/roblox";
- import { events, filesystem, os } from "@neutralinojs/lib";
+ import { filesystem, os } from "@neutralinojs/lib";
import AppIcon from "@/assets/play.icns";
import path from "path-browserify";
import { pathExists } from "../ts/utils";
- import { disableConsoleRedirection, enableConsoleRedirection } from "../ts/debugging";
+ import { clearLogs, disableConsoleRedirection, enableConsoleRedirection } from "../ts/debugging";
+ import * as AlertDialog from "$lib/components/ui/alert-dialog/index.js";
+ import { Button } from "$lib/components/ui/button/index.js";
- function settingsChanged(o: {[key: string]: any}) {
+ function settingsChanged(o: { [key: string]: any }) {
saveSettings("misc", o);
}
@@ -20,6 +22,8 @@
return blob;
}
+ let clearLogsPopup = false;
+
async function buttonClicked(e: CustomEvent) {
const id = e.detail;
switch (id) {
@@ -113,6 +117,10 @@
return;
}
os.execCommand(`open "${logPath}"`).catch(console.error);
+ break;
+ case "clear_logs":
+ clearLogsPopup = true;
+ break;
}
}
@@ -121,7 +129,6 @@
switch (id) {
case "redirect_console":
if (state) {
- console.log(state)
enableConsoleRedirection();
} else {
disableConsoleRedirection();
@@ -222,12 +229,45 @@
style: "outline",
},
},
+ {
+ label: "Clear logs",
+ description: "Clears the logs file",
+ id: "clear_logs",
+ options: {
+ type: "button",
+ style: "destructive",
+ },
+ },
],
},
],
};
+
+
+
+ Are you absolutely sure?
+
+ This action cannot be undone. This will permanently delete your logs.
+
+
+
+ Cancel
+ {
+ clearLogs().then(()=>{
+ toast.success("The logs have been cleared")
+ }).
+ catch(() => {
+ toast.error("An error occured while clearing the logs");
+ });
+ }}>Continue
+
+
+
+
();
+ const dispatch = createEventDispatcher<{
+ settingsChanged: Object;
+ buttonClicked: string;
+ switchClicked: { id: string; state: boolean };
+ }>();
let settingsLoaded = false;
let sections: any = {};
@@ -56,7 +60,6 @@
dispatch("settingsChanged", sections);
}
}
-
{#if settingsLoaded}
@@ -99,9 +102,13 @@
{:else if inter.options.type == "ff_buttons_custom"}
{:else if inter.options.type === "boolean"}
- {
- dispatch("switchClicked",{id: inter.id, state: !sections[section.id][inter.id]})
- }} />
+ {
+ dispatch("switchClicked", { id: inter.id, state: !sections[section.id][inter.id] });
+ }}
+ />
{:else if inter.options.type === "string"}
-
+
{#each inter.options.list || [] as item}
{item.label}
diff --git a/frontend/src/windows/main/ts/debugging.ts b/frontend/src/windows/main/ts/debugging.ts
index 180b9d1..98cfe0d 100644
--- a/frontend/src/windows/main/ts/debugging.ts
+++ b/frontend/src/windows/main/ts/debugging.ts
@@ -6,29 +6,32 @@ import { pathExists } from "./utils";
/** Tries to format every variable to a string */
function formatConsoleLog(...args: any[]): string {
- return `[${new Date().toLocaleTimeString()}] ` + args
- .map((arg) => {
- if (arg === null) {
- return "null";
- } else if (arg === undefined) {
- return "undefined";
- } else if (typeof arg === "string") {
- return arg;
- } else if (typeof arg === "number") {
- return arg.toString();
- } else if (typeof arg === "boolean") {
- return arg.toString();
- } else if (Array.isArray(arg)) {
- return JSON.stringify(arg);
- } else if (typeof arg === "object") {
- return JSON.stringify(arg, getCircularReplacer());
- } else if (typeof arg === "function") {
- return arg.toString();
- } else {
- return String(arg);
- }
- })
- .join(" ");
+ return (
+ `[${new Date().toLocaleTimeString()}] ` +
+ args
+ .map((arg) => {
+ if (arg === null) {
+ return "null";
+ } else if (arg === undefined) {
+ return "undefined";
+ } else if (typeof arg === "string") {
+ return arg;
+ } else if (typeof arg === "number") {
+ return arg.toString();
+ } else if (typeof arg === "boolean") {
+ return arg.toString();
+ } else if (Array.isArray(arg)) {
+ return JSON.stringify(arg);
+ } else if (typeof arg === "object") {
+ return JSON.stringify(arg, getCircularReplacer());
+ } else if (typeof arg === "function") {
+ return arg.toString();
+ } else {
+ return String(arg);
+ }
+ })
+ .join(" ")
+ );
}
function getCircularReplacer() {
@@ -44,6 +47,17 @@ function getCircularReplacer() {
};
}
+/** Clears the logs */
+export async function clearLogs() {
+ try {
+ const appleBloxDir = path.dirname(await dataPath());
+ await filesystem.writeFile(path.join(appleBloxDir, "appleblox.log"), "");
+ } catch (err) {
+ console.error("Failed to clear the logs:");
+ console.error(err);
+ }
+}
+
/** Appends a message to the log file */
async function appendLog(message: string) {
try {
diff --git a/package.json b/package.json
index 3e177f0..2e5e7c6 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "appleblox",
- "version": "0.3.1",
+ "version": "0.3.2",
"description": "MacOS roblox launcher",
"main": "frontend/src/windows/main/main.ts",
"scripts": {