import type { ISettingColor } from '@rocket.chat/core-typings'; import { Settings } from '@rocket.chat/models'; import { escapeHTML } from '@rocket.chat/tools'; import { Meteor } from 'meteor/meteor'; import { Inject } from 'meteor/meteorhacks:inject-initial'; import { Tracker } from 'meteor/tracker'; import { applyHeadInjections, headInjections, injectIntoBody, injectIntoHead } from './inject'; import { getMessageMaxParseLength } from '../../../lib/getMessageMaxParseLength'; import { withDebouncing } from '../../../lib/utils/highOrderFunctions'; import { settings } from '../../settings'; import { getURL } from '../utils/getURL'; import './scripts'; export * from './inject'; Meteor.startup(() => { Tracker.autorun(() => { const injections = Object.values(headInjections.all()).filter((injection): injection is NonNullable => !!injection); Inject.rawModHtml('headInjections', applyHeadInjections(injections)); }); settings.watch('Default_Referrer_Policy', (value) => { if (!value) { return injectIntoHead('noreferrer', ''); } injectIntoHead('noreferrer', ``); }); settings.watch('Use_RC_SDK', (value) => { injectIntoHead('Use_RC_SDK', ``); }); if (process.env.DISABLE_ANIMATION) { injectIntoHead( 'disable-animation', ` `, ); } settings.watch('Assets_SvgFavicon_Enable', (value) => { const standardFavicons = ` `; if (value) { injectIntoHead( 'Assets_SvgFavicon_Enable', `${standardFavicons} `, ); } else { injectIntoHead('Assets_SvgFavicon_Enable', standardFavicons); } }); settings.watch('theme-color-sidebar-background', (value) => { const escapedValue = escapeHTML(value); injectIntoHead( 'theme-color-sidebar-background', ``, ); }); settings.watch('Site_Name', (value = 'Rocket.Chat') => { const escapedValue = escapeHTML(value); injectIntoHead( 'Site_Name', `${escapedValue}` + `` + ``, ); }); settings.watch('Meta_language', (value = '') => { const escapedValue = escapeHTML(value); injectIntoHead( 'Meta_language', ``, ); }); settings.watch('Meta_robots', (value = '') => { const escapedValue = escapeHTML(value); injectIntoHead('Meta_robots', ``); }); settings.watch('Meta_msvalidate01', (value = '') => { const escapedValue = escapeHTML(value); injectIntoHead('Meta_msvalidate01', ``); }); settings.watch('Meta_google-site-verification', (value = '') => { const escapedValue = escapeHTML(value); injectIntoHead('Meta_google-site-verification', ``); }); settings.watch('Meta_fb_app_id', (value = '') => { const escapedValue = escapeHTML(value); injectIntoHead('Meta_fb_app_id', ``); }); settings.watch('Meta_custom', (value = '') => { injectIntoHead('Meta_custom', value); }); const baseUrl = ((prefix) => { if (!prefix) { return '/'; } prefix = prefix.trim(); if (!prefix) { return '/'; } return /\/$/.test(prefix) ? prefix : `${prefix}/`; })(__meteor_runtime_config__.ROOT_URL_PATH_PREFIX); injectIntoHead('base', ``); const escapedMessageMaxParseLength = escapeHTML(String(getMessageMaxParseLength())); injectIntoHead('MESSAGE_MAX_PARSE_LENGTH', ``); }); const renderDynamicCssList = withDebouncing({ wait: 500 })(async () => { // const variables = RocketChat.models.Settings.findOne({_id:'theme-custom-variables'}, {fields: { value: 1}}); const colors = await Settings.find({ _id: /theme-color-rc/i }, { projection: { value: 1, editor: 1 } }).toArray(); const css = colors .filter((color): color is ISettingColor => !!color?.value) .map(({ _id, value, editor }) => { if (editor === 'expression') { return `--${_id.replace('theme-color-', '')}: var(--${value});`; } return `--${_id.replace('theme-color-', '')}: ${value};`; }) .join('\n'); injectIntoBody('dynamic-variables', ``); }); await renderDynamicCssList(); settings.watchByRegex(/theme-color-rc/i, renderDynamicCssList); injectIntoBody( 'react-root', `
`, );