-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into test-palette-parse
- Loading branch information
Showing
43 changed files
with
1,083 additions
and
622 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
import DeviceMap from "./DeviceMap"; | ||
import log from "electron-log/renderer"; | ||
|
||
|
||
describe('DeviceMap', () => { | ||
beforeEach(() => { | ||
vi.mock("electron-log/renderer", () => ({ | ||
default: { | ||
error: vi.fn(), | ||
warn: vi.fn(), | ||
info: vi.fn(), | ||
verbose: vi.fn(), | ||
debug: vi.fn(), | ||
silly: vi.fn(), | ||
}, | ||
})); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('should return false with new key', async () => { | ||
const map = new DeviceMap(); | ||
expect(map.isUpdated("key", "value")).toBe(false); | ||
|
||
expect(log.warn).toHaveBeenCalledTimes(1); | ||
expect(log.warn).toHaveBeenCalledWith("comparison between keys", false, undefined, "value"); | ||
}); | ||
it('should return false with differing values', async () => { | ||
const map = new DeviceMap(); | ||
map.set("key", "original"); | ||
expect(map.isUpdated("key", "value")).toBe(false); | ||
|
||
expect(log.warn).toHaveBeenCalledTimes(1); | ||
expect(log.warn).toHaveBeenCalledWith("comparison between keys", false, "original", "value"); | ||
|
||
}); | ||
it('should return true with same value', async () => { | ||
const map = new DeviceMap(); | ||
map.set("key", "value"); | ||
expect(map.isUpdated("key", "value")).toBe(true); | ||
|
||
expect(log.warn).toHaveBeenCalledTimes(1); | ||
expect(log.warn).toHaveBeenCalledWith("comparison between keys", true, "value", "value"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,45 @@ | ||
import { DygmaDeviceType } from "@Renderer/types/dygmaDefs"; | ||
import { DeviceTools } from "@Renderer/DeviceContext"; | ||
import log from "electron-log/renderer"; | ||
import { DeviceTools } from "@Renderer/DeviceContext"; | ||
import { DygmaDeviceType } from "@Renderer/types/dygmaDefs"; | ||
import { ExtendedPort } from "../comms/serial/SerialAPI"; | ||
import Hardware from "../hardware"; | ||
|
||
function getDeviceList(deviceType: "serial" | "nonSerial" | "bootloader", desiredDevice?: DygmaDeviceType): DygmaDeviceType[] { | ||
if (deviceType === "serial" && desiredDevice?.info.keyboardType !== undefined) { | ||
return [desiredDevice]; | ||
} | ||
return Hardware[deviceType]; | ||
} | ||
|
||
export const findDevice = async ( | ||
deviceType: "serial" | "nonSerial" | "bootloader", | ||
message: string, | ||
desiredDevice?: DygmaDeviceType, | ||
) => { | ||
log.info("Going to list devices"); | ||
let devices = Hardware[deviceType] as DygmaDeviceType[]; | ||
const bootloader = deviceType === "bootloader"; | ||
const list: ExtendedPort[] = (await DeviceTools.enumerateSerial(bootloader)).foundDevices as ExtendedPort[]; | ||
if (deviceType === "serial" && desiredDevice?.info.keyboardType !== undefined) devices = [desiredDevice]; | ||
log.verbose("List of Devices: ", list); | ||
const detected = list.find(dev => { | ||
log.info("Searching for Device"); | ||
let found = false; | ||
devices.forEach(device => { | ||
): Promise<ExtendedPort> => { | ||
log.info(`Going to list devices for type: ${deviceType}`); | ||
const lookupDevices: DygmaDeviceType[] = getDeviceList(deviceType, desiredDevice); | ||
|
||
const isBootloader = deviceType === "bootloader"; | ||
const hwDevices: ExtendedPort[] = (await DeviceTools.enumerateSerial(isBootloader)).foundDevices; | ||
log.verbose("List of Devices: ", hwDevices); | ||
|
||
const matchingDevice: ExtendedPort = hwDevices.find(hwDevice => | ||
lookupDevices.some(lookupDevice => { | ||
log.info( | ||
`Dev bootloader: ${dev.device.bootloader} & HW: ${bootloader}, Dev KBType: ${device.info.keyboardType} & HW: ${dev.device.info.keyboardType}`, | ||
`Bootloader - Lookup: ${isBootloader} & HW: ${hwDevice.device.bootloader} | KBType - Lookup: ${lookupDevice.info.keyboardType} & HW: ${hwDevice.device.info.keyboardType}`, | ||
); | ||
if ( | ||
found !== true && bootloader | ||
? dev.device.bootloader !== undefined && | ||
dev.device.bootloader === bootloader && | ||
device.usb.vendorId === dev.device.usb.vendorId && | ||
device.usb.productId === dev.device.usb.productId | ||
: device.usb.vendorId === dev.device.usb.vendorId && | ||
device.usb.productId === dev.device.usb.productId && | ||
device.info.keyboardType === dev.device.info.keyboardType | ||
) { | ||
found = true; | ||
|
||
if (lookupDevice.usb.vendorId !== hwDevice.device.usb.vendorId) { | ||
return false; | ||
} | ||
if (lookupDevice.usb.productId !== hwDevice.device.usb.productId) { | ||
return false; | ||
} | ||
if (isBootloader) { | ||
return hwDevice.device.bootloader === true; | ||
} | ||
}); | ||
return found; | ||
}); | ||
log.info(message, detected); | ||
return detected; | ||
return lookupDevice.info.keyboardType === hwDevice.device.info.keyboardType; | ||
}), | ||
); | ||
log.info(`${deviceType === "serial" ? "keyboard" : deviceType} detected`, matchingDevice); | ||
return matchingDevice; | ||
}; |
Oops, something went wrong.