Commit de2d16db authored by carlosperate's avatar carlosperate

Enable Node integration into Electron desktop app.

This is done to have better control of some rendering features.
Some javascript libraries have to be loaded differently on Node, so all Electron code in the front end is now located in the ardublockly_desktop.js file.
Also updated the electron version.
parent 461a911a
......@@ -29,13 +29,6 @@ window.addEventListener('load', function load(event) {
document.location.hostname != '192.168.0.7') {
Ardublockly.openNotConnectedModal();
}
// Check if running on the Desktop app
if (navigator.userAgent.toLowerCase().indexOf('ardublockly') > -1) {
// It is, so remove container padding and side menu button
Ardublockly.containerFullWidth();
Ardublockly.hideSideMenuButton();
}
});
/** Binds functions to each of the buttons, nav links, and related. */
......
......@@ -341,20 +341,6 @@ Ardublockly.resetIdeOutputContent = function(bodyEl) {
'the IDE output...</span>';
};
/** Hides the side menu button. */
Ardublockly.hideSideMenuButton = function() {
var sideMenuButton = document.getElementById('button-collapse');
sideMenuButton.style.display = 'none';
};
/** Sets all the elements using the container class to have a width of 100%. */
Ardublockly.containerFullWidth = function() {
var containers = $('.container');
for (var i = 0; i < containers.length; i++) {
containers[i].style.width = '100%';
}
};
/**
* Initialises the sketch name input text JavaScript to dynamically adjust its
* width to the width of its contents.
......
/**
* @license Licensed under the Apache License, Version 2.0 (the "License"):
* http://www.apache.org/licenses/LICENSE-2.0
*
* @fileoverview Front end code relevant only to the Desktop version of
* Ardublockly.
*/
'use strict';
/** Create a namespace for the application. */
var Ardublockly = Ardublockly || {};
/**
* Checks if the current JavaScript is loaded in the rendered process of
* Electron. Works even if the node integration is turned off.
* @return {!boolean} True if Ardublockly running in Electron application
*/
Ardublockly.isRunningElectron = function() {
return navigator.userAgent.toLowerCase().indexOf('ardublockly') > -1;
};
/**
* Because the Node integration causes conflicts with the way JavaScript
* libraries are declared as modules, this declares them in the window context.
* This function is to be executed as soon as this file is loaded, and because
* of that this file must be called in the HTML before the Materialize library
* is loaded.
*/
Ardublockly.loadJsInElectron = function() {
if (Ardublockly.isRunningElectron()) {
var projectRootLocator = require('remote').require('./rootlocator.js');
var projectRoot = projectRootLocator.getProjectRootPath();
window.$ = window.jQuery = require(projectRoot +
'/ardublockly/js_libs/jquery-2.1.3.min.js');
window.Hammer = require(projectRoot + '/ardublockly/js_libs/hammer.min.js');
window.JsDiff = require(projectRoot + '/ardublockly/js_libs/diff.js');
}
};
Ardublockly.loadJsInElectron();
/** Sets all the elements using the container class to have a width of 100%. */
Ardublockly.containerFullWidth = function() {
var containers = $('.container');
for (var i = 0; i < containers.length; i++) {
containers[i].style.width = '100%';
}
};
/** Hides the side menu button. */
Ardublockly.hideSideMenuButton = function() {
var sideMenuButton = document.getElementById('button-collapse');
sideMenuButton.style.display = 'none';
};
/** Initialize Ardublockly code required for Electron on page load. */
window.addEventListener('load', function load(event) {
window.removeEventListener('load', load, false);
if (Ardublockly.isRunningElectron()) {
Ardublockly.containerFullWidth();
Ardublockly.hideSideMenuButton();
}
});
......@@ -278,6 +278,8 @@
</div>
</div>
<!-- Desktop version of Ardublockly JS, needs to be loaded first. -->
<script src="ardublockly_desktop.js"></script>
<!-- jQuery and Materialize JS -->
<script src="js_libs/jquery-2.1.3.min.js"></script>
<script src="materialize/materialize.js"></script>
......
This diff is collapsed.
......@@ -10,7 +10,7 @@ This project is based on the excellent [electron-boilerplate](https://github.com
## Quick start
The only dependency of this project is [Node.js](https://nodejs.org).
The only software installation required for this project is [Node.js](https://nodejs.org).
To run, execute these commands from the Ardublockly project root directory:
......@@ -43,6 +43,7 @@ The original boilerplate by Jakub Szwacz is release under the following license.
The MIT License (MIT)
Copyright (c) 2015 Jakub Szwacz
Copyright (c) 2015 carlosperate https://github.com/carlosperate/
Permission is hereby granted, free of charge, to any person obtaining a copy
......
......@@ -53,7 +53,7 @@ app.on('ready', function() {
transparent: false,
frame: true,
show: false,
'node-integration': false,
'node-integration': true,
'web-preferences': {
'web-security': true,
'java': false,
......
{
"devDependencies": {
"asar": "^0.7.2",
"electron-prebuilt": "^0.31.1",
"electron-prebuilt": "^0.31.2",
"fs-jetpack": "^0.7.0",
"gulp": "^3.9.0",
"gulp-babel": "^5.2.1",
......
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