Skip to content

Commit 122dd27

Browse files
committed
Clone .xinitrc template before modifying
1 parent 7f0036b commit 122dd27

7 files changed

Lines changed: 36 additions & 22 deletions

File tree

.gitignore

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

extension.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ module.exports = new Extension({
1515
'display_name': 'Website',
1616
'download': false,
1717
'start_command': function(args, tokens) {
18+
// 1. clone template .xinitrc
19+
var filePath = _cloneTemplate(this.xinitrcTplPath);
1820
// 1. replace tokens in .xinitrc
19-
_replaceTokens(this.xinitrcPath, tokens);
21+
_replaceTokens(filePath, tokens);
2022
// 2. return xinit
21-
return 'xinit ' + this.xinitrcPath;
23+
return 'xinit ' + filePath;
2224
},
23-
'end_command': 'sudo pkill -f chromium',
24-
xinitrcPath: __dirname + '/scripts/.xinitrc'
25+
'end_command': 'pkill -f X',
26+
xinitrcTplPath: __dirname + '/scripts/.xinitrc.tpl'
2527
},
2628
});
2729

@@ -33,11 +35,13 @@ module.exports = new Extension({
3335
* @return {string} The string with tokens replaced.
3436
*/
3537
function _replaceTokens(filePath, tokens) {
38+
console.log(_replaceTokens, filePath, tokens);
3639

3740
function replace(token, value) {
38-
// tokens start with a $, oops
39-
token = '\\' + token;
40-
var cmd = 'sed -i "s,' + token + ',' + value + ',g" ' + filePath;
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 = 'sudo sed -i "s,' + _token + ',' + value + ',g" ' + filePath;
4145
execSync(cmd);
4246
}
4347

@@ -47,3 +51,17 @@ function _replaceTokens(filePath, tokens) {
4751
replace(key, tokens[key]);
4852
}
4953
}
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"
File renamed without changes.

test/.xinitrc.spec

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/extension.spec.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ describe('instantiation', function() {
1111
});
1212

1313
describe('properties', function() {
14-
before(function(done) {
15-
exec('cp ' + __dirname + '/.xinitrc.spec ' + __dirname + '/.xinitrc', done);
16-
});
17-
1814
after(function(done) {
1915
exec('rm ' + __dirname + '/.xinitrc', done);
2016
});
@@ -48,7 +44,8 @@ describe('properties', function() {
4844
expected = 'exec /usr/bin/chromium --noerrdialogs --kiosk --incognito http://test.com';
4945

5046
// use test .xinitrc
51-
format.xinitrcPath = __dirname + '/.xinitrc';
47+
format.xinitrcTplPath = __dirname + '/.xinitrc.tpl';
48+
format.xinitrcFinalPath = format.xinitrcTplPath.replace('.tpl', '');
5249

5350
// replace $url token with url string
5451
command = format.start_command({}, {
@@ -57,8 +54,10 @@ describe('properties', function() {
5754

5855
assert(typeof command === 'string');
5956

60-
fs.readFile(format.xinitrcPath, 'utf8', function(err, data) {
61-
if (err) throw err;
57+
fs.readFile(format.xinitrcFinalPath, 'utf8', function(err, data) {
58+
if (err) {
59+
throw err;
60+
}
6261
assert.equal(data, expected);
6362
done();
6463
});

0 commit comments

Comments
 (0)