Skip to content

Commit

Permalink
Remove unused system info data
Browse files Browse the repository at this point in the history
  • Loading branch information
retrogeek46 committed Mar 12, 2023
1 parent d904d4f commit 7c4eb78
Show file tree
Hide file tree
Showing 10 changed files with 385 additions and 70 deletions.
Binary file modified app/Resources/publish/ActiveWinTest.dll
Binary file not shown.
Binary file modified app/Resources/publish/ActiveWinTest.pdb
Binary file not shown.
17 changes: 8 additions & 9 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const createMainWindow = () => {
let win = new BrowserWindow({
width: 900,
height: 480,
icon: path.join(__dirname, "/Resources/cut-paper.png"),
transparent: true,
resizable: true,
webPreferences: {
Expand Down Expand Up @@ -53,8 +52,6 @@ const createDrawWindow = (height, width) => {
let win = new BrowserWindow({
width: width,
height: height,
// icon: path.join(__dirname, "/Resources/cut-paper.png"),
// transparent: true,
frame: false,
alwaysOnTop: true,
backgroundColor: "#2e2c29",
Expand Down Expand Up @@ -122,7 +119,6 @@ const attachKeyboardListener = async (retryCount=0) => {
};

const createTray = async () => {
let appIcon = new Tray(path.join(__dirname, "/Resources/cut-paper.png"));
const contextMenu = Menu.buildFromTemplate([
{
label: "Send Snippet",
Expand Down Expand Up @@ -166,11 +162,9 @@ const createTray = async () => {

const spawnActiveWinProcess = () => {
// TODO: add check for os, spawn correct process etc based on os
// TODO: pass app port to spawned process
// activeWinProcess = spawn('cd E:/Coding/C#/ActiveWinTest && dotnet run Program.cs', { shell: true })
logger.info("spawning activeWinTest");
activeWinProcess = spawn(
path.join(__dirname, "Resources/publish/ActiveWinTest.exe 3456"),
path.join(__dirname, "Resources/publish/ActiveWinTest.exe " + constants.PORT),
{ shell: true }
);
}
Expand All @@ -195,8 +189,8 @@ app.on('ready', async () => {
await server.server(this);
await server.startSystemInfoTimer();

// TODO: handle active win so that it is optional based on os
// spawnActiveWinProcess();
// TODO: handle active win so that it is optional and based on os
spawnActiveWinProcess();
attachKeyboardListener();

const qmkGetKeyboardState = globalShortcut.register(
Expand Down Expand Up @@ -256,6 +250,7 @@ app.on('ready', async () => {
app.on('will-quit', () => {
globalShortcut.unregisterAll();
killActiveWinProcess();
resetKeyboard();
})

ipcMain.on("applyKeyboardRGB", (event, message) => {
Expand All @@ -270,3 +265,7 @@ exports.initDrawWindow = (height, width) => {
exports.updateCurrentOS = (currentOS) => {
mainWindow.webContents.send("updateCurrentOS", currentOS);
};

exports.updateCurrentMedia = (mediaTitle, mediaArtist) => {
mainWindow.webContents.send("updateCurrentMedia", mediaTitle, mediaArtist);
};
35 changes: 9 additions & 26 deletions app/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,39 +62,18 @@ const server = async (electronObj) => {
const socket = require("socket.io");
const io = socket(server, {
cors: {
origin: "https://localhost:3444",
origin: "https://localhost:" + constants.PORT,
methods: ["GET", "POST"],
},
});
let currentBarrierOS = constants.OS.WINDOWS;

exports.startSystemInfoTimer = async () => {
logger.info("Starting system info timer");
// TODO: add toggle to enable and disable system info stuff
systemInfoTimer = setInterval(async () => {
const systemData = await systemInfo.getSystemInfo();
// logger.info(systemData);
const systemInfoValues =
systemData["HKCU\\SOFTWARE\\HWiNFO64\\VSB"]["values"];
// logger.info(systemData["HKCU\\SOFTWARE\\HWiNFO64\\VSB"]);

let cpuVoltage = systemInfoValues["Value2"]["value"];
let cpuTempRaw = systemInfoValues["ValueRaw4"]["value"];
let cpuUsageRaw = systemInfoValues["ValueRaw3"]["value"];
let cpuTemp = cpuTempRaw.toString() + "C";
let cpuUsage = cpuUsageRaw.toString() + "%";
// if (Number(cpuTempRaw) > 60) {
// keyboardQmk.updateKeyboard(3);
// } else {
// keyboardQmk.updateKeyboard(4);
// }
// XXX: stop sending cpu data to keyboard till rgb/oled is added to keeb
// keyboardQmk.updateKeyboard(3, parseInt(cpuUsageRaw));
keyboardQmk.updateKeyboard(2);
keyboardQmk.updateKeyboard(8, formatDateTime());
// let cpuVoltage = systemInfoValues["Value2"]["value"];
const msg = `CPU Temp: ${cpuTemp}, CPU Voltage: ${cpuVoltage}, CPU Usage: ${cpuUsage}`;
// logger.sysinfo(msg);
this.emitMessage("systemInfo", msg);
}, systemInfoInterval);
};

Expand Down Expand Up @@ -128,29 +107,33 @@ const server = async (electronObj) => {
});

app.post("/updateCurrentMedia", (req, res) => {
const currentMediaTitle = req.body.currentMediaTitle.toUpperCase().replace(/[^A-Z ]/g, "");
const currentArtist = req.body.currentArtist.toUpperCase().replace(/[^A-Z ]/g, "");
// console.log(currentArtist);
const pattern = /[^A-Z\-=#;`',.\/:\s]+/g;
const currentMediaTitle = req.body.currentMediaTitle.toUpperCase().replace(pattern, "");
const currentArtist = req.body.currentArtist.toUpperCase().replace(pattern, "");
const [mediaTitleArray, mediaArtistArray] = formatMediaInfo(
currentMediaTitle,
currentArtist
);
electronObj.updateCurrentMedia(currentMediaTitle, currentArtist);
keyboardQmk.updateKeyboard(6, mediaTitleArray);
keyboardQmk.updateKeyboard(7, mediaArtistArray);
res.send("received");
});

app.post("/debugActiveWin", (req, res) => {
logger.info("Received args " + req.body.message);
res.send("received");
})

const formatMediaInfo = (currentMediaTitle, currentArtist) => {
// remove artist name from title
currentMediaTitle = currentMediaTitle.replace(currentArtist, "");
currentMediaTitle = currentMediaTitle.trim();
currentMediaTitle = currentMediaTitle.replace(" ", " ");
let mediaTitleArray = [...currentMediaTitle].map(i => constants.CHAR_TO_CODE_MAPPING[i]);
mediaTitleArray = mediaTitleArray.slice(0, 21);

currentArtist = currentArtist.replace(" ", " ");
let mediaArtistArray = [...currentArtist].map((i) => constants.CHAR_TO_CODE_MAPPING[i]);
mediaArtistArray = mediaArtistArray.slice(0, 21);

Expand Down
2 changes: 1 addition & 1 deletion app/services/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ exports.updateKeyboard = (value, extraValues=0) => {
}
return 1;
} catch (ex) {
logger.error("Error in update keyboard \n" + ex.toString());
logger.error("Error in update keyboard \n" + value + ", " + extraValues + "\n" + ex.toString());
this.resetKeyboard();
return 0;
}
Expand Down
35 changes: 12 additions & 23 deletions app/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8"></meta>
<title>Snip Share</title>
<title>KeybKontroller</title>
</head>
<body>
<script defer src="render.js"></script>
Expand Down Expand Up @@ -56,41 +56,30 @@
transform: translate(-50%, -50%);">
</p>

<p id="keyboardParamsPara" style="
text-align:left;
font-family: 'JetBrains Mono', 'Courier New';
color: yellow;
<p id="currentMedia" style="
text-align:left;
font-family: 'JetBrains Mono', 'Courier New';
color: white;
font-size:90%;
margin: 0;
position: absolute;
top: 90%;
top: 80%;
left: 50%;
transform: translate(-50%, -50%);">
</p>

<!-- <form style="
text-align:left;
font-family: 'JetBrains Mono', 'Courier New';
<p id="keyboardParamsPara" style="
text-align:left;
font-family: 'JetBrains Mono', 'Courier New';
color: yellow;
font-size:90%;
margin: 0;
color: white;
position: absolute;
top: 90%;
left: 50%;
transform: translate(-50%, -50%);"
onsubmit="applyKeyboardRGB();return false"
>
<label>R</label><input type="number" id="rValue" name="r" min="0" max="255" value="255">
<label>G</label><input type="number" id="gValue" name="g" min="0" max="255" value="255">
<label>B</label><input type="number" id="bValue" name="b" min="0" max="255" value="255">
<div id="rgbBox" style="
height: 20px;
width: 20px;
border: 1px solid black;"></div>
<input type="submit" value="Apply">
transform: translate(-50%, -50%);">
</p>

</form> -->


</body>
Expand Down
11 changes: 9 additions & 2 deletions app/static/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const ipAddressPara = document.getElementById("ipAddressPara");
const cpuParamsPara = document.getElementById("cpuParamsPara");
const keyboardParamsPara = document.getElementById("keyboardParamsPara");
const currentOSPara = document.getElementById("currentOS");
const currentMediaPara = document.getElementById("currentMedia");
const rgbBoxPara = document.getElementById("rgbBox");

let serverIPText = "";
Expand Down Expand Up @@ -67,14 +68,20 @@ ipcRenderer.on("updateVersionServerIP", (event, [version, serverIP]) => {
});

ipcRenderer.on("updateCurrentOS", (event, currentOS) => {
// console.log("in ipc renderer");
currentOSPara.innerHTML = "Current OS: " + currentOS;
});

ipcRenderer.on("updateCurrentKeyboard", (event, currentKeyboard) => {
currentKeyboardPara.innerHTML = "Current Keyboard: " + currentKeyboard;
});

ipcRenderer.on("updateKeyboardState", (event, keebState) => {
keyboardParamsPara.innerHTML = `Keyboard<br>Encoder: ${C.ENCODER_STATES[keebState["encoderState"]]} &nbsp;&nbsp; Layer: ${C.KEEB_LAYERS[keebState["layerState"]]} &nbsp;&nbsp; OS: ${C.OS_STATES[keebState["currentOS"]]}`;
});

startSystemInfoUITimer();
ipcRenderer.on("updateCurrentMedia", (event, mediaTitle, mediaArtist) => {
currentMediaPara.innerHTML = "Playing '" + mediaTitle + "' by " + mediaArtist;
});



22 changes: 22 additions & 0 deletions forge.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
packagerConfig: {},
rebuildConfig: {},
makers: [
{
name: '@electron-forge/maker-squirrel',
config: {},
},
{
name: '@electron-forge/maker-zip',
platforms: ['darwin'],
},
{
name: '@electron-forge/maker-deb',
config: {},
},
{
name: '@electron-forge/maker-rpm',
config: {},
},
],
};
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "keybkontroller",
"version": "1.0.0",
"version": "1.0.1",
"description": "Control your qmk enabled keyboard using raw HID protocol",
"main": "app/main.js",
"scripts": {
Expand All @@ -15,12 +15,17 @@
"private": false,
"devDependencies": {
"@electron-forge/cli": "^6.0.4",
"@electron-forge/maker-deb": "^6.0.4",
"@electron-forge/maker-rpm": "^6.0.4",
"@electron-forge/maker-squirrel": "^6.0.4",
"@electron-forge/maker-zip": "^6.0.4",
"electron": "^22.1.0",
"electron-rebuild": "^3.2.9"
},
"dependencies": {
"compression": "^1.7.4",
"cors": "^2.8.5",
"electron-squirrel-startup": "^1.0.0",
"express": "^4.18.2",
"helmet": "^6.0.1",
"node-hid": "^2.1.2",
Expand Down
Loading

0 comments on commit 7c4eb78

Please sign in to comment.