mirror of
https://gitlab.com/aviortheking/code-stats-vscode.git
synced 2025-08-11 02:31:58 +00:00
Make API URL configurable and listen to config changes
Also prevents useless API call when no API key is set
This commit is contained in:
committed by
Juha Ristolainen
parent
24ee812c7d
commit
2bff22d53f
@@ -26,14 +26,7 @@ export class XpCounter {
|
||||
);
|
||||
*/
|
||||
|
||||
let config: WorkspaceConfiguration = workspace.getConfiguration("codestats");
|
||||
if (!config) {
|
||||
return;
|
||||
}
|
||||
|
||||
// tslint:disable-next-line:typedef
|
||||
let apiKey = config.get("apikey");
|
||||
this.api = new CodeStatsAPI(`${apiKey}`);
|
||||
this.initAPI();
|
||||
|
||||
if (!this.statusBarItem) {
|
||||
this.statusBarItem = window.createStatusBarItem(StatusBarAlignment.Left);
|
||||
@@ -41,6 +34,7 @@ export class XpCounter {
|
||||
|
||||
let subscriptions: Disposable[] = [];
|
||||
workspace.onDidChangeTextDocument(this.onTextDocumentChanged, this, subscriptions);
|
||||
workspace.onDidChangeConfiguration(this.initAPI, this, subscriptions);
|
||||
this.combinedDisposable = Disposable.from(...subscriptions);
|
||||
}
|
||||
|
||||
@@ -117,4 +111,15 @@ export class XpCounter {
|
||||
return true;
|
||||
}
|
||||
|
||||
private initAPI() {
|
||||
let config: WorkspaceConfiguration = workspace.getConfiguration("codestats");
|
||||
if (!config) {
|
||||
return;
|
||||
}
|
||||
|
||||
const apiKey: string = config.get("apikey");
|
||||
const apiURL: string = config.get("apiurl");
|
||||
console.log("code-stats-vscode setting up with API URL", apiURL, "and key", apiKey);
|
||||
this.api = new CodeStatsAPI(apiKey, apiURL);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user