Commit 7b7a6381 authored by carlosperate's avatar carlosperate

Electron: Add splash screen while app loads.

parent 6e85cc32
...@@ -11,8 +11,9 @@ ...@@ -11,8 +11,9 @@
var app = require('app'); var app = require('app');
var shell = require('shell'); var shell = require('shell');
var server = require('./servermgr.js'); var jetpack = require('fs-jetpack');
var appMenu = require('./appmenu.js'); var appMenu = require('./appmenu.js');
var server = require('./servermgr.js');
var BrowserWindow = require('browser-window'); var BrowserWindow = require('browser-window');
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');
...@@ -28,6 +29,8 @@ var mainWindowState = windowStateKeeper('main', { ...@@ -28,6 +29,8 @@ var mainWindowState = windowStateKeeper('main', {
}); });
app.on('ready', function () { app.on('ready', function () {
var splashWindow = createSplashWindow();
server.startServer(); server.startServer();
mainWindow = new BrowserWindow({ mainWindow = new BrowserWindow({
...@@ -38,6 +41,7 @@ app.on('ready', function () { ...@@ -38,6 +41,7 @@ app.on('ready', function () {
title: 'Ardublockly', title: 'Ardublockly',
transparent: false, transparent: false,
frame: true, frame: true,
show: false,
'node-integration': false, 'node-integration': false,
'web-preferences': { 'web-preferences': {
'web-security': true, 'web-security': true,
...@@ -69,6 +73,11 @@ app.on('ready', function () { ...@@ -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.loadUrl('http://localhost:8000/ardublockly');
mainWindow.on('close', function () { mainWindow.on('close', function () {
...@@ -83,3 +92,23 @@ app.on('window-all-closed', function () { ...@@ -83,3 +92,23 @@ app.on('window-all-closed', function () {
// https://github.com/atom/electron/issues/1357 // https://github.com/atom/electron/issues/1357
app.quit(); 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,45 +17,54 @@ var env = require('./vendor/electron_boilerplate/env_config'); ...@@ -17,45 +17,54 @@ 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) {
//console.log(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('.'));
}
}
console.log(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
console.log(tag + 'OS detected: ' + process.platform); console.log(tag + 'OS detected: ' + process.platform);
// First, work out the project root directory var ardublocklyProjRootDir = module.exports.getProjectJetpack();
if (env.name === 'development') {
// In dev mode the file cwd is on the project/package/electron dir
var ardublocklyRootDir = jetpack.dir('../../');
} else {
// Cannot use relative paths with Production, 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: ' +
// ardublocklyRootDir.cwd());
// Check if file /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(jetpack.path('.'));
}
}
console.log(tag + 'Ardublockly root dir: ' + ardublocklyRootDir.cwd());
// 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") {
var arduexecDir = ardublocklyRootDir.dir('arduexec.app/server') var arduexecDir = ardublocklyProjRootDir.dir('arduexec.app/server');
} else { } else {
var arduexecDir = ardublocklyRootDir.dir('arduexec/server') var arduexecDir = ardublocklyProjRootDir.dir('arduexec/server');
} }
// Finally, work out the name of the executable // 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