From 4b6e38995a36bad40718a21c1add2dd651ac1b5a Mon Sep 17 00:00:00 2001 From: Alejandro Parcet Gonzalez Date: Fri, 7 Feb 2025 15:35:37 +0100 Subject: [PATCH] fix: correctly called serialport from focus and removed unnecesary logs Signed-off-by: Alejandro Parcet Gonzalez --- src/api/colormap/index.js | 14 ---- src/api/focus/Focus.ts | 12 ++-- src/api/keymap/bazecor-keymap.ts | 71 ------------------- .../CustomModal/VersionUpdateDialog.tsx | 6 +- src/renderer/views/MacroEditor.tsx | 6 +- 5 files changed, 10 insertions(+), 99 deletions(-) diff --git a/src/api/colormap/index.js b/src/api/colormap/index.js index 148fb1f6d..fd8b59217 100644 --- a/src/api/colormap/index.js +++ b/src/api/colormap/index.js @@ -134,18 +134,4 @@ export default class Colormap { const args = this._flatten(colormap).map(v => v.toString()); return await s.request("colormap.map", ...args); } - - // async focus(s, palette, colormap) { - // if (!palette && !colormap) { - // return this._pull(s); - // } - - // if (palette) await this._updatePalette(s, palette); - // if (colormap) await this._updateColormap(s, colormap); - // } } - -// const focus = Focus.getInstance(); -// focus.addCommands({ colormap: new Colormap() }); -// focus.addMethod("setLayerSize", "colormap"); -// focus.addMethod("setLEDMode", "colormap"); diff --git a/src/api/focus/Focus.ts b/src/api/focus/Focus.ts index 1d42f5431..f7da3ec42 100644 --- a/src/api/focus/Focus.ts +++ b/src/api/focus/Focus.ts @@ -19,14 +19,10 @@ */ import log from "electron-log/renderer"; import { spawn } from "child_process"; -import type { SerialPortOpenOptions } from "serialport"; -import { SerialPort } from "serialport"; +import type { SerialPort, SerialPortOpenOptions } from "serialport"; import type { AutoDetectTypes, PortInfo } from "@serialport/bindings-cpp"; -import { DelimiterParser } from "@serialport/parser-delimiter"; import { DygmaDeviceType } from "@Renderer/types/dygmaDefs"; -import { VirtualType } from "@Renderer/types/virtual"; import { delay } from "../../main/utils/delay"; -import { ctx } from "./Focus.ctx"; // TODO: any reason we can't import directly? const sp = eval('require("serialport")'); @@ -55,14 +51,14 @@ export class Focus { commands: CommandOverrides = { help: this._help }; protected async listSerialPorts(): Promise { - return SerialPort.list(); + return sp.SerialPort.list(); } protected createSerialPort( options: SerialPortOpenOptions, openCallback?: ErrorCallback, ): SerialPort { - return new SerialPort(options, openCallback); + return new sp.SerialPort(options, openCallback); } async find(...devices: DygmaDeviceType[]) { @@ -92,7 +88,7 @@ export class Focus { callbacks: Array<(value: unknown) => void>; supportedCommands: Array; _port: SerialPort; - parser: DelimiterParser; + parser: typeof DelimiterParser; async open(path: string, info: DygmaDeviceType): Promise { if (this._port !== undefined && this._port.isOpen === false) { diff --git a/src/api/keymap/bazecor-keymap.ts b/src/api/keymap/bazecor-keymap.ts index e52f5c937..41fb87302 100644 --- a/src/api/keymap/bazecor-keymap.ts +++ b/src/api/keymap/bazecor-keymap.ts @@ -60,77 +60,6 @@ class Keymap { for (let i = 0; i < a.length; i += chunkSize) R.push(a.slice(i, i + chunkSize)); return R; } - - // async focus(s: Focus, keymap: KeymapType) { - // if (keymap && keymap.custom && keymap.custom.length > 0) { - // const flatten = (arr: any) => [].concat(...arr); - - // if (this.legacyInterface) { - // const args = flatten(keymap.default.concat(keymap.custom)).map(k => this.db.serialize(k)); - - // return (await s.request("keymap.map", ...args)) as string; - // } - - // const args = flatten(keymap.custom).map(k => this.db.serialize(k)); - - // await s.request("keymap.onlyCustom", keymap.onlyCustom ? "1" : "0"); - // return s.request("keymap.custom", ...args); - // } - // let defaults: string; - // let custom: string; - // let onlyCustom: boolean; - - // if (!this.legacyInterface) { - // defaults = (await s.request("keymap.default")) as string; - // custom = (await s.request("keymap.custom")) as string; - // onlyCustom = Boolean(parseInt(await s.request("keymap.onlyCustom"), 10)) as boolean; - // } - - // if (!defaults && !custom) { - // const localKeymap = ((await s.request("keymap.map")) as string).split(" ").filter(v => v.length > 0); - // const roLayers = parseInt((await s.request("keymap.roLayers")) || "0", 10); - - // defaults = localKeymap.slice(0, this._layerSize * roLayers).join(" "); - // custom = localKeymap.slice(this._layerSize * roLayers, localKeymap.length).join(" "); - - // onlyCustom = false; - // this.legacyInterface = true; - // } - // const defaultKeymap = defaults - // .split(" ") - // .filter(v => v.length > 0) - // .map(k => this.db.parse(parseInt(k, 10))); - // const customKeymap = custom - // .split(" ") - // .filter(v => v.length > 0) - // .map(k => this.db.parse(parseInt(k, 10))); - - // if (customKeymap.length === 0) { - // onlyCustom = false; - // } - - // return { - // onlyCustom, - // custom: this._chunk(customKeymap, this._layerSize), - // default: this._chunk(defaultKeymap, this._layerSize), - // }; - // } } -// class OnlyCustom { -// async focus(s, onlyCustom) { -// if (onlyCustom === undefined) { -// return Boolean(parseInt(await s.request("keymap.onlyCustom"))); -// } - -// return await s.request("keymap.onlyCustom", onlyCustom ? "1" : "0"); -// } -// } - -// const focus = Focus.getInstance(); -// focus.addCommands({ -// keymap: new Keymap(), -// }); -// focus.addMethod("setLayerSize", "keymap"); - export default Keymap; diff --git a/src/renderer/components/molecules/CustomModal/VersionUpdateDialog.tsx b/src/renderer/components/molecules/CustomModal/VersionUpdateDialog.tsx index 9d615e91b..7ac74a54d 100644 --- a/src/renderer/components/molecules/CustomModal/VersionUpdateDialog.tsx +++ b/src/renderer/components/molecules/CustomModal/VersionUpdateDialog.tsx @@ -17,7 +17,7 @@ import React, { useEffect, useState } from "react"; import { Octokit } from "@octokit/core"; -import log from "electron-log/renderer"; +// import log from "electron-log/renderer"; import SemVer from "semver"; import parse, { domToReact } from "html-react-parser"; @@ -111,14 +111,14 @@ export function VersionUpdateDialog(props: VersionUpdateProps) { format: "full", }, }); - log.info("Testing", GHdata); + // log.info("Testing", GHdata); GHdata.data.forEach(release => { // eslint-disable-next-line @typescript-eslint/naming-convention const { prerelease, name, published_at, body_html, tag_name } = release; const newRelease = { name, version: tag_name, date: published_at, content: body_html }; if (!prerelease) releases.push(newRelease); }); - log.info("Data from Dialog: ", releases, version, oldVersion); + // log.info("Data from Dialog: ", releases, version, oldVersion); const parsedData = releases.filter(r => oldVersion ? SemVer.compare(r.version, oldVersion) > 0 && SemVer.compare(r.version, version) <= 0 diff --git a/src/renderer/views/MacroEditor.tsx b/src/renderer/views/MacroEditor.tsx index 2ea055fa9..e1b6ab03b 100644 --- a/src/renderer/views/MacroEditor.tsx +++ b/src/renderer/views/MacroEditor.tsx @@ -273,7 +273,7 @@ function MacroEditor(props: MacroEditorProps) { const { selectedList, listToDelete, listToDeleteS, listToDeleteM, keymap, superkeys } = state; const { startContext } = props; let macros = localstate ? localstate.futureMacros : state.futureMacros; - log.info("Checking list to delete macros", listToDeleteM, macros); + // log.info("Checking list to delete macros", listToDeleteM, macros); for (let i = 0; i < listToDelete.length; i += 1) { if (listToDelete[i].newKey === -1) { keymap.custom[listToDelete[i].layer][listToDelete[i].pos] = keymapDB.parse( @@ -311,7 +311,7 @@ function MacroEditor(props: MacroEditorProps) { item.id = idx; return item; }); - log.info("result!", macros); + // log.info("result!", macros); state.keymap = keymap; state.superkeys = superkeys; state.macros = macros; @@ -360,7 +360,7 @@ function MacroEditor(props: MacroEditorProps) { customMacrosList = customMacrosList.concat(macrosList); } - log.info("result of macro exploration: ", macros, customKeymapList, customSuperList, customMacrosList); + // log.info("result of macro exploration: ", macros, customKeymapList, customSuperList, customMacrosList); state.futureMacros = localMacros; state.listToDelete = customKeymapList;