Skip to content

Commit

Permalink
Merge pull request #36 from valeth/wakatime-home-env
Browse files Browse the repository at this point in the history
Search WAKATIME_HOME for configuration if set
  • Loading branch information
alanhamlett authored Nov 29, 2017
2 parents 41d0ef9 + 08c4b66 commit fa3e5cb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ Visit https://wakatime.com to see your coding activity.

Configuring
-----------
> `$WAKATIME_HOME` defaults to `$HOME`
Some settings are available from CMD+SHIFT+p, then typing `wakatime`.

Settings are stored in the INI file at `$HOME/.wakatime.cfg`.
Settings are stored in the INI file at `$WAKATIME_HOME/.wakatime.cfg`.

More information can be found from [wakatime core](https://github.com/wakatime/wakatime#configuring).

Expand All @@ -55,7 +56,7 @@ Next, open your Developer Console to view logs and errors:

`Help → Toggle Developer Tools`

Errors outside the scope of vscode-wakatime go to `~/.wakatime.log` from [wakatime-cli][wakatime-cli-help].
Errors outside the scope of vscode-wakatime go to `$WAKATIME_HOME/.wakatime.log` from [wakatime-cli][wakatime-cli-help].

The [How to Debug Plugins][how to debug] guide shows how to check when coding activity was last received from your editor using the [User Agents API][user agents api].
For more general troubleshooting info, see the [wakatime-cli Troubleshooting Section][wakatime-cli-help].
Expand Down
23 changes: 16 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,11 @@ export class WakaTime {
} else if (code == 102) {
this.statusBar.text =
'$(clock) WakaTime Offline, coding activity will sync when online.';
logger.warn('API Error (102); Check your ~/.wakatime.log file for more details.');
logger.warn('API Error (102); Check your ' + options.getLogFile() + ' file for more details.');
} else if (code == 103) {
this.statusBar.text = '$(clock) WakaTime Error';
let error_msg =
'Config Parsing Error (103); Check your ~/.wakatime.log file for more details.';
'Config Parsing Error (103); Check your ' + options.getLogFile() + ' file for more details.';
this.statusBar.tooltip = error_msg;
logger.error(error_msg);
} else if (code == 104) {
Expand All @@ -314,7 +314,7 @@ export class WakaTime {
} else {
this.statusBar.text = '$(clock) WakaTime Error';
let error_msg =
'Unknown Error (' + code + '); Check your ~/.wakatime.log file for more details.';
'Unknown Error (' + code + '); Check your ' + options.getLogFile() + ' file for more details.';
this.statusBar.tooltip = error_msg;
logger.error(error_msg);
}
Expand Down Expand Up @@ -678,13 +678,22 @@ class Dependencies {
}

class Options {
private _configFile = path.join(this.getUserHomeDir(), '.wakatime.cfg');
private _logFile = path.join(this.getUserHomeDir(), '.wakatime.log');
private _configFile = path.join(this.getWakaHome(), '.wakatime.cfg');
private _logFile = path.join(this.getWakaHome(), '.wakatime.log');

private getWakaHome() {
let home = process.env.WAKATIME_HOME;
if (home) {
return home;
} else {
return this.getUserHomeDir();
}
}

public getSetting(section: string, key: string, callback?) {
fs.readFile(this.getConfigFile(), 'utf-8', (err, content) => {
if (err) {
if (callback) callback(new Error('could not read ~/.wakatime.cfg'), null);
if (callback) callback(new Error('could not read ' + this.getConfigFile()), null);
} else {
let currentSection = '';
let lines = content.split('\n');
Expand Down Expand Up @@ -757,7 +766,7 @@ class Options {

fs.writeFile(this.getConfigFile(), contents.join('\n'), function(err2) {
if (err) {
if (callback) callback(new Error('could not write to ~/.wakatime.cfg'));
if (callback) callback(new Error('could not write to ' + this.getConfigFile()));
} else {
if (callback) callback(null);
}
Expand Down

0 comments on commit fa3e5cb

Please sign in to comment.