code-server-2/packages/web/src/index.ts

48 lines
1.3 KiB
TypeScript
Raw Normal View History

2019-01-12 00:21:31 +00:00
import { logger, field, time } from "@coder/logger";
import { load } from "@coder/vscode";
2019-01-11 18:58:25 +00:00
import "./index.scss";
2019-01-12 00:21:31 +00:00
const loadTime = time(2500);
2019-01-14 23:19:29 +00:00
logger.info("Loading IDE");
2019-01-12 00:11:34 +00:00
2019-01-11 17:50:54 +00:00
const overlay = document.getElementById("overlay");
const logo = document.getElementById("logo");
2019-01-12 00:21:31 +00:00
const msgElement = overlay
? overlay.querySelector(".message") as HTMLElement
: undefined;
2019-01-11 17:50:54 +00:00
if (overlay && logo) {
overlay.addEventListener("mousemove", (event) => {
const xPos = ((event.clientX - logo.offsetLeft) / 24).toFixed(2);
const yPos = ((logo.offsetTop - event.clientY) / 24).toFixed(2);
logo.style.transform = `perspective(200px) rotateX(${yPos}deg) rotateY(${xPos}deg)`;
});
}
2019-01-12 00:11:34 +00:00
2019-01-12 00:21:31 +00:00
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) {
2019-01-14 23:19:29 +00:00
const button = document.createElement("div");
button.className = "reload-button";
button.innerText = "Reload";
button.addEventListener("click", () => {
location.reload();
});
msgElement.innerText = `Failed to load: ${error.message}.`;
msgElement.parentElement!.appendChild(button);
2019-01-12 00:21:31 +00:00
}
}).finally(() => {
logger.info("Load completed", field("duration", loadTime));
});