|
@@ -1,79 +1,86 @@
|
|
|
-const { app, BrowserWindow, Menu, ipcMain, globalShortcut } = require('electron');// 引入electron
|
|
|
|
|
|
|
+const { app, BrowserWindow, Menu, ipcMain, globalShortcut } = require('electron');
|
|
|
const path = require('path');
|
|
const path = require('path');
|
|
|
-let win, loadingWin;
|
|
|
|
|
-Menu.setApplicationMenu(null) // 去掉菜单栏
|
|
|
|
|
-app.commandLine.appendSwitch('wm-window-animations-disabled') // 拖动闪屏
|
|
|
|
|
|
|
+const HID = require('node-hid');
|
|
|
|
|
+const devices = HID.devices();
|
|
|
|
|
+const logitech = devices.filter(el => el.manufacturer == 'Logitech');
|
|
|
|
|
+const data = new HID.HID(logitech[0].vendorId, logitech[0].productId);
|
|
|
|
|
|
|
|
|
|
+class MainSerivce {
|
|
|
|
|
+ constructor() {
|
|
|
|
|
+ Menu.setApplicationMenu(null) // 去掉菜单栏
|
|
|
|
|
+ app.commandLine.appendSwitch('wm-window-animations-disabled') // 拖动闪屏
|
|
|
|
|
+ this.loadingWin = null
|
|
|
|
|
+ this.mainWin = null
|
|
|
|
|
+ app.on('ready', this.onRead.bind(this))
|
|
|
|
|
+ app.on('activate', this.createWindow.bind(this))
|
|
|
|
|
+ app.on('window-all-closed',app.quit)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ createLoading() {
|
|
|
|
|
+ this.loadingWin = new BrowserWindow({
|
|
|
|
|
+ frame: false, // 无边框(窗口、工具栏等),只包含网页内容
|
|
|
|
|
+ width: 200,
|
|
|
|
|
+ height: 200,
|
|
|
|
|
+ resizable: false,
|
|
|
|
|
+ center: true,
|
|
|
|
|
+ alwaysOnTop: true,
|
|
|
|
|
+ transparent: true // 窗口是否支持透明,如果想做高级效果最好为true
|
|
|
|
|
+ })
|
|
|
|
|
+ this.loadingWin.loadFile('loading.html')
|
|
|
|
|
+ this.loadingWin.on('close', () => {
|
|
|
|
|
+ this.loadingWin = null
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
-// 创建loading 窗口
|
|
|
|
|
-const showLoading = () => {
|
|
|
|
|
- loadingWin = new BrowserWindow({
|
|
|
|
|
- frame: false, // 无边框(窗口、工具栏等),只包含网页内容
|
|
|
|
|
- width: 200,
|
|
|
|
|
- height: 200,
|
|
|
|
|
- resizable: false,
|
|
|
|
|
- center: true,
|
|
|
|
|
- alwaysOnTop: true,
|
|
|
|
|
- transparent: true // 窗口是否支持透明,如果想做高级效果最好为true
|
|
|
|
|
- })
|
|
|
|
|
- loadingWin.loadFile('loading.html')
|
|
|
|
|
- loadingWin.on('close', () => {
|
|
|
|
|
- loadingWin = null
|
|
|
|
|
- })
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ createWindow() {
|
|
|
|
|
+ if (!this.mainWin) {
|
|
|
|
|
+ this.mainWin = new BrowserWindow({
|
|
|
|
|
+ minWidth: 1300,
|
|
|
|
|
+ minHeight: 760,
|
|
|
|
|
+ width: 1300,
|
|
|
|
|
+ height: 760,
|
|
|
|
|
+ frame: false,
|
|
|
|
|
+ transparent: true,
|
|
|
|
|
+ webPreferences: {
|
|
|
|
|
+ contextIsolation: true,
|
|
|
|
|
+ nodeIntegration: true,
|
|
|
|
|
+ webSecurity: false, // 去掉跨越
|
|
|
|
|
+ nodeIntegrationInWorker: true,
|
|
|
|
|
+ preload: path.join(__dirname, './preload.js')
|
|
|
|
|
+ },
|
|
|
|
|
+ show: false
|
|
|
|
|
+ })// 创建一个窗口
|
|
|
|
|
|
|
|
-// 创建主程序 窗口
|
|
|
|
|
-const createWindow = () => {
|
|
|
|
|
- win = new BrowserWindow({
|
|
|
|
|
- minWidth: 1300,
|
|
|
|
|
- minHeight: 760,
|
|
|
|
|
- width: 1300,
|
|
|
|
|
- height: 760,
|
|
|
|
|
- webPreferences: {
|
|
|
|
|
- contextIsolation: true,
|
|
|
|
|
- nodeIntegration: true,
|
|
|
|
|
- webSecurity: false, // 去掉跨越
|
|
|
|
|
- preload: path.join(__dirname, './preload.js')
|
|
|
|
|
- },
|
|
|
|
|
- show: false
|
|
|
|
|
- })// 创建一个窗口
|
|
|
|
|
|
|
+ // 不同环境加载不同文件
|
|
|
|
|
+ if (app.isPackaged) {
|
|
|
|
|
+ this.mainWin.loadFile('dist/index.html')
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.mainWin.loadURL('http://localhost:6547/')
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // 不同环境加载不同文件
|
|
|
|
|
- if (app.isPackaged) {
|
|
|
|
|
- win.loadFile('dist/index.html')
|
|
|
|
|
- } else {
|
|
|
|
|
- win.loadURL('http://localhost:6547/')
|
|
|
|
|
|
|
+ // 事件监听
|
|
|
|
|
+ this.mainWin.on('close', () => {this.mainWin = null})
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 事件监听
|
|
|
|
|
- win.on('close', () => {
|
|
|
|
|
- // 回收BrowserWindow对象
|
|
|
|
|
- win = null
|
|
|
|
|
- })
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// 事件监听
|
|
|
|
|
-app.on('ready', async () => {
|
|
|
|
|
- showLoading()
|
|
|
|
|
- createWindow()
|
|
|
|
|
- // 监听渲染进行
|
|
|
|
|
- ipcMain.once('close-loading', () => {
|
|
|
|
|
- loadingWin?.close()
|
|
|
|
|
- win?.show()
|
|
|
|
|
- })
|
|
|
|
|
- // 在BrowserWindow创建完成后,注册全局快捷键
|
|
|
|
|
- globalShortcut.register('Control+F12', () => {
|
|
|
|
|
- win?.webContents.toggleDevTools()
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ onRead() {
|
|
|
|
|
+ this.createLoading()
|
|
|
|
|
+ this.createWindow()
|
|
|
|
|
|
|
|
-})
|
|
|
|
|
|
|
+ // 注册调试模式
|
|
|
|
|
+ globalShortcut.register('Control+F12', () => {
|
|
|
|
|
+ // win.flashFrame(true)
|
|
|
|
|
+ this.mainWin.webContents.toggleDevTools()
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
-app.on('window-all-closed', () => {
|
|
|
|
|
- app.quit()
|
|
|
|
|
-})
|
|
|
|
|
|
|
+ ipcMain.once('close-loading', () => {
|
|
|
|
|
+ this.loadingWin.close()
|
|
|
|
|
+ this.mainWin.show()
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
-app.on('activate', () => {
|
|
|
|
|
- if (win == null) {
|
|
|
|
|
- createWindow()
|
|
|
|
|
|
|
+ data.on('data', (db) => {
|
|
|
|
|
+ if(this.mainWin.isEnabled()) this.mainWin?.webContents.send('contrlData',db)
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
-})
|
|
|
|
|
|
|
+};
|
|
|
|
|
+new MainSerivce()
|