diff --git a/assets/profile.css b/assets/profile.css index 3a61517..5bafd5d 100644 --- a/assets/profile.css +++ b/assets/profile.css @@ -4,19 +4,16 @@ --color-primary: #E3C23D; --color-secondary: #5D5535; --color-bar-background: #303030; -} - -.vscode-dark1 { - --color-language: #ddca7e; - --color-primary: #dcc97e; - --color-secondary: #318245; - --color-bar-background: #303030; + --color-bar-border: #424242; } /* Light theme color palette */ .vscode-light { - --color-language: blue; - --color-primary: #00ca7e; + --color-language: #1B2334; + --color-primary: #5D78B3; + --color-secondary: #354567; + --color-bar-background: #939DB3; + --color-bar-border: #697080; } .profile { @@ -43,13 +40,11 @@ sup { .language-progress .tooltiptext { visibility: hidden; width: 120px; - background-color: var(--color-primary); - color: black; + background-color: var(--color-bar-border); + color: var(--color-language); text-align: center; border-radius: 6px; padding: 5px 0; - - /* Position the tooltip */ position: absolute; z-index: 1; } @@ -112,9 +107,7 @@ circle.oldxp { background-color: var(--color-bar-background); border-radius: 4px; border: solid 1px; - border-color: #424242; - -webkit-box-shadow: inset 0 1px 2px rgba(0,0,0,.1); - box-shadow: inset 0 1px 2px rgba(0,0,0,.1); + border-color: var(--color-bar-border); } .progress-bar { @@ -123,11 +116,8 @@ circle.oldxp { height: 100%; font-size: 12px; line-height: 20px; - text-align: center; - + text-align: center; background-color: var(--color-secondary); - -webkit-box-shadow: inset 0 -1px 0 rgba(0,0,0,.15); - box-shadow: inset 0 -1px 0 rgba(0,0,0,.15); } .progress-bar-new { diff --git a/assets/profile.html.eex b/assets/profile.html.eex index 11461bf..19ea7df 100644 --- a/assets/profile.html.eex +++ b/assets/profile.html.eex @@ -19,7 +19,7 @@ <%=languages[l].xp %> xp <% if( languages[l].new_xp > 0 ) { %> - +<%= languages[l].new_xp %> + +<%= languages[l].new_xp %> <% } %> diff --git a/src/code-stats-api.ts b/src/code-stats-api.ts index 188c8f3..23d720d 100644 --- a/src/code-stats-api.ts +++ b/src/code-stats-api.ts @@ -10,6 +10,11 @@ export class CodeStatsAPI { private axios = null; constructor(apiKey: string, apiURL: string, userName: string) { + this.updateSettings(apiKey, apiURL, userName); + } + + public updateSettings( apiKey: string, apiURL: string, userName: string) { + this.API_KEY = apiKey; this.UPDATE_URL = apiURL; this.USER_NAME = userName; @@ -71,6 +76,7 @@ export class CodeStatsAPI { }) .catch(error => { console.log(error); + return null; }); } } diff --git a/src/profile-provider.ts b/src/profile-provider.ts index 92e7f66..089110e 100644 --- a/src/profile-provider.ts +++ b/src/profile-provider.ts @@ -18,6 +18,9 @@ export class ProfileProvider implements TextDocumentContentProvider { provideTextDocumentContent(uri: Uri, token: CancellationToken): string | Thenable { + if( token.isCancellationRequested ) + return; + const LEVEL_FACTOR = 0.025; function getLevel(xp: number): number { @@ -66,6 +69,11 @@ export class ProfileProvider implements TextDocumentContentProvider { return this.api.getProfile().then(profile => { + if( profile === null ) + { + return `

Can't fetch profile. Please try again later

Make sure codestats.username setting is set to correct user name.`; + } + let htmlTemplate = fs.readFileSync(this.context.asAbsolutePath("assets/profile.html.eex")); profile["level"] = getLevel(profile["total_xp"]); diff --git a/src/xp-counter.ts b/src/xp-counter.ts index bda4189..1fa1d24 100644 --- a/src/xp-counter.ts +++ b/src/xp-counter.ts @@ -51,17 +51,26 @@ export class XpCounter { this.statusBarItem.command = "code-stats.profile"; } - let provider = new ProfileProvider(context, this.api); - - let registration = workspace.registerTextDocumentContentProvider('code-stats', provider); - - subscriptions.push(registration); - - let previewUri = Uri.parse('code-stats://profile') - + subscriptions.push(workspace.registerTextDocumentContentProvider('code-stats', new ProfileProvider(context, this.api))); + subscriptions.push(commands.registerCommand("code-stats.profile", () => { - commands.executeCommand('vscode.previewHtml', previewUri, ViewColumn.Two, 'Code::Stats Profile'); - } ) ); + + let config: WorkspaceConfiguration = workspace.getConfiguration( + "codestats" + ); + + if (!config) { + window.showErrorMessage('codestats.username configuration setting is missing'); + return; + } + + if( config.get("username") === '' ){ + window.showErrorMessage('codestats.username configuration setting is missing'); + return; + } + + commands.executeCommand('vscode.previewHtml', Uri.parse('code-stats://profile'), ViewColumn.Two, 'Code::Stats Profile'); + })); workspace.onDidChangeTextDocument( this.onTextDocumentChanged, @@ -145,6 +154,9 @@ export class XpCounter { ` ); - this.api = new CodeStatsAPI(apiKey, apiURL, userName); + if( this.api != null ) + this.api.updateSettings(apiKey, apiURL, userName); + else + this.api = new CodeStatsAPI(apiKey,apiURL,userName); } }