Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
feat: add information message on first startup
Browse files Browse the repository at this point in the history
add information message on startup without token
  • Loading branch information
KnisterPeter committed Nov 15, 2016
1 parent 2f84efd commit f336239
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
"dependencies": {
"execa": "0.5.0",
"lru-cache": "4.0.1",
"pretend": "0.4.0"
"pretend": "0.4.0",
"sander": "0.5.1"
},
"repository": {
"type": "git",
Expand Down
34 changes: 28 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import {join} from 'path';
import * as sander from 'sander';
import * as vscode from 'vscode';
import * as git from './git';
import {getClient, GitHub, GitHubError, ListPullRequestsParameters, CreatePullRequestBody} from './github';

let cwd: string;
let token: string;
let storedToken: string;
let github: GitHub;
let channel: vscode.OutputChannel;
let statusBar: vscode.StatusBarItem;

export function activate(context: vscode.ExtensionContext): void {
checkVersionAndToken(context);

cwd = vscode.workspace.rootPath;
getToken(context)
.then(_token => {
token = _token;
storedToken = _token;
refreshPullRequestStatus();
});

Expand Down Expand Up @@ -40,8 +44,26 @@ export function activate(context: vscode.ExtensionContext): void {
context.subscriptions.push(statusBar);
}

function checkVersionAndToken(context: vscode.ExtensionContext): void {
sander.readFile(join(context.extensionPath, 'package.json'))
.then(content => JSON.parse(content))
.then(json => json.version as string)
.then(version => {
return getToken(context)
.then(token => ({token, version}));
})
.then(({version, token}) => {
const storedVersion = context.globalState.get('version-test');
if (version !== storedVersion && !Boolean(token)) {
context.globalState.update('version-test', version);
vscode.window.showInformationMessage(
'To enable the Visual Studio Code GitHub Support, please set a Personal Access Token');
}
});
}

async function refreshPullRequestStatus(): Promise<void> {
if (token) {
if (storedToken) {
await updatePullRequestStatus();
}
setTimeout(refreshPullRequestStatus, 5000);
Expand Down Expand Up @@ -74,7 +96,7 @@ async function updatePullRequestStatus(forceState?: boolean): Promise<void> {

function wrapCommand<T>(command: T): T {
const wrap: any = (...args: any[]) => {
if (Boolean(token) && Boolean(cwd)) {
if (Boolean(storedToken) && Boolean(cwd)) {
return (command as any).apply(null, args);
} else {
vscode.window.showWarningMessage('Please setup your Github Personal Access Token '
Expand All @@ -90,7 +112,7 @@ function getToken(context: vscode.ExtensionContext): PromiseLike<string> {

function getGitHubClient(): GitHub {
if (!github) {
github = getClient(token);
github = getClient(storedToken);
}
return github;
}
Expand All @@ -115,7 +137,7 @@ function createGithubTokenCommand(context: vscode.ExtensionContext): () => Promi
return vscode.window.showInputBox(options)
.then(input => {
context.globalState.update('token', input);
token = input;
storedToken = input;
});
};
}
Expand Down
3 changes: 3 additions & 0 deletions typings/sander.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module 'sander' {
export function readFile(path: string): Promise<string>;
}

0 comments on commit f336239

Please sign in to comment.