From d128ca6d685a125408f939118bb1934ec5949a63 Mon Sep 17 00:00:00 2001 From: Asher Date: Fri, 11 Jan 2019 18:21:31 -0600 Subject: [PATCH] More loading --- packages/app/src/index.ts | 32 ++++++++- packages/node-browser/src/child_process.ts | 3 +- packages/node-browser/src/util.ts | 1 - packages/vscode/src/index.ts | 75 +++++++++------------- 4 files changed, 60 insertions(+), 51 deletions(-) diff --git a/packages/app/src/index.ts b/packages/app/src/index.ts index 94e8605..70b5b1d 100644 --- a/packages/app/src/index.ts +++ b/packages/app/src/index.ts @@ -1,10 +1,16 @@ -import { logger } from "@coder/logger"; +import { logger, field, time } from "@coder/logger"; +import { load } from "@coder/vscode"; import "./index.scss"; -logger.info("Starting app"); +const loadTime = time(2500); +logger.info("Loading IDE..."); const overlay = document.getElementById("overlay"); const logo = document.getElementById("logo"); +const msgElement = overlay + ? overlay.querySelector(".message") as HTMLElement + : undefined; + if (overlay && logo) { overlay.addEventListener("mousemove", (event) => { const xPos = ((event.clientX - logo.offsetLeft) / 24).toFixed(2); @@ -14,4 +20,24 @@ if (overlay && logo) { }); } -import "@coder/vscode"; +load().then(() => { + if (overlay) { + overlay.style.opacity = "0"; + overlay.addEventListener("transitionend", () => { + overlay.remove(); + }); + } +}).catch((error: Error) => { + logger.error(error.message); + if (overlay) { + overlay.classList.add("error"); + } + if (msgElement) { + msgElement.innerText = `Failed to load: ${error.message}. Retrying in 3 seconds...`; + } + setTimeout(() => { + location.reload(); + }, 3000); +}).finally(() => { + logger.info("Load completed", field("duration", loadTime)); +}); diff --git a/packages/node-browser/src/child_process.ts b/packages/node-browser/src/child_process.ts index b17e641..33a3bcb 100644 --- a/packages/node-browser/src/child_process.ts +++ b/packages/node-browser/src/child_process.ts @@ -2,7 +2,6 @@ import * as cp from "child_process"; import * as stream from "stream"; import * as events from "events"; import * as net from "net"; -import { wush, Session } from "@coder/wush"; import { useBuffer, throwUnimplementedError, throwSyncError } from "./util"; /** @@ -34,7 +33,7 @@ class ChildProcess extends events.EventEmitter implements cp.ChildProcess { private emitter = new events.EventEmitter(); - public constructor(private session: Session) { + public constructor(private session) { super(); this.emitter = new events.EventEmitter(); diff --git a/packages/node-browser/src/util.ts b/packages/node-browser/src/util.ts index a2003b0..10bef94 100644 --- a/packages/node-browser/src/util.ts +++ b/packages/node-browser/src/util.ts @@ -59,7 +59,6 @@ export abstract class Queue { public constructor(max?: number) { this.items = new Map(); - this.run = run; this.max = max; } diff --git a/packages/vscode/src/index.ts b/packages/vscode/src/index.ts index 9e1b3f4..a7dfb83 100644 --- a/packages/vscode/src/index.ts +++ b/packages/vscode/src/index.ts @@ -1,54 +1,39 @@ import { field, logger, time } from "@coder/logger"; -const loadTime = time(2500); - import { Client, IURI, setUriFactory } from "@coder/ide"; import { URI } from "vs/base/common/uri"; import "./firefox"; -setUriFactory({ - // TODO: not sure why this is an error. - // tslint:disable-next-line no-any - create: (uri: IURI): URI => URI.from(uri) as any, - file: (path: string): IURI => URI.file(path), - parse: (raw: string): IURI => URI.parse(raw), -}); +const load = (): Promise => { + return new Promise((resolve, reject) => { + setUriFactory({ + // TODO: not sure why this is an error. + // tslint:disable-next-line no-any + create: (uri: IURI): URI => URI.from(uri) as any, + file: (path: string): IURI => URI.file(path), + parse: (raw: string): IURI => URI.parse(raw), + }); -// export const client = new Client({ -// mkDirs: [ -// "~/vscode/extensions", -// "~/.config/User", -// ], -// }); + reject(new Error("not finished")); -// const overlayElement = document.getElementById("overlay"); -// const msgElement = overlayElement -// ? overlayElement.querySelector(".message") as HTMLElement -// : undefined; + // export const client = new Client({ + // mkDirs: [ + // "~/vscode/extensions", + // "~/.config/User", + // ], + // }); -// const importTime = time(1500); -// import(/* webpackPrefetch: true */ "./workbench").then((module) => { -// logger.info("Loaded workbench bundle", field("duration", importTime)); -// const initTime = time(1500); + // const importTime = time(1500); + // import(/* webpackPrefetch: true */ "./workbench").then((module) => { + // logger.info("Loaded workbench bundle", field("duration", importTime)); + // const initTime = time(1500); -// return module.initialize(client).then(() => { -// logger.info("Initialized workbench", field("duration", initTime)); -// logger.info("Load completed", field("duration", loadTime)); -// if (overlayElement) { -// overlayElement.style.opacity = "0"; -// overlayElement.addEventListener("transitionend", () => { -// overlayElement.remove(); -// }); -// } -// }); -// }).catch((error) => { -// logger.error(error); -// if (overlayElement) { -// overlayElement.classList.add("error"); -// } -// if (msgElement) { -// msgElement.innerText = `Failed to load: ${error.message}. Retrying in 3 seconds...`; -// } -// setTimeout(() => { -// location.reload(); -// }, 3000); -// }); + // return module.initialize(client).then(() => { + // logger.info("Initialized workbench", field("duration", initTime)); + // + // }); + // }).catch((error) => { + // }); + }); +}; + +export { load };