mcopy/app/main.js

153 lines
3.6 KiB
JavaScript
Raw Normal View History

/* 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
//process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
2017-12-20 03:54:39 +00:00
const electron = require('electron')
const { Menu, BrowserWindow, app } = electron
const { EventEmitter } = require('events')
const { join } = require('path')
2019-02-08 18:17:14 +00:00
require('@electron/remote/main').initialize()
const ee = new 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')
const { delay } = require('delay')
const { Log } = require('log')
//Objects
2017-12-20 03:54:39 +00:00
const mcopy = {}
2016-04-11 06:01:26 +00:00
2023-02-28 19:30:17 +00:00
let SYSTEM
let log
let mainWindow
let arduino
let menu
let display
let ffmpeg
let ffprobe
let cam
let cam2
let proj
let proj2
let light
let filmout
let dev
let cmd
let seq
let capper
let alert
let server
2019-02-08 18:17:14 +00:00
const cfg = require('./data/cfg.json')
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')
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 () {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
minWidth : 800,
minHeight : 600,
icon: join(__dirname, 'assets/icons/icon.png'),
2019-06-26 22:03:54 +00:00
skipTaskbar: true,
toolbar: false,
webPreferences : {
nodeIntegration : true,
enableRemoteModule: true,
contextIsolation : false
}
})
mainWindow.loadURL('file://' + __dirname + '/index.html')
if (process.argv.indexOf('-d') !== -1 || process.argv.indexOf('--dev') !== -1) {
mainWindow.webContents.openDevTools()
} else {
mainWindow.setMenu(null)
mainWindow.setAutoHideMenuBar(true)
}
mainWindow.on('closed', () => {
mainWindow = null
2018-01-05 04:42:36 +00:00
})
require('@electron/remote/main').enable(mainWindow.webContents)
2016-04-11 06:01:26 +00:00
}
var errorState = function () {
if (seq && seq.running) {
//pause sequence if running
seq.pause();
}
mainWindow.webContents.send('error_state', { stop : true });
}
var init = async function () {
log = await Log({ label : 'mcopy' })
2019-03-21 19:47:25 +00:00
2019-06-24 16:42:27 +00:00
createWindow()
createMenu()
2019-02-08 18:17:14 +00:00
try {
2019-06-24 16:42:27 +00:00
SYSTEM = await system(mainWindow.webContents)
2019-02-08 18:17:14 +00:00
} catch (err) {
console.error(err)
2019-02-08 18:17:14 +00:00
}
await settings.restore()
display = require('display')(SYSTEM)
ffmpeg = require('ffmpeg')(SYSTEM)
ffprobe = require('ffprobe')(SYSTEM)
arduino = require('arduino')(cfg, ee, errorState)
2019-04-16 14:01:42 +00:00
dev = require('devices')(arduino, settings, mainWindow)
server = require('server')(mainWindow.webContents)
light = require('light')(arduino, cfg, mainWindow.webContents)
filmout = require('filmout')(display, server, ffmpeg, ffprobe, mainWindow.webContents, light)
cam = require('cam')(arduino, cfg, mainWindow.webContents, filmout)
proj = require('proj')(arduino, cfg, mainWindow.webContents, filmout)
alert = require('alert')(mainWindow.webContents)
try {
await dev.enumerate()
} catch (err) {
log.error('Error enumerating connected devices', err)
}
if (dev && dev.connected && dev.connected.camera_second) {
cam2 = require('cam')(arduino, cfg, mainWindow.webContents, filmout, true)
}
if (dev && dev.connected && dev.connected.projector_second) {
proj2 = require('proj')(arduino, cfg, mainWindow.webContents, filmout, true)
}
if (dev && dev.connected && dev.connected.capper) {
capper = require('capper')(arduino, cfg, mainWindow.webContents, filmout, true)
}
cmd = require('cmd')(cfg, proj, cam, light, alert, cam2, proj2, capper)
seq = require('sequencer')(cfg, cmd, mainWindow.webContents)
}
2016-06-21 15:05:44 +00:00
app.on('ready', init)
2016-06-21 15:05:44 +00:00
app.on('window-all-closed', () => {
2023-02-28 19:30:17 +00:00
app.quit()
2016-06-21 15:05:44 +00:00
});
app.on('activate', () => {
2016-06-21 15:05:44 +00:00
if (mainWindow === null) {
2023-02-28 19:30:17 +00:00
createWindow()
2016-06-21 15:05:44 +00:00
}
});
mcopy.relaunch = function () {
app.relaunch({args: process.argv.slice(1).concat(['--relaunch'])})
app.exit(0)
}