@@ -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 */
3537function _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+ }
0 commit comments