From 2e2af4b0ea3ebdb0d2afe2a537e5ed2f47a22cbd Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Tue, 26 Nov 2024 13:23:59 -0800 Subject: [PATCH] Remove ancient partial legacy keymap update, steer model 01 users with initial factory firmware to firmware update, make bootloader reconnect in firmware update a little more user friendly by showing reconnect instructions --- src/api/focus/keymap.js | 21 ++++++--------------- src/api/focus/keymap/language_maps.js | 14 +++++++------- src/renderer/i18n.js | 16 ++++++++-------- src/renderer/i18n/en.json | 2 +- src/renderer/screens/Editor.js | 8 ++++++-- src/renderer/screens/FirmwareUpdate.js | 9 +++++++-- src/renderer/utils/connectToSerialport.js | 12 +++++++++++- 7 files changed, 46 insertions(+), 36 deletions(-) diff --git a/src/api/focus/keymap.js b/src/api/focus/keymap.js index 29fdcd76c..1206bb7f2 100644 --- a/src/api/focus/keymap.js +++ b/src/api/focus/keymap.js @@ -23,7 +23,7 @@ class Keymap { constructor(opts) { if (!global.chrysalis_keymap_instance) { global.chrysalis_keymap_instance = this; - this.legacyInterface = false; + this.unsupportedFirmware = false; } global.chrysalis_keymap_instance.setLayerSize(opts); @@ -78,12 +78,6 @@ class Keymap { return [].concat(...arr); }; - if (this.legacyInterface) { - const args = flatten(keymap.default.concat(keymap.custom)).map((k) => db.serialize(k)); - - return await s.request("keymap.map", ...args); - } - const args = flatten(keymap.custom).map((k) => db.serialize(k)); await s.request("keymap.onlyCustom", keymap.onlyCustom ? "1" : "0"); @@ -91,21 +85,17 @@ class Keymap { } else { let defaults, custom, onlyCustom; - if (!this.legacyInterface) { + if (!this.unsupportedFirmware) { defaults = await s.request("keymap.default"); custom = await s.request("keymap.custom"); onlyCustom = Boolean(parseInt(await s.request("keymap.onlyCustom"))); } if (!defaults && !custom) { - const keymap = (await s.request("keymap.map"))?.split(" ").filter((v) => v.length > 0); - const roLayers = parseInt((await s.request("keymap.roLayers")) || "0"); - - defaults = keymap?.slice(0, this._layerSize * roLayers).join(" "); - custom = keymap?.slice(this._layerSize * roLayers, keymap.length).join(" "); - onlyCustom = false; - this.legacyInterface = true; + this.unsupportedFirmware = true; + } else if (!custom) { + custom = defaults; } const defaultKeymap = defaults ?.split(" ") @@ -122,6 +112,7 @@ class Keymap { return { onlyCustom: onlyCustom, + unsupportedFirmware: this.unsupportedFirmware, custom: this._chunk(customKeymap, this._layerSize), default: this._chunk(defaultKeymap, this._layerSize), }; diff --git a/src/api/focus/keymap/language_maps.js b/src/api/focus/keymap/language_maps.js index 9d6f4e6ce..f48792ade 100644 --- a/src/api/focus/keymap/language_maps.js +++ b/src/api/focus/keymap/language_maps.js @@ -1,11 +1,11 @@ // This file is auto-generated. Do not edit manually. export const languageMaps = { - de: require("./cldr_languages/de.json"), - en: require("./cldr_languages/en.json"), - es: require("./cldr_languages/es.json"), - fr: require("./cldr_languages/fr.json"), - id: require("./cldr_languages/id.json"), + "de": require("./cldr_languages/de.json"), + "en": require("./cldr_languages/en.json"), + "es": require("./cldr_languages/es.json"), + "fr": require("./cldr_languages/fr.json"), + "id": require("./cldr_languages/id.json"), "nb-NO": require("./cldr_languages/nb_no.json"), - nl: require("./cldr_languages/nl.json"), - "zh-Hans": require("./cldr_languages/zh_hans.json"), + "nl": require("./cldr_languages/nl.json"), + "zh-Hans": require("./cldr_languages/zh_hans.json") }; diff --git a/src/renderer/i18n.js b/src/renderer/i18n.js index 5d3627f83..62243c0ad 100644 --- a/src/renderer/i18n.js +++ b/src/renderer/i18n.js @@ -11,25 +11,25 @@ import i18n from "i18next"; import { initReactI18next } from "react-i18next"; const resources = { - de: { + "de": { messages: de, }, - en: { + "en": { messages: en, }, - es: { + "es": { messages: es, }, - fr: { + "fr": { messages: fr, }, - id: { + "id": { messages: id, }, "nb-NO": { messages: nb_NO, }, - nl: { + "nl": { messages: nl, }, "zh-Hans": { @@ -37,7 +37,7 @@ const resources = { }, }; -i18n // eslint-disable-line import/no-named-as-default-member +i18n .use(initReactI18next) .init({ react: { @@ -59,7 +59,7 @@ i18n.refreshHardware = (device) => { Object.keys(i18n.options.resources).forEach((code) => { const key = "devices." + device?.info.vendor + "." + device?.info.product + ".updateInstructions"; const instructions = { - updateInstructions: i18n.exists(key) ? i18n.t(key) : undefined, // eslint-disable-line import/no-named-as-default-member + updateInstructions: i18n.exists(key) ? i18n.t(key) : undefined, }; i18n.addResource(code, "messages", "hardware", instructions); }); diff --git a/src/renderer/i18n/en.json b/src/renderer/i18n/en.json index d906a8ee1..628551771 100644 --- a/src/renderer/i18n/en.json +++ b/src/renderer/i18n/en.json @@ -559,7 +559,7 @@ "factoryResetTitle": "Factory reset", "bootloaderConnectDialog": { "title": "Connecting to your keyboard...", - "contents": "Next up, we need to connect to your keyboard's bootloader. After you click the button below, select your keyboard from the list of devices shown by your browser." + "contents": "Chrysalis needs to connect to your keyboard's bootloader. Click the button below, then pick your keyboard from the list shown by your browser. If your keyboard does not show up, unplug it from your computer and reconnect it while holding in the 'bootloader' key. On the Atreus, that's `Esc`. On the Model 01 and Model 100, it's `Prog` and on the Preonic, it's `Hyper`." }, "factoryResetDescription": "Erase everything on your keyboard, restoring it to factory defaults.", "factoryResetWarning": "Selecting this option will not backup your current layout or settings.", diff --git a/src/renderer/screens/Editor.js b/src/renderer/screens/Editor.js index 3f4bea607..11648a48c 100644 --- a/src/renderer/screens/Editor.js +++ b/src/renderer/screens/Editor.js @@ -40,6 +40,7 @@ import { KeyPicker } from "./Editor/components/KeyPicker"; import { LayerNamesStorageAlert } from "./Editor/components/LayerNamesStorageAlert"; import { MacroStorageAlert } from "./Editor/components/MacroStorageAlert"; import OnlyCustomScreen from "./Editor/components/OnlyCustomScreen"; +import { navigate } from "@renderer/routerHistory"; const db = new KeymapDB(); @@ -392,9 +393,12 @@ const Editor = (props) => { if (loading) { return ; - } else if (!keymap.onlyCustom) { - return ; + } else if (keymap.unsupportedFirmware) { + navigate("/focus-not-detected"); + return null; } + console.log("keymap"); + console.log(keymap); const KeymapSVG = activeDevice.focusDeviceDescriptor().components.keymap; diff --git a/src/renderer/screens/FirmwareUpdate.js b/src/renderer/screens/FirmwareUpdate.js index f94d1f35e..254763bcb 100644 --- a/src/renderer/screens/FirmwareUpdate.js +++ b/src/renderer/screens/FirmwareUpdate.js @@ -258,11 +258,16 @@ const FirmwareUpdate = (props) => { }; const connectToBootloaderPort = async () => { + const bootloaderVid = focusDeviceDescriptor?.usb?.bootloader?.vendorId; + const bootloaderPid = focusDeviceDescriptor?.usb?.bootloader?.productId; + logger.log("bootloaderVid", bootloaderVid); + logger.log("bootloaderPid", bootloaderPid); + if (bootloaderProtocol == "avr109") { - const focus = await connectToSerialport(); + const focus = await connectToSerialport(bootloaderVid, bootloaderPid); return focus; } else if (bootloaderProtocol == "dfu") { - const focus = await connectToDfuUsbPort(); + const focus = await connectToDfuUsbPort(bootloaderVid, bootloaderPid); if (focus) { // Store the USB device reference for flashing setUsbDevice(focus._port); diff --git a/src/renderer/utils/connectToSerialport.js b/src/renderer/utils/connectToSerialport.js index 379362bdf..72ad6fc2a 100644 --- a/src/renderer/utils/connectToSerialport.js +++ b/src/renderer/utils/connectToSerialport.js @@ -26,8 +26,18 @@ export const connectToSerialport = async (targetVid, targetPid) => { const openPort = async () => { while (!serialPort) { try { + let filters = supportedDeviceVIDPIDs(); + + // If we have target VID/PID, only look for that specific device + if (targetVid && targetPid) { + filters = [{ + usbVendorId: targetVid, + usbProductId: targetPid + }]; + } + serialPort = await navigator.serial.requestPort({ - filters: supportedDeviceVIDPIDs(), + filters: filters, }); } catch (e) { if (!serialPort) {