UNPKG

3.3 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2022 TypeFox and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.preload = void 0;
19const nls_1 = require("../common/nls");
20const endpoint_1 = require("./endpoint");
21const os_1 = require("../common/os");
22const frontend_application_config_provider_1 = require("./frontend-application-config-provider");
23function fetchFrom(path) {
24 const endpoint = new endpoint_1.Endpoint({ path }).getRestUrl().toString();
25 return fetch(endpoint);
26}
27async function loadTranslations() {
28 const defaultLocale = frontend_application_config_provider_1.FrontendApplicationConfigProvider.get().defaultLocale;
29 if (defaultLocale && !nls_1.nls.locale) {
30 Object.assign(nls_1.nls, {
31 locale: defaultLocale
32 });
33 }
34 if (nls_1.nls.locale) {
35 const response = await fetchFrom(`/i18n/${nls_1.nls.locale}`);
36 const localization = await response.json();
37 if (localization.languagePack) {
38 nls_1.nls.localization = localization;
39 }
40 else {
41 // In case the localization that we've loaded doesn't localize Theia completely (languagePack is false)
42 // We simply reset the locale to the default again
43 Object.assign(nls_1.nls, {
44 locale: defaultLocale || undefined
45 });
46 }
47 }
48}
49async function loadBackendOS() {
50 const response = await fetchFrom('/os');
51 const osType = await response.text();
52 const isWindows = osType === 'Windows';
53 const isOSX = osType === 'OSX';
54 os_1.OS.backend.isOSX = isOSX;
55 os_1.OS.backend.isWindows = isWindows;
56 os_1.OS.backend.type = () => osType;
57}
58function initBackground() {
59 // The default light background color is based on the `colors#editor.background` value from
60 // `packages/monaco/data/monaco-themes/vscode/dark_vs.json` and the dark background comes from the `light_vs.json`.
61 const dark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
62 const value = window.localStorage.getItem(frontend_application_config_provider_1.DEFAULT_BACKGROUND_COLOR_STORAGE_KEY) || (dark ? '#1E1E1E' : '#FFFFFF');
63 const documentElement = document.documentElement;
64 documentElement.style.setProperty('--theia-editor-background', value);
65}
66async function preload() {
67 await Promise.allSettled([
68 loadTranslations(),
69 loadBackendOS(),
70 initBackground(),
71 ]);
72}
73exports.preload = preload;
74//# sourceMappingURL=preloader.js.map
\No newline at end of file