Skip to content

Commit 1c5b2e0

Browse files
committed
WIP
1 parent d2d06e6 commit 1c5b2e0

File tree

5 files changed

+146
-54
lines changed

5 files changed

+146
-54
lines changed

package.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,28 +226,29 @@
226226
},
227227
{
228228
"command": "intersystems-community.servermanager.addToStarred",
229-
"category": "InterSystems Server Manager",
230229
"title": "Add to Starred",
231230
"icon": "$(star-full)"
232231
},
233232
{
234233
"command": "intersystems-community.servermanager.removeFromStarred",
235-
"category": "InterSystems Server Manager",
236234
"title": "Remove from Starred",
237235
"icon": "$(star-empty)"
238236
},
239237
{
240238
"command": "intersystems-community.servermanager.openPortalExternal",
241-
"category": "InterSystems Server Manager",
242239
"title": "Open Management Portal in External Browser",
243240
"icon": "$(link-external)"
244241
},
245242
{
246243
"command": "intersystems-community.servermanager.openPortalTab",
247-
"category": "InterSystems Server Manager",
248244
"title": "Open Management Portal in Tab",
249245
"icon": "$(tools)"
250246
},
247+
{
248+
"command": "intersystems-community.servermanager.retryServer",
249+
"title": "Reconnect",
250+
"icon": "$(refresh)"
251+
},
251252
{
252253
"command": "intersystems-community.servermanager.editSettings",
253254
"category": "InterSystems Server Manager",
@@ -268,7 +269,7 @@
268269
{
269270
"command": "intersystems-community.servermanager.importServers",
270271
"category": "InterSystems Server Manager",
271-
"title": "Import Servers from Registry"
272+
"title": "Import Servers from Windows Registry"
272273
},
273274
{
274275
"command": "intersystems-community.servermanager.setIconRed",
@@ -401,6 +402,11 @@
401402
"when": "view == intersystems-community_servermanager && viewItem == starred.server.starred",
402403
"group": "inline@10"
403404
},
405+
{
406+
"command": "intersystems-community.servermanager.retryServer",
407+
"when": "view == intersystems-community_servermanager && viewItem =~ /offline$/",
408+
"group": "inline@10"
409+
},
404410
{
405411
"command": "intersystems-community.servermanager.editNamespace",
406412
"when": "view == intersystems-community_servermanager && viewItem =~ /namespace$/",

src/api/getServerSpec.ts

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as vscode from 'vscode';
2+
import { filePassword } from '../commands/managePasswords';
23
import { ServerSpec } from '../extension';
34
import { Keychain } from '../keychain';
45

@@ -82,16 +83,38 @@ export async function getServerSpec(name: string, scope?: vscode.ConfigurationSc
8283

8384
}
8485
if (server.username && !server.password) {
85-
await vscode.window
86-
.showInputBox({
87-
password: true,
88-
placeHolder: `Password for user '${server.username}' on InterSystems server '${name}'`,
89-
validateInput: (value => {
90-
return value.length > 0 ? '' : 'Mandatory field';
91-
}),
92-
ignoreFocusOut: true,
93-
})
94-
.then((password) => {
86+
const doInputBox = async (): Promise<string | undefined> => {
87+
return await new Promise<string | undefined>((resolve, reject) => {
88+
const inputBox = vscode.window.createInputBox();
89+
inputBox.password = true,
90+
inputBox.title = `Password for InterSystems server '${name}'`,
91+
inputBox.placeholder = `Password for user '${server?.username}' on '${name}'`,
92+
inputBox.prompt = 'To store your password securely, submit it using the $(key) button',
93+
inputBox.ignoreFocusOut = true,
94+
inputBox.buttons = [{ iconPath: new vscode.ThemeIcon('key'), tooltip: 'Store Password in Keychain' }]
95+
96+
async function done(store: boolean) {
97+
// File the password and return it
98+
if (store) {
99+
await filePassword(name, inputBox.value)
100+
}
101+
// Resolve the promise and tidy up
102+
resolve(inputBox.value);
103+
inputBox.hide();
104+
inputBox.dispose();
105+
}
106+
107+
inputBox.onDidTriggerButton((button) => {
108+
// We only added one button
109+
done(true);
110+
});
111+
inputBox.onDidAccept(() => {
112+
done(false);
113+
});
114+
inputBox.show();
115+
})
116+
};
117+
await doInputBox().then((password) => {
95118
if (password && server) {
96119
server.password = password;
97120
credentialCache[name] = {username: server.username, password: password};

src/commands/managePasswords.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ export async function storePassword(treeItem?: ServerTreeItem): Promise<string>
2424
})
2525
.then((password) => {
2626
if (password) {
27-
credentialCache[name] = undefined;
28-
new Keychain(name).setPassword(password).then(() => {
27+
filePassword(name, password).then(() => {
2928
vscode.window.showInformationMessage(`Password for '${name}' stored in keychain.`);
3029
});
3130
reply = name;
@@ -35,6 +34,11 @@ export async function storePassword(treeItem?: ServerTreeItem): Promise<string>
3534
return reply;
3635
}
3736

37+
export async function filePassword(serverName: string, password: string): Promise<boolean> {
38+
credentialCache[serverName] = undefined;
39+
return new Keychain(serverName).setPassword(password).then(() => true, () => false);
40+
}
41+
3842
export async function clearPassword(treeItem?: ServerTreeItem): Promise<string> {
3943
if (treeItem && !getServerNames().some((value) => value.name === treeItem?.label)) {
4044
treeItem = undefined;

src/extension.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ export function activate(context: vscode.ExtensionContext) {
187187
})
188188
);
189189

190+
context.subscriptions.push(
191+
vscode.commands.registerCommand(`${extensionId}.retryServer`, () => {
192+
view.refreshTree();
193+
})
194+
);
195+
190196
const addWorkspaceFolderAsync = async (readonly: boolean, namespaceTreeItem?: ServerTreeItem) => {
191197
if (namespaceTreeItem) {
192198
const pathParts = namespaceTreeItem.id?.split(':');

0 commit comments

Comments
 (0)