Uploader online (#26)

This commit is contained in:
Asher
2019-01-30 15:40:01 -06:00
committed by Kyle Carberry
parent 62b1e0ef00
commit ebe5e1b1a9
20 changed files with 430 additions and 264 deletions

View File

@@ -1,4 +1,10 @@
import { CP } from "@coder/protocol";
import { client } from "./client";
import { promisify } from "./util";
export = new CP(client);
const cp = new CP(client);
// tslint:disable-next-line no-any makes util.promisify return an object
(cp as any).exec[promisify.customPromisifyArgs] = ["stdout", "stderr"];
export = cp;

View File

@@ -16,7 +16,7 @@ class Connection implements ReadWriteConnection {
private readonly downEmitter: Emitter<void> = new Emitter();
private readonly messageBuffer: Uint8Array[] = [];
private socketTimeoutDelay = 60 * 1000;
private retryName = "Web socket";
private retryName = "Socket";
private isUp: boolean = false;
private closed: boolean = false;

View File

@@ -0,0 +1,114 @@
import { logger, field } from "@coder/logger";
/**
* Handle for a notification that allows it to be closed and updated.
*/
export interface INotificationHandle {
/**
* Closes the notification.
*/
close(): void;
/**
* Update the message.
*/
updateMessage(message: string): void;
/**
* Update the buttons.
*/
updateButtons(buttons: INotificationButton[]): void;
}
/**
* Notification severity.
*/
export enum Severity {
Ignore = 0,
Info = 1,
Warning = 2,
Error = 3,
}
/**
* Notification button.
*/
export interface INotificationButton {
label: string;
run(): void;
}
/**
* Optional notification service.
*/
export interface INotificationService {
/**
* Display an error message.
*/
error(error: Error): void;
/**
* Show a notification.
*/
prompt(severity: Severity, message: string, buttons: INotificationButton[], onCancel: () => void): INotificationHandle;
}
/**
* Updatable progress.
*/
export interface IProgress {
/**
* Report progress. Progress is the completed percentage from 0 to 100.
*/
report(progress: number): void;
}
/**
* Option progress reporting service.
*/
export interface IProgressService {
/**
* Start a new progress bar that resolves & disappears when the task finishes.
*/
start<T>(title: string, task: (progress: IProgress) => Promise<T>, onCancel: () => void): Promise<T>;
}
/**
* Temporary notification service.
*/
export class NotificationService implements INotificationService {
public error(error: Error): void {
logger.error(error.message, field("error", error));
}
public prompt(_severity: Severity, message: string, _buttons: INotificationButton[], _onCancel: () => void): INotificationHandle {
throw new Error(`cannot prompt using the console: ${message}`);
}
}
/**
* Temporary progress service.
*/
export class ProgressService implements IProgressService {
public start<T>(title: string, task: (progress: IProgress) => Promise<T>): Promise<T> {
logger.info(title);
return task({
report: (progress): void => {
logger.info(`${title} progress: ${progress}`);
},
});
}
}

View File

@@ -0,0 +1,18 @@
export interface IURI {
readonly path: string;
readonly fsPath: string;
readonly scheme: string;
}
export interface IURIFactory {
/**
* Convert the object to an instance of a real URI.
*/
create<T extends IURI>(uri: IURI): T;
file(path: string): IURI;
parse(raw: string): IURI;
}

View File

@@ -1,4 +1,4 @@
export * from "../../../../node_modules/util";
import { implementation } from "util.promisify";
import { implementation } from "../../../../node_modules/util.promisify";
export const promisify = implementation;