Skip to content

Commit

Permalink
Remove ancient partial legacy keymap update, steer model 01 users wit…
Browse files Browse the repository at this point in the history
…h initial factory firmware to firmware update, make bootloader reconnect in firmware update a little more user friendly by showing reconnect instructions
  • Loading branch information
obra committed Nov 26, 2024
1 parent 53f7667 commit 2e2af4b
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 36 deletions.
21 changes: 6 additions & 15 deletions src/api/focus/keymap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -78,34 +78,24 @@ 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");
return await s.request("keymap.custom", ...args);
} 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(" ")
Expand All @@ -122,6 +112,7 @@ class Keymap {

return {
onlyCustom: onlyCustom,
unsupportedFirmware: this.unsupportedFirmware,
custom: this._chunk(customKeymap, this._layerSize),
default: this._chunk(defaultKeymap, this._layerSize),
};
Expand Down
14 changes: 7 additions & 7 deletions src/api/focus/keymap/language_maps.js
Original file line number Diff line number Diff line change
@@ -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")
};
16 changes: 8 additions & 8 deletions src/renderer/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,33 @@ import i18n from "i18next";
import { initReactI18next } from "react-i18next";

const resources = {
de: {
"de": {

Check failure on line 14 in src/renderer/i18n.js

View workflow job for this annotation

GitHub Actions / Lint

Replace `"de"` with `de`
messages: de,
},
en: {
"en": {

Check failure on line 17 in src/renderer/i18n.js

View workflow job for this annotation

GitHub Actions / Lint

Replace `"en"` with `en`
messages: en,
},
es: {
"es": {

Check failure on line 20 in src/renderer/i18n.js

View workflow job for this annotation

GitHub Actions / Lint

Replace `"es"` with `es`
messages: es,
},
fr: {
"fr": {

Check failure on line 23 in src/renderer/i18n.js

View workflow job for this annotation

GitHub Actions / Lint

Replace `"fr"` with `fr`
messages: fr,
},
id: {
"id": {

Check failure on line 26 in src/renderer/i18n.js

View workflow job for this annotation

GitHub Actions / Lint

Replace `"id"` with `id`
messages: id,
},
"nb-NO": {
messages: nb_NO,
},
nl: {
"nl": {

Check failure on line 32 in src/renderer/i18n.js

View workflow job for this annotation

GitHub Actions / Lint

Replace `"nl"` with `nl`
messages: nl,
},
"zh-Hans": {
messages: zh_Hans,
},
};

i18n // eslint-disable-line import/no-named-as-default-member
i18n

Check warning on line 40 in src/renderer/i18n.js

View workflow job for this annotation

GitHub Actions / Lint

Caution: `i18n` also has a named export `use`. Check if you meant to write `import {use} from 'i18next'` instead

Check failure on line 40 in src/renderer/i18n.js

View workflow job for this annotation

GitHub Actions / Lint

Replace `⏎··.use(initReactI18next)⏎··` with `.use(initReactI18next)`
.use(initReactI18next)
.init({
react: {

Check failure on line 43 in src/renderer/i18n.js

View workflow job for this annotation

GitHub Actions / Lint

Delete `··`
Expand All @@ -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,

Check warning on line 62 in src/renderer/i18n.js

View workflow job for this annotation

GitHub Actions / Lint

Caution: `i18n` also has a named export `exists`. Check if you meant to write `import {exists} from 'i18next'` instead

Check warning on line 62 in src/renderer/i18n.js

View workflow job for this annotation

GitHub Actions / Lint

Caution: `i18n` also has a named export `t`. Check if you meant to write `import {t} from 'i18next'` instead
};
i18n.addResource(code, "messages", "hardware", instructions);
});
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
8 changes: 6 additions & 2 deletions src/renderer/screens/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -392,9 +393,12 @@ const Editor = (props) => {

if (loading) {
return <LoadingScreen />;
} else if (!keymap.onlyCustom) {
return <OnlyCustomScreen />;
} else if (keymap.unsupportedFirmware) {
navigate("/focus-not-detected");
return null;
}
console.log("keymap");
console.log(keymap);

const KeymapSVG = activeDevice.focusDeviceDescriptor().components.keymap;

Expand Down
9 changes: 7 additions & 2 deletions src/renderer/screens/FirmwareUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 11 additions & 1 deletion src/renderer/utils/connectToSerialport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2e2af4b

Please sign in to comment.