diff --git a/src/vs/code/electron-main/app.ts b/src/vs/code/electron-main/app.ts index 53762b3d899..23470739b82 100644 --- a/src/vs/code/electron-main/app.ts +++ b/src/vs/code/electron-main/app.ts @@ -44,7 +44,7 @@ import { resolveCommonProperties, machineIdStorageKey, machineIdIpcChannel } fro import { getDelayedChannel } from 'vs/base/parts/ipc/common/ipc'; import product from 'vs/platform/node/product'; import pkg from 'vs/platform/node/package'; -import { AuthHandler } from './auth'; +import { ProxyAuthHandler } from './auth'; import { IDisposable, dispose } from "vs/base/common/lifecycle"; import { ConfigurationService } from "vs/platform/configuration/node/configurationService"; import { TPromise } from "vs/base/common/winjs.base"; @@ -157,7 +157,7 @@ export class VSCodeApplication { const appInstantiationService = this.initServices(); // Setup Auth Handler - const authHandler = appInstantiationService.createInstance(AuthHandler); + const authHandler = appInstantiationService.createInstance(ProxyAuthHandler); this.toDispose.push(authHandler); // Open Windows diff --git a/src/vs/code/electron-main/auth.html b/src/vs/code/electron-main/auth.html index 207f7219438..e27ec2fc02e 100644 --- a/src/vs/code/electron-main/auth.html +++ b/src/vs/code/electron-main/auth.html @@ -16,18 +16,18 @@ -webkit-user-select: none; user-select: none; } - + body { font-family: "Segoe WPC", "Segoe UI", "HelveticaNeue-Light", sans-serif, "Droid Sans Fallback"; font-size: 10pt; background-color: #F3F3F3; } - + #main { box-sizing: border-box; padding: 10px; } - + h1 { margin: 0; padding: 10px 0; @@ -36,11 +36,11 @@ color: #f0f0f0; text-align: center; } - + #form { margin-top: 10px; } - + #username, #password { padding: 6px 10px; @@ -48,15 +48,15 @@ box-sizing: border-box; width: 100%; } - + #buttons { text-align: center; } - + p { margin: 6px 0; } - + input { font-family: "Segoe WPC", "Segoe UI", "HelveticaNeue-Light", sans-serif, "Droid Sans Fallback" !important; } @@ -64,7 +64,7 @@ -

Authentication Required

+

@@ -87,6 +87,7 @@ function promptForCredentials(data) { return new Promise((c, e) => { + const $title = document.getElementById('title'); const $username = document.getElementById('username'); const $password = document.getElementById('password'); const $form = document.getElementById('form'); @@ -113,6 +114,7 @@ } }); + $title.textContent = data.title; $message.textContent = data.message; $username.focus(); }); diff --git a/src/vs/code/electron-main/auth.ts b/src/vs/code/electron-main/auth.ts index 7c522cf39ea..27c4e6d2f1d 100644 --- a/src/vs/code/electron-main/auth.ts +++ b/src/vs/code/electron-main/auth.ts @@ -19,10 +19,16 @@ type LoginEvent = { cb: (username: string, password: string) => void; }; -export class AuthHandler { +type Credentials = { + username: string; + password: string; +}; + +export class ProxyAuthHandler { _serviceBrand: any; + private retryCount = 0; private disposables: IDisposable[] = []; constructor( @@ -33,14 +39,22 @@ export class AuthHandler { } private onLogin({ event, authInfo, cb }: LoginEvent): void { + if (!authInfo.isProxy) { + return; + } + + if (this.retryCount++ > 1) { + return; + } + const opts: any = { alwaysOnTop: true, skipTaskbar: true, resizable: false, width: 450, - height: 260, + height: 220, show: true, - title: localize('authRequired', "Authentication Required") + title: 'VS Code' }; const focusedWindow = this.windowsService.getFocusedWindow(); @@ -51,18 +65,19 @@ export class AuthHandler { } const win = new BrowserWindow(opts); - const config = {}; - const baseUrl = require.toUrl('./auth.html'); const url = `${baseUrl}?config=${encodeURIComponent(JSON.stringify(config))}`; win.loadURL(url); const proxyUrl = `${authInfo.host}:${authInfo.port}`; - const message = localize('proxyauth', "The proxy {0} requires a username and password.", proxyUrl); + const title = localize('authRequire', "Proxy Authentication Required"); + const message = localize('proxyauth', "The proxy {0} requires authentication.", proxyUrl); + const data = { title, message }; + const javascript = 'promptForCredentials(' + JSON.stringify(data) + ')'; event.preventDefault(); - win.webContents.executeJavaScript('promptForCredentials(' + JSON.stringify({ message }) + ')', true).then(({ username, password }: { username: string, password: string }) => { + win.webContents.executeJavaScript(javascript, true).then(({ username, password }: Credentials) => { cb(username, password); win.close(); });