Skip to content

Commit 7f0036b

Browse files
committed
WIP - use xinitrc
1 parent f5ad188 commit 7f0036b

6 files changed

Lines changed: 80 additions & 5 deletions

File tree

.gitignore

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

extension.js

Lines changed: 34 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,36 @@ 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. replace tokens in .xinitrc
19+
_replaceTokens(this.xinitrcPath, tokens);
20+
// 2. return xinit
21+
return 'xinit ' + this.xinitrcPath;
22+
},
23+
'end_command': 'sudo pkill -f chromium',
24+
xinitrcPath: __dirname + '/scripts/.xinitrc'
25+
},
1926
});
27+
28+
/**
29+
* Replace tokens in a file.
30+
*
31+
* @param {string} _str
32+
* @param {object} tokens
33+
* @return {string} The string with tokens replaced.
34+
*/
35+
function _replaceTokens(filePath, tokens) {
36+
37+
function replace(token, value) {
38+
// tokens start with a $, oops
39+
token = '\\' + token;
40+
var cmd = 'sed -i "s,' + token + ',' + value + ',g" ' + filePath;
41+
execSync(cmd);
42+
}
43+
44+
var key;
45+
for (key in tokens) {
46+
// TODO: better token replacement (global replacement?
47+
replace(key, tokens[key]);
48+
}
49+
}

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

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.spec

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: 32 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,14 @@ describe('instantiation', function() {
911
});
1012

1113
describe('properties', function() {
14+
before(function(done) {
15+
exec('cp ' + __dirname + '/.xinitrc.spec ' + __dirname + '/.xinitrc', done);
16+
});
17+
18+
after(function(done) {
19+
exec('rm ' + __dirname + '/.xinitrc', done);
20+
});
21+
1222
it('should include all required format properties', function() {
1323
var format = WebsiteExtension.props.format;
1424

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

0 commit comments

Comments
 (0)