Skip to content

Commit

Permalink
Merge pull request #166 from wakatime/headless-windows
Browse files Browse the repository at this point in the history
Prevent opening cmd window when sending heartbeats on Windows platform
  • Loading branch information
alanhamlett authored Oct 5, 2020
2 parents 5ea523f + 0295e6a commit 2d51907
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 26 deletions.
62 changes: 38 additions & 24 deletions src/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,11 @@ export class Dependencies {
this.logger.debug(`Looking for python at: ${binary}`);

const args = ['--version'];
const options = {
windowsHide: true,
};
try {
child_process.execFile(binary, args, (error, stdout, stderr) => {
child_process.execFile(binary, args, options, (error, stdout, stderr) => {
const output: string = stdout.toString() + stderr.toString();
if (!error && this.isSupportedPythonVersion(binary, output)) {
this.cachedPythonLocation = binary;
Expand All @@ -154,7 +157,10 @@ export class Dependencies {
this.getPythonLocation(pythonBinary => {
if (pythonBinary) {
let args = [this.getCliLocation(), '--version'];
child_process.execFile(pythonBinary, args, (error, _stdout, stderr) => {
const options = {
windowsHide: true,
};
child_process.execFile(pythonBinary, args, options, (error, _stdout, stderr) => {
if (!(error != null)) {
let currentVersion = _stdout.toString().trim() + stderr.toString().trim();
this.logger.debug(`Current wakatime-cli version is ${currentVersion}`);
Expand Down Expand Up @@ -184,28 +190,36 @@ export class Dependencies {

private isStandaloneCliLatest(callback: (arg0: boolean) => void): void {
let args = ['--version'];
child_process.execFile(this.getStandaloneCliLocation(), args, (error, _stdout, stderr) => {
if (!(error != null)) {
let currentVersion = _stdout.toString().trim() + stderr.toString().trim();
this.logger.debug(`Current wakatime-cli version is ${currentVersion}`);

this.logger.debug('Checking for updates to wakatime-cli...');
this.getLatestStandaloneCliVersion(latestVersion => {
if (currentVersion === latestVersion) {
this.logger.debug('wakatime-cli is up to date');
callback(true);
} else if (latestVersion) {
this.logger.debug(`Found an updated wakatime-cli v${latestVersion}`);
callback(false);
} else {
this.logger.debug('Unable to find latest wakatime-cli version');
callback(false);
}
});
} else {
callback(false);
}
});
const options = {
windowsHide: true,
};
child_process.execFile(
this.getStandaloneCliLocation(),
args,
options,
(error, _stdout, stderr) => {
if (!(error != null)) {
let currentVersion = _stdout.toString().trim() + stderr.toString().trim();
this.logger.debug(`Current wakatime-cli version is ${currentVersion}`);

this.logger.debug('Checking for updates to wakatime-cli...');
this.getLatestStandaloneCliVersion(latestVersion => {
if (currentVersion === latestVersion) {
this.logger.debug('wakatime-cli is up to date');
callback(true);
} else if (latestVersion) {
this.logger.debug(`Found an updated wakatime-cli v${latestVersion}`);
callback(false);
} else {
this.logger.debug('Unable to find latest wakatime-cli version');
callback(false);
}
});
} else {
callback(false);
}
},
);
}

private getLatestCliVersion(callback: (arg0: string) => void): void {
Expand Down
10 changes: 8 additions & 2 deletions src/wakatime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,10 @@ export class WakaTime {

const binary = this.standalone || !pythonBinary ? cli : pythonBinary;
this.logger.debug(`Sending heartbeat: ${this.formatArguments(binary, args)}`);
let process = child_process.execFile(binary, args, (error, stdout, stderr) => {
const options = {
windowsHide: true,
};
let process = child_process.execFile(binary, args, options, (error, stdout, stderr) => {
if (error != null) {
if (stderr && stderr.toString() != '') this.logger.error(stderr.toString());
if (stdout && stdout.toString() != '') this.logger.error(stdout.toString());
Expand Down Expand Up @@ -449,7 +452,10 @@ export class WakaTime {
this.logger.debug(
`Fetching coding activity for Today from api: ${this.formatArguments(binary, args)}`,
);
let process = child_process.execFile(binary, args, (error, stdout, stderr) => {
const options = {
windowsHide: true,
};
let process = child_process.execFile(binary, args, options, (error, stdout, stderr) => {
if (error != null) {
if (stderr && stderr.toString() != '') this.logger.error(stderr.toString());
if (stdout && stdout.toString() != '') this.logger.error(stdout.toString());
Expand Down

0 comments on commit 2d51907

Please sign in to comment.