Passage à Electron

This commit is contained in:
wpetit 2015-10-07 14:25:30 +02:00
parent f7be43c558
commit 0c5e2443fe
6 changed files with 46 additions and 136 deletions

View File

@ -1,118 +0,0 @@
/* jshint node: true */
var _ = require('lodash');
var path = require('path');
module.exports = function(grunt) {
var NW_VERSION = '0.12.3';
var BUILD_DIR = 'build';
var BUILD_TARGETS = {
linux_ia32: true,
linux_x64: true,
win: false,
osx: false
};
var PKG = grunt.file.readJSON('package.json');
var PKG_OVERWRITE = {
window: {
toolbar: false,
kiosk: true
}
};
// Create build tasks options
var buildOptions = _.merge({
runtimeVersion: NW_VERSION
}, BUILD_TARGETS);
// Define copy:build tasks files
var appFiles = [];
_.forEach(BUILD_TARGETS, function(isEnabled, target) {
if(!isEnabled) return;
var arch = 'ia32';
var platform = target;
if(platform.indexOf('linux') !== -1) {
arch = platform.split('_')[1];
platform = 'linux';
}
var dirName = PKG.name + '-' + PKG.version + '-' + platform + '-' + arch;
var destPath = path.join(BUILD_DIR, dirName + '/');
// Retreive NPM dependencies
var npmDeps = _.keys(PKG.dependencies).map(function(moduleName) {
return path.join('node_modules', moduleName, '**');
});
appFiles.push({ src: npmDeps, dest: destPath });
// Add main files, licence, & config
appFiles.push({
src: [
'index.html',
'package.json',
'default-profile.json',
'LICENCE',
'css/**',
'js/**',
'img/**'
],
dest: destPath
});
});
// Configure tasks
grunt.initConfig({
pkg: PKG,
download: {
options: {
runtimeVersion: NW_VERSION
}
},
run: {
options: {
nwArgs: ['.'].concat(process.argv.slice(3)),
runtimeVersion: NW_VERSION
}
},
build: {
options: buildOptions
},
clean: {
build: [BUILD_DIR]
},
copy: {
build: {
files: appFiles,
options: {
noProcess: ['**','!package.json'],
process: function() {
var pkg = _.merge(PKG, PKG_OVERWRITE);
return JSON.stringify(pkg, null, 2);
}
}
}
}
});
grunt.registerTask('pitaya:run', ['download', 'run']);
grunt.registerTask(
'pitaya:build',
['download', 'build', 'copy:build']
);
grunt.registerTask('default', ['pitaya:run']);
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-nw');
};

View File

@ -5,8 +5,9 @@ var AnimateMixin = require('../mixins/animate');
var actions = require('../../store/actions');
var connect = require('react-redux').connect;
var debug = require('../../util/debug')('launcher-view');
var path = require('path');
var DEFAULT_PROFILE = './default-profile.json';
var DEFAULT_PROFILE = path.join(__dirname, '..', '..', '..', 'default-profile.json');
var LauncherView = React.createClass({

View File

@ -1,7 +1,6 @@
var minimist = require('minimist');
var gui = global.window.require('nw.gui');
var opts = minimist(gui.App.argv);
var opts = minimist(process.argv);
module.exports = function(state, action) {
return opts;

View File

@ -249,7 +249,9 @@ exports.findPixmapsIcon = function(iconName) {
exports.findIconThemes = function() {
return System.findFiles('*/', {cwd: ICON_THEMES_ROOTDIR, realpath: true})
.then(function(files) {
return files.map(path.basename.bind(path));
return files.map(function(f) {
return path.basename(f);
});
})
;
};

35
main.js Normal file
View File

@ -0,0 +1,35 @@
var app = require('app'); // Module to control application life.
var BrowserWindow = require('browser-window'); // Module to create native browser window.
var mainWindow = null;
// Quit when all windows are closed.
app.on('window-all-closed', function() {
app.quit();
});
app.on('ready', function() {
// Create the browser window.
var electronScreen = require('screen');
var size = electronScreen.getPrimaryDisplay().workAreaSize;
mainWindow = new BrowserWindow({
type: 'desktop',
'skip-taskbar': true,
frame: false,
width: size.width,
height: size.height
});
if(process.env.NODE_ENV === 'development') {
mainWindow.openDevTools();
}
// and load the index.html of the app.
mainWindow.loadUrl('file://' + __dirname + '/index.html');
mainWindow.on('closed', function() {
mainWindow = null;
});
});

View File

@ -2,25 +2,16 @@
"name": "pitaya",
"version": "0.0.0",
"private": "true",
"main": "index.html",
"main": "main.js",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-copy": "^0.7.0",
"grunt-nw": "git+https://github.com/snap-project/grunt-nw#develop",
"lodash": "^3.0.1",
"electron-packager": "^5.1.0",
"electron-prebuilt": "^0.33.6",
"nodeunit": "^0.9.1"
},
"scripts": {
"test": "./node_modules/.bin/nodeunit test",
"start": "./node_modules/.bin/grunt pitaya:run",
"build": "./node_modules/.bin/grunt pitaya:build"
},
"chromium-args": "--ignore-certificate-errors",
"window": {
"toolbar": true,
"kiosk": false
"start": "./node_modules/.bin/electron .",
"build": "./node_modules/.bin/electron-packager ./ pitaya --platform=linux --arch=ia32,x64 --version=0.33.6 --out=build --overwrite"
},
"dependencies": {
"bootstrap": "^3.3.5",