Skip to content

Commit

Permalink
preparing for companion beta1
Browse files Browse the repository at this point in the history
  • Loading branch information
willosof committed May 22, 2018
1 parent 1bf7dd5 commit f33969b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 12 deletions.
23 changes: 18 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,23 @@ var system = new EventEmitter();
var fs = require("fs");
var path = require('path')
var debug = require('debug')('app');
var mkdirp = require('mkdirp');
var config;
var cfgDir;

var config = new (require('./bitfocus-libs/config'))(system, {
http_port: 8000,
bind_ip: "127.0.0.1",
});
system.on('skeleton-info', function(key, val) {
if (key == 'configDir') {
debug('configuration directory', val);
cfgDir = val + "/elgato/";
mkdirp(cfgDir, function(err) {
debug("mkdirp",cfgDir,err);
config = new (require('./bitfocus-libs/config'))(system, cfgDir, {
http_port: 8000,
bind_ip: "127.0.0.1"
});
});
}
});

system.on('config_loaded', function(config) {
system.emit('skeleton-info', 'appURL', 'Waiting for webserver..');
Expand All @@ -24,6 +36,7 @@ system.on('exit', function() {
});
});


system.on('skeleton-bind-ip', function(ip) {
config.bind_ip = ip;
system.emit('config_set', 'bind_ip', ip);
Expand All @@ -34,7 +47,7 @@ system.on('skeleton-ready', function() {

var http = require('./lib/http')(system, 80);
var io = require('./lib/io')(system, http);
var db = new (require('./lib/db'))(system);
var db = new (require('./lib/db'))(system,cfgDir);
var appRoot = require('app-root-path');
var express = require('express');
var panel = new (require('./lib/elgato'))(system);
Expand Down
2 changes: 1 addition & 1 deletion bitfocus-libs
Submodule bitfocus-libs updated 1 files
+5 −5 config.js
2 changes: 1 addition & 1 deletion bitfocus-skeleton
Submodule bitfocus-skeleton updated 1 files
+3 −2 main.js
10 changes: 5 additions & 5 deletions lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ var lastsave = 0;
var saveInterval = 4000; // Minimum 4 seconds between each save
var dirty = false;

module.exports = exports = function (system) {
return new db(system);
module.exports = exports = function (system,cfgDir) {
return new db(system, cfgDir);
};

function db(system) {
function db(system,cfgDir) {
debug('new(db)');
var self = this;
self._system = system;
self.db = {};

try {
var data = fs.readFileSync(__dirname + '/../db');
var data = fs.readFileSync(cfgDir + '/db');

self.db = JSON.parse(data);
debug('db loaded');
Expand Down Expand Up @@ -98,7 +98,7 @@ function db(system) {
if (new Date().getTime() - lastsave > saveInterval) {
debug("db_save","begin", self.db );

fs.writeFile(__dirname + '/../db', JSON.stringify(self.db), function (err) {
fs.writeFile(cfgDir + '/db', JSON.stringify(self.db), function (err) {
if (err) {
debug('db_save', 'Error saving: ' + err);
system.emit('db_saved', err);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"font-awesome": "4.7.0",
"jquery": "3.3.1",
"json-parser": "^1.1.5",
"mkdirp": "^0.5.1",
"pace-progress": "1.0.2",
"perfect-scrollbar": "^1.3.0",
"pngjs": "^3.3.3",
Expand Down
4 changes: 4 additions & 0 deletions tools/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

yarn
npm run dist

0 comments on commit f33969b

Please sign in to comment.