Skip to content

Commit

Permalink
Added a clear logs button
Browse files Browse the repository at this point in the history
  • Loading branch information
OrigamingWasTaken committed Jul 3, 2024
1 parent b420dbc commit 6c2ff06
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 34 deletions.
48 changes: 44 additions & 4 deletions frontend/src/windows/main/pages/Misc.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -20,6 +22,8 @@
return blob;
}
let clearLogsPopup = false;
async function buttonClicked(e: CustomEvent) {
const id = e.detail;
switch (id) {
Expand Down Expand Up @@ -113,6 +117,10 @@
return;
}
os.execCommand(`open "${logPath}"`).catch(console.error);
break;
case "clear_logs":
clearLogsPopup = true;
break;
}
}
Expand All @@ -121,7 +129,6 @@
switch (id) {
case "redirect_console":
if (state) {
console.log(state)
enableConsoleRedirection();
} else {
disableConsoleRedirection();
Expand Down Expand Up @@ -222,12 +229,45 @@
style: "outline",
},
},
{
label: "Clear logs",
description: "Clears the logs file",
id: "clear_logs",
options: {
type: "button",
style: "destructive",
},
},
],
},
],
};
</script>

<AlertDialog.Root bind:open={clearLogsPopup}>
<AlertDialog.Content>
<AlertDialog.Header>
<AlertDialog.Title>Are you absolutely sure?</AlertDialog.Title>
<AlertDialog.Description>
This action cannot be undone. This will permanently delete your logs.
</AlertDialog.Description>
</AlertDialog.Header>
<AlertDialog.Footer>
<AlertDialog.Cancel>Cancel</AlertDialog.Cancel>
<AlertDialog.Action
on:click={() => {
clearLogs().then(()=>{
toast.success("The logs have been cleared")
}).
catch(() => {
toast.error("An error occured while clearing the logs");
});
}}>Continue</AlertDialog.Action
>
</AlertDialog.Footer>
</AlertDialog.Content>
</AlertDialog.Root>

<Panel
panel={panelOpts}
on:buttonClicked={buttonClicked}
Expand Down
21 changes: 15 additions & 6 deletions frontend/src/windows/main/pages/Settings/Panel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
export let panel: SettingsPanel;
const dispatch = createEventDispatcher<{ settingsChanged: Object; buttonClicked: string; switchClicked: {id: string,state:boolean} }>();
const dispatch = createEventDispatcher<{
settingsChanged: Object;
buttonClicked: string;
switchClicked: { id: string; state: boolean };
}>();
let settingsLoaded = false;
let sections: any = {};
Expand Down Expand Up @@ -56,7 +60,6 @@
dispatch("settingsChanged", sections);
}
}
</script>

{#if settingsLoaded}
Expand Down Expand Up @@ -99,9 +102,13 @@
{:else if inter.options.type == "ff_buttons_custom"}
<FfButtonsCustom />
{:else if inter.options.type === "boolean"}
<Switch class="ml-auto mr-4" bind:checked={sections[section.id][inter.id]} on:click={()=>{
dispatch("switchClicked",{id: inter.id, state: !sections[section.id][inter.id]})
}} />
<Switch
class="ml-auto mr-4"
bind:checked={sections[section.id][inter.id]}
on:click={() => {
dispatch("switchClicked", { id: inter.id, state: !sections[section.id][inter.id] });
}}
/>
{:else if inter.options.type === "string"}
<Input
class="dark:bg-neutral-900 bg-neutral-300 text-center border-none w-[250px] ml-auto mr-4 font-sans"
Expand All @@ -113,7 +120,9 @@
<Select.Trigger class="w-[180px] dark:bg-neutral-900 bg-neutral-300 ml-auto mr-4 border-none">
<Select.Value class="text-black dark:text-white" placeholder={inter.options.default.label} />
</Select.Trigger>
<Select.Content class="dark:bg-gray-900 bg-neutral-200 grayscale border-none dark:text-white text-black">
<Select.Content
class="dark:bg-gray-900 bg-neutral-200 grayscale border-none dark:text-white text-black"
>
<Select.Group>
{#each inter.options.list || [] as item}
<Select.Item value={item} label={item.label}>{item.label}</Select.Item>
Expand Down
60 changes: 37 additions & 23 deletions frontend/src/windows/main/ts/debugging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 6c2ff06

Please sign in to comment.