Skip to content

Commit 9396dd4

Browse files
committed
improve proxy auth dialog
1 parent 608cdfb commit 9396dd4

3 files changed

Lines changed: 35 additions & 18 deletions

File tree

src/vs/code/electron-main/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import { resolveCommonProperties, machineIdStorageKey, machineIdIpcChannel } fro
4444
import { getDelayedChannel } from 'vs/base/parts/ipc/common/ipc';
4545
import product from 'vs/platform/node/product';
4646
import pkg from 'vs/platform/node/package';
47-
import { AuthHandler } from './auth';
47+
import { ProxyAuthHandler } from './auth';
4848
import { IDisposable, dispose } from "vs/base/common/lifecycle";
4949
import { ConfigurationService } from "vs/platform/configuration/node/configurationService";
5050
import { TPromise } from "vs/base/common/winjs.base";
@@ -157,7 +157,7 @@ export class VSCodeApplication {
157157
const appInstantiationService = this.initServices();
158158

159159
// Setup Auth Handler
160-
const authHandler = appInstantiationService.createInstance(AuthHandler);
160+
const authHandler = appInstantiationService.createInstance(ProxyAuthHandler);
161161
this.toDispose.push(authHandler);
162162

163163
// Open Windows

src/vs/code/electron-main/auth.html

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616
-webkit-user-select: none;
1717
user-select: none;
1818
}
19-
19+
2020
body {
2121
font-family: "Segoe WPC", "Segoe UI", "HelveticaNeue-Light", sans-serif, "Droid Sans Fallback";
2222
font-size: 10pt;
2323
background-color: #F3F3F3;
2424
}
25-
25+
2626
#main {
2727
box-sizing: border-box;
2828
padding: 10px;
2929
}
30-
30+
3131
h1 {
3232
margin: 0;
3333
padding: 10px 0;
@@ -36,35 +36,35 @@
3636
color: #f0f0f0;
3737
text-align: center;
3838
}
39-
39+
4040
#form {
4141
margin-top: 10px;
4242
}
43-
43+
4444
#username,
4545
#password {
4646
padding: 6px 10px;
4747
font-size: 12px;
4848
box-sizing: border-box;
4949
width: 100%;
5050
}
51-
51+
5252
#buttons {
5353
text-align: center;
5454
}
55-
55+
5656
p {
5757
margin: 6px 0;
5858
}
59-
59+
6060
input {
6161
font-family: "Segoe WPC", "Segoe UI", "HelveticaNeue-Light", sans-serif, "Droid Sans Fallback" !important;
6262
}
6363
</style>
6464
</head>
6565

6666
<body>
67-
<h1>Authentication Required</h1>
67+
<h1 id="title"></h1>
6868
<section id="main">
6969
<p id="message"></p>
7070
<form id="form">
@@ -87,6 +87,7 @@ <h1>Authentication Required</h1>
8787

8888
function promptForCredentials(data) {
8989
return new Promise((c, e) => {
90+
const $title = document.getElementById('title');
9091
const $username = document.getElementById('username');
9192
const $password = document.getElementById('password');
9293
const $form = document.getElementById('form');
@@ -113,6 +114,7 @@ <h1>Authentication Required</h1>
113114
}
114115
});
115116

117+
$title.textContent = data.title;
116118
$message.textContent = data.message;
117119
$username.focus();
118120
});

src/vs/code/electron-main/auth.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@ type LoginEvent = {
1919
cb: (username: string, password: string) => void;
2020
};
2121

22-
export class AuthHandler {
22+
type Credentials = {
23+
username: string;
24+
password: string;
25+
};
26+
27+
export class ProxyAuthHandler {
2328

2429
_serviceBrand: any;
2530

31+
private retryCount = 0;
2632
private disposables: IDisposable[] = [];
2733

2834
constructor(
@@ -33,14 +39,22 @@ export class AuthHandler {
3339
}
3440

3541
private onLogin({ event, authInfo, cb }: LoginEvent): void {
42+
if (!authInfo.isProxy) {
43+
return;
44+
}
45+
46+
if (this.retryCount++ > 1) {
47+
return;
48+
}
49+
3650
const opts: any = {
3751
alwaysOnTop: true,
3852
skipTaskbar: true,
3953
resizable: false,
4054
width: 450,
41-
height: 260,
55+
height: 220,
4256
show: true,
43-
title: localize('authRequired', "Authentication Required")
57+
title: 'VS Code'
4458
};
4559

4660
const focusedWindow = this.windowsService.getFocusedWindow();
@@ -51,18 +65,19 @@ export class AuthHandler {
5165
}
5266

5367
const win = new BrowserWindow(opts);
54-
5568
const config = {};
56-
5769
const baseUrl = require.toUrl('./auth.html');
5870
const url = `${baseUrl}?config=${encodeURIComponent(JSON.stringify(config))}`;
5971
win.loadURL(url);
6072

6173
const proxyUrl = `${authInfo.host}:${authInfo.port}`;
62-
const message = localize('proxyauth', "The proxy {0} requires a username and password.", proxyUrl);
74+
const title = localize('authRequire', "Proxy Authentication Required");
75+
const message = localize('proxyauth', "The proxy {0} requires authentication.", proxyUrl);
76+
const data = { title, message };
77+
const javascript = 'promptForCredentials(' + JSON.stringify(data) + ')';
6378

6479
event.preventDefault();
65-
win.webContents.executeJavaScript('promptForCredentials(' + JSON.stringify({ message }) + ')', true).then(({ username, password }: { username: string, password: string }) => {
80+
win.webContents.executeJavaScript(javascript, true).then(({ username, password }: Credentials) => {
6681
cb(username, password);
6782
win.close();
6883
});

0 commit comments

Comments
 (0)