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'; 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 () => { (async () => {
const { startServer, startOSCServer, startOSCClient } = await import( try {
path.join('file:///', __dirname, env == 'prod' ? '../' : '', 'src/app.js') const { startServer, startOSCServer, startOSCClient } = await import(
); nodePath
// Start express server );
startServer(); // Start express server
// Start OSC Server (API) loaded = startServer();
startOSCServer(); // Start OSC Server (API)
// Start OSC Client (Feedback) startOSCServer();
startOSCClient(); // Start OSC Client (Feedback)
startOSCClient();
} catch (error) {
loaded = error;
}
})(); })();
// Load Icons // Load Icons
@@ -52,7 +63,6 @@ function showNotification(text) {
let win; let win;
let splash; let splash;
let tray = null; let tray = null;
let loaded = false;
function createWindow() { function createWindow() {
// create a new `splash`-Window // create a new `splash`-Window
@@ -97,17 +107,12 @@ function createWindow() {
win.loadURL(reactApp).then(() => { win.loadURL(reactApp).then(() => {
win.webContents.setBackgroundThrottling(false); win.webContents.setBackgroundThrottling(false);
}); });
// Show dev tools
win.webContents.openDevTools({ mode: 'detach' });
} }
app app.whenReady().then(() => {
.whenReady() createWindow();
.then(() => {
createWindow();
/* ====================================== /* ======================================
* CONTEXT MENU CREATION ON REACT SIDE * CONTEXT MENU CREATION ON REACT SIDE
// Create context menu // Create context menu
// const contextMenu = new Menu(); // const contextMenu = new Menu();
@@ -124,62 +129,67 @@ app
* ====================================== * ======================================
*/ */
// register global shortcuts // register global shortcuts
// (available regardless of wheter app is in focus) // (available regardless of wheter app is in focus)
// bring focus to window // bring focus to window
globalShortcut.register('Alt+1', () => { 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(); win.show();
}); splash.destroy();
showNotification(loaded.toString());
}, 2000);
});
// recreate window if no others open // Hide on close
app.on('activate', () => { win.on('close', function (event) {
if (BrowserWindow.getAllWindows().length === 0) { event.preventDefault();
createWindow(); showNotification('App running in background');
} win.hide();
}); return false;
});
win.once('ready-to-show', () => { // create tray
setTimeout(() => { // TODO: Design better icon
win.show(); tray = new Tray(trayIcon);
splash.destroy();
}, 2000);
});
// Hide on close // TODO: Move to separate file
win.on('close', function (event) { // Define context menu
event.preventDefault(); const trayMenuTemplate = [
showNotification('App running in background'); {
win.hide(); label: 'Show App',
return false; click: () => win.show(),
}); },
{
// create tray label: 'Close',
// TODO: Design better icon click: () => {
tray = new Tray(trayIcon); win.destroy();
app.quit();
// TODO: Move to separate file
// Define context menu
const trayMenuTemplate = [
{
label: 'Show App',
click: () => win.show(),
}, },
{ },
label: 'Close', ];
click: () => {
win.destroy();
app.quit();
},
},
];
const trayContextMenu = Menu.buildFromTemplate(trayMenuTemplate); const trayContextMenu = Menu.buildFromTemplate(trayMenuTemplate);
tray.setContextMenu(trayContextMenu); tray.setContextMenu(trayContextMenu);
// TODO: get IP Address // TODO: get IP Address
tray.setToolTip('ontime running on http://localhost:4001/'); tray.setToolTip('ontime running on http://localhost:4001/');
}) });
.then(() => showNotification(loaded));
// unregister shortcuts before quitting // unregister shortcuts before quitting
app.once('will-quit', () => { app.once('will-quit', () => {
@@ -198,10 +208,8 @@ ipcMain.on('shutdown', (event, arg) => {
// terminate node service // terminate node service
(async () => { (async () => {
const { shutdown } = await import( const { shutdown } = await import(nodePath);
path.join('file:///', __dirname, env == 'prod' ? '../' : '', 'src/app.js') // Shutdown service
);
// Start express server
await shutdown(); await shutdown();
})(); })();
+4 -15
View File
@@ -4,18 +4,6 @@
"author": "Carlos Valente", "author": "Carlos Valente",
"description": "Time keeping for live events", "description": "Time keeping for live events",
"main": "main.js", "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": { "devDependencies": {
"concurrently": "^6.1.0", "concurrently": "^6.1.0",
"electron": "^12.0.7", "electron": "^12.0.7",
@@ -28,6 +16,7 @@
"eslint-plugin-react-hooks": "^4.2.0", "eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-simple-import-sort": "^7.0.0" "eslint-plugin-simple-import-sort": "^7.0.0"
}, },
"scripts": { "scripts": {
"nodestart": "NODE_ENV=development node app.js", "nodestart": "NODE_ENV=development node app.js",
"start": "NODE_ENV=development electron .", "start": "NODE_ENV=development electron .",
@@ -44,17 +33,17 @@
"files": [ "files": [
"**/*" "**/*"
], ],
"extraFiles": [ "extraResources": [
{ {
"from": "../client/build", "from": "../client/build",
"to": "resources/client/build", "to": "extraResources/client/build",
"filter": [ "filter": [
"**/*" "**/*"
] ]
}, },
{ {
"from": "src", "from": "src",
"to": "resources/src", "to": "extraResources/src",
"filter": [ "filter": [
"**/*" "**/*"
] ]
+4 -3
View File
@@ -96,13 +96,14 @@ export const startServer = (overrideConfig = null) => {
const serverPort = overrideConfig?.port || config.server.port; const serverPort = overrideConfig?.port || config.server.port;
// Start server // Start server
server.listen(serverPort, '0.0.0.0', () => const returnMessage = `HTTP Server is listening on port ${serverPort}`;
console.log(`HTTP Server is listening on port ${serverPort}`) server.listen(serverPort, '0.0.0.0', () => console.log(returnMessage));
);
// init timer // init timer
global.timer = new EventTimer(server, config); global.timer = new EventTimer(server, config);
global.timer.setupWithEventList(data.events); global.timer.setupWithEventList(data.events);
return returnMessage;
}; };
// Start OSC server // Start OSC server
+21
View File
@@ -1,5 +1,26 @@
{ {
"type": "module", "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": { "scripts": {
"nodestart": "nodemon app.js", "nodestart": "nodemon app.js",
"start": "node 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