mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-30 05:36:42 +01:00
Use choice server for log uploader
This commit is contained in:
@@ -9,7 +9,6 @@ import * as os from 'os';
|
||||
import * as cp from 'child_process';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as readline from 'readline';
|
||||
|
||||
import { localize } from 'vs/nls';
|
||||
import { ILaunchChannel } from 'vs/code/electron-main/launch';
|
||||
@@ -17,6 +16,8 @@ import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import product from 'vs/platform/node/product';
|
||||
import { IRequestService } from 'vs/platform/request/node/request';
|
||||
import { IRequestContext } from 'vs/base/node/request';
|
||||
import { IChoiceService } from 'vs/platform/message/common/message';
|
||||
import Severity from 'vs/base/common/severity';
|
||||
|
||||
interface PostResult {
|
||||
readonly blob_id: string;
|
||||
@@ -35,7 +36,8 @@ class Endpoint {
|
||||
|
||||
export async function uploadLogs(
|
||||
channel: ILaunchChannel,
|
||||
requestService: IRequestService
|
||||
requestService: IRequestService,
|
||||
choiceService: IChoiceService
|
||||
): TPromise<any> {
|
||||
const endpoint = Endpoint.getFromProduct();
|
||||
if (!endpoint) {
|
||||
@@ -45,7 +47,8 @@ export async function uploadLogs(
|
||||
|
||||
const logsPath = await channel.call('get-logs-path', null);
|
||||
|
||||
if (await promptUserToConfirmLogUpload(logsPath)) {
|
||||
if (await promptUserToConfirmLogUpload(logsPath, choiceService)) {
|
||||
console.log(localize('beginUploading', 'Uploading...'));
|
||||
const outZip = await zipLogs(logsPath);
|
||||
const result = await postLogs(endpoint, outZip, requestService);
|
||||
console.log(localize('didUploadLogs', 'Uploaded logs ID: {0}', result.blob_id));
|
||||
@@ -55,22 +58,18 @@ export async function uploadLogs(
|
||||
}
|
||||
|
||||
async function promptUserToConfirmLogUpload(
|
||||
logsPath: string
|
||||
logsPath: string,
|
||||
choiceService: IChoiceService
|
||||
): Promise<boolean> {
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
return new TPromise<boolean>(resolve =>
|
||||
rl.question(
|
||||
localize('logUploadPromptHeader', 'Upload session logs to secure endpoint?')
|
||||
+ '\n\n' + localize('logUploadPromptBody', 'Please review your log files: \'{0}\'', logsPath)
|
||||
+ '\n\n' + localize('logUploadPromptKey', 'Enter \'y\' to confirm upload...'),
|
||||
(answer: string) => {
|
||||
rl.close();
|
||||
resolve(answer && answer.trim()[0].toLowerCase() === 'y');
|
||||
}));
|
||||
const message = localize('logUploadPromptHeader', 'Upload session logs to secure endpoint?')
|
||||
+ '\n\n' + localize('logUploadPromptBody', 'Please review your log files here: \'{0}\'', logsPath)
|
||||
+ '\n\n' + localize('logUploadPromptBodyDetails', 'Logs may contain personal information such as full paths and file contents.')
|
||||
+ '\n\n';
|
||||
const choice = await choiceService.choose(Severity.Info, message, [
|
||||
localize('logUploadPromptKey', 'I have reviewed my logs. Proceed with upload...'),
|
||||
localize('logUploadPromptCancel', 'Cancel'),
|
||||
], 1);
|
||||
return choice === 0;
|
||||
}
|
||||
|
||||
async function postLogs(
|
||||
|
||||
@@ -46,6 +46,8 @@ import { createSpdLogService } from 'vs/platform/log/node/spdlogService';
|
||||
import { printDiagnostics } from 'vs/code/electron-main/diagnostics';
|
||||
import { BufferLogService } from 'vs/platform/log/common/bufferLog';
|
||||
import { uploadLogs } from 'vs/code/electron-main/logUploader';
|
||||
import { IChoiceService } from 'vs/platform/message/common/message';
|
||||
import { ChoiceCliService } from 'vs/platform/message/node/messageCli';
|
||||
|
||||
function createServices(args: ParsedArgs, bufferLogService: BufferLogService): IInstantiationService {
|
||||
const services = new ServiceCollection();
|
||||
@@ -69,6 +71,7 @@ function createServices(args: ParsedArgs, bufferLogService: BufferLogService): I
|
||||
services.set(IRequestService, new SyncDescriptor(RequestService));
|
||||
services.set(IURLService, new SyncDescriptor(URLService, args['open-url'] ? args._urls : []));
|
||||
services.set(IBackupMainService, new SyncDescriptor(BackupMainService));
|
||||
services.set(IChoiceService, new SyncDescriptor(ChoiceCliService));
|
||||
|
||||
return new InstantiationService(services, true);
|
||||
}
|
||||
@@ -106,6 +109,7 @@ function setupIPC(accessor: ServicesAccessor): TPromise<Server> {
|
||||
const logService = accessor.get(ILogService);
|
||||
const environmentService = accessor.get(IEnvironmentService);
|
||||
const requestService = accessor.get(IRequestService);
|
||||
const choiceService = accessor.get(IChoiceService);
|
||||
|
||||
function allowSetForegroundWindow(service: LaunchChannelClient): TPromise<void> {
|
||||
let promise = TPromise.wrap<void>(void 0);
|
||||
@@ -199,7 +203,7 @@ function setupIPC(accessor: ServicesAccessor): TPromise<Server> {
|
||||
|
||||
// Log uploader
|
||||
if (environmentService.args['upload-logs']) {
|
||||
return uploadLogs(channel, requestService)
|
||||
return uploadLogs(channel, requestService, choiceService)
|
||||
.then(() => TPromise.wrapError(new ExpectedError()));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user