Updated panel to use Webview API

(Also removed some dead code)
This commit is contained in:
Julien Stebenne 2019-03-30 00:49:50 -04:00 committed by Juha Ristolainen
parent 84993aef7f
commit 9d70e7cd7f
3 changed files with 20 additions and 18 deletions

View File

@ -1,4 +1,4 @@
<link rel="stylesheet" href="file:///${style}"> <link rel="stylesheet" href="${style}">
<div class="profile"> <div class="profile">
<h3> ${profile.user} <sup>${profile.level}</sup> ${profile.total_xp} xp <h3> ${profile.user} <sup>${profile.level}</sup> ${profile.total_xp} xp
<% if( profile.new_xp > 0 ) { %> <% if( profile.new_xp > 0 ) { %>

View File

@ -2,6 +2,7 @@
import * as fs from 'fs'; import * as fs from 'fs';
import { CancellationToken, Event, ExtensionContext, TextDocumentContentProvider, Uri } from "vscode"; import { CancellationToken, Event, ExtensionContext, TextDocumentContentProvider, Uri } from "vscode";
import { CodeStatsAPI } from "./code-stats-api"; import { CodeStatsAPI } from "./code-stats-api";
import * as path from 'path';
import template = require('lodash.template'); import template = require('lodash.template');
@ -88,7 +89,10 @@ export class ProfileProvider implements TextDocumentContentProvider {
let html = template(htmlTemplate); let html = template(htmlTemplate);
return html({profile: profile, languages: languages, machines: machines, style: this.context.asAbsolutePath("assets/profile.css")}); const stylePath = Uri.file(path.join(this.context.extensionPath, 'assets', 'profile.css'));
const styleSrc = stylePath.with({scheme: 'vscode-resource'});
return html({profile: profile, languages: languages, machines: machines, style: styleSrc});
}); });
} }

View File

@ -1,4 +1,3 @@
// tslint:disable-next-line:max-line-length
import { import {
Disposable, Disposable,
workspace, workspace,
@ -10,13 +9,13 @@ import {
TextDocument, TextDocument,
StatusBarAlignment, StatusBarAlignment,
TextDocumentChangeEvent, TextDocumentChangeEvent,
Range,
WorkspaceConfiguration, WorkspaceConfiguration,
ExtensionContext ExtensionContext
} from "vscode"; } from "vscode";
import { Pulse } from "./pulse"; import { Pulse } from "./pulse";
import { CodeStatsAPI } from "./code-stats-api"; import { CodeStatsAPI } from "./code-stats-api";
import { ProfileProvider } from "./profile-provider"; import { ProfileProvider } from "./profile-provider";
import * as path from 'path';
export class XpCounter { export class XpCounter {
private combinedDisposable: Disposable; private combinedDisposable: Disposable;
@ -25,23 +24,11 @@ export class XpCounter {
private api: CodeStatsAPI; private api: CodeStatsAPI;
private updateTimeout: any; private updateTimeout: any;
// private languages: Array<string> = ["typescript", "javascript"];
// wait 10s after each change in the document before sending an update // wait 10s after each change in the document before sending an update
private UPDATE_DELAY = 10000; private UPDATE_DELAY = 10000;
constructor(context: ExtensionContext) { constructor(context: ExtensionContext) {
this.pulse = new Pulse(); this.pulse = new Pulse();
/* // print out supported language names
let allLanguages = languages.getLanguages().then(
(result => {
console.log(JSON.stringify(result));
})
);
*/
this.initAPI(); this.initAPI();
let subscriptions: Disposable[] = []; let subscriptions: Disposable[] = [];
@ -68,8 +55,19 @@ export class XpCounter {
window.showErrorMessage('codestats.username configuration setting is missing'); window.showErrorMessage('codestats.username configuration setting is missing');
return; return;
} }
const panel = window.createWebviewPanel(
'codeStatsPanel',
'Code::Stats Profile',
ViewColumn.Two,
{
localResourceRoots: [Uri.file(path.join(context.extensionPath, 'assets'))]
}
);
commands.executeCommand('vscode.previewHtml', Uri.parse('code-stats://profile'), ViewColumn.Two, 'Code::Stats Profile'); workspace.openTextDocument(Uri.parse('code-stats://profile')).then((value) => {
panel.webview.html = value.getText();
});
})); }));
workspace.onDidChangeTextDocument( workspace.onDidChangeTextDocument(
@ -154,7 +152,7 @@ export class XpCounter {
` `
); );
if( this.api != null ) if(this.api != null )
this.api.updateSettings(apiKey, apiURL, userName); this.api.updateSettings(apiKey, apiURL, userName);
else else
this.api = new CodeStatsAPI(apiKey,apiURL,userName); this.api = new CodeStatsAPI(apiKey,apiURL,userName);