Skip to content

Commit afc0faf

Browse files
committed
Merge pull request #4 from OpenframeProject/xinit-settings
Xinit settings
2 parents f5ad188 + fc6014a commit afc0faf

8 files changed

Lines changed: 102 additions & 11 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ log/*
44
artwork/
55
npm-debug.log
66
coverage/*
7-
player/*
7+
player/*
8+
.xinitrc
9+
!.xinitrc.tpl

extension.js

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var pjson = require('./package.json'),
2-
Extension = require('openframe-extension');
2+
Extension = require('openframe-extension'),
3+
execSync = require('child_process').execSync;
34

45
/**
56
* Extensions should expose an instance of the Extension class.
@@ -13,7 +14,54 @@ module.exports = new Extension({
1314
// this is what might get displayed to users (not currently used)
1415
'display_name': 'Website',
1516
'download': false,
16-
'start_command': 'xinit /usr/bin/chromium --kiosk $url',
17-
'end_command': 'sudo pkill -f chromium'
18-
}
17+
'start_command': function(args, tokens) {
18+
// 1. clone template .xinitrc
19+
var filePath = _cloneTemplate(this.xinitrcTplPath);
20+
// 1. replace tokens in .xinitrc
21+
_replaceTokens(filePath, tokens);
22+
// 2. return xinit
23+
return 'xinit ' + filePath;
24+
},
25+
'end_command': 'pkill -f X',
26+
xinitrcTplPath: __dirname + '/scripts/.xinitrc.tpl'
27+
},
1928
});
29+
30+
/**
31+
* Replace tokens in a file.
32+
*
33+
* @param {string} _str
34+
* @param {object} tokens
35+
* @return {string} The string with tokens replaced.
36+
*/
37+
function _replaceTokens(filePath, tokens) {
38+
console.log(_replaceTokens, filePath, tokens);
39+
40+
function replace(token, value) {
41+
// tokens start with a $ which needs to be escaped, oops
42+
var _token = '\\' + token,
43+
// use commas as delims so that we don't need to escape value, which might be a URL
44+
cmd = 'sed -i "s,' + _token + ',' + value + ',g" ' + filePath;
45+
execSync(cmd);
46+
}
47+
48+
var key;
49+
for (key in tokens) {
50+
// TODO: better token replacement (global replacement?
51+
replace(key, tokens[key]);
52+
}
53+
}
54+
55+
/**
56+
* Clone xinitrc
57+
*
58+
* @return {string} The string with tokens replaced.
59+
*/
60+
function _cloneTemplate(filePath) {
61+
var newFilePath = filePath.replace('.tpl', ''),
62+
cmd = 'cp -f ' + filePath + ' ' + newFilePath;
63+
64+
execSync(cmd);
65+
66+
return newFilePath;
67+
}

install.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ if [ $os == "Linux" ]; then
2323
# same for any debian disto (untested), including rpi (tested)
2424
sudo apt-get install chromium
2525

26-
if [ $arq == "armv7l" ]; then
27-
# on RaspberryPi
26+
if [ $arq == "armv7l" ] || [ $arq == "armv6l" ]; then
27+
# on RaspberryPi or other arm 6/7 device
2828

2929
# ####
3030
#
@@ -62,12 +62,10 @@ if [ $os == "Linux" ]; then
6262
fi
6363

6464
# TODO: update chromium window_placement settings
65-
echo "armv7l"
6665

6766

6867
else
69-
# Non-arm7 Debian...
70-
echo "non armv7l"
68+
# Non-arm Debian...
7169
fi
7270

7371
elif [ $os == "Darwin" ]; then

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"license": "GPL-3.0",
3939
"devDependencies": {
4040
"coveralls": "^2.11.9",
41-
"eslint": "^2.8.0",
41+
"eslint": "^2.9.0",
4242
"istanbul": "^0.4.2",
4343
"mocha": "^2.3.4",
4444
"sinon": "^1.17.2"

scripts/.end_command

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
# cleanup chromium in case it dies unexpectedly
4+
sed -i 's/"exited_cleanly": false/"exited_cleanly": true/' ~/.config/chromium/Default/Preferences

scripts/.xinitrc.tpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
xscreensaver -no-splash
2+
3+
xset s off
4+
xset -dpms
5+
xset s noblank
6+
7+
exec /usr/bin/chromium --noerrdialogs --kiosk --incognito $url

test/.xinitrc.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exec /usr/bin/chromium --noerrdialogs --kiosk --incognito $url

test/extension.spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
var assert = require('assert'),
2+
exec = require('child_process').exec,
3+
fs = require('fs'),
24
Extension = require('openframe-extension'),
35
WebsiteExtension = require('../extension');
46

@@ -9,6 +11,10 @@ describe('instantiation', function() {
911
});
1012

1113
describe('properties', function() {
14+
after(function(done) {
15+
exec('rm ' + __dirname + '/.xinitrc', done);
16+
});
17+
1218
it('should include all required format properties', function() {
1319
var format = WebsiteExtension.props.format;
1420

@@ -31,4 +37,29 @@ describe('properties', function() {
3137
assert(format.end_command);
3238
assert(typeof format.end_command === 'string');
3339
});
40+
41+
it('start_command should update .xinitrc file with supplied token', function(done) {
42+
var format = WebsiteExtension.props.format,
43+
command,
44+
expected = 'exec /usr/bin/chromium --noerrdialogs --kiosk --incognito http://test.com';
45+
46+
// use test .xinitrc
47+
format.xinitrcTplPath = __dirname + '/.xinitrc.tpl';
48+
format.xinitrcFinalPath = format.xinitrcTplPath.replace('.tpl', '');
49+
50+
// replace $url token with url string
51+
command = format.start_command({}, {
52+
$url: 'http://test.com'
53+
});
54+
55+
assert(typeof command === 'string');
56+
57+
fs.readFile(format.xinitrcFinalPath, 'utf8', function(err, data) {
58+
if (err) {
59+
throw err;
60+
}
61+
assert.equal(data, expected);
62+
done();
63+
});
64+
});
3465
});

0 commit comments

Comments
 (0)