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')
|
|
|
|
const { combine, timestamp, label, printf, prettyPrint } = 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 digital = require('./lib/digital')
|
2018-02-01 19:52:47 +00:00
|
|
|
//const capture = require('./lib/capture')(ee)
|
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 = {}
|
2018-02-01 19:52:47 +00:00
|
|
|
const log = {}
|
|
|
|
const proj = {}
|
|
|
|
const cam = {}
|
|
|
|
const light = {}
|
|
|
|
const dev = {}
|
2016-04-11 06:01:26 +00:00
|
|
|
|
2017-12-20 03:54:39 +00:00
|
|
|
let mainWindow
|
|
|
|
let mscript
|
|
|
|
let arduino
|
2018-01-06 22:53:05 +00:00
|
|
|
let intval
|
2017-12-20 03:54:39 +00:00
|
|
|
let projector
|
|
|
|
let camera
|
2018-01-05 04:42:36 +00:00
|
|
|
let server
|
|
|
|
let menu
|
2017-02-09 14:35:07 +00:00
|
|
|
|
2019-02-08 18:17:14 +00:00
|
|
|
let SYSTEM
|
|
|
|
let capture
|
|
|
|
let display
|
|
|
|
let ffmpeg
|
|
|
|
let ffprobe
|
|
|
|
|
2018-01-05 04:42:36 +00:00
|
|
|
mcopy.cfg = require('./data/cfg.json')
|
2018-01-21 23:53:15 +00:00
|
|
|
mcopy.settings = {}
|
2016-04-15 22:16:14 +00:00
|
|
|
|
2019-02-22 18:33:48 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
|
2018-02-07 18:44:24 +00:00
|
|
|
dev.init = function () {
|
|
|
|
dev.listen()
|
|
|
|
}
|
|
|
|
|
|
|
|
dev.listen = function () {
|
|
|
|
ipcMain.on('profile', (event, arg) => {
|
2018-12-11 03:14:55 +00:00
|
|
|
log.info(`Saving profile ${arg.profile}`, 'SETTINGS', false, false)
|
2018-02-07 18:44:24 +00:00
|
|
|
settings.update('profile', arg.profile)
|
|
|
|
settings.save()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-03-03 03:42:15 +00:00
|
|
|
dev.enumerate = async function () {
|
|
|
|
let devices
|
|
|
|
try{
|
|
|
|
devices = await arduino.enumerate()
|
|
|
|
} catch (err) {
|
2017-12-20 06:20:37 +00:00
|
|
|
log.info(err, 'SERIAL', false, true)
|
2018-03-03 03:42:15 +00:00
|
|
|
await delay(1000)
|
|
|
|
return dev.all([])
|
2016-04-19 01:26:45 +00:00
|
|
|
}
|
2018-03-03 03:42:15 +00:00
|
|
|
log.info(`Found ${devices.length} USB devices`, 'SERIAL', true, true)
|
|
|
|
devices = dev.favor(devices)
|
2018-12-11 02:52:48 +00:00
|
|
|
return await dev.all(devices)
|
2017-12-20 06:20:37 +00:00
|
|
|
}
|
2016-04-19 01:26:45 +00:00
|
|
|
|
2018-02-01 19:52:47 +00:00
|
|
|
dev.favor = function (devices) {
|
|
|
|
const past = mcopy.settings.devices.filter(device => {
|
|
|
|
if (device.arduino) {
|
|
|
|
return device
|
2018-02-01 02:46:03 +00:00
|
|
|
}
|
2018-02-01 19:52:47 +00:00
|
|
|
}).map(device => {
|
|
|
|
return device.arduino
|
2018-02-01 02:46:03 +00:00
|
|
|
})
|
|
|
|
if (past.length === 0) {
|
|
|
|
return devices
|
|
|
|
}
|
|
|
|
devices.sort((a, b) => {
|
|
|
|
if (past.indexOf(a) !== -1 && past.indexOf(b) === -1) {
|
|
|
|
return 1
|
|
|
|
} else if (past.indexOf(a) === -1 && past.indexOf(b) !== -1) {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
})
|
|
|
|
return devices
|
|
|
|
}
|
|
|
|
|
2018-03-03 05:27:49 +00:00
|
|
|
dev.distinguish = async function (device) {
|
2018-03-03 03:42:15 +00:00
|
|
|
let connectSuccess
|
|
|
|
let verifySuccess
|
|
|
|
let type
|
|
|
|
|
|
|
|
try {
|
|
|
|
connectSuccess = await arduino.connect('connect', device, true)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
await delay(2000)
|
|
|
|
|
|
|
|
try {
|
|
|
|
verifySuccess = await arduino.verify()
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
log.info(`Verified ${device} as mcopy device`, 'SERIAL', true, true)
|
|
|
|
|
|
|
|
await delay(1000)
|
|
|
|
|
|
|
|
try {
|
|
|
|
type = await arduino.distinguish()
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
dev.remember('arduino', device, type)
|
|
|
|
log.info(`Determined ${device} to be ${type}`, 'SERIAL', true, true)
|
|
|
|
|
|
|
|
return type
|
|
|
|
}
|
|
|
|
|
|
|
|
dev.fakeProjector = async function () {
|
|
|
|
dev.connected.projector = '/dev/fake'
|
|
|
|
try {
|
|
|
|
await arduino.fakeConnect('projector')
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
log.error(`Error connecting to fake PRONECTOR device`, 'SERIAL', true, true)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
log.info('Connected to fake PROJECTOR device', 'SERIAL', true, true)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
dev.fakeCamera = async function () {
|
|
|
|
dev.connected.camera = '/dev/fake'
|
|
|
|
try {
|
|
|
|
await arduino.fakeConnect('camera')
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
log.error(`Error connecting to fake CAMERA device`, 'SERIAL', true, true)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
log.info('Connected to fake CAMERA device', 'SERIAL', true, true)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
dev.fakeLight = async function () {
|
|
|
|
dev.connected.light = '/dev/fake'
|
|
|
|
try {
|
|
|
|
await arduino.fakeConnect('light')
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
log.error(`Error connecting to fake LIGHT device`, 'SERIAL', true, true)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
log.info('Connected to fake LIGHT device', 'SERIAL', true, true)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
dev.connectDevice = async function (device, type) {
|
|
|
|
let closeSuccess
|
|
|
|
let connectSuccess
|
|
|
|
try {
|
|
|
|
closeSuccess = await arduino.close()
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (type === 'projector') {
|
|
|
|
dev.connected.projector = device
|
|
|
|
try {
|
|
|
|
connectSuccess = await arduino.connect('projector', device, false)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
return false
|
2016-04-19 01:26:45 +00:00
|
|
|
}
|
2018-03-03 03:42:15 +00:00
|
|
|
log.info(`Connected to ${device} as PROJECTOR`, 'SERIAL', true, true)
|
|
|
|
} else if (type === 'camera') {
|
|
|
|
dev.connected.camera = device
|
|
|
|
try {
|
|
|
|
connectSuccess = await arduino.connect('camera', device, false)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
return false
|
2016-04-19 01:26:45 +00:00
|
|
|
}
|
2018-03-03 03:42:15 +00:00
|
|
|
log.info(`Connected to ${device} as CAMERA`, 'SERIAL', true, true)
|
|
|
|
} else if (type === 'light') {
|
|
|
|
dev.connected.light = device
|
|
|
|
try {
|
|
|
|
connectSuccess = await arduino.connect('light', device, false)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
return false
|
2016-04-19 01:26:45 +00:00
|
|
|
}
|
2018-03-03 03:42:15 +00:00
|
|
|
log.info(`Connected to ${device} as LIGHT`, 'SERIAL', true, true)
|
|
|
|
} else if (type === 'projector,light') {
|
|
|
|
dev.connected.projector = device
|
|
|
|
dev.connected.light = device
|
2019-03-09 03:33:03 +00:00
|
|
|
arduino.aliasSerial('light', device)
|
2018-03-03 03:42:15 +00:00
|
|
|
try{
|
|
|
|
connectSuccess = await arduino.connect('projector', device, false)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
log.info(`Connected to ${device} as PROJECTOR + LIGHT`, 'SERIAL', true, true)
|
|
|
|
|
|
|
|
} else if (type === 'projector,camera,light') {
|
|
|
|
dev.connected.projector = device
|
|
|
|
dev.connected.camera = device
|
|
|
|
dev.connected.light = device
|
2019-03-09 03:33:03 +00:00
|
|
|
arduino.aliasSerial('camera', device)
|
|
|
|
arduino.aliasSerial('light', device)
|
2018-03-03 03:42:15 +00:00
|
|
|
try {
|
|
|
|
connectSuccess = await arduino.connect('projector', device, false)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
log.info(`Connected to ${device} as PROJECTOR + CAMERA + LIGHT`, 'SERIAL', true, true)
|
|
|
|
|
|
|
|
} else if (type === 'projector,camera') {
|
|
|
|
dev.connected.projector = device
|
|
|
|
dev.connected.camera = device
|
2019-03-09 03:33:03 +00:00
|
|
|
arduino.aliasSerial('camera', device)
|
2018-03-03 03:42:15 +00:00
|
|
|
try {
|
|
|
|
connectSuccess = await arduino.connect('projector', device, false)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
log.info(`Connected to ${device} as PROJECTOR`, 'SERIAL', true, true)
|
2019-02-25 23:14:19 +00:00
|
|
|
} else if (type === 'projector_second') {
|
|
|
|
dev.connected.projector_second = device
|
2019-03-09 03:33:03 +00:00
|
|
|
arduino.aliasSerial('projector_second', device)
|
2019-02-25 23:14:19 +00:00
|
|
|
try {
|
|
|
|
connectSuccess = await arduino.connect('projector_second', device, false)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
return false
|
|
|
|
}
|
2016-04-19 01:26:45 +00:00
|
|
|
}
|
2018-03-03 03:42:15 +00:00
|
|
|
return connectSuccess
|
|
|
|
}
|
2016-04-19 01:26:45 +00:00
|
|
|
|
|
|
|
//Cases for 1 or 2 arduinos connected
|
2018-03-03 03:42:15 +00:00
|
|
|
dev.all = async function (devices) {
|
2018-03-03 05:27:49 +00:00
|
|
|
let c = {}
|
|
|
|
let p = {}
|
|
|
|
let l = {}
|
2018-12-11 02:52:48 +00:00
|
|
|
let type
|
|
|
|
let d
|
2019-02-26 16:49:00 +00:00
|
|
|
let s = {}
|
2018-12-11 02:52:48 +00:00
|
|
|
|
2018-03-03 05:27:49 +00:00
|
|
|
|
2018-03-03 03:42:15 +00:00
|
|
|
dev.connected = {
|
2018-01-02 06:16:33 +00:00
|
|
|
projector : false,
|
|
|
|
camera : false,
|
2019-02-25 23:14:19 +00:00
|
|
|
light : false,
|
|
|
|
projector_second : false
|
2018-01-02 06:16:33 +00:00
|
|
|
}
|
2018-01-05 04:42:36 +00:00
|
|
|
|
|
|
|
let checklist = []
|
2018-03-03 03:42:15 +00:00
|
|
|
|
2018-12-11 02:52:48 +00:00
|
|
|
for (let device of devices) {
|
|
|
|
try {
|
|
|
|
type = await dev.distinguish(device)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
return reject(err)
|
|
|
|
}
|
2018-03-03 05:27:49 +00:00
|
|
|
|
2018-12-11 02:52:48 +00:00
|
|
|
try {
|
|
|
|
await dev.connectDevice(device, type)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
return reject(err)
|
|
|
|
}
|
|
|
|
}
|
2018-01-02 06:16:33 +00:00
|
|
|
|
2018-03-03 03:42:15 +00:00
|
|
|
//done checking devices
|
2018-01-31 15:42:11 +00:00
|
|
|
|
2018-03-03 03:42:15 +00:00
|
|
|
if (!dev.connected.projector) {
|
|
|
|
await dev.fakeProjector()
|
|
|
|
}
|
|
|
|
p.arduino = dev.connected.projector
|
|
|
|
if (!dev.connected.camera) {
|
|
|
|
await dev.fakeCamera()
|
|
|
|
}
|
|
|
|
c.arduino = dev.connected.camera
|
2018-02-01 19:52:47 +00:00
|
|
|
|
2018-03-03 03:42:15 +00:00
|
|
|
if (mcopy.settings.camera.intval) {
|
|
|
|
c.intval = mcopy.settings.camera.intval
|
|
|
|
await delay(1000)
|
2019-02-24 03:19:42 +00:00
|
|
|
await cam.connectIntval(null, { connect : true, url : c.intval })
|
2018-03-03 03:42:15 +00:00
|
|
|
}
|
2018-02-01 19:52:47 +00:00
|
|
|
|
2018-03-03 03:42:15 +00:00
|
|
|
if (!dev.connected.light) {
|
|
|
|
await dev.fakeLight()
|
|
|
|
}
|
2018-02-01 19:52:47 +00:00
|
|
|
|
2018-03-03 03:42:15 +00:00
|
|
|
l.arduino = dev.connected.light
|
|
|
|
|
2019-02-26 16:49:00 +00:00
|
|
|
if (dev.connected.projector_second) {
|
|
|
|
s = dev.connected.projector_second
|
|
|
|
}
|
|
|
|
|
|
|
|
return dev.ready(p, c, l, s)
|
2018-03-03 03:42:15 +00:00
|
|
|
}
|
2016-04-11 06:01:26 +00:00
|
|
|
|
2018-02-01 19:52:47 +00:00
|
|
|
dev.remember = function (which, device, type) {
|
2018-01-22 20:04:08 +00:00
|
|
|
let deviceEntry
|
2018-02-01 19:52:47 +00:00
|
|
|
const match = mcopy.settings.devices.filter(dev => {
|
|
|
|
if (dev[which] && dev[which] === device) {
|
2018-01-22 20:04:08 +00:00
|
|
|
return dev
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (match.length === 0) {
|
|
|
|
deviceEntry = {
|
|
|
|
type : type
|
|
|
|
}
|
2018-02-01 19:52:47 +00:00
|
|
|
deviceEntry[which] = device
|
2018-01-22 20:04:08 +00:00
|
|
|
mcopy.settings.devices.push(deviceEntry)
|
|
|
|
settings.update('devices', mcopy.settings.devices)
|
|
|
|
settings.save()
|
|
|
|
}
|
2018-02-01 19:52:47 +00:00
|
|
|
};
|
2018-01-22 20:04:08 +00:00
|
|
|
|
2019-02-26 21:43:14 +00:00
|
|
|
dev.ready = function (projector, camera, light, projector_second) {
|
|
|
|
let args = {
|
2018-12-11 02:52:48 +00:00
|
|
|
camera,
|
|
|
|
projector,
|
|
|
|
light,
|
2018-02-01 19:52:47 +00:00
|
|
|
profile: mcopy.settings.profile
|
2019-02-26 21:43:14 +00:00
|
|
|
}
|
|
|
|
if (projector_second && projector_second.arduino) {
|
|
|
|
args.projector_second = projector_second
|
|
|
|
}
|
|
|
|
mainWindow.webContents.send('ready', args)
|
2018-02-01 19:52:47 +00:00
|
|
|
settings.update('camera', camera)
|
|
|
|
settings.update('projector', projector)
|
|
|
|
settings.update('light', light)
|
2019-02-26 21:43:14 +00:00
|
|
|
if (projector_second && projector_second.arduino) {
|
|
|
|
settings.update('projector_second', projector_second)
|
|
|
|
mainWindow.setSize(800, 800)
|
|
|
|
}
|
2018-01-05 04:42:36 +00:00
|
|
|
settings.save()
|
2018-03-03 05:27:49 +00:00
|
|
|
return true
|
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-02-11 06:08:20 +00:00
|
|
|
light.state = {
|
2019-02-13 23:57:18 +00:00
|
|
|
color : [0, 0, 0]
|
2019-02-11 06:08:20 +00:00
|
|
|
}
|
|
|
|
|
2016-04-17 21:55:23 +00:00
|
|
|
light.init = function () {
|
2017-12-20 06:20:37 +00:00
|
|
|
light.listen()
|
2018-02-01 19:52:47 +00:00
|
|
|
}
|
2016-04-17 21:55:23 +00:00
|
|
|
light.listen = function () {
|
2018-03-15 15:55:10 +00:00
|
|
|
ipcMain.on('light', async (event, arg) => {
|
2018-03-15 16:08:23 +00:00
|
|
|
try {
|
2019-02-13 23:57:18 +00:00
|
|
|
await light.set(arg.rgb, arg.id)
|
2018-03-15 16:08:23 +00:00
|
|
|
}catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
return reject(err)
|
|
|
|
}
|
|
|
|
event.returnValue = true
|
2017-12-20 06:20:37 +00:00
|
|
|
})
|
2018-02-01 19:52:47 +00:00
|
|
|
}
|
2019-02-11 06:08:20 +00:00
|
|
|
light.set = async function (rgb, id, on) {
|
2018-03-03 05:27:49 +00:00
|
|
|
const str = rgb.join(',');
|
|
|
|
let ms
|
2019-02-11 06:08:20 +00:00
|
|
|
light.state.color = rgb;
|
2018-03-03 05:27:49 +00:00
|
|
|
try {
|
2018-03-15 16:08:23 +00:00
|
|
|
ms = arduino.send('light', mcopy.cfg.arduino.cmd.light)
|
2018-03-03 05:27:49 +00:00
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
2018-03-15 16:08:23 +00:00
|
|
|
await delay(1)
|
2018-03-15 15:55:10 +00:00
|
|
|
try {
|
|
|
|
arduino.string('light', str)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
2018-03-15 16:08:23 +00:00
|
|
|
await delay(1)
|
|
|
|
await ms
|
2018-03-03 05:27:49 +00:00
|
|
|
return await light.end(rgb, id, ms)
|
2018-02-01 19:52:47 +00:00
|
|
|
}
|
2018-03-03 05:27:49 +00:00
|
|
|
light.end = async function (rgb, id, ms) {
|
2017-12-20 06:20:37 +00:00
|
|
|
log.info('Light set to ' + rgb.join(','), 'LIGHT', true, true)
|
2018-03-15 16:08:23 +00:00
|
|
|
return await mainWindow.webContents.send('light', { rgb: rgb, id : id, ms: ms })
|
2018-02-01 19:52:47 +00:00
|
|
|
}
|
2016-04-13 04:06:19 +00:00
|
|
|
|
2016-04-18 02:22:18 +00:00
|
|
|
proj.state = {
|
2019-02-08 23:21:16 +00:00
|
|
|
dir : true, //default dir
|
|
|
|
digital : false
|
2018-02-01 19:52:47 +00:00
|
|
|
}
|
2016-04-18 02:22:18 +00:00
|
|
|
proj.init = function () {
|
2017-12-20 06:20:37 +00:00
|
|
|
proj.listen()
|
|
|
|
}
|
2018-03-03 05:27:49 +00:00
|
|
|
proj.set = async function (dir, id) {
|
|
|
|
let cmd
|
|
|
|
let ms
|
2016-04-18 02:22:18 +00:00
|
|
|
if (dir) {
|
2017-12-20 06:20:37 +00:00
|
|
|
cmd = mcopy.cfg.arduino.cmd.proj_forward
|
2016-04-18 02:22:18 +00:00
|
|
|
} else {
|
2017-12-20 06:20:37 +00:00
|
|
|
cmd = mcopy.cfg.arduino.cmd.proj_backward
|
2016-04-18 02:22:18 +00:00
|
|
|
}
|
2017-12-20 06:20:37 +00:00
|
|
|
proj.state.dir = dir
|
2019-02-24 03:19:42 +00:00
|
|
|
if (proj.state.digital) {
|
2019-02-08 23:21:16 +00:00
|
|
|
dig.set(dir)
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
ms = await arduino.send('projector', cmd)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
2018-03-03 05:27:49 +00:00
|
|
|
}
|
|
|
|
return await proj.end(cmd, id, ms)
|
2017-12-20 06:20:37 +00:00
|
|
|
}
|
2018-03-03 05:27:49 +00:00
|
|
|
proj.move = async function (frame, id) {
|
|
|
|
const cmd = mcopy.cfg.arduino.cmd.projector
|
|
|
|
let ms
|
2019-02-08 23:21:16 +00:00
|
|
|
if (proj.digital) {
|
|
|
|
try {
|
|
|
|
ms = await dig.move()
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
ms = await arduino.send('projector', cmd)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
2018-03-03 05:27:49 +00:00
|
|
|
}
|
|
|
|
return await proj.end(mcopy.cfg.arduino.cmd.projector, id, ms)
|
2017-12-20 06:20:37 +00:00
|
|
|
}
|
2016-04-18 02:22:18 +00:00
|
|
|
proj.listen = function () {
|
2018-03-15 15:55:10 +00:00
|
|
|
ipcMain.on('proj', async (event, arg) => {
|
2016-04-18 02:22:18 +00:00
|
|
|
if (typeof arg.dir !== 'undefined') {
|
2018-03-15 15:55:10 +00:00
|
|
|
try {
|
|
|
|
await proj.set(arg.dir, arg.id)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
2016-04-18 02:22:18 +00:00
|
|
|
} else if (typeof arg.frame !== 'undefined') {
|
2018-03-15 15:55:10 +00:00
|
|
|
try {
|
|
|
|
await proj.move(arg.frame, arg.id)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
2019-02-24 03:19:42 +00:00
|
|
|
} else if (typeof arg.val !== 'undefined') {
|
|
|
|
dig.state.frame = arg.val
|
2016-04-18 02:22:18 +00:00
|
|
|
}
|
2017-12-20 06:20:37 +00:00
|
|
|
event.returnValue = true
|
|
|
|
})
|
2019-02-08 23:21:16 +00:00
|
|
|
ipcMain.on('digital', proj.connectDigital)
|
2017-12-20 06:20:37 +00:00
|
|
|
}
|
2018-03-03 05:27:49 +00:00
|
|
|
proj.end = async function (cmd, id, ms) {
|
|
|
|
let message = ''
|
2016-04-18 02:22:18 +00:00
|
|
|
if (cmd === mcopy.cfg.arduino.cmd.proj_forward) {
|
2017-12-20 06:20:37 +00:00
|
|
|
message = 'Projector set to FORWARD'
|
2016-04-18 02:22:18 +00:00
|
|
|
} else if (cmd === mcopy.cfg.arduino.cmd.proj_backward) {
|
2017-12-20 06:20:37 +00:00
|
|
|
message = 'Projector set to BACKWARD'
|
2016-04-18 02:22:18 +00:00
|
|
|
} else if (cmd === mcopy.cfg.arduino.cmd.projector) {
|
2017-12-20 06:20:37 +00:00
|
|
|
message = 'Projector '
|
2016-04-18 02:22:18 +00:00
|
|
|
if (proj.state.dir) {
|
2017-12-20 06:20:37 +00:00
|
|
|
message += 'ADVANCED'
|
2016-04-18 02:22:18 +00:00
|
|
|
} else {
|
|
|
|
message += 'REWOUND'
|
|
|
|
}
|
2017-12-20 06:20:37 +00:00
|
|
|
message += ' 1 frame'
|
2016-04-18 02:22:18 +00:00
|
|
|
}
|
2017-12-20 06:20:37 +00:00
|
|
|
log.info(message, 'PROJECTOR', true, true)
|
2018-03-03 05:27:49 +00:00
|
|
|
return await mainWindow.webContents.send('proj', {cmd: cmd, id : id, ms: ms})
|
2017-12-20 06:20:37 +00:00
|
|
|
}
|
2016-04-18 03:02:22 +00:00
|
|
|
|
2019-02-08 23:21:16 +00:00
|
|
|
/**
|
|
|
|
* Use a file as the "digital" source on "projector"
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
proj.connectDigital = async function (evt, arg) {
|
|
|
|
let info;
|
|
|
|
let frames = 0;
|
|
|
|
|
|
|
|
try {
|
|
|
|
info = await ffprobe.info(arg.path);
|
|
|
|
} catch (err) {
|
|
|
|
log.error(err, 'DIGITAL', true, true);
|
|
|
|
proj.digital = false;
|
|
|
|
await mainWindow.webContents.send('digital', { valid : false });
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
frames = await ffprobe.frames(arg.path);
|
|
|
|
} catch (err) {
|
|
|
|
log.error(err, 'DIGITAL', true, true);
|
|
|
|
proj.digital = false;
|
|
|
|
await mainWindow.webContents.send('digital', { valid : false });
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
dig.state.frame = 0;
|
|
|
|
dig.state.path = arg.path;
|
|
|
|
dig.state.fileName = arg.fileName;
|
|
|
|
dig.state.frames = frames;
|
|
|
|
dig.state.info = info;
|
|
|
|
|
2019-02-11 06:08:20 +00:00
|
|
|
//console.dir(dig.state);
|
2019-02-08 23:21:16 +00:00
|
|
|
|
|
|
|
log.info(`Opened ${dig.state.fileName}`, 'DIGITAL', true, true);
|
|
|
|
log.info(`Frames : ${frames}`, 'DIGITAL', true, true);
|
|
|
|
proj.digital = true;
|
|
|
|
return await mainWindow.webContents.send('digital', { valid : true, state : JSON.stringify(dig.state) });
|
|
|
|
}
|
|
|
|
|
|
|
|
const dig = {};
|
|
|
|
dig.state = {
|
|
|
|
frame : 0,
|
|
|
|
frames : 0,
|
|
|
|
path : null,
|
|
|
|
fileName : null,
|
|
|
|
info : {},
|
|
|
|
dir : true
|
|
|
|
};
|
|
|
|
|
|
|
|
dig.set = function (dir) {
|
|
|
|
dig.state.dir = dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
dig.move = async function () {
|
|
|
|
let start = +new Date()
|
|
|
|
let last = dig.state.dir + 0;
|
|
|
|
if (dig.state.dir) {
|
|
|
|
dig.state.frame++
|
|
|
|
} else {
|
|
|
|
dig.state.frame--
|
|
|
|
}
|
|
|
|
if (dig.state.frame < 1) {
|
|
|
|
dig.state.frame = 1
|
|
|
|
}
|
2019-02-13 23:49:59 +00:00
|
|
|
return (+new Date()) - start
|
|
|
|
}
|
2019-02-08 23:21:16 +00:00
|
|
|
|
2019-02-13 23:49:59 +00:00
|
|
|
dig.start = async function () {
|
2019-02-08 23:21:16 +00:00
|
|
|
try {
|
2019-02-10 19:07:07 +00:00
|
|
|
await ffmpeg.clearAll()
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2019-02-11 06:08:20 +00:00
|
|
|
await ffmpeg.frame(dig.state, light.state)
|
2019-02-08 23:21:16 +00:00
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
display.start(dig.state.frame)
|
2019-02-13 23:49:59 +00:00
|
|
|
await delay(20)
|
|
|
|
}
|
2019-02-08 23:21:16 +00:00
|
|
|
|
2019-02-13 23:49:59 +00:00
|
|
|
dig.end = async function () {
|
|
|
|
await delay(20)
|
|
|
|
display.end()
|
2019-02-08 23:21:16 +00:00
|
|
|
}
|
|
|
|
|
2018-02-01 19:52:47 +00:00
|
|
|
cam.intval = null
|
2016-04-18 03:02:22 +00:00
|
|
|
cam.state = {
|
|
|
|
dir : true //default dir
|
2017-12-20 06:20:37 +00:00
|
|
|
}
|
2016-04-18 03:02:22 +00:00
|
|
|
cam.init = function () {
|
2017-12-20 06:20:37 +00:00
|
|
|
cam.listen()
|
|
|
|
}
|
2018-03-03 05:27:49 +00:00
|
|
|
cam.set = async function (dir, id) {
|
2018-01-06 22:53:05 +00:00
|
|
|
let cmd
|
2018-03-03 05:27:49 +00:00
|
|
|
let ms
|
2016-04-18 03:02:22 +00:00
|
|
|
if (dir) {
|
2017-12-20 06:20:37 +00:00
|
|
|
cmd = mcopy.cfg.arduino.cmd.cam_forward
|
2016-04-18 03:02:22 +00:00
|
|
|
} else {
|
2017-12-20 06:20:37 +00:00
|
|
|
cmd = mcopy.cfg.arduino.cmd.cam_backward
|
2016-04-18 03:02:22 +00:00
|
|
|
}
|
2017-12-20 06:20:37 +00:00
|
|
|
cam.state.dir = dir
|
2018-02-01 19:52:47 +00:00
|
|
|
|
|
|
|
if (cam.intval) {
|
2018-03-03 05:27:49 +00:00
|
|
|
try {
|
|
|
|
ms = await cam.intval.setDir(dir)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
2018-02-01 19:52:47 +00:00
|
|
|
} else {
|
2018-03-03 05:27:49 +00:00
|
|
|
try {
|
|
|
|
ms = await arduino.send('camera', cmd)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
2018-02-01 19:52:47 +00:00
|
|
|
}
|
2018-03-03 05:27:49 +00:00
|
|
|
return await cam.end(cmd, id, ms)
|
2017-12-20 06:20:37 +00:00
|
|
|
}
|
2018-01-05 04:42:36 +00:00
|
|
|
|
2018-03-03 05:27:49 +00:00
|
|
|
cam.move = async function (frame, id) {
|
|
|
|
const cmd = mcopy.cfg.arduino.cmd.camera
|
|
|
|
let ms
|
2019-02-13 23:49:59 +00:00
|
|
|
if (proj.digital) {
|
|
|
|
await dig.start()
|
|
|
|
}
|
2018-02-01 19:52:47 +00:00
|
|
|
if (cam.intval) {
|
2019-02-08 23:21:16 +00:00
|
|
|
try {
|
|
|
|
ms = await cam.intval.move()
|
|
|
|
} catch (err) {
|
2019-02-13 23:49:59 +00:00
|
|
|
console.error(err)
|
2019-02-08 23:21:16 +00:00
|
|
|
}
|
2018-02-01 19:52:47 +00:00
|
|
|
} else {
|
2019-02-08 23:21:16 +00:00
|
|
|
try {
|
|
|
|
ms = await arduino.send('camera', cmd)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
2018-02-01 19:52:47 +00:00
|
|
|
}
|
2019-02-13 23:49:59 +00:00
|
|
|
if (proj.digital) {
|
|
|
|
await dig.end()
|
|
|
|
}
|
2018-12-11 03:14:55 +00:00
|
|
|
log.info('Camera move time', { ms })
|
2018-03-03 05:27:49 +00:00
|
|
|
return cam.end(cmd, id, ms)
|
2018-01-17 17:23:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cam.exposure = function (exposure, id) {
|
2018-02-01 19:52:47 +00:00
|
|
|
let cmd = 'E'
|
|
|
|
cam.intval.setDir('camera', exposure, ms => {
|
2018-01-06 22:53:05 +00:00
|
|
|
cam.end(cmd, id, ms)
|
2017-12-20 06:20:37 +00:00
|
|
|
})
|
|
|
|
}
|
2018-01-05 04:42:36 +00:00
|
|
|
|
2018-12-11 02:52:48 +00:00
|
|
|
cam.connectIntval = async function (event, arg) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
if (arg.connect) {
|
|
|
|
cam.intval = new Intval(arg.url)
|
|
|
|
cam.intval.connect((err, ms, state) => {
|
|
|
|
if (err) {
|
|
|
|
mainWindow.webContents.send('intval', { connected : false })
|
|
|
|
log.info(`Cannot connect to ${arg.url}`, 'INTVAL', true, true)
|
|
|
|
cam.intval = null
|
|
|
|
delete cam.intval
|
|
|
|
} else {
|
|
|
|
mainWindow.webContents.send('intval', { connected : true, url : arg.url, state : state })
|
|
|
|
log.info(`Connected to INTVAL3 @ ${arg.url}`, 'INTVAL', true, true)
|
|
|
|
settings.update('camera', { intval : arg.url })
|
|
|
|
settings.save()
|
|
|
|
dev.remember('intval', arg.url, 'camera')
|
|
|
|
}
|
|
|
|
return resolve(true)
|
|
|
|
})
|
|
|
|
} else if (arg.disconnect) {
|
|
|
|
cam.intval = null
|
|
|
|
return resolve(false)
|
|
|
|
}
|
|
|
|
})
|
2018-02-01 19:52:47 +00:00
|
|
|
}
|
|
|
|
|
2016-04-18 03:02:22 +00:00
|
|
|
cam.listen = function () {
|
2018-03-15 15:55:10 +00:00
|
|
|
ipcMain.on('cam', async (event, arg) => {
|
2016-04-18 03:02:22 +00:00
|
|
|
if (typeof arg.dir !== 'undefined') {
|
2018-03-15 15:55:10 +00:00
|
|
|
try {
|
|
|
|
await cam.set(arg.dir, arg.id)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
2016-04-18 03:02:22 +00:00
|
|
|
} else if (typeof arg.frame !== 'undefined') {
|
2018-03-15 15:55:10 +00:00
|
|
|
try {
|
|
|
|
await cam.move(arg.frame, arg.id)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
2016-04-18 03:02:22 +00:00
|
|
|
}
|
2017-12-20 06:20:37 +00:00
|
|
|
event.returnValue = true
|
2018-01-31 15:42:11 +00:00
|
|
|
})
|
2018-02-01 19:52:47 +00:00
|
|
|
ipcMain.on('intval', cam.connectIntval)
|
2018-01-31 15:42:11 +00:00
|
|
|
}
|
2018-03-03 05:27:49 +00:00
|
|
|
cam.end = async function (cmd, id, ms) {
|
2017-12-20 06:20:37 +00:00
|
|
|
var message = ''
|
2016-04-18 03:02:22 +00:00
|
|
|
if (cmd === mcopy.cfg.arduino.cmd.cam_forward) {
|
2017-12-20 06:20:37 +00:00
|
|
|
message = 'Camera set to FORWARD'
|
2016-04-18 03:02:22 +00:00
|
|
|
} else if (cmd === mcopy.cfg.arduino.cmd.cam_backward) {
|
2017-12-20 06:20:37 +00:00
|
|
|
message = 'Camera set to BACKWARD'
|
2016-04-18 03:02:22 +00:00
|
|
|
} else if (cmd === mcopy.cfg.arduino.cmd.camera) {
|
2017-12-20 06:20:37 +00:00
|
|
|
message = 'Camera '
|
2016-04-18 03:02:22 +00:00
|
|
|
if (cam.state.dir) {
|
2017-12-20 06:20:37 +00:00
|
|
|
message += 'ADVANCED'
|
2016-04-18 03:02:22 +00:00
|
|
|
} else {
|
|
|
|
message += 'REWOUND'
|
|
|
|
}
|
2017-12-20 06:20:37 +00:00
|
|
|
message += ' 1 frame'
|
2016-04-18 03:02:22 +00:00
|
|
|
}
|
2017-12-20 06:20:37 +00:00
|
|
|
log.info(message, 'CAMERA', true, true)
|
|
|
|
mainWindow.webContents.send('cam', {cmd: cmd, id : id, ms: ms})
|
2016-04-18 02:22:18 +00:00
|
|
|
};
|
|
|
|
|
2019-02-08 23:21:16 +00:00
|
|
|
const seq = {};
|
|
|
|
seq.init = function () {
|
|
|
|
seq.listen();
|
|
|
|
}
|
|
|
|
|
|
|
|
seq.listen = function () {
|
|
|
|
ipcMain.on('seq', async (evt, arg) => {
|
|
|
|
if (arg.action === 'stop' && proj.digital) {
|
|
|
|
display.end()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-01-05 04:42:36 +00:00
|
|
|
log.file = function () {
|
2018-01-06 22:53:05 +00:00
|
|
|
let logPath = path.join(os.homedir(), `/.config/mcopy/`)
|
2018-01-05 14:17:41 +00:00
|
|
|
if (process.platform === 'darwin') {
|
2018-01-06 22:53:05 +00:00
|
|
|
logPath = path.join(os.homedir(), `/Library/Logs/mcopy/`)
|
2018-01-05 14:17:41 +00:00
|
|
|
} else if (process.platform === 'win32') {
|
2018-01-06 22:53:05 +00:00
|
|
|
logPath = path.join(os.homedir(), `/AppData/Roaming/mcopy/`)
|
|
|
|
}
|
|
|
|
if (!fs.existsSync(logPath)) {
|
|
|
|
fs.mkdirSync(logPath)
|
2018-01-05 04:42:36 +00:00
|
|
|
}
|
|
|
|
return path.join(logPath, 'mcopy.log')
|
|
|
|
}
|
2017-12-20 06:20:37 +00:00
|
|
|
log.time = 'MM/DD/YY-HH:mm:ss'
|
2019-03-09 03:33:03 +00:00
|
|
|
log.formatter = (options) => {
|
|
|
|
console.dir(options)
|
|
|
|
return options.timestamp() +' ['+ options.level.toUpperCase() +'] '+ (undefined !== options.message ? options.message : '') +
|
|
|
|
(options.meta && Object.keys(options.meta).length ? '\n\t'+ JSON.stringify(options.meta) : '' );
|
|
|
|
}
|
|
|
|
log.transport = createLogger({
|
2016-04-13 02:55:51 +00:00
|
|
|
transports: [
|
2019-03-09 03:33:03 +00:00
|
|
|
new (transports.Console)({
|
|
|
|
json : false,
|
|
|
|
format : combine(
|
2019-03-09 18:17:32 +00:00
|
|
|
label({ label: 'mcopy-app' }),
|
|
|
|
timestamp(),
|
2019-03-09 03:33:03 +00:00
|
|
|
//format.colorize({ all: true }),
|
|
|
|
//format.splat(),
|
|
|
|
//format.json(),
|
2019-03-09 18:17:32 +00:00
|
|
|
format.simple(),
|
|
|
|
//log.formatter
|
2019-03-09 03:33:03 +00:00
|
|
|
)
|
|
|
|
}),
|
|
|
|
new (transports.File)({
|
|
|
|
filename: log.file()
|
|
|
|
})
|
2016-04-13 02:55:51 +00:00
|
|
|
]
|
2017-12-20 06:20:37 +00:00
|
|
|
})
|
2016-04-13 02:51:47 +00:00
|
|
|
log.init = function () {
|
2017-12-20 06:20:37 +00:00
|
|
|
log.listen()
|
2018-01-05 04:42:36 +00:00
|
|
|
}
|
2016-04-13 03:08:56 +00:00
|
|
|
log.display = function (obj) {
|
2017-12-20 06:20:37 +00:00
|
|
|
mainWindow.webContents.send('log', obj)
|
2018-01-05 04:42:36 +00:00
|
|
|
}
|
2016-04-13 02:51:47 +00:00
|
|
|
log.listen = function () {
|
2017-12-20 06:20:37 +00:00
|
|
|
ipcMain.on('log', (event, arg) => {
|
2019-03-09 18:17:32 +00:00
|
|
|
log.transport.info(`[renderer] action=${arg.action} service=${arg.service} status=${arg.status}`)
|
2017-12-20 06:20:37 +00:00
|
|
|
event.returnValue = true
|
|
|
|
})
|
2018-01-05 04:42:36 +00:00
|
|
|
}
|
2016-04-13 03:08:56 +00:00
|
|
|
log.info = function (action, service, status, display) {
|
|
|
|
var obj = {
|
|
|
|
action : action,
|
|
|
|
service : service,
|
|
|
|
status : status
|
2017-12-20 06:20:37 +00:00
|
|
|
}
|
2019-03-09 18:17:32 +00:00
|
|
|
log.transport.info(`[main] action=${action} service=${service} status=${status}`)
|
2016-04-13 03:08:56 +00:00
|
|
|
if (display) {
|
2017-12-20 06:20:37 +00:00
|
|
|
log.display(obj)
|
2016-04-13 03:08:56 +00:00
|
|
|
}
|
2018-01-05 04:42:36 +00:00
|
|
|
}
|
2018-02-01 19:52:47 +00:00
|
|
|
/*
|
2017-12-20 06:20:37 +00:00
|
|
|
var transfer = {}
|
2016-06-21 19:25:46 +00:00
|
|
|
|
|
|
|
transfer.init = function () {
|
2017-12-20 06:20:37 +00:00
|
|
|
transfer.listen()
|
2016-06-21 19:25:46 +00:00
|
|
|
};
|
|
|
|
transfer.listen = function () {
|
2017-12-20 06:20:37 +00:00
|
|
|
ipcMain.on('transfer', (event, arg) => {
|
2018-02-01 19:52:47 +00:00
|
|
|
let res = '';
|
2016-06-21 19:53:07 +00:00
|
|
|
//also turn on and off
|
2016-06-29 16:01:17 +00:00
|
|
|
if (arg.action === 'enable') {
|
2017-12-20 06:20:37 +00:00
|
|
|
capture.active = true
|
|
|
|
res = capture.active
|
2016-06-29 16:01:17 +00:00
|
|
|
} else if (arg.action === 'disable') {
|
2017-12-20 06:20:37 +00:00
|
|
|
capture.active = false
|
|
|
|
res = capture.active
|
2016-06-29 16:01:17 +00:00
|
|
|
} else if (arg.action === 'start') {
|
2017-12-20 06:20:37 +00:00
|
|
|
capture.start()
|
2016-06-21 19:53:07 +00:00
|
|
|
} else if (arg.action === 'end') {
|
2017-12-20 06:20:37 +00:00
|
|
|
res = capture.end()
|
2016-06-21 19:53:07 +00:00
|
|
|
}
|
2017-12-20 06:20:37 +00:00
|
|
|
event.returnValue = res
|
|
|
|
})
|
|
|
|
}
|
2018-02-01 19:52:47 +00:00
|
|
|
*/
|
2018-03-03 03:42:15 +00:00
|
|
|
var init = async function () {
|
2018-01-05 04:42:36 +00:00
|
|
|
|
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()
|
|
|
|
mcopy.settings = await settings.all()
|
|
|
|
|
2017-12-20 06:20:37 +00:00
|
|
|
log.init()
|
|
|
|
light.init()
|
|
|
|
proj.init()
|
|
|
|
cam.init()
|
2018-02-07 18:44:24 +00:00
|
|
|
dev.init()
|
2019-02-08 23:21:16 +00:00
|
|
|
seq.init()
|
2018-02-07 18:44:24 +00:00
|
|
|
|
2019-02-11 06:08:20 +00:00
|
|
|
//capture = require('capture')(SYSTEM) //redundant
|
|
|
|
display = require('display')(SYSTEM)
|
|
|
|
ffmpeg = require('ffmpeg')(SYSTEM)
|
|
|
|
ffprobe = require('ffprobe')(SYSTEM)
|
2019-02-08 18:17:14 +00:00
|
|
|
|
2018-01-05 04:42:36 +00:00
|
|
|
//transfer.init()
|
|
|
|
//capture.init()
|
2016-06-21 15:05:44 +00:00
|
|
|
|
2018-01-05 20:48:10 +00:00
|
|
|
arduino = require('./lib/arduino')(mcopy.cfg, ee)
|
2018-01-05 19:22:40 +00:00
|
|
|
mscript = require('./lib/mscript')
|
2016-06-21 15:05:44 +00:00
|
|
|
|
2019-02-22 18:33:48 +00:00
|
|
|
|
2018-01-05 04:42:36 +00:00
|
|
|
|
2018-12-11 02:52:48 +00:00
|
|
|
await delay(2000)
|
2019-02-11 06:08:20 +00:00
|
|
|
try {
|
|
|
|
await dev.enumerate()
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
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', () => {
|
2016-06-21 15:05:44 +00:00
|
|
|
//if (process.platform !== 'darwin') {
|
|
|
|
app.quit();
|
|
|
|
//}
|
|
|
|
});
|
|
|
|
|
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
|
|
|
}
|