From 13f035ad86297b29b5091dda8a081278fd5fd004 Mon Sep 17 00:00:00 2001 From: Javier Guzman <906599+javierguzman@users.noreply.github.com> Date: Mon, 28 Aug 2023 15:25:40 +0200 Subject: [PATCH 1/5] fix: rewrite udevs if they do not have latest expected rules --- src/main/utils/udev.ts | 43 ++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/main/utils/udev.ts b/src/main/utils/udev.ts index 6fb1281fe..d481cb605 100644 --- a/src/main/utils/udev.ts +++ b/src/main/utils/udev.ts @@ -2,11 +2,18 @@ import { BrowserWindow, dialog, MessageBoxOptions } from "electron"; import fs from "fs"; import * as sudo from "sudo-prompt"; -const checkUdev = () => { - const filename = "/etc/udev/rules.d/10-dygma.rules"; +const udevRulesToWrite = + 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="1209", ATTRS{idProduct}=="2201", GROUP="users", MODE="0666"\nSUBSYSTEMS=="usb", ATTRS{idVendor}=="1209", ATTRS{idProduct}=="2200", GROUP="users", MODE="0666"\nSUBSYSTEMS=="usb", ATTRS{idVendor}=="35EF", MODE="0666"'; + +const filename = "/etc/udev/rules.d/10-dygma.rules"; +const checkUdev = () => { try { if (fs.existsSync(filename)) { + const currentUdevRules = fs.readFileSync(filename, "utf-8"); + if (currentUdevRules !== udevRulesToWrite) { + return false; + } return true; } } catch (err) { @@ -31,24 +38,20 @@ const installUdev = (mainWindow: BrowserWindow) => { }; dialog.showMessageBox(mainWindow, dialogOpts).then(response => { if (response.response === 1) { - sudo.exec( - `echo 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="1209", ATTRS{idProduct}=="2201", GROUP="users", MODE="0666"\nSUBSYSTEMS=="usb", ATTRS{idVendor}=="1209", ATTRS{idProduct}=="2200", GROUP="users", MODE="0666"\nSUBSYSTEMS=="usb", ATTRS{idVendor}=="35EF", MODE="0666"' > /etc/udev/rules.d/10-dygma.rules && udevadm control --reload-rules && udevadm trigger`, - options, - error => { - if (error !== null) { - console.log(`stdout: ${error.message}`); - const errorOpts: MessageBoxOptions = { - type: "error", - buttons: ["Ok"], - defaultId: 0, - title: "Error when launching sudo prompt", - message: "An error happened when launching a sudo prompt window", - detail: `Your linux distribution lacks a polkit agent, installing polkit-1-auth-agent, policykit-1-gnome, or polkit-kde-1 (depending on your desktop manager) will solve this problem\n\n${error.message}`, - }; - dialog.showMessageBox(mainWindow, errorOpts); - } - }, - ); + sudo.exec(`echo ${udevRulesToWrite} > ${filename} && udevadm control --reload-rules && udevadm trigger`, options, error => { + if (error !== null) { + console.log(`stdout: ${error.message}`); + const errorOpts: MessageBoxOptions = { + type: "error", + buttons: ["Ok"], + defaultId: 0, + title: "Error when launching sudo prompt", + message: "An error happened when launching a sudo prompt window", + detail: `Your linux distribution lacks a polkit agent, installing polkit-1-auth-agent, policykit-1-gnome, or polkit-kde-1 (depending on your desktop manager) will solve this problem\n\n${error.message}`, + }; + dialog.showMessageBox(mainWindow, errorOpts); + } + }); } }); }; From 88652cc7fb4a5edd9f7cc4ad88f0688cc0203a76 Mon Sep 17 00:00:00 2001 From: Javier Guzman <906599+javierguzman@users.noreply.github.com> Date: Mon, 28 Aug 2023 16:20:22 +0200 Subject: [PATCH 2/5] fix: add quotes to echo command for udevs --- src/main/utils/udev.ts | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main/utils/udev.ts b/src/main/utils/udev.ts index d481cb605..8a4993174 100644 --- a/src/main/utils/udev.ts +++ b/src/main/utils/udev.ts @@ -38,20 +38,24 @@ const installUdev = (mainWindow: BrowserWindow) => { }; dialog.showMessageBox(mainWindow, dialogOpts).then(response => { if (response.response === 1) { - sudo.exec(`echo ${udevRulesToWrite} > ${filename} && udevadm control --reload-rules && udevadm trigger`, options, error => { - if (error !== null) { - console.log(`stdout: ${error.message}`); - const errorOpts: MessageBoxOptions = { - type: "error", - buttons: ["Ok"], - defaultId: 0, - title: "Error when launching sudo prompt", - message: "An error happened when launching a sudo prompt window", - detail: `Your linux distribution lacks a polkit agent, installing polkit-1-auth-agent, policykit-1-gnome, or polkit-kde-1 (depending on your desktop manager) will solve this problem\n\n${error.message}`, - }; - dialog.showMessageBox(mainWindow, errorOpts); - } - }); + sudo.exec( + `echo '${udevRulesToWrite}' > ${filename} && udevadm control --reload-rules && udevadm trigger`, + options, + error => { + if (error !== null) { + console.log(`stdout: ${error.message}`); + const errorOpts: MessageBoxOptions = { + type: "error", + buttons: ["Ok"], + defaultId: 0, + title: "Error when launching sudo prompt", + message: "An error happened when launching a sudo prompt window", + detail: `Your linux distribution lacks a polkit agent, installing polkit-1-auth-agent, policykit-1-gnome, or polkit-kde-1 (depending on your desktop manager) will solve this problem\n\n${error.message}`, + }; + dialog.showMessageBox(mainWindow, errorOpts); + } + }, + ); } }); }; From 8338a3b663eab667a1cdc8a9796ba6f8d5541f53 Mon Sep 17 00:00:00 2001 From: Javier Guzman <906599+javierguzman@users.noreply.github.com> Date: Wed, 30 Aug 2023 16:55:59 +0200 Subject: [PATCH 3/5] refactor: add console log --- src/main/utils/udev.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/utils/udev.ts b/src/main/utils/udev.ts index 8a4993174..a1975741c 100644 --- a/src/main/utils/udev.ts +++ b/src/main/utils/udev.ts @@ -11,6 +11,8 @@ const checkUdev = () => { try { if (fs.existsSync(filename)) { const currentUdevRules = fs.readFileSync(filename, "utf-8"); + console.log(currentUdevRules); + console.log(udevRulesToWrite); if (currentUdevRules !== udevRulesToWrite) { return false; } From 47aaa121286877f4c5dd4d126bd0bfd29ed33c19 Mon Sep 17 00:00:00 2001 From: Javier Guzman <906599+javierguzman@users.noreply.github.com> Date: Wed, 30 Aug 2023 17:21:31 +0200 Subject: [PATCH 4/5] fix: fix always overwriting udev file --- src/main/utils/udev.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/utils/udev.ts b/src/main/utils/udev.ts index a1975741c..bcac81108 100644 --- a/src/main/utils/udev.ts +++ b/src/main/utils/udev.ts @@ -11,17 +11,15 @@ const checkUdev = () => { try { if (fs.existsSync(filename)) { const currentUdevRules = fs.readFileSync(filename, "utf-8"); - console.log(currentUdevRules); - console.log(udevRulesToWrite); - if (currentUdevRules !== udevRulesToWrite) { + if (currentUdevRules.trim() !== udevRulesToWrite.trim()) { return false; } return true; } } catch (err) { console.error(err); - return false; } + return false; }; const installUdev = (mainWindow: BrowserWindow) => { From aa99968ea866abad22ad550e5b090196538776b3 Mon Sep 17 00:00:00 2001 From: Javier Guzman <906599+javierguzman@users.noreply.github.com> Date: Thu, 31 Aug 2023 12:00:07 +0200 Subject: [PATCH 5/5] refactor: refactor of HW codes and remove bluetooth status mode --- .eslintrc.js | 1 + src/api/keymap/db/wireless.js | 21 ++++---- src/hw/battery.ts | 3 ++ src/hw/bluetooth.ts | 3 ++ src/hw/energy.ts | 3 ++ src/hw/rf.ts | 3 ++ .../Select/SelectWirelessDropdown.tsx | 54 +++++++++---------- src/renderer/i18n/en.js | 2 - src/renderer/modules/KeysTabs/WirelessTab.tsx | 31 +++-------- src/renderer/types/energy.ts | 0 10 files changed, 53 insertions(+), 68 deletions(-) create mode 100644 src/hw/battery.ts create mode 100644 src/hw/bluetooth.ts create mode 100644 src/hw/energy.ts create mode 100644 src/hw/rf.ts create mode 100644 src/renderer/types/energy.ts diff --git a/.eslintrc.js b/.eslintrc.js index 413dc33ce..b3164ad1d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -51,6 +51,7 @@ module.exports = { "no-underscore-dangle": "off", // we should not use _ in variables in any case "react/require-default-props": "off", "react/function-component-definition": "off", + "import/prefer-default-export": "off", }, ignorePatterns: ["/*", "!/src"], // we only care about linting src folder }; diff --git a/src/api/keymap/db/wireless.js b/src/api/keymap/db/wireless.js index add811c70..43921cbd8 100644 --- a/src/api/keymap/db/wireless.js +++ b/src/api/keymap/db/wireless.js @@ -13,12 +13,16 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +import { BatteryCodes } from "../../../hw/battery"; +import { RFCodes } from "../../../hw/rf"; +import { BluetoothCodes } from "../../../hw/bluetooth"; +import { EnergyCodes } from "../../../hw/energy"; const Battery = { groupName: "Battery", keys: [ { - code: 54108, + code: BatteryCodes.STATUS, labels: { top: "BATT.", primary: "LEVEL", @@ -30,17 +34,10 @@ const Bluetooth = { groupName: "Bluetooth", keys: [ { - code: 54109, + code: BluetoothCodes.PAIRING, labels: { top: "BLUET.", - primary: "STAT.", - }, - }, - { - code: 54110, - labels: { - top: "BLUET.", - primary: "DISC.", + primary: "PAIR.", }, }, ], @@ -49,7 +46,7 @@ const Energy = { groupName: "Energy", keys: [ { - code: 54111, + code: EnergyCodes.STATUS, labels: { top: "ENERGY", primary: "STATUS", @@ -61,7 +58,7 @@ const RF = { groupName: "RF", keys: [ { - code: 54112, + code: RFCodes.STATUS, labels: { top: "RF", primary: "STATUS", diff --git a/src/hw/battery.ts b/src/hw/battery.ts new file mode 100644 index 000000000..2b6f83937 --- /dev/null +++ b/src/hw/battery.ts @@ -0,0 +1,3 @@ +export enum BatteryCodes { + STATUS = 54108, +} diff --git a/src/hw/bluetooth.ts b/src/hw/bluetooth.ts new file mode 100644 index 000000000..97beece99 --- /dev/null +++ b/src/hw/bluetooth.ts @@ -0,0 +1,3 @@ +export enum BluetoothCodes { + PAIRING = 54109, +} diff --git a/src/hw/energy.ts b/src/hw/energy.ts new file mode 100644 index 000000000..52573791e --- /dev/null +++ b/src/hw/energy.ts @@ -0,0 +1,3 @@ +export enum EnergyCodes { + STATUS = 54111, +} diff --git a/src/hw/rf.ts b/src/hw/rf.ts new file mode 100644 index 000000000..78bd1956a --- /dev/null +++ b/src/hw/rf.ts @@ -0,0 +1,3 @@ +export enum RFCodes { + STATUS = 54112, +} diff --git a/src/renderer/component/Select/SelectWirelessDropdown.tsx b/src/renderer/component/Select/SelectWirelessDropdown.tsx index 38418fefc..ade2a2b36 100644 --- a/src/renderer/component/Select/SelectWirelessDropdown.tsx +++ b/src/renderer/component/Select/SelectWirelessDropdown.tsx @@ -4,6 +4,8 @@ import Dropdown from "react-bootstrap/Dropdown"; import i18n from "@Renderer/i18n"; import { SelectWirelessDropdownProps, WirelessButton } from "@Renderer/types/wireless"; +import { BluetoothCodes } from "@Renderer/../hw/bluetooth"; +import { BatteryCodes } from "@Renderer/../hw/battery"; const Style = Styled.div` width: 100%; @@ -137,12 +139,16 @@ width: 100%; } `; +enum WirelessButtonOrder { + BATTERY_LEVEL = 0, + PAIRING_MODE = 1, +} + function SelectWirelessDropdown(props: SelectWirelessDropdownProps) { const { keyCode, onKeySelect } = props; const WirelessButtons: Array = [ - { name: i18n.editor.standardView.wireless.batteryLevel, keynum: 54108 }, - { name: i18n.wireless.bluetooth.StatusButton, keynum: 54109 }, - { name: i18n.wireless.bluetooth.pairingModeButton, keynum: 54110 }, + { name: i18n.editor.standardView.wireless.batteryLevel, keynum: BatteryCodes.STATUS }, + { name: i18n.wireless.bluetooth.pairingModeButton, keynum: BluetoothCodes.PAIRING }, ]; const KC: number = keyCode.base + keyCode.modified; // const verifiedKC = WirelessButtons.findIndex((param: WirelessButton) => param.keynum === KC); @@ -169,29 +175,17 @@ function SelectWirelessDropdown(props: SelectWirelessDropdownProps) {
-
{WirelessButtons[0].name}
-
-
- -
-
- Bluetooth {i18n.wireless.bluetooth.StatusTitle} -
-
- -
{WirelessButtons[1].name}
+
{WirelessButtons[WirelessButtonOrder.BATTERY_LEVEL].name}
@@ -201,13 +195,15 @@ function SelectWirelessDropdown(props: SelectWirelessDropdownProps) {
-
{WirelessButtons[2].name}
+
{WirelessButtons[WirelessButtonOrder.PAIRING_MODE].name}
diff --git a/src/renderer/i18n/en.js b/src/renderer/i18n/en.js index 619c37412..6fae94bd1 100644 --- a/src/renderer/i18n/en.js +++ b/src/renderer/i18n/en.js @@ -478,8 +478,6 @@ const English = { wireless: { title: "Wireless", bluetooth: { - StatusTitle: "Status", - StatusButton: "Bluetooth Status", pairingMode: "Pairing mode", pairingModeButton: "Bluetooth Pairing Mode", pairingModeDescription: "Activate Pairing Mode for easy device connection.", diff --git a/src/renderer/modules/KeysTabs/WirelessTab.tsx b/src/renderer/modules/KeysTabs/WirelessTab.tsx index e52aef6ca..1f78800f1 100644 --- a/src/renderer/modules/KeysTabs/WirelessTab.tsx +++ b/src/renderer/modules/KeysTabs/WirelessTab.tsx @@ -8,6 +8,8 @@ import i18n from "@Renderer/i18n"; import Title from "@Renderer/component/Title"; import Callout from "@Renderer/component/Callout"; import { ButtonConfig } from "@Renderer/component/Button"; +import { BatteryCodes } from "@Renderer/../hw/battery"; +import { BluetoothCodes } from "@Renderer/../hw/bluetooth"; const Styles = Styled.div` width: 100%; @@ -48,30 +50,9 @@ function WirelessTab(props: TabLayoutEditorProps) { { - onKeySelect(54108); + onKeySelect(BatteryCodes.STATUS); }} - selected={isStandardView ? keyCode === 54108 : false} - size={undefined} - tooltip={undefined} - tooltipPlacement={undefined} - tooltipClassName={undefined} - variation={undefined} - icoSVG={undefined} - icoPosition={undefined} - tooltipDelay={undefined} - disabled={undefined} - dataAnimate={undefined} - /> - -
- - <p className="description">{i18n.editor.standardView.wireless.savingModeDescription}</p> - <ButtonConfig - buttonText={i18n.general.onOff} - onClick={() => { - onKeySelect(54109); - }} - selected={isStandardView ? keyCode === 54109 : false} + selected={isStandardView ? keyCode === BatteryCodes.STATUS : false} size={undefined} tooltip={undefined} tooltipPlacement={undefined} @@ -90,9 +71,9 @@ function WirelessTab(props: TabLayoutEditorProps) { <ButtonConfig buttonText={i18n.wireless.bluetooth.pair} onClick={() => { - onKeySelect(54110); + onKeySelect(BluetoothCodes.PAIRING); }} - selected={isStandardView ? keyCode === 54110 : false} + selected={isStandardView ? keyCode === BluetoothCodes.PAIRING : false} size={undefined} tooltip={undefined} tooltipPlacement={undefined} diff --git a/src/renderer/types/energy.ts b/src/renderer/types/energy.ts new file mode 100644 index 000000000..e69de29bb