Skip to content

Commit

Permalink
Version: 1.1.23-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
dzatoah committed Feb 12, 2020
1 parent a54f3f7 commit 5bc46e2
Show file tree
Hide file tree
Showing 7 changed files with 451 additions and 121 deletions.
12 changes: 11 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "makrotastatur",
"productName": "Makrotastatur GUI",
"version": "v1.1.22-alpha",
"productName": "Makrotastatur",
"version": "1.1.23-alpha",
"description": "Programmiere deine Makrotastatur mit diesem Programm.",
"main": "src/main.js",
"scripts": {
Expand Down Expand Up @@ -46,8 +46,10 @@
"bootstrap": "latest",
"bootswatch": "^4.4.1",
"electron-compile": "latest",
"electron-is-dev": "^1.1.0",
"electron-squirrel-startup": "^1.0.0",
"jquery": "latest",
"jqueryui": "^1.11.1",
"mdbootstrap": "latest",
"popper.js": "latest",
"serialport": "latest",
Expand Down
37 changes: 28 additions & 9 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ <h3 id="titleText">Makrotastatur - Startseite</h3>

window.Bridge.getSerialCOMsList().then(function(data){
data.forEach(function(device){
if (device.manufacturer == "SparkFun" && device.serialNumber == "HIDPC" || widerSearch) {
console.log(device);
if (device.productId == "9206" && device.serialNumber == "HIDPC" || widerSearch) {
if (!foundDevice) $("#deviceList").empty();
foundDevice = true;

Expand Down Expand Up @@ -77,7 +78,7 @@ <h3 id="titleText">Makrotastatur - Startseite</h3>
console.log("Kein passendes serielles Gerät gefunden!");
$("#deviceList").append(`<li class="list-group-item-danger list-group-item" id="option_nodevice">
<span class="align-text-top">Kein passendes serielles Gerät gefunden!</span>
<button onclick="reloadDeviceList(true);" class="float-right btn btn-sm btn-secondary">Suchparameter ausweiten</button>
<button onclick="reloadDeviceList(true);" class="float-right btn btn-sm btn-secondary mt-3 m-sm-0">Suchparameter ausweiten</button>
</li>`);
}
}, 1000);
Expand Down Expand Up @@ -132,15 +133,14 @@ <h3 id="titleText">Makrotastatur - Startseite</h3>

window.addEventListener('DOMContentLoaded', () => {
// IF DARK MODE ADD BOOTSWATCH CSS FILES
console.error(localStorage.getItem("dark_mode_active") + " " + window.Bridge.checkDarkMode());
if (window.Bridge.checkDarkMode() == true || localStorage.getItem("dark_mode_active") == "true") {
if (window.Bridge.isDarkMode == true || localStorage.getItem("dark_mode_active") == "true") {
loadDarkMode();
} else {
console.warn("Sicher, dass du lightmode verwenden willst?");
displayAlertMessage("Darkmode?",
`Du möchtest doch sicher den darkmode benutzen oder?
<div class='align-text-top' style="min-height: 3rem;">
<button class='btn float-right btn-primary' onclick="$('#bsAlert').slideUp('fast'); loadDarkMode();">Darkmode laden</button>
<button class='btn float-right btn-primary mt-2 m-md-0' onclick="$('#bsAlert').slideUp('fast'); loadDarkMode();">Darkmode laden</button>
</div>`, "alert-info");
}

Expand All @@ -158,10 +158,19 @@ <h3 id="titleText">Makrotastatur - Startseite</h3>
window.Bridge.setCOMPath(devicePath);

window.Bridge.onDataReceive = function(msg){console.log("lol: " + msg);}
window.Bridge.onDisconnect = () => {
console.error("%cPORT DISCONNECTED", "color: red;");
location.href="index.html";
}
window.Bridge.onClose = () => {
console.error("%cPORT CLOSED", "color: red;");
location.href="index.html";
}

window.Bridge.onOpen = function() {
console.log("Verbindung zu Gerät '" + devicePath + "' geöffnet!");

displayAlertMessage("Erfolgreich verbunden!", "Sie werden <strong>weitergeleitet.</strong>", "alert-success", openTime="fast");
displayAlertMessage("Verbunden!", "Sie werden <strong>weitergeleitet.</strong>", "alert-success", openTime="fast");
// Redirect user to the next site.
setTimeout(function(){location.href='selectButton.html';}, 1000);

Expand All @@ -173,8 +182,18 @@ <h3 id="titleText">Makrotastatur - Startseite</h3>
}
</script>
</main>

<!-- You can also require other files to run in this process -->
<script src="./renderer.js"></script>
<footer class="fixed-bottom px-2 text-muted">
<div class="row">
<div class="col float-right text-left pr-1" id="footer_appVersion"></div>
<div class="col text-center p-0 ">teichm-sh.de/makro</div>
<div class="col float-left text-right pl-1">© Daniel Teichmann</div>
</div>
<script>
window.addEventListener("DOMContentLoaded", () => {
var version = window.Bridge.appVersion;
$("#footer_appVersion").append(version);
});
</script>
</footer>
</body>
</html>
37 changes: 32 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,28 @@ const { ipcMain } = require('electron')
const { systemPreferences } = require('electron')

ipcMain.on('isDarkMode', (event, arg) => {
console.log("IsDarkMode?: " + false);
event.returnValue = false;
var isDarkMode = systemPreferences.isDarkMode();
console.log("Got event: 'IsDarkMode'\tReturning: '" + isDarkMode + "'");
event.returnValue = isDarkMode;
});

ipcMain.on('getVersion', (event, arg) => {
var version = app.getVersion();
console.log("Got event: 'getVersion'\tReturning: '" + version + "'");
event.returnValue = version;
});

global.commands;
global.buttonCommands;
global.selectedButtonID;
ipcMain.on("setCommandsObj", (event, argObj) => {
global.commands = argObj;
});
ipcMain.on("setButtonCommandsObj", (event, argObj) => {
global.buttonCommands = argObj;
});
ipcMain.on("setSelectedButtonIDObj", (event, argObj) => {
global.selectedButtonID = argObj;
});

// Keep a global reference of the window object, if you don't, the window will
Expand All @@ -25,15 +45,22 @@ const createWindow = () => {
width: 1000,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: false,
contextIsolation: false
}
})

// and load the index.html of the app.
mainWindow.loadFile(path.join(__dirname, 'index.html'));

// Open the DevTools.
mainWindow.webContents.openDevTools()
const isDev = require('electron-is-dev');
if (isDev) {
console.log('App is running in development mode...');

// Open the DevTools.
mainWindow.webContents.openDevTools();
}

// Emitted when the window is closed.
mainWindow.on('closed', function () {
Expand Down
37 changes: 28 additions & 9 deletions src/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// It has the same sandbox as a Chrome extension.

// In renderer process (web page).
const { ipcRenderer } = require('electron')
const { ipcRenderer, remote } = require("electron");

const SerialPort = require('serialport');
const parsers = SerialPort.parsers
Expand All @@ -17,6 +17,7 @@ comPath = null;

window.addEventListener('DOMContentLoaded', () => {
window.$ = window.jQuery = require('jquery');
window.jQueryUI = require('jqueryui');
window.Bootstrap = require('bootstrap');
window.Sortable = require('sortablejs');

Expand All @@ -30,16 +31,21 @@ window.addEventListener('DOMContentLoaded', () => {
isPortOpen: isOpen,
onOpen: onOpen,
onError: onError,
checkDarkMode: checkDarkMode
onClose: onClose,
onDisconnect: onDisconnect,
isDarkMode: ipcRenderer.sendSync('isDarkMode', "gimme"),
appVersion: ipcRenderer.sendSync("getVersion", "please"),
getGlobal: getGlobal,
sendEvent: sendEvent
};
})

var isDarkMode = false;
// Send request...
isDarkMode = ipcRenderer.sendSync('isDarkMode', "gimme");
function sendEvent(topic, value) {
ipcRenderer.send(topic, value);
}

function checkDarkMode() {
return isDarkMode;
function getGlobal(value) {
return remote.getGlobal(value);
}

function isOpen() {
Expand All @@ -50,6 +56,14 @@ function onOpen() {
console.log(comPath + " port opened!");
}

function onDisconnect() {
console.log(comPath + " port disconnected!");
}

function onClose() {
console.log(comPath + " port closed!");
}

function onError(message) {
console.error(message);
}
Expand All @@ -73,9 +87,14 @@ function sendMessage(message) {

function updateEvents() {
parser.removeAllListeners("data");
port.removeAllListeners("open");
port.removeAllListeners("open");
port.removeAllListeners("disconnect");
port.removeAllListeners("close");

parser.on('data', window.Bridge.onDataReceive);
port.on('open', window.Bridge.onOpen);
port.on('open', window.Bridge.onOpen);
port.on('disconnect', window.Bridge.onDisconnect);
port.on('close', window.Bridge.onClose);
}

function openSerialConnection() {
Expand Down
Loading

0 comments on commit 5bc46e2

Please sign in to comment.