|
|
@@ -1,6 +1,6 @@
|
|
|
const { app, BrowserWindow, Menu, ipcMain, globalShortcut, dialog, screen, Tray } = require('electron');
|
|
|
const { join } = require('path');
|
|
|
-const HID = require('node-hid');
|
|
|
+const { fork } = require('child_process');
|
|
|
|
|
|
class MainSerivce {
|
|
|
constructor() {
|
|
|
@@ -100,7 +100,7 @@ class MainSerivce {
|
|
|
if (evt === 'close-loading') {
|
|
|
if (this.loadingWin) this.loadingWin.close()
|
|
|
this.mainWin.show()
|
|
|
- // this.connectLogi()
|
|
|
+ if(this.mainWin.isVisible()) this.connectLogi()
|
|
|
} else if (evt === 'minWin') {
|
|
|
this.mainWin.minimize()
|
|
|
} else if (evt === 'closeWin') {
|
|
|
@@ -116,21 +116,20 @@ class MainSerivce {
|
|
|
}
|
|
|
|
|
|
connectLogi() {
|
|
|
- try {
|
|
|
- const devices = HID.devices();
|
|
|
- const logitech = devices.filter(el => el.manufacturer == 'Logitech');
|
|
|
- const data = new HID.HID(logitech[0].vendorId, logitech[0].productId);
|
|
|
- data.on('data', (db) => {
|
|
|
- if (this.mainWin) this.mainWin?.webContents.send('contrlData', db)
|
|
|
- })
|
|
|
- } catch (error) {
|
|
|
- dialog.showMessageBox(this.mainWin, { message: '连接方向盘失败', type: 'error', title: '连接错误', detail: '请检查方向盘是否连接' }).then(({ response }) => {
|
|
|
- if (!response) {
|
|
|
- this.mainWin.close()
|
|
|
- app.quit()
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
+ const signal = fork(join(__dirname, './logiControl.js'))
|
|
|
+ signal.on('message',msg=>{
|
|
|
+ if(msg.type === 'err'){
|
|
|
+ dialog.showMessageBox(this.mainWin, { message: '连接方向盘失败', type: 'error', title: '连接错误', detail: '请检查方向盘是否连接' }).then(({ response }) => {
|
|
|
+ if (!response) {
|
|
|
+ this.mainWin.close()
|
|
|
+ app.quit()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }else{
|
|
|
+ console.log(msg.data);
|
|
|
+ if (this.mainWin && !this.mainWin.isDestroyed()) this.mainWin?.webContents.send('contrlData', msg.data)
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
};
|
|
|
new MainSerivce()
|