diff --git a/extension.js b/extension.js index eada459..0364d56 100644 --- a/extension.js +++ b/extension.js @@ -6,7 +6,8 @@ var pjson = require('./package.json'), path = require('path'), DecompressZip = require('decompress-zip'), replace = require('replace-in-file'), - os = require('os') + os = require('os'), + psList = require('ps-list'); let tmpDir = '/tmp/' // TODO: the preferences are stored in different path on each OS. This currently only works on the Pi @@ -35,29 +36,48 @@ module.exports = new Extension({ 'start_command': function(options, tokens) { var thisExtension = this return new Promise(function(resolve, reject) { - - prepareSketch(options, tokens).then(function(result) { - tokens['$tmpSketchPath'] = result - - // 1. clone template .xinitrc - debug('clone template') - var filePath = _cloneTemplate(thisExtension.xinitrcTplPath) - // 2. parse options from options into tokens - debug('extend tokens') - var _tokens = _extendTokens(options, tokens) - // 3. replace tokens in .xinitrc - debug('replace tokens') - _replaceTokens(filePath, _tokens) - // 4. return xinit - debug('build command') - var command = 'xinit ' + filePath - // console.log(command) - return resolve(command) - }) + // is X server running? + psList().then(function(processes) { + processes = processes.filter(function(process) { process.name.indexOf('Xorg') > -1; }); + let commandLineMode = processes.length > 0; + + prepareSketch(options, tokens).then(function(result) { + tokens['$tmpSketchPath'] = result + + // 1. clone template .xinitrc + debug('clone template') + var filePath = _cloneTemplate(thisExtension.xinitrcTplPath) + // 2. parse options from options into tokens + debug('extend tokens') + var _tokens = _extendTokens(options, tokens) + // 3. replace tokens in .xinitrc + debug('replace tokens') + _replaceTokens(filePath, _tokens) + // 4. return xinit + debug('build command') + + // command line mode + if (commandLineMode) { + var command = 'xinit ' + filePath + // console.log(command) + return resolve(command) + } + // desktop mode + else { + + var command = '/usr/local/bin/processing-java ' + command += '--sketch=' + _tokens['$tmpSketchPath'] + ' ' + command += '--present' + // console.log(command) + return resolve(command); + } + }) + }); }) }, // how do we stop this type of artwork? - 'end_command': 'pkill -f X && pkill -f java', + // 'end_command': 'pkill -f X && pkill -f java', + 'end_command': 'pkill -f java', // function () { // // cleanUp() // console.log(end_command) diff --git a/install.sh b/install.sh index 837a676..7c3b56f 100755 --- a/install.sh +++ b/install.sh @@ -22,7 +22,7 @@ if [ $os == "Linux" ]; then # on Linux distributions # on RaspberryPi - if [ $arq == "armv7l" ]; then + if [ $arq == "armv7l" ] || [ $arq == "armv6l" ]; then curl https://processing.org/download/install-arm.sh | sudo sh else echo "Install Processing manually from: https://processing.org/download/" diff --git a/package.json b/package.json index 7fc9368..4defbc6 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,8 @@ "fs-extra": "^8.1.0", "openframe-extension": "^0.1.0", "replace-in-file": "^4.1.3", - "unzip": "^0.1.11" + "unzip": "^0.1.11", + "ps-list": "^5.0.1" }, "repository": { "type": "git",