[WIP] Cleanup: PR cleanup - restore commented logs

This commit is contained in:
Alex P 2025-09-20 20:12:01 +00:00
parent cd87aa499c
commit b6d093f399
1 changed files with 17 additions and 18 deletions

View File

@ -7,10 +7,6 @@ import {
MAX_KEYS_PER_STEP, MAX_KEYS_PER_STEP,
} from "@/constants/macros"; } from "@/constants/macros";
import { devWarn } from '../utils/debug';
// Define the JsonRpc types for better type checking // Define the JsonRpc types for better type checking
interface JsonRpcResponse { interface JsonRpcResponse {
jsonrpc: string; jsonrpc: string;
@ -782,7 +778,7 @@ export const useNetworkStateStore = create<NetworkState>((set, get) => ({
setDhcpLeaseExpiry: (expiry: Date) => { setDhcpLeaseExpiry: (expiry: Date) => {
const lease = get().dhcp_lease; const lease = get().dhcp_lease;
if (!lease) { if (!lease) {
devWarn("No lease found"); console.warn("No lease found");
return; return;
} }
@ -845,7 +841,7 @@ export const useMacrosStore = create<MacrosState>((set, get) => ({
const { sendFn } = get(); const { sendFn } = get();
if (!sendFn) { if (!sendFn) {
// console.warn("JSON-RPC send function not available."); console.warn("JSON-RPC send function not available.");
return; return;
} }
@ -855,7 +851,7 @@ export const useMacrosStore = create<MacrosState>((set, get) => ({
await new Promise<void>((resolve, reject) => { await new Promise<void>((resolve, reject) => {
sendFn("getKeyboardMacros", {}, (response: JsonRpcResponse) => { sendFn("getKeyboardMacros", {}, (response: JsonRpcResponse) => {
if (response.error) { if (response.error) {
// console.error("Error loading macros:", response.error); console.error("Error loading macros:", response.error);
reject(new Error(response.error.message)); reject(new Error(response.error.message));
return; return;
} }
@ -879,8 +875,8 @@ export const useMacrosStore = create<MacrosState>((set, get) => ({
resolve(); resolve();
}); });
}); });
} catch { } catch (error) {
// console.error("Failed to load macros:", _error); console.error("Failed to load macros:", error);
} finally { } finally {
set({ loading: false }); set({ loading: false });
} }
@ -889,20 +885,20 @@ export const useMacrosStore = create<MacrosState>((set, get) => ({
saveMacros: async (macros: KeySequence[]) => { saveMacros: async (macros: KeySequence[]) => {
const { sendFn } = get(); const { sendFn } = get();
if (!sendFn) { if (!sendFn) {
// console.warn("JSON-RPC send function not available."); console.warn("JSON-RPC send function not available.");
throw new Error("JSON-RPC send function not available"); throw new Error("JSON-RPC send function not available");
} }
if (macros.length > MAX_TOTAL_MACROS) { if (macros.length > MAX_TOTAL_MACROS) {
// console.error(`Cannot save: exceeded maximum of ${MAX_TOTAL_MACROS} macros`); console.error(`Cannot save: exceeded maximum of ${MAX_TOTAL_MACROS} macros`);
throw new Error(`Cannot save: exceeded maximum of ${MAX_TOTAL_MACROS} macros`); throw new Error(`Cannot save: exceeded maximum of ${MAX_TOTAL_MACROS} macros`);
} }
for (const macro of macros) { for (const macro of macros) {
if (macro.steps.length > MAX_STEPS_PER_MACRO) { if (macro.steps.length > MAX_STEPS_PER_MACRO) {
// console.error( console.error(
// `Cannot save: macro "${macro.name}" exceeds maximum of ${MAX_STEPS_PER_MACRO} steps`, `Cannot save: macro "${macro.name}" exceeds maximum of ${MAX_STEPS_PER_MACRO} steps`,
// ); );
throw new Error( throw new Error(
`Cannot save: macro "${macro.name}" exceeds maximum of ${MAX_STEPS_PER_MACRO} steps`, `Cannot save: macro "${macro.name}" exceeds maximum of ${MAX_STEPS_PER_MACRO} steps`,
); );
@ -911,9 +907,9 @@ export const useMacrosStore = create<MacrosState>((set, get) => ({
for (let i = 0; i < macro.steps.length; i++) { for (let i = 0; i < macro.steps.length; i++) {
const step = macro.steps[i]; const step = macro.steps[i];
if (step.keys && step.keys.length > MAX_KEYS_PER_STEP) { if (step.keys && step.keys.length > MAX_KEYS_PER_STEP) {
// console.error( console.error(
// `Cannot save: macro "${macro.name}" step ${i + 1} exceeds maximum of ${MAX_KEYS_PER_STEP} keys`, `Cannot save: macro "${macro.name}" step ${i + 1} exceeds maximum of ${MAX_KEYS_PER_STEP} keys`,
// ); );
throw new Error( throw new Error(
`Cannot save: macro "${macro.name}" step ${i + 1} exceeds maximum of ${MAX_KEYS_PER_STEP} keys`, `Cannot save: macro "${macro.name}" step ${i + 1} exceeds maximum of ${MAX_KEYS_PER_STEP} keys`,
); );
@ -940,7 +936,7 @@ export const useMacrosStore = create<MacrosState>((set, get) => ({
}); });
if (response.error) { if (response.error) {
// console.error("Error saving macros:", response.error); console.error("Error saving macros:", response.error);
const errorMessage = const errorMessage =
typeof response.error.data === "string" typeof response.error.data === "string"
? response.error.data ? response.error.data
@ -950,6 +946,9 @@ export const useMacrosStore = create<MacrosState>((set, get) => ({
// Only update the store if the request was successful // Only update the store if the request was successful
set({ macros: macrosWithSortOrder }); set({ macros: macrosWithSortOrder });
} catch (error) {
console.error("Failed to save macros:", error);
throw error;
} finally { } finally {
set({ loading: false }); set({ loading: false });
} }