Commit 54dd1b3e authored by carlosperate's avatar carlosperate

Extract Electron server code to locate project root into own module.

parent e8771137
...@@ -14,6 +14,7 @@ var winston = require('winston'); ...@@ -14,6 +14,7 @@ var winston = require('winston');
var appMenu = require('./appmenu.js'); var appMenu = require('./appmenu.js');
var server = require('./servermgr.js'); var server = require('./servermgr.js');
var BrowserWindow = require('browser-window'); var BrowserWindow = require('browser-window');
var projectRootLocator = require('./rootlocator.js');
var env = require('./vendor/electron_boilerplate/env_config'); var env = require('./vendor/electron_boilerplate/env_config');
var windowStateKeeper = require('./vendor/electron_boilerplate/window_state'); var windowStateKeeper = require('./vendor/electron_boilerplate/window_state');
...@@ -21,7 +22,6 @@ var windowStateKeeper = require('./vendor/electron_boilerplate/window_state'); ...@@ -21,7 +22,6 @@ var windowStateKeeper = require('./vendor/electron_boilerplate/window_state');
// be closed automatically when the JavaScript object is garbage collected. // be closed automatically when the JavaScript object is garbage collected.
var mainWindow = null; var mainWindow = null;
var splashWindow = null; var splashWindow = null;
var projectJetPath = null;
// Preserver of the window size and position between app launches. // Preserver of the window size and position between app launches.
var mainWindowState = windowStateKeeper('main', { var mainWindowState = windowStateKeeper('main', {
...@@ -31,14 +31,15 @@ var mainWindowState = windowStateKeeper('main', { ...@@ -31,14 +31,15 @@ var mainWindowState = windowStateKeeper('main', {
app.on('ready', function () { app.on('ready', function () {
// Finding project path // Finding project path
projectJetPath = server.getProjectJetpack(); var projectRootPath = projectRootLocator.getProjectRootPath();
// Setting up logging system // Setting up logging system
winston.add(winston.transports.File, { winston.add(winston.transports.File, {
json: false, json: false,
filename: projectJetPath.path() + '/ardublockly.log', filename: projectRootPath + '/ardublockly.log',
maxsize: 10485760, maxsize: 10485760,
maxFiles: 2 }); maxFiles: 2
});
createSplashWindow(); createSplashWindow();
...@@ -112,6 +113,7 @@ app.on('window-all-closed', function () { ...@@ -112,6 +113,7 @@ app.on('window-all-closed', function () {
function createSplashWindow() { function createSplashWindow() {
if (splashWindow === null) { if (splashWindow === null) {
var projectJetPath = projectRootLocator.getProjectRootJetpack();
var imagePath = 'file://' + projectJetPath.path( var imagePath = 'file://' + projectJetPath.path(
'ardublockly', 'img', 'ardublockly_splash.png'); 'ardublockly', 'img', 'ardublockly_splash.png');
......
/**
* @author carlosperate
* @copyright 2015 carlosperate https://github.com/carlosperate
* @license Licensed under the The MIT License (MIT), a copy can be found in
* the electron project directory LICENSE file.
*
* @fileoverview Finds the Ardublockly root directory path.
*/
'use strict';
var winston = require('winston');
var jetpack = require('fs-jetpack');
var env = require('./vendor/electron_boilerplate/env_config');
var tag = '[Project Root Locator] '
var ardublocklyRootDir = null;
module.exports.getProjectRootJetpack = function() {
if (ardublocklyRootDir === null) {
// First, work out the project root directory
if (env.name === 'development') {
// In dev mode the file cwd is on the project/package/electron dir
ardublocklyRootDir = jetpack.dir('../../');
} else {
// Cannot use relative paths in build, so let's try to find the
// ardublockly folder in a node from the executable file path tree
ardublocklyRootDir = jetpack.dir(__dirname);
var oldArdublocklyRootDir = '';
while (ardublocklyRootDir.path() != oldArdublocklyRootDir) {
//winston.log('info', tag + 'Search for Ardublockly project ' +
// 'dir: ' + ardublocklyRootDir.cwd());
// Check if /ardublokly/index.html exists within current path
if (jetpack.exists(
ardublocklyRootDir.path('ardublockly', 'index.html'))) {
// Found the right folder, break with this dir loaded
break;
}
oldArdublocklyRootDir = ardublocklyRootDir.path();
ardublocklyRootDir = ardublocklyRootDir.dir('../');
}
if (ardublocklyRootDir.path() == oldArdublocklyRootDir) {
ardublocklyRootDir = jetpack.dir('.');
ardublocklyNotFound(ardublocklyRootDir.path('.'));
}
}
winston.info(tag + 'Ardublockly root dir: ' + ardublocklyRootDir.cwd());
}
return ardublocklyRootDir;
};
module.exports.getProjectRootPath = function() {
return module.exports.getProjectRootJetpack().path();
};
...@@ -13,53 +13,18 @@ var dialog = require('dialog'); ...@@ -13,53 +13,18 @@ var dialog = require('dialog');
var winston = require('winston'); var winston = require('winston');
var jetpack = require('fs-jetpack'); var jetpack = require('fs-jetpack');
var childProcess = require('child_process'); var childProcess = require('child_process');
var projectRootLocator = require('./rootlocator.js');
var env = require('./vendor/electron_boilerplate/env_config'); var env = require('./vendor/electron_boilerplate/env_config');
var tag = '[Server mgr] ' var tag = '[Server mgr] '
var serverProcess = null; var serverProcess = null;
var ardublocklyRootDir = null;
module.exports.getProjectJetpack = function() {
if (ardublocklyRootDir == null) {
// First, work out the project root directory
if (env.name === 'development') {
// In dev mode the file cwd is on the project/package/electron dir
ardublocklyRootDir = jetpack.dir('../../');
} else {
// Cannot use relative paths in build, so let's try to find the
// ardublockly folder in a node from the executable file path tree
var ardublocklyRootDir = jetpack.dir(__dirname);
var oldArdublocklyRootDir = '';
while (ardublocklyRootDir.path() != oldArdublocklyRootDir) {
//winston.log('info', tag + 'Search for Ardublockly project ' +
// 'dir: ' + ardublocklyRootDir.cwd());
// Check if /ardublokly/index.html exists within current path
if (jetpack.exists(
ardublocklyRootDir.path('ardublockly', 'index.html'))) {
// Found the right folder, break with this dir loaded
break;
}
oldArdublocklyRootDir = ardublocklyRootDir.path();
ardublocklyRootDir = ardublocklyRootDir.dir('../');
}
if (ardublocklyRootDir.path() == oldArdublocklyRootDir) {
ardublocklyRootDir = jetpack.dir('.');
ardublocklyNotFound(ardublocklyRootDir.path('.'));
}
}
winston.info(tag + 'Ardublockly root dir: ' + ardublocklyRootDir.cwd());
}
return ardublocklyRootDir;
};
function getServerExecLocation() { function getServerExecLocation() {
// Relevant OS could be win32, linux, darwin // Relevant OS could be win32, linux, darwin
winston.info(tag + 'OS detected: ' + process.platform); winston.info(tag + 'OS detected: ' + process.platform);
var ardublocklyProjRootDir = module.exports.getProjectJetpack(); var ardublocklyProjRootDir = projectRootLocator.getProjectRootJetpack();
// Then, work out the location of the python executable files // Then, work out the location of the python executable files
if (process.platform == "darwin") { if (process.platform == "darwin") {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment