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

Commit f336239

Browse files
committed
feat: add information message on first startup
add information message on startup without token
1 parent 2f84efd commit f336239

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
"dependencies": {
6868
"execa": "0.5.0",
6969
"lru-cache": "4.0.1",
70-
"pretend": "0.4.0"
70+
"pretend": "0.4.0",
71+
"sander": "0.5.1"
7172
},
7273
"repository": {
7374
"type": "git",

src/extension.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1+
import {join} from 'path';
2+
import * as sander from 'sander';
13
import * as vscode from 'vscode';
24
import * as git from './git';
35
import {getClient, GitHub, GitHubError, ListPullRequestsParameters, CreatePullRequestBody} from './github';
46

57
let cwd: string;
6-
let token: string;
8+
let storedToken: string;
79
let github: GitHub;
810
let channel: vscode.OutputChannel;
911
let statusBar: vscode.StatusBarItem;
1012

1113
export function activate(context: vscode.ExtensionContext): void {
14+
checkVersionAndToken(context);
15+
1216
cwd = vscode.workspace.rootPath;
1317
getToken(context)
1418
.then(_token => {
15-
token = _token;
19+
storedToken = _token;
1620
refreshPullRequestStatus();
1721
});
1822

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

47+
function checkVersionAndToken(context: vscode.ExtensionContext): void {
48+
sander.readFile(join(context.extensionPath, 'package.json'))
49+
.then(content => JSON.parse(content))
50+
.then(json => json.version as string)
51+
.then(version => {
52+
return getToken(context)
53+
.then(token => ({token, version}));
54+
})
55+
.then(({version, token}) => {
56+
const storedVersion = context.globalState.get('version-test');
57+
if (version !== storedVersion && !Boolean(token)) {
58+
context.globalState.update('version-test', version);
59+
vscode.window.showInformationMessage(
60+
'To enable the Visual Studio Code GitHub Support, please set a Personal Access Token');
61+
}
62+
});
63+
}
64+
4365
async function refreshPullRequestStatus(): Promise<void> {
44-
if (token) {
66+
if (storedToken) {
4567
await updatePullRequestStatus();
4668
}
4769
setTimeout(refreshPullRequestStatus, 5000);
@@ -74,7 +96,7 @@ async function updatePullRequestStatus(forceState?: boolean): Promise<void> {
7496

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

91113
function getGitHubClient(): GitHub {
92114
if (!github) {
93-
github = getClient(token);
115+
github = getClient(storedToken);
94116
}
95117
return github;
96118
}
@@ -115,7 +137,7 @@ function createGithubTokenCommand(context: vscode.ExtensionContext): () => Promi
115137
return vscode.window.showInputBox(options)
116138
.then(input => {
117139
context.globalState.update('token', input);
118-
token = input;
140+
storedToken = input;
119141
});
120142
};
121143
}

typings/sander.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module 'sander' {
2+
export function readFile(path: string): Promise<string>;
3+
}

0 commit comments

Comments
 (0)