2018-02-01 19:52:47 +00:00
|
|
|
/* jshint esversion: 6, asi: true, strict: true*/
|
|
|
|
/* global require, setTimeout, process, console*/
|
|
|
|
|
2017-12-20 03:54:39 +00:00
|
|
|
'use strict'
|
2017-02-09 14:35:07 +00:00
|
|
|
|
2017-12-20 03:54:39 +00:00
|
|
|
const electron = require('electron')
|
2017-12-20 06:20:37 +00:00
|
|
|
const { Menu, MenuItem, ipcMain, BrowserWindow, app } = electron
|
2017-12-20 03:54:39 +00:00
|
|
|
const fs = require('fs')
|
2018-01-06 22:53:05 +00:00
|
|
|
const os = require('os')
|
2019-03-09 03:33:03 +00:00
|
|
|
const { createLogger, format, transports } = require('winston')
|
2019-03-19 18:48:01 +00:00
|
|
|
const { combine, timestamp, label, printf, colorize, prettyPrint, simple } = format
|
2017-12-20 03:54:39 +00:00
|
|
|
const moment = require('moment')
|
|
|
|
const uuid = require('uuid')
|
|
|
|
const events = require('events')
|
2018-01-05 04:42:36 +00:00
|
|
|
const path = require('path')
|
2019-02-08 18:17:14 +00:00
|
|
|
|
2017-12-20 03:54:39 +00:00
|
|
|
const ee = new events.EventEmitter()
|
2019-02-08 18:17:14 +00:00
|
|
|
const settings = require('settings')
|
2019-02-08 19:28:57 +00:00
|
|
|
const system = require('system')
|
2019-02-08 18:17:14 +00:00
|
|
|
const Server = require('server')
|
|
|
|
const Intval = require('intval')
|
2019-02-11 06:08:20 +00:00
|
|
|
const delay = require('delay')
|
2018-01-06 22:53:05 +00:00
|
|
|
|
2019-02-22 18:33:48 +00:00
|
|
|
//Objects
|
2017-12-20 03:54:39 +00:00
|
|
|
const mcopy = {}
|
2016-04-11 06:01:26 +00:00
|
|
|
|
2019-03-21 19:02:54 +00:00
|
|
|
let SYSTEM;
|
2019-03-21 22:09:14 +00:00
|
|
|
let log;
|
2019-03-21 19:02:54 +00:00
|
|
|
let mainWindow;
|
|
|
|
let mscript;
|
|
|
|
let arduino;
|
|
|
|
let server;
|
|
|
|
let menu;
|
|
|
|
let display;
|
|
|
|
let ffmpeg;
|
|
|
|
let ffprobe;
|
|
|
|
let cam;
|
2019-03-21 23:36:37 +00:00
|
|
|
let cam2;
|
2019-03-21 19:02:54 +00:00
|
|
|
let proj;
|
2019-03-21 23:36:37 +00:00
|
|
|
let proj2;
|
2019-03-21 19:02:54 +00:00
|
|
|
let light;
|
|
|
|
let dig;
|
2019-03-21 22:09:14 +00:00
|
|
|
let dev;
|
2019-03-22 07:13:46 +00:00
|
|
|
let cmd;
|
2019-03-22 08:33:53 +00:00
|
|
|
let seq;
|
2019-02-08 18:17:14 +00:00
|
|
|
|
2019-03-21 22:09:14 +00:00
|
|
|
const cfg = require('./data/cfg.json')
|
2016-04-19 03:44:51 +00:00
|
|
|
|
2016-04-11 14:49:57 +00:00
|
|
|
var createMenu = function () {
|
2018-01-05 04:42:36 +00:00
|
|
|
const template = require('./data/menu.json')
|
2017-12-20 06:20:37 +00:00
|
|
|
menu = Menu.buildFromTemplate(template)
|
|
|
|
Menu.setApplicationMenu(menu)
|
|
|
|
}
|
2016-04-11 06:01:26 +00:00
|
|
|
|
2016-04-11 14:49:57 +00:00
|
|
|
var createWindow = function () {
|
2016-04-17 21:55:23 +00:00
|
|
|
mainWindow = new BrowserWindow({
|
|
|
|
width: 800,
|
|
|
|
height: 600,
|
|
|
|
minWidth : 800,
|
2018-03-15 15:55:10 +00:00
|
|
|
minHeight : 600,
|
|
|
|
icon: path.join(__dirname, 'assets/icons/icon.png')
|
2017-12-20 06:20:37 +00:00
|
|
|
})
|
|
|
|
mainWindow.loadURL('file://' + __dirname + '/index.html')
|
2018-02-01 19:52:47 +00:00
|
|
|
if (process.argv.indexOf('-d') !== -1 || process.argv.indexOf('--dev') !== -1) {
|
|
|
|
mainWindow.webContents.openDevTools()
|
|
|
|
}
|
2017-12-20 06:20:37 +00:00
|
|
|
mainWindow.on('closed', () => {
|
|
|
|
mainWindow = null
|
2018-01-05 04:42:36 +00:00
|
|
|
})
|
2016-04-11 06:01:26 +00:00
|
|
|
}
|
|
|
|
|
2019-03-22 08:33:53 +00:00
|
|
|
/*const seq = {};
|
2019-02-08 23:21:16 +00:00
|
|
|
seq.init = function () {
|
|
|
|
seq.listen();
|
|
|
|
}
|
|
|
|
|
|
|
|
seq.listen = function () {
|
|
|
|
ipcMain.on('seq', async (evt, arg) => {
|
|
|
|
if (arg.action === 'stop' && proj.digital) {
|
2019-03-22 02:33:30 +00:00
|
|
|
display.close()
|
|
|
|
} else if (arg.action === 'start' && proj.digital) {
|
|
|
|
display.open()
|
2019-02-08 23:21:16 +00:00
|
|
|
}
|
|
|
|
})
|
2019-03-22 08:33:53 +00:00
|
|
|
}*/
|
2019-02-08 23:21:16 +00:00
|
|
|
|
2018-03-03 03:42:15 +00:00
|
|
|
var init = async function () {
|
2018-01-05 04:42:36 +00:00
|
|
|
|
2019-03-21 19:47:25 +00:00
|
|
|
log = await require('log')({})
|
|
|
|
|
2019-02-08 18:17:14 +00:00
|
|
|
try {
|
2019-02-11 06:08:20 +00:00
|
|
|
SYSTEM = await system()
|
2019-02-08 18:17:14 +00:00
|
|
|
} catch (err) {
|
2019-02-11 06:08:20 +00:00
|
|
|
console.error(err)
|
2019-02-08 18:17:14 +00:00
|
|
|
}
|
|
|
|
|
2017-12-20 06:20:37 +00:00
|
|
|
createWindow()
|
2018-02-01 19:52:47 +00:00
|
|
|
createMenu()
|
2019-02-08 18:17:14 +00:00
|
|
|
|
2019-02-22 18:33:48 +00:00
|
|
|
await settings.restore()
|
|
|
|
|
2019-02-11 06:08:20 +00:00
|
|
|
display = require('display')(SYSTEM)
|
|
|
|
ffmpeg = require('ffmpeg')(SYSTEM)
|
|
|
|
ffprobe = require('ffprobe')(SYSTEM)
|
2019-03-21 22:09:14 +00:00
|
|
|
arduino = require('arduino')(cfg, ee)
|
2019-03-21 19:02:54 +00:00
|
|
|
mscript = require('mscript')
|
2019-03-21 19:08:54 +00:00
|
|
|
|
2019-03-21 22:09:14 +00:00
|
|
|
dev = require('devices')(arduino, settings, mainWindow, cam)
|
2018-01-05 04:42:36 +00:00
|
|
|
|
2019-03-22 08:33:53 +00:00
|
|
|
//why is delay happening still?
|
2018-12-11 02:52:48 +00:00
|
|
|
await delay(2000)
|
2019-03-21 22:09:14 +00:00
|
|
|
|
2019-02-11 06:08:20 +00:00
|
|
|
try {
|
|
|
|
await dev.enumerate()
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
2019-03-21 22:09:14 +00:00
|
|
|
log.error('Error enumerating connected devices', err)
|
2019-02-11 06:08:20 +00:00
|
|
|
}
|
2019-03-21 23:36:37 +00:00
|
|
|
|
|
|
|
light = require('light')(arduino, cfg, mainWindow.webContents)
|
|
|
|
dig = require('digital')(display, ffmpeg, ffprobe, mainWindow.webContents, light)
|
|
|
|
cam = require('cam')(arduino, cfg, mainWindow.webContents, dig)
|
|
|
|
proj = require('proj')(arduino, cfg, mainWindow.webContents, dig)
|
|
|
|
|
2019-03-22 21:06:57 +00:00
|
|
|
cmd = require('cmd')(cfg, proj, cam, light)
|
2019-03-24 01:58:22 +00:00
|
|
|
seq = require('sequencer')(cfg, cmd, mainWindow.webContents)
|
2017-12-20 06:20:37 +00:00
|
|
|
}
|
2016-06-21 15:05:44 +00:00
|
|
|
|
2017-12-20 06:20:37 +00:00
|
|
|
app.on('ready', init)
|
2016-06-21 15:05:44 +00:00
|
|
|
|
2017-12-20 06:20:37 +00:00
|
|
|
app.on('window-all-closed', () => {
|
2019-03-22 21:06:57 +00:00
|
|
|
app.quit();
|
2016-06-21 15:05:44 +00:00
|
|
|
});
|
|
|
|
|
2017-12-20 06:20:37 +00:00
|
|
|
app.on('activate', () => {
|
2016-06-21 15:05:44 +00:00
|
|
|
if (mainWindow === null) {
|
|
|
|
createWindow();
|
|
|
|
}
|
|
|
|
});
|
2018-02-01 19:52:47 +00:00
|
|
|
|
|
|
|
mcopy.relaunch = function () {
|
|
|
|
app.relaunch({args: process.argv.slice(1).concat(['--relaunch'])})
|
|
|
|
app.exit(0)
|
2019-02-11 06:08:20 +00:00
|
|
|
}
|