UNPKG

5.43 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2019 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-only WITH Classpath-exception-2.0
16// *****************************************************************************
17var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21 return c > 3 && r && Object.defineProperty(target, key, r), r;
22};
23var __metadata = (this && this.__metadata) || function (k, v) {
24 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25};
26Object.defineProperty(exports, "__esModule", { value: true });
27exports.ColorApplicationContribution = exports.ColorContribution = void 0;
28const inversify_1 = require("inversify");
29const color_registry_1 = require("./color-registry");
30const event_1 = require("../common/event");
31const theming_1 = require("./theming");
32const contribution_provider_1 = require("../common/contribution-provider");
33const disposable_1 = require("../common/disposable");
34const frontend_application_config_provider_1 = require("./frontend-application-config-provider");
35exports.ColorContribution = Symbol('ColorContribution');
36let ColorApplicationContribution = class ColorApplicationContribution {
37 constructor() {
38 this.onDidChangeEmitter = new event_1.Emitter();
39 this.onDidChange = this.onDidChangeEmitter.event;
40 this.windows = new Set();
41 this.toUpdate = new disposable_1.DisposableCollection();
42 }
43 onStart() {
44 for (const contribution of this.colorContributions.getContributions()) {
45 contribution.registerColors(this.colors);
46 }
47 this.themeService.initialized.then(() => this.update());
48 this.themeService.onDidColorThemeChange(() => {
49 this.update();
50 this.updateThemeBackground();
51 });
52 this.colors.onDidChange(() => this.update());
53 this.registerWindow(window);
54 }
55 registerWindow(win) {
56 this.windows.add(win);
57 this.updateWindow(win);
58 this.onDidChangeEmitter.fire();
59 return disposable_1.Disposable.create(() => this.windows.delete(win));
60 }
61 update() {
62 this.toUpdate.dispose();
63 this.windows.forEach(win => this.updateWindow(win));
64 this.onDidChangeEmitter.fire();
65 }
66 updateWindow(win) {
67 const theme = 'theia-' + this.themeService.getCurrentTheme().type;
68 win.document.body.classList.add(theme);
69 this.toUpdate.push(disposable_1.Disposable.create(() => win.document.body.classList.remove(theme)));
70 const documentElement = win.document.documentElement;
71 if (documentElement) {
72 for (const id of this.colors.getColors()) {
73 const variable = this.colors.getCurrentCssVariable(id);
74 if (variable) {
75 const { name, value } = variable;
76 documentElement.style.setProperty(name, value);
77 this.toUpdate.push(disposable_1.Disposable.create(() => documentElement.style.removeProperty(name)));
78 }
79 }
80 }
81 }
82 updateThemeBackground() {
83 const color = this.colors.getCurrentColor('editor.background');
84 if (color) {
85 window.localStorage.setItem(frontend_application_config_provider_1.DEFAULT_BACKGROUND_COLOR_STORAGE_KEY, color);
86 }
87 else {
88 window.localStorage.removeItem(frontend_application_config_provider_1.DEFAULT_BACKGROUND_COLOR_STORAGE_KEY);
89 }
90 }
91};
92__decorate([
93 (0, inversify_1.inject)(color_registry_1.ColorRegistry),
94 __metadata("design:type", color_registry_1.ColorRegistry)
95], ColorApplicationContribution.prototype, "colors", void 0);
96__decorate([
97 (0, inversify_1.inject)(contribution_provider_1.ContributionProvider),
98 (0, inversify_1.named)(exports.ColorContribution),
99 __metadata("design:type", Object)
100], ColorApplicationContribution.prototype, "colorContributions", void 0);
101__decorate([
102 (0, inversify_1.inject)(theming_1.ThemeService),
103 __metadata("design:type", theming_1.ThemeService)
104], ColorApplicationContribution.prototype, "themeService", void 0);
105ColorApplicationContribution = __decorate([
106 (0, inversify_1.injectable)()
107], ColorApplicationContribution);
108exports.ColorApplicationContribution = ColorApplicationContribution;
109//# sourceMappingURL=color-application-contribution.js.map
\No newline at end of file