Skip to content

Commit

Permalink
Made console redirection a switch and added a switch click detection
Browse files Browse the repository at this point in the history
  • Loading branch information
OrigamingWasTaken committed Jul 2, 2024
1 parent d13f8c4 commit 446ff7d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
31 changes: 22 additions & 9 deletions frontend/src/windows/main/pages/Misc.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import AppIcon from "@/assets/play.icns";
import path from "path-browserify";
import { pathExists } from "../ts/utils";
import { enableConsoleRedirection } from "../ts/debugging";
import { disableConsoleRedirection, enableConsoleRedirection } from "../ts/debugging";
function settingsChanged(o: Object) {
saveSettings("misc", o);
Expand Down Expand Up @@ -108,12 +108,25 @@
toast.success("Console redirection enabled", { duration: 1000 });
break;
case "open_logs":
const logPath = path.join(path.dirname(await dataPath()),"appleblox.log")
if (!await pathExists(logPath)) {
toast.error("The logs file doesn't seem to exist.")
const logPath = path.join(path.dirname(await dataPath()), "appleblox.log");
if (!(await pathExists(logPath))) {
toast.error("The logs file doesn't seem to exist.");
return;
}
os.execCommand(`open "${logPath}"`).catch(console.error)
os.execCommand(`open "${logPath}"`).catch(console.error);
}
}
async function switchClicked(e: CustomEvent) {
const { id, state } = e.detail;
switch (id) {
case "redirect_console":
if (state) {
enableConsoleRedirection();
} else {
disableConsoleRedirection();
}
break;
}
}
Expand Down Expand Up @@ -196,14 +209,13 @@
"Redirects every console.log(), console.error(), etc... to the Neutralino logs. Useful for finding bugs and errors.",
id: "redirect_console",
options: {
type: "button",
style: "destructive",
type: "boolean",
state: true,
},
},
{
label: "Open logs file",
description:
"Opens the logs file in the preffered text editor.",
description: "Opens the logs file in the preffered text editor.",
id: "open_logs",
options: {
type: "button",
Expand All @@ -219,6 +231,7 @@
<Panel
panel={panelOpts}
on:buttonClicked={buttonClicked}
on:switchClicked={switchClicked}
on:settingsChanged={(e) => {
settingsChanged(e.detail);
}}
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/windows/main/pages/Settings/Panel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
export let panel: SettingsPanel;
const dispatch = createEventDispatcher<{ settingsChanged: Object; buttonClicked: string }>();
const dispatch = createEventDispatcher<{ settingsChanged: Object; buttonClicked: string; switchClicked: {id: string,state:boolean} }>();
let settingsLoaded = true;
let sections: any = {};
Expand Down Expand Up @@ -56,6 +56,7 @@
dispatch("settingsChanged", sections);
}
}
</script>

{#if settingsLoaded}
Expand Down Expand Up @@ -98,7 +99,9 @@
{: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]} />
<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 Down

0 comments on commit 446ff7d

Please sign in to comment.