1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | var __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 | };
|
23 | var __metadata = (this && this.__metadata) || function (k, v) {
|
24 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
25 | };
|
26 | Object.defineProperty(exports, "__esModule", { value: true });
|
27 | exports.ColorApplicationContribution = exports.ColorContribution = void 0;
|
28 | const inversify_1 = require("inversify");
|
29 | const color_registry_1 = require("./color-registry");
|
30 | const event_1 = require("../common/event");
|
31 | const theming_1 = require("./theming");
|
32 | const contribution_provider_1 = require("../common/contribution-provider");
|
33 | const disposable_1 = require("../common/disposable");
|
34 | const frontend_application_config_provider_1 = require("./frontend-application-config-provider");
|
35 | exports.ColorContribution = Symbol('ColorContribution');
|
36 | let 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);
|
105 | ColorApplicationContribution = __decorate([
|
106 | (0, inversify_1.injectable)()
|
107 | ], ColorApplicationContribution);
|
108 | exports.ColorApplicationContribution = ColorApplicationContribution;
|
109 |
|
\ | No newline at end of file |