[Updater > Module] Rewrite bootstrap to be clean (#32), additional source cleanup

This commit is contained in:
Ducko 2022-04-04 18:41:32 +01:00
parent 61d3201843
commit 4f2a8599f0

View file

@ -10,13 +10,12 @@ const request = require('./request');
const events = exports.events = new (require('events').EventEmitter)(); const events = exports.events = new (require('events').EventEmitter)();
exports.INSTALLED_MODULE = 'installed-module'; // Fixes DiscordNative ensureModule as it uses export exports.INSTALLED_MODULE = 'installed-module'; // Fixes DiscordNative ensureModule as it uses export
let settings, let bootstrapping,
bootstrapping,
skipHost, skipModule, skipHost, skipModule,
remote = {}, remote = {},
installed = {}, installed = {},
downloading, installing, downloading, installing,
basePath, manifestPath, downloadPath, bootstrapPath, basePath, manifestPath, downloadPath,
hostUpdater, hostUpdater,
baseUrl, baseQuery, baseUrl, baseQuery,
checking, hostAvail, lastUpdate; checking, hostAvail, lastUpdate;
@ -32,16 +31,13 @@ const resetTracking = () => {
installing = Object.assign({}, base); installing = Object.assign({}, base);
}; };
exports.init = (endpoint, _settings, { releaseChannel, version }) => { exports.init = (endpoint, settings, { releaseChannel, version }) => {
settings = _settings;
skipHost = settings.get('SKIP_HOST_UPDATE'); skipHost = settings.get('SKIP_HOST_UPDATE');
skipModule = settings.get('SKIP_MODULE_UPDATE'); skipModule = settings.get('SKIP_MODULE_UPDATE');
basePath = join(paths.getUserDataVersioned(), 'modules'); basePath = join(paths.getUserDataVersioned(), 'modules');
manifestPath = join(basePath, 'installed.json'); manifestPath = join(basePath, 'installed.json');
downloadPath = join(basePath, 'pending'); downloadPath = join(basePath, 'pending');
bootstrapPath = join(paths.getResources(), 'bootstrap', 'manifest.json');
resetTracking(); resetTracking();
@ -402,16 +398,11 @@ exports.installPendingUpdates = () => {
if (bootstrapping) { if (bootstrapping) {
log('Modules', 'Bootstrapping...'); log('Modules', 'Bootstrapping...');
try { for (const m in JSON.parse(fs.readFileSync(join(paths.getResources(), 'bootstrap', 'manifest.json')))) { // Read [resources]/bootstrap/manifest.json, with "moduleName": version (always 0)
for (const m in JSON.parse(fs.readFileSync(bootstrapPath))) { // Read [resources]/bootstrap/manifest.json, with "moduleName": version (always 0) installed[m] = { installedVersion: 0 }; // Set initial version as 0
installed[m] = { installedVersion: 0 }; // Set initial
installModule(m, 0, join(bootstrapPath, m)); // Intentional invalid path
}
} catch (e) {
log('Modules', e);
} }
return; return exports.checkForUpdates();
} }
events.emit('no-pending-updates'); events.emit('no-pending-updates');