feat(device): Read only filled user configuration and fix app close on mac (#486)

* feat(device): Save user configuration length

* feat(device): Read only filled user configuration from EEPROM

* fix(agent): Close device connections and quit from app on Mac
This commit is contained in:
Róbert Kiss
2017-11-02 23:06:53 +01:00
committed by László Monda
parent fe6cd68c55
commit 0c30eccaca
5 changed files with 46 additions and 11 deletions
+6 -5
View File
@@ -39,6 +39,8 @@ let appService: AppService;
let sudoService: SudoService;
function createWindow() {
logger.info('[Electron Main] Create new window.');
// Create the browser window.
win = new BrowserWindow({
title: 'UHK Agent',
@@ -73,10 +75,13 @@ function createWindow() {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
logger.info('[Electron Main] win closed');
win = null;
deviceService.close();
deviceService = null;
appUpdateService = null;
appService = null;
uhkHidDeviceService.close();
uhkHidDeviceService = null;
sudoService = null;
});
@@ -96,11 +101,7 @@ app.on('ready', createWindow);
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit();
}
app.quit();
});
app.on('will-quit', () => {
@@ -83,10 +83,11 @@ export class DeviceService {
try {
this.logService.debug(`[DeviceService] USB[T]: Read ${configName} size from keyboard`);
const configSize = await this.getConfigSizeFromKeyboard(property);
let configSize = await this.getConfigSizeFromKeyboard(property);
const chunkSize = 63;
let offset = 0;
let configBuffer = new Buffer(0);
let firstRead = true;
this.logService.debug(`[DeviceService] USB[T]: Read ${configName} from keyboard`);
while (offset < configSize) {
@@ -95,6 +96,11 @@ export class DeviceService {
const readBuffer = await this.device.write(writeBuffer);
configBuffer = Buffer.concat([configBuffer, new Buffer(readBuffer.slice(1, chunkSizeToRead + 1))]);
offset += chunkSizeToRead;
if (firstRead && config === UsbCommand.ReadUserConfig) {
firstRead = false;
configSize = readBuffer[3] + (readBuffer[4] << 8);
}
}
response = UhkHidDevice.convertBufferToIntArray(configBuffer);
return Promise.resolve(JSON.stringify(response));
@@ -105,6 +111,13 @@ export class DeviceService {
}
}
public close(): void {
this.connected = false;
this.pollTimer$.unsubscribe();
this.logService.info('[DeviceService] Device connection checker stopped.');
}
/**
* HID API not support device attached and detached event.
* This method check the keyboard is attached to the computer or not.