fix: node imports

changed the config.json files so that the dependencies in node_modules are in the right place
This commit is contained in:
cv
2021-06-06 11:52:13 +02:00
parent 706aca57fe
commit 86878c1d2e
6 changed files with 2501 additions and 902 deletions
+79 -71
View File
@@ -14,16 +14,27 @@ const { Notification } = require('electron');
const env = process.env.NODE_ENV || 'prod';
let loaded = 'Nothing loaded';
const nodePath =
env != 'prod'
? path.join('file://', __dirname, 'src/app.js')
: path.join('file://', __dirname, '../', 'extraResources', 'src/app.js');
(async () => {
const { startServer, startOSCServer, startOSCClient } = await import(
path.join('file:///', __dirname, env == 'prod' ? '../' : '', 'src/app.js')
);
// Start express server
startServer();
// Start OSC Server (API)
startOSCServer();
// Start OSC Client (Feedback)
startOSCClient();
try {
const { startServer, startOSCServer, startOSCClient } = await import(
nodePath
);
// Start express server
loaded = startServer();
// Start OSC Server (API)
startOSCServer();
// Start OSC Client (Feedback)
startOSCClient();
} catch (error) {
loaded = error;
}
})();
// Load Icons
@@ -52,7 +63,6 @@ function showNotification(text) {
let win;
let splash;
let tray = null;
let loaded = false;
function createWindow() {
// create a new `splash`-Window
@@ -97,17 +107,12 @@ function createWindow() {
win.loadURL(reactApp).then(() => {
win.webContents.setBackgroundThrottling(false);
});
// Show dev tools
win.webContents.openDevTools({ mode: 'detach' });
}
app
.whenReady()
.then(() => {
createWindow();
app.whenReady().then(() => {
createWindow();
/* ======================================
/* ======================================
* CONTEXT MENU CREATION ON REACT SIDE
// Create context menu
// const contextMenu = new Menu();
@@ -124,62 +129,67 @@ app
* ======================================
*/
// register global shortcuts
// (available regardless of wheter app is in focus)
// bring focus to window
globalShortcut.register('Alt+1', () => {
// register global shortcuts
// (available regardless of wheter app is in focus)
// bring focus to window
globalShortcut.register('Alt+1', () => {
win.show();
});
globalShortcut.register('Alt+t', () => {
// Show dev tools
win.webContents.openDevTools({ mode: 'detach' });
});
// recreate window if no others open
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
win.once('ready-to-show', () => {
setTimeout(() => {
win.show();
});
splash.destroy();
showNotification(loaded.toString());
}, 2000);
});
// recreate window if no others open
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
// Hide on close
win.on('close', function (event) {
event.preventDefault();
showNotification('App running in background');
win.hide();
return false;
});
win.once('ready-to-show', () => {
setTimeout(() => {
win.show();
splash.destroy();
}, 2000);
});
// create tray
// TODO: Design better icon
tray = new Tray(trayIcon);
// Hide on close
win.on('close', function (event) {
event.preventDefault();
showNotification('App running in background');
win.hide();
return false;
});
// create tray
// TODO: Design better icon
tray = new Tray(trayIcon);
// TODO: Move to separate file
// Define context menu
const trayMenuTemplate = [
{
label: 'Show App',
click: () => win.show(),
// TODO: Move to separate file
// Define context menu
const trayMenuTemplate = [
{
label: 'Show App',
click: () => win.show(),
},
{
label: 'Close',
click: () => {
win.destroy();
app.quit();
},
{
label: 'Close',
click: () => {
win.destroy();
app.quit();
},
},
];
},
];
const trayContextMenu = Menu.buildFromTemplate(trayMenuTemplate);
const trayContextMenu = Menu.buildFromTemplate(trayMenuTemplate);
tray.setContextMenu(trayContextMenu);
// TODO: get IP Address
tray.setToolTip('ontime running on http://localhost:4001/');
})
.then(() => showNotification(loaded));
tray.setContextMenu(trayContextMenu);
// TODO: get IP Address
tray.setToolTip('ontime running on http://localhost:4001/');
});
// unregister shortcuts before quitting
app.once('will-quit', () => {
@@ -198,10 +208,8 @@ ipcMain.on('shutdown', (event, arg) => {
// terminate node service
(async () => {
const { shutdown } = await import(
path.join('file:///', __dirname, env == 'prod' ? '../' : '', 'src/app.js')
);
// Start express server
const { shutdown } = await import(nodePath);
// Shutdown service
await shutdown();
})();
+4 -15
View File
@@ -4,18 +4,6 @@
"author": "Carlos Valente",
"description": "Time keeping for live events",
"main": "main.js",
"dependencies": {
"body-parser": "~1.19.0",
"express": "~4.17.1",
"express-session": "~1.17.1",
"lowdb": "2.1.0",
"multer": "^1.4.2",
"nanoid": "^3.1.22",
"node-osc": "6.0.2",
"passport": "~0.4.1",
"passport-local": "~1.0.0",
"socket.io": "^4.0.0"
},
"devDependencies": {
"concurrently": "^6.1.0",
"electron": "^12.0.7",
@@ -28,6 +16,7 @@
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-simple-import-sort": "^7.0.0"
},
"scripts": {
"nodestart": "NODE_ENV=development node app.js",
"start": "NODE_ENV=development electron .",
@@ -44,17 +33,17 @@
"files": [
"**/*"
],
"extraFiles": [
"extraResources": [
{
"from": "../client/build",
"to": "resources/client/build",
"to": "extraResources/client/build",
"filter": [
"**/*"
]
},
{
"from": "src",
"to": "resources/src",
"to": "extraResources/src",
"filter": [
"**/*"
]
+4 -3
View File
@@ -96,13 +96,14 @@ export const startServer = (overrideConfig = null) => {
const serverPort = overrideConfig?.port || config.server.port;
// Start server
server.listen(serverPort, '0.0.0.0', () =>
console.log(`HTTP Server is listening on port ${serverPort}`)
);
const returnMessage = `HTTP Server is listening on port ${serverPort}`;
server.listen(serverPort, '0.0.0.0', () => console.log(returnMessage));
// init timer
global.timer = new EventTimer(server, config);
global.timer.setupWithEventList(data.events);
return returnMessage;
};
// Start OSC server
+21
View File
@@ -1,5 +1,26 @@
{
"type": "module",
"dependencies": {
"body-parser": "~1.19.0",
"express": "~4.17.1",
"express-session": "~1.17.1",
"lowdb": "2.1.0",
"multer": "^1.4.2",
"nanoid": "^3.1.22",
"node-osc": "6.0.2",
"passport": "~0.4.1",
"passport-local": "~1.0.0",
"socket.io": "^4.0.0"
},
"devDependencies": {
"eslint": "^7.26.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.23.2",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-simple-import-sort": "^7.0.0"
},
"scripts": {
"nodestart": "nodemon app.js",
"start": "node app.js"
+2189
View File
File diff suppressed because it is too large Load Diff
+204 -813
View File
File diff suppressed because it is too large Load Diff