Use settings and now a menu.json file.

This commit is contained in:
mmcw-dev 2018-01-04 23:42:36 -05:00
parent 8bb1997694
commit 6f7350169b
2 changed files with 162 additions and 149 deletions

116
app/data/menu.json Normal file
View File

@ -0,0 +1,116 @@
[
{
"label": "mcopy",
"submenu": [
{
"label": "Services",
"submenu": []
},
{
"type": "separator"
},
{
"label": "Hide mcopy",
"accelerator": "Command+H",
"selector": "hide:"
},
{
"label": "Hide Others",
"accelerator": "Command+Shift+H",
"selector": "hideOtherApplications:"
},
{
"label": "Show All",
"selector": "unhideAllApplications:"
},
{
"type": "separator"
},
{
"label": "Quit",
"accelerator": "Command+Q",
"selector": "terminate:"
}
]
},
{
"label": "Edit",
"submenu": [
{
"label": "Undo",
"accelerator": "Command+Z",
"selector": "undo:"
},
{
"label": "Redo",
"accelerator": "Shift+Command+Z",
"selector": "redo:"
},
{
"type": "separator"
},
{
"label": "Cut",
"accelerator": "Command+X",
"selector": "cut:"
},
{
"label": "Copy",
"accelerator": "Command+C",
"selector": "copy:"
},
{
"label": "Paste",
"accelerator": "Command+V",
"selector": "paste:"
},
{
"label": "Select All",
"accelerator": "Command+A",
"selector": "selectAll:"
}
]
},
{
"label": "View",
"submenu": [
{
"label": "Reload",
"accelerator": "Command+R"
},
{
"label": "Toggle DevTools",
"accelerator": "Alt+Command+I"
}
]
},
{
"label": "Window",
"submenu": [
{
"label": "Minimize",
"accelerator": "Command+M",
"selector": "performMiniaturize:"
},
{
"label": "Close",
"accelerator": "Command+W",
"selector": "performClose:"
}, {
"type": "separator"
},
{
"label": "Bring All to Front",
"selector": "arrangeInFront:"
}
]
},
{ "label": "Help",
"submenu": [
{
"label": "About mcopy",
"role" : "about"
}
]
}
]

View File

@ -6,11 +6,13 @@ const fs = require('fs')
const winston = require('winston') const winston = require('winston')
const moment = require('moment') const moment = require('moment')
const uuid = require('uuid') const uuid = require('uuid')
const Q = require('q')
const events = require('events') const events = require('events')
const async = require('async') const async = require('async')
const path = require('path')
const ee = new events.EventEmitter() const ee = new events.EventEmitter()
const capture = require('./lib/capture-report.js')(ee) const capture = require('./lib/capture-report.js')(ee)
const Server = require('./lib/server')
const settings = require('./lib/settings')
const mcopy = {} const mcopy = {}
@ -19,23 +21,15 @@ let mscript
let arduino let arduino
let projector let projector
let camera let camera
let server
let menu
let log = {} let log = {}
//console.log(process.version) //console.log(process.version)
mcopy.cfg = {} //cfg is now hardcoded, should only be modified by developers
mcopy.cfgFile = './data/cfg.json' //settings is now the source of user editable variables
mcopy.cfgInit = function () { mcopy.cfg = require('./data/cfg.json')
if (!fs.existsSync(mcopy.cfgFile)) {
console.log('Using default configuration...')
fs.writeFileSync(mcopy.cfgFile, fs.readFileSync('./data/cfg.json.default'))
}
mcopy.cfg = JSON.parse(fs.readFileSync(mcopy.cfgFile, 'utf8'))
}
mcopy.cfgStore = function () {
var data = JSON.stringify(mcopy.cfg, null, '\t')
fs.writeFileSync(mcopy.cfgFile, data, 'utf8')
}
var enumerateDevices = function (err, devices) { var enumerateDevices = function (err, devices) {
if (err) { if (err) {
@ -79,12 +73,13 @@ var distinguishDevice = function (device, callback) {
//Cases for 1 or 2 arduinos connected //Cases for 1 or 2 arduinos connected
var distinguishDevices = function (devices) { var distinguishDevices = function (devices) {
var connected = { const connected = {
projector : false, projector : false,
camera : false, camera : false,
light : false light : false
} }
var checklist = []
let checklist = []
var fakeProjector = function () { var fakeProjector = function () {
connected.projector = '/dev/fake' connected.projector = '/dev/fake'
arduino.fakeConnect('projector', () => { arduino.fakeConnect('projector', () => {
@ -185,134 +180,15 @@ var distinguishDevices = function (devices) {
var devicesReady = function (camera, projector, light) { var devicesReady = function (camera, projector, light) {
mainWindow.webContents.send('ready', {camera: camera, projector: projector, light: light }) mainWindow.webContents.send('ready', {camera: camera, projector: projector, light: light })
settings.update('camera', { arduino : camera })
settings.update('projector', { arduino : projector })
settings.update('light', { arduino : light })
settings.save()
}; };
var createMenu = function () { var createMenu = function () {
var template = [ const template = require('./data/menu.json')
{
label: 'mcopy',
submenu: [
{
label: 'About mcopy',
selector: 'orderFrontStandardAboutPanel:'
},
{
type: 'separator'
},
{
label: 'Services',
submenu: []
},
{
type: 'separator'
},
{
label: 'Hide mcopy',
accelerator: 'Command+H',
selector: 'hide:'
},
{
label: 'Hide Others',
accelerator: 'Command+Shift+H',
selector: 'hideOtherApplications:'
},
{
label: 'Show All',
selector: 'unhideAllApplications:'
},
{
type: 'separator'
},
{
label: 'Quit',
accelerator: 'Command+Q',
selector: 'terminate:'
},
]
},
{
label: 'Edit',
submenu: [
{
label: 'Undo',
accelerator: 'Command+Z',
selector: 'undo:'
},
{
label: 'Redo',
accelerator: 'Shift+Command+Z',
selector: 'redo:'
},
{
type: 'separator'
},
{
label: 'Cut',
accelerator: 'Command+X',
selector: 'cut:'
},
{
label: 'Copy',
accelerator: 'Command+C',
selector: 'copy:'
},
{
label: 'Paste',
accelerator: 'Command+V',
selector: 'paste:'
},
{
label: 'Select All',
accelerator: 'Command+A',
selector: 'selectAll:'
}
]
},
{
label: 'View',
submenu: [
{
label: 'Reload',
accelerator: 'Command+R',
click: function() { getCurrentWindow().reload(); }
},
{
label: 'Toggle DevTools',
accelerator: 'Alt+Command+I',
click: function() { getCurrentWindow().toggleDevTools(); }
},
]
},
{
label: 'Window',
submenu: [
{
label: 'Minimize',
accelerator: 'Command+M',
selector: 'performMiniaturize:'
},
{
label: 'Close',
accelerator: 'Command+W',
selector: 'performClose:'
},
{
type: 'separator'
},
{
label: 'Bring All to Front',
selector: 'arrangeInFront:'
}
]
},
{
label: 'Help',
submenu: []
}
]
menu = Menu.buildFromTemplate(template) menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu) Menu.setApplicationMenu(menu)
} }
@ -327,7 +203,7 @@ var createWindow = function () {
//mainWindow.webContents.openDevTools() //mainWindow.webContents.openDevTools()
mainWindow.on('closed', () => { mainWindow.on('closed', () => {
mainWindow = null mainWindow = null
}); })
} }
var light = {} var light = {}
@ -424,11 +300,19 @@ cam.set = function (dir, id) {
cam.end(cmd, id, ms) cam.end(cmd, id, ms)
}) })
} }
cam.setWeb = function (dir, id) {
}
cam.move = function (frame, id) { cam.move = function (frame, id) {
arduino.send('camera', mcopy.cfg.arduino.cmd.camera, (ms) => { arduino.send('camera', mcopy.cfg.arduino.cmd.camera, (ms) => {
cam.end(mcopy.cfg.arduino.cmd.camera, id, ms) cam.end(mcopy.cfg.arduino.cmd.camera, id, ms)
}) })
} }
cam.moveWeb = function (frame, id) {
}
cam.listen = function () { cam.listen = function () {
ipcMain.on('cam', (event, arg) => { ipcMain.on('cam', (event, arg) => {
if (typeof arg.dir !== 'undefined') { if (typeof arg.dir !== 'undefined') {
@ -458,6 +342,17 @@ cam.end = function (cmd, id, ms) {
mainWindow.webContents.send('cam', {cmd: cmd, id : id, ms: ms}) mainWindow.webContents.send('cam', {cmd: cmd, id : id, ms: ms})
}; };
log.file = function () {
const platform = process.platform
let logPath = `/var/log/mcopy/`
if (platform === 'darwin') {
} else if (platform === 'win32') {
}
return path.join(logPath, 'mcopy.log')
}
log.time = 'MM/DD/YY-HH:mm:ss' log.time = 'MM/DD/YY-HH:mm:ss'
log.transport = new (winston.Logger)({ log.transport = new (winston.Logger)({
transports: [ transports: [
@ -467,16 +362,16 @@ log.transport = new (winston.Logger)({
}) })
log.init = function () { log.init = function () {
log.listen() log.listen()
}; }
log.display = function (obj) { log.display = function (obj) {
mainWindow.webContents.send('log', obj) mainWindow.webContents.send('log', obj)
}; }
log.listen = function () { log.listen = function () {
ipcMain.on('log', (event, arg) => { ipcMain.on('log', (event, arg) => {
log.transport.info('renderer', arg) log.transport.info('renderer', arg)
event.returnValue = true event.returnValue = true
}) })
}; }
log.info = function (action, service, status, display) { log.info = function (action, service, status, display) {
var obj = { var obj = {
time : moment().format(log.time), time : moment().format(log.time),
@ -488,7 +383,7 @@ log.info = function (action, service, status, display) {
if (display) { if (display) {
log.display(obj) log.display(obj)
} }
}; }
var transfer = {} var transfer = {}
@ -516,20 +411,22 @@ transfer.listen = function () {
var init = function () { var init = function () {
mcopy.cfgInit() settings.restore()
createWindow() createWindow()
//createMenu() createMenu()
log.init() log.init()
light.init() light.init()
proj.init() proj.init()
cam.init() cam.init()
transfer.init() //transfer.init()
capture.init() //capture.init()
arduino = require('./lib/mcopy-arduino.js')(mcopy.cfg, ee) arduino = require('./lib/mcopy-arduino.js')(mcopy.cfg, ee)
mscript = require('./lib/mscript.js') mscript = require('./lib/mscript.js')
setTimeout( () => { setTimeout( () => {
arduino.enumerate(enumerateDevices) arduino.enumerate(enumerateDevices)
}, 1000) }, 1000)