Skip to content

Commit

Permalink
fix: now verbose logging toggle works as expected
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Parcet Gonzalez <[email protected]>
  • Loading branch information
alexpargon committed Dec 3, 2024
1 parent b0ad93c commit 79f6847
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { removeIPCs } from "./setup/configureIPCs";
import configureAutoUpdate from "./setup/configureAutoUpdate";

if (process.env.NODE_ENV === "development") {
log.transports.console.level = "debug";
log.transports.console.level = "verbose";
} else {
log.transports.console.level = "info";
}
log.initialize();
configureAutoUpdate();
Expand Down
2 changes: 2 additions & 0 deletions src/main/managers/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const schema: Schema<StorageType> = {
hideBluetoothExperimental: { type: "boolean" },
showDefaults: { type: "boolean" },
autoUpdate: { type: "boolean" },
verbose: { type: "boolean" },
version: { type: "string" },
},
default: {
Expand All @@ -25,6 +26,7 @@ const schema: Schema<StorageType> = {
hideBluetoothExperimental: false,
showDefaults: false,
autoUpdate: undefined,
verbose: false,
version: undefined,
},
required: [],
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ const English = {
language: "",
},
advanced: "Advanced",
verboseFocus: "Verbose logging",
verbose: "Verbose logging",
onlyCustom: "Use only custom layers",
allowBeta: "Show Beta firmwares",
autoUpdate: "Enable AutoUpdate",
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/modules/Settings/GeneralSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ const GeneralSettings = ({
</div>
<div className="flex items-center w-full justify-between py-2 border-b-[1px] border-gray-50 dark:border-gray-700">
<label htmlFor="verboseSwitch" className="m-0 text-sm font-semibold tracking-tight">
{i18n.preferences.verboseFocus}
{i18n.preferences.verbose}
</label>
<Switch
id="verboseSwitch"
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/types/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ export interface Preferences {
interface: string;
tooltips: Tooltips;
advanced: string;
verboseFocus: string;
verbose: string;
onlyCustom: string;
allowBeta: string;
darkMode: DarkMode;
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/types/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export interface KBDataPref {
export interface PrefState {
devTools: boolean;
advanced: boolean;
verboseFocus: boolean;
verbose: boolean;
darkMode: string;
neurons: Array<Neuron>;
selectedNeuron: number;
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/utils/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const schema: Schema<StorageType> = {
hideBluetoothExperimental: { type: "boolean" },
showDefaults: { type: "boolean" },
autoUpdate: { type: "boolean" },
verbose: { type: "boolean" },
version: { type: "string" },
},
default: {
Expand All @@ -25,6 +26,7 @@ const schema: Schema<StorageType> = {
hideBluetoothExperimental: false,
showDefaults: false,
autoUpdate: undefined,
verbose: false,
version: undefined,
},
required: [],
Expand Down
23 changes: 13 additions & 10 deletions src/renderer/views/Preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import {
IconChip,
IconWrench,
} from "@Renderer/components/atoms/icons";
import Version from "@Renderer/components/atoms/Version";

import Store from "@Renderer/utils/Store";
import { useDevice } from "@Renderer/DeviceContext";
Expand Down Expand Up @@ -131,7 +130,7 @@ const initialKBData = {
const initialPreferences = {
devTools: false,
advanced: false,
verboseFocus: false,
verbose: store.get("settings.verbose") as boolean,
darkMode: store.get("settings.darkMode") as string,
neurons: store.get("neurons") as Array<Neuron>,
selectedNeuron: 0,
Expand Down Expand Up @@ -510,10 +509,14 @@ const Preferences = (props: PreferencesProps) => {
};

const onChangeVerbose = () => {
setPreferencesState(prevState => ({
...prevState,
verboseFocus: !prevState.verboseFocus,
}));
setPreferencesState(prevState => {
log.transports.console.level = !prevState.verbose ? "verbose" : "info";
store.set("settings.verbose", !prevState.verbose);
return {
...prevState,
verbose: !prevState.verbose,
};
});
};

const openDevTool = useCallback(() => {
Expand Down Expand Up @@ -609,12 +612,13 @@ const Preferences = (props: PreferencesProps) => {
if (!darkMode) {
darkMode = "system";
}
const verbose = store.get("settings.verbose") as boolean;
setPreferencesState(prevPreferencesState => ({
...prevPreferencesState,
devTools,
darkMode,
verbose,
selectedNeuron: prevPreferencesState.neurons.indexOf(prevPreferencesState.neurons.find((x: Neuron) => x.id === NID)),
verboseFocus: true,
}));

ipcRenderer.on("opened-devtool", openDevTool);
Expand All @@ -637,7 +641,7 @@ const Preferences = (props: PreferencesProps) => {
visible: { opacity: 1, transition: { duration: 0.5 } },
};

const { neurons, selectedNeuron, darkMode, neuronID, devTools, verboseFocus } = preferencesState;
const { neurons, selectedNeuron, darkMode, neuronID, devTools, verbose } = preferencesState;
const { defaultLayer } = kbData;

if (localloading)
Expand Down Expand Up @@ -798,7 +802,7 @@ const Preferences = (props: PreferencesProps) => {
selectedNeuron={selectedNeuron}
devTools={devTools}
onChangeDevTools={onChangeDevTools}
verbose={verboseFocus}
verbose={verbose}
onChangeVerbose={onChangeVerbose}
allowBeta={allowBeta}
onChangeAllowBetas={updateAllowBetas}
Expand Down Expand Up @@ -842,7 +846,6 @@ const Preferences = (props: PreferencesProps) => {
)}
</div>
</div>
<Version />
</Tabs>
</div>
</div>
Expand Down

0 comments on commit 79f6847

Please sign in to comment.