2021-07-07 16:14:20 +03:00
|
|
|
const activate = require('./activate');
|
2019-01-28 20:06:47 +03:00
|
|
|
const themeLoader = require('./loader');
|
2021-07-07 16:14:20 +03:00
|
|
|
const storage = require('./storage');
|
|
|
|
const getJSON = require('./to-json');
|
2021-09-03 19:29:37 +03:00
|
|
|
const installer = require('./installer');
|
2019-01-28 20:06:47 +03:00
|
|
|
|
2021-07-07 16:14:20 +03:00
|
|
|
const settingsCache = require('../../../shared/settings-cache');
|
2021-07-06 16:54:02 +03:00
|
|
|
|
2021-10-04 12:58:20 +03:00
|
|
|
// Needed for theme re-activation after customThemeSettings flag is toggled
|
|
|
|
// @TODO: remove when customThemeSettings flag is removed
|
|
|
|
const labs = require('../../../shared/labs');
|
|
|
|
const events = require('../../lib/common/events');
|
|
|
|
let _lastLabsValue;
|
|
|
|
|
2017-02-22 02:26:19 +03:00
|
|
|
module.exports = {
|
2021-07-07 16:14:20 +03:00
|
|
|
/*
|
|
|
|
* Load the currently active theme
|
|
|
|
*/
|
2021-07-07 15:49:40 +03:00
|
|
|
init: async () => {
|
2021-07-07 16:14:20 +03:00
|
|
|
const themeName = settingsCache.get('active_theme');
|
2021-07-07 15:49:40 +03:00
|
|
|
|
2021-10-04 12:58:20 +03:00
|
|
|
/**
|
|
|
|
* When customThemeSettings labs flag is toggled we need to re-validate and activate
|
|
|
|
* the active theme so that it's settings are read and synced
|
|
|
|
*
|
|
|
|
* @TODO: remove when customThemeSettings labs flag is removed
|
|
|
|
*/
|
|
|
|
_lastLabsValue = labs.isSet('customThemeSettings');
|
|
|
|
events.on('settings.labs.edited', () => {
|
|
|
|
if (labs.isSet('customThemeSettings') !== _lastLabsValue) {
|
|
|
|
_lastLabsValue = labs.isSet('customThemeSettings');
|
|
|
|
|
|
|
|
activate.activate(settingsCache.get('active_theme'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-07-07 16:14:20 +03:00
|
|
|
return activate.loadAndActivate(themeName);
|
2017-03-13 19:30:35 +03:00
|
|
|
},
|
2021-02-22 20:30:25 +03:00
|
|
|
/**
|
|
|
|
* Load all inactive themes
|
|
|
|
*/
|
2021-07-07 16:14:20 +03:00
|
|
|
loadInactiveThemes: themeLoader.loadAllThemes,
|
|
|
|
/**
|
|
|
|
* Methods used in the API
|
|
|
|
*/
|
|
|
|
api: {
|
|
|
|
getJSON,
|
|
|
|
activate: activate.activate,
|
|
|
|
getZip: storage.getZip,
|
|
|
|
setFromZip: storage.setFromZip,
|
2021-09-03 19:29:37 +03:00
|
|
|
installFromGithub: installer.installFromGithub,
|
2021-07-07 16:14:20 +03:00
|
|
|
destroy: storage.destroy
|
2021-02-22 20:30:25 +03:00
|
|
|
}
|
2017-02-22 02:26:19 +03:00
|
|
|
};
|