Commit 7b7a6381 authored by carlosperate's avatar carlosperate

Electron: Add splash screen while app loads.

parent 6e85cc32
......@@ -11,8 +11,9 @@
var app = require('app');
var shell = require('shell');
var server = require('./servermgr.js');
var jetpack = require('fs-jetpack');
var appMenu = require('./appmenu.js');
var server = require('./servermgr.js');
var BrowserWindow = require('browser-window');
var env = require('./vendor/electron_boilerplate/env_config');
var windowStateKeeper = require('./vendor/electron_boilerplate/window_state');
......@@ -28,6 +29,8 @@ var mainWindowState = windowStateKeeper('main', {
});
app.on('ready', function () {
var splashWindow = createSplashWindow();
server.startServer();
mainWindow = new BrowserWindow({
......@@ -38,6 +41,7 @@ app.on('ready', function () {
title: 'Ardublockly',
transparent: false,
frame: true,
show: false,
'node-integration': false,
'web-preferences': {
'web-security': true,
......@@ -69,6 +73,11 @@ app.on('ready', function () {
}
);
mainWindow.webContents.on('did-finish-load', function () {
mainWindow.show();
splashWindow.close();
});
mainWindow.loadUrl('http://localhost:8000/ardublockly');
mainWindow.on('close', function () {
......@@ -83,3 +92,23 @@ app.on('window-all-closed', function () {
// https://github.com/atom/electron/issues/1357
app.quit();
});
function createSplashWindow() {
var imagePath = 'file://' + server.getProjectJetpack().path(
'ardublockly', 'img', 'ardublockly_splash.png');
var splashWindow = new BrowserWindow({
width: 500,
height: 225,
frame: false,
show: true,
transparent: true,
images: true,
center: true,
'use-content-size': true,
'always-on-top': true,
});
splashWindow.loadUrl(imagePath);
return splashWindow;
}
......@@ -17,24 +17,23 @@ var env = require('./vendor/electron_boilerplate/env_config');
var tag = '[Server mgr] '
var serverProcess = null;
var ardublocklyRootDir = null;
function getServerExecLocation() {
// Relevant OS could be win32, linux, darwin
console.log(tag + 'OS detected: ' + process.platform);
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
var ardublocklyRootDir = jetpack.dir('../../');
ardublocklyRootDir = jetpack.dir('../../');
} else {
// Cannot use relative paths with Production, so let's try to find the
// 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) {
//console.log(tag + 'Search for Ardublockly project root dir: ' +
//console.log(tag + 'Search for Ardublockly project dir: ' +
// ardublocklyRootDir.cwd());
// Check if file /ardublokly/index.html exists within current path
// 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
......@@ -46,16 +45,26 @@ function getServerExecLocation() {
if (ardublocklyRootDir.path() == oldArdublocklyRootDir) {
ardublocklyRootDir = jetpack.dir('.');
ardublocklyNotFound(jetpack.path('.'));
ardublocklyNotFound(ardublocklyRootDir.path('.'));
}
}
console.log(tag + 'Ardublockly root dir: ' + ardublocklyRootDir.cwd());
}
return ardublocklyRootDir;
};
function getServerExecLocation() {
// Relevant OS could be win32, linux, darwin
console.log(tag + 'OS detected: ' + process.platform);
var ardublocklyProjRootDir = module.exports.getProjectJetpack();
// Then, work out the location of the python executable files
if (process.platform == "darwin") {
var arduexecDir = ardublocklyRootDir.dir('arduexec.app/server')
var arduexecDir = ardublocklyProjRootDir.dir('arduexec.app/server');
} else {
var arduexecDir = ardublocklyRootDir.dir('arduexec/server')
var arduexecDir = ardublocklyProjRootDir.dir('arduexec/server');
}
// Finally, work out the name of the executable
......
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