Add tray status support

This commit is contained in:
GHOSCHT 2022-03-14 20:17:05 +01:00
parent d55f68fedb
commit 1bb9b6c5bf
No known key found for this signature in database
GPG key ID: A35BD466B8871994
4 changed files with 945 additions and 37 deletions

View file

@ -104,7 +104,8 @@
"ts-loader": "^9.2.6", "ts-loader": "^9.2.6",
"wait-on": "^6.0.0", "wait-on": "^6.0.0",
"webpack": "^5.57.1", "webpack": "^5.57.1",
"webpack-cli": "^4.9.2" "webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.7.4"
}, },
"presets": [ "presets": [
"@babel/preset-env", "@babel/preset-env",

View file

@ -107,7 +107,7 @@ app.on("browser-window-blur", () => {
// code. You can also put them in separate files and require them here. // code. You can also put them in separate files and require them here.
function createTray() { function createTray() {
const trayIcon = new Tray(getAssetPath("tray/tray-default-32.png")); const trayIcon = new Tray(getAssetPath("tray/tray-yellow-32.png"));
const contextMenu = Menu.buildFromTemplate([ const contextMenu = Menu.buildFromTemplate([
{ {
label: "Show", label: "Show",

View file

@ -1,4 +1,5 @@
import { Middleware, Action } from "@reduxjs/toolkit"; import { Middleware, Action } from "@reduxjs/toolkit";
import electron from "electron";
import { RootState } from "../store/types.d"; import { RootState } from "../store/types.d";
import { import {
connect, disconnect, setSerialPort, setMessage, sendMessage, connectionStart, connectionFailure, connectionSuccess, connectionEnd, connect, disconnect, setSerialPort, setMessage, sendMessage, connectionStart, connectionFailure, connectionSuccess, connectionEnd,
@ -31,15 +32,24 @@ const serialConnection: Middleware<{}, RootState> = (state) => (next) => (action
if (connect.match(action)) { if (connect.match(action)) {
state.dispatch(connectionStart()); state.dispatch(connectionStart());
if (state.getState().serialConnection.port === "") { if (state.getState().serialConnection.port === "" || serialPort === null) {
state.dispatch(connectionFailure("No Serial Port set")); state.dispatch(connectionFailure("No Serial Port set"));
return next(action); return next(action);
} }
if (serialPort.isOpen) {
state.dispatch(disconnect());
}
serialPort?.open(errorCalbackHandler, closeCalbackHandler); serialPort?.open(errorCalbackHandler, closeCalbackHandler);
serialPort?.parser.on("data", serialDataListener); serialPort?.parser.on("data", serialDataListener);
} else if (connectionSuccess.match(action)) {
electron.ipcRenderer.send("asynchronous-message", "default");
} else if (connectionFailure.match(action)) {
electron.ipcRenderer.send("asynchronous-message", "red");
} else if (disconnect.match(action)) { } else if (disconnect.match(action)) {
serialPort?.close(); serialPort?.close();
state.dispatch(connectionEnd()); state.dispatch(connectionEnd());
} else if (connectionEnd.match(action)) {
electron.ipcRenderer.send("asynchronous-message", "yellow");
} else if (setSerialPort.match(action)) { } else if (setSerialPort.match(action)) {
serialPort = new PortController(action.payload); serialPort = new PortController(action.payload);
} else if (sendMessage.match(action)) { } else if (sendMessage.match(action)) {

File diff suppressed because it is too large Load diff