Skip to content
This repository has been archived by the owner on Apr 11, 2018. It is now read-only.

Commit

Permalink
Support for enableAutostart()
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrimue committed Aug 26, 2015
1 parent d782ab3 commit f7a0ed2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
34 changes: 30 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,28 @@
var fs = require('fs'),
exec = require('child_process').exec,
os = require('os'),
crontab = require('crontab');
username = require('username');

if(process.env.NODE_ENV === 'test') var test = true;

/**
* Returns the path for the startup folder in Windows
* @returns {String} path
*/

function getWinStartupPath() {
var path;
var majorRelease = os.release().substring(1, 0);
if(majorRelease >= 6) {
path = 'C:\\Users\\' + username.sync() + '\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup';
}
else {
path = 'C:\\Documents and Settings\\' + username.sync() + '\\Start Menu\\Programs\\Startup';
}

return path;
}

/**
* Enables autostart
* @param {String} key
Expand Down Expand Up @@ -73,8 +91,15 @@ function enableAutostart(key, command, path, callback) {
});
//} else if (os.platform() === 'linux') {
//crontab stuff
//} else if (os.platform() === 'win32') {
} else if (os.platform() === 'win32') {
var batchFileContent; //File to be placed in the startup folder, will be generated here
batchFileContent = 'cd ' + path + ' && ' + command;
fs.writeFile(getWinStartupPath() + '/' + key + '.bat', batchFileContent, function (error) {
err = error;

if (err === '' || err === undefined) err = null;
callback(err);
});
}
});
}
Expand Down Expand Up @@ -191,8 +216,9 @@ function isAutostartEnabled(key, callback) {
});
//} else if (os.platform() === "linux") {
//crontab stuff
//} else if (os.platform() === "win32") {

} else if (os.platform() === "win32") {
if(err === '' || err === undefined) err = null;
callback(isEnabled = false, err);
}
/* istanbul ignore else */
else {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"dependencies": {
"crontab": "1.x.x",
"username": "^1.0.0",
"yargs": "^3.19.0"
},
"devDependencies": {
Expand Down

0 comments on commit f7a0ed2

Please sign in to comment.