From 0c5e2443fee7e52d32d19c3e118e7bd0a2e76ebb Mon Sep 17 00:00:00 2001 From: William Petit Date: Wed, 7 Oct 2015 14:25:30 +0200 Subject: [PATCH] =?UTF-8?q?Passage=20=C3=A0=20Electron?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gruntfile.js | 118 ----------------------- js/components/launcher/launcher-view.jsx | 3 +- js/store/reducers/process-opts.js | 3 +- js/util/desktop-apps.js | 4 +- main.js | 35 +++++++ package.json | 19 +--- 6 files changed, 46 insertions(+), 136 deletions(-) delete mode 100644 Gruntfile.js create mode 100644 main.js diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index fccf38b..0000000 --- a/Gruntfile.js +++ /dev/null @@ -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'); - -}; diff --git a/js/components/launcher/launcher-view.jsx b/js/components/launcher/launcher-view.jsx index cedecc9..7be494e 100644 --- a/js/components/launcher/launcher-view.jsx +++ b/js/components/launcher/launcher-view.jsx @@ -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({ diff --git a/js/store/reducers/process-opts.js b/js/store/reducers/process-opts.js index f9b8964..79bf1d0 100644 --- a/js/store/reducers/process-opts.js +++ b/js/store/reducers/process-opts.js @@ -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; diff --git a/js/util/desktop-apps.js b/js/util/desktop-apps.js index 385fbe2..1b0f0f6 100644 --- a/js/util/desktop-apps.js +++ b/js/util/desktop-apps.js @@ -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); + }); }) ; }; diff --git a/main.js b/main.js new file mode 100644 index 0000000..07d4351 --- /dev/null +++ b/main.js @@ -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; + }); + +}); diff --git a/package.json b/package.json index ca67f35..42ceea1 100644 --- a/package.json +++ b/package.json @@ -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",