2021-07-07 14:14:20 +01:00
|
|
|
const activate = require('./activate');
|
2019-01-28 22:36:47 +05:30
|
|
|
const themeLoader = require('./loader');
|
2021-07-07 14:14:20 +01:00
|
|
|
const storage = require('./storage');
|
|
|
|
const getJSON = require('./to-json');
|
2021-09-03 20:29:37 +04:00
|
|
|
const installer = require('./installer');
|
2019-01-28 22:36:47 +05:30
|
|
|
|
2021-07-07 14:14:20 +01:00
|
|
|
const settingsCache = require('../../../shared/settings-cache');
|
2021-07-06 14:54:02 +01:00
|
|
|
|
2021-10-04 10:58:20 +01: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-21 23:26:19 +00:00
|
|
|
module.exports = {
|
2021-07-07 14:14:20 +01:00
|
|
|
/*
|
|
|
|
* Load the currently active theme
|
|
|
|
*/
|
2021-07-07 13:49:40 +01:00
|
|
|
init: async () => {
|
2021-07-07 14:14:20 +01:00
|
|
|
const themeName = settingsCache.get('active_theme');
|
2021-07-07 13:49:40 +01:00
|
|
|
|
2021-10-04 10:58:20 +01: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 14:14:20 +01:00
|
|
|
return activate.loadAndActivate(themeName);
|
2017-03-13 16:30:35 +00:00
|
|
|
},
|
2021-02-22 17:30:25 +00:00
|
|
|
/**
|
|
|
|
* Load all inactive themes
|
|
|
|
*/
|
2021-07-07 14:14:20 +01:00
|
|
|
loadInactiveThemes: themeLoader.loadAllThemes,
|
|
|
|
/**
|
|
|
|
* Methods used in the API
|
|
|
|
*/
|
|
|
|
api: {
|
|
|
|
getJSON,
|
|
|
|
activate: activate.activate,
|
|
|
|
getZip: storage.getZip,
|
|
|
|
setFromZip: storage.setFromZip,
|
2021-09-03 20:29:37 +04:00
|
|
|
installFromGithub: installer.installFromGithub,
|
2021-07-07 14:14:20 +01:00
|
|
|
destroy: storage.destroy
|
2021-02-22 17:30:25 +00:00
|
|
|
}
|
2017-02-21 23:26:19 +00:00
|
|
|
};
|