[Paths] Move setting globals and cleanOldVersions into paths itself

This commit is contained in:
Ducko 2022-03-29 18:14:18 +01:00
parent 99d1aff934
commit cd2136a94e
2 changed files with 6 additions and 11 deletions

8
src/bootstrap.js vendored
View File

@ -8,10 +8,6 @@ process.env.PULSE_LATENCY_MSEC = process.env.PULSE_LATENCY_MSEC ?? 30;
app.setAppUserModelId(Constants.APP_ID); app.setAppUserModelId(Constants.APP_ID);
app.name = 'discord'; // Force name as sometimes breaks app.name = 'discord'; // Force name as sometimes breaks
const paths = require('./paths');
global.moduleDataPath = paths.getModuleDataPath(); // Global because discord
app.setPath('userData', paths.getUserData()); // Set userData properly because electron
const buildInfo = require('./utils/buildInfo'); const buildInfo = require('./utils/buildInfo');
app.setVersion(buildInfo.version); // More global because discord / electron app.setVersion(buildInfo.version); // More global because discord / electron
global.releaseChannel = buildInfo.releaseChannel; global.releaseChannel = buildInfo.releaseChannel;
@ -37,13 +33,13 @@ const startCore = () => {
log('Bootstrap', 'Required core'); log('Bootstrap', 'Required core');
desktopCore.startup({ desktopCore.startup({
paths,
splashScreen, splashScreen,
moduleUpdater, moduleUpdater,
buildInfo, buildInfo,
appSettings, appSettings,
Constants, Constants,
updater, updater,
paths: require('./paths'),
GPUSettings: require('./GPUSettings'), GPUSettings: require('./GPUSettings'),
autoStart: require('./autoStart'), autoStart: require('./autoStart'),
crashReporterSetup: require('./crashReporterSetup'), crashReporterSetup: require('./crashReporterSetup'),
@ -77,8 +73,6 @@ const startCore = () => {
const startUpdate = async () => { const startUpdate = async () => {
const startMinimized = process.argv.includes('--start-minimized'); const startMinimized = process.argv.includes('--start-minimized');
paths.cleanOldVersions();
appUpdater.update(startMinimized, () => { appUpdater.update(startMinimized, () => {
if (process.env.OPENASAR_NOSTART) return; if (process.env.OPENASAR_NOSTART) return;

View File

@ -26,12 +26,13 @@ exports.init = () => {
moduleData = buildInfo.newUpdater ? join(userData, 'module_data') : join(userDataVersioned, 'modules'); moduleData = buildInfo.newUpdater ? join(userData, 'module_data') : join(userDataVersioned, 'modules');
resourcesPath = join(process.resourcesPath); resourcesPath = join(process.resourcesPath);
};
exports.cleanOldVersions = () => { global.moduleDataPath = moduleData; // Global because discord
if (!installPath) return; app.setPath('userData', userData); // Set userData properly because electron
for (const x of fs.readdirSync(installPath)) {
// cleanOldVersions
if (installPath) for (const x of fs.readdirSync(installPath)) {
if (x.startsWith('app-') && !x.includes(buildInfo.version)) fs.rmSync(join(installPath, x), { recursive: true, force: true }); if (x.startsWith('app-') && !x.includes(buildInfo.version)) fs.rmSync(join(installPath, x), { recursive: true, force: true });
} }
}; };