|
|
@ -3,6 +3,7 @@ const fs = require('fs');
|
|
|
|
const mkdirp = require('mkdirp');
|
|
|
|
const mkdirp = require('mkdirp');
|
|
|
|
const Module = require('module');
|
|
|
|
const Module = require('module');
|
|
|
|
const { execFile } = require('child_process');
|
|
|
|
const { execFile } = require('child_process');
|
|
|
|
|
|
|
|
const zlib = require('zlib');
|
|
|
|
|
|
|
|
|
|
|
|
const paths = require('../paths');
|
|
|
|
const paths = require('../paths');
|
|
|
|
const request = require('./request');
|
|
|
|
const request = require('./request');
|
|
|
@ -16,7 +17,7 @@ let skipHost, skipModule,
|
|
|
|
downloading, installing,
|
|
|
|
downloading, installing,
|
|
|
|
basePath, manifestPath, downloadPath,
|
|
|
|
basePath, manifestPath, downloadPath,
|
|
|
|
hostUpdater,
|
|
|
|
hostUpdater,
|
|
|
|
baseUrl, baseQuery,
|
|
|
|
baseUrl,
|
|
|
|
checking, hostAvail, last;
|
|
|
|
checking, hostAvail, last;
|
|
|
|
|
|
|
|
|
|
|
|
const resetTracking = () => {
|
|
|
|
const resetTracking = () => {
|
|
|
@ -49,7 +50,7 @@ exports.init = (endpoint, { releaseChannel, version }) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
installed = JSON.parse(fs.readFileSync(manifestPath));
|
|
|
|
installed = JSON.parse(fs.readFileSync(manifestPath));
|
|
|
|
} catch {
|
|
|
|
} catch {
|
|
|
|
for (const m of [ 'desktop_core', 'utils', 'voice' ]) { // Ignore actual bootstrap manifest and choose our own core 3, others are installed as/when needed
|
|
|
|
for (const m of [ 'desktop_core', 'utils' ]) { // Ignore actual bootstrap manifest and choose our own core 3, others are installed as/when needed
|
|
|
|
installed['discord_' + m] = { installedVersion: 0 }; // Set initial version as 0
|
|
|
|
installed['discord_' + m] = { installedVersion: 0 }; // Set initial version as 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -112,11 +113,10 @@ exports.init = (endpoint, { releaseChannel, version }) => {
|
|
|
|
const platform = process.platform === 'darwin' ? 'osx' : 'linux';
|
|
|
|
const platform = process.platform === 'darwin' ? 'osx' : 'linux';
|
|
|
|
hostUpdater.setFeedURL(`${endpoint}/updates/${releaseChannel}?platform=${platform}&version=${version}`);
|
|
|
|
hostUpdater.setFeedURL(`${endpoint}/updates/${releaseChannel}?platform=${platform}&version=${version}`);
|
|
|
|
|
|
|
|
|
|
|
|
baseUrl = `${endpoint}/modules/${releaseChannel}`;
|
|
|
|
// endpoint = 'https://cdn.jsdelivr.net/gh/openasar/mu@gh-pages';
|
|
|
|
baseQuery = {
|
|
|
|
// endpoint = 'https://openasar.dev/Mu';
|
|
|
|
host_version: version,
|
|
|
|
endpoint = 'https://mu.openasar.dev'
|
|
|
|
platform
|
|
|
|
baseUrl = `${endpoint}/${platform}/${releaseChannel}`;
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const hostPassed = (skip = skipModule) => {
|
|
|
|
const hostPassed = (skip = skipModule) => {
|
|
|
@ -134,13 +134,7 @@ const checkModules = async () => {
|
|
|
|
hostAvail = false;
|
|
|
|
hostAvail = false;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const { body } = await request.get({
|
|
|
|
const { body } = await request.get(baseUrl + '/modules.json');
|
|
|
|
url: baseUrl + '/versions.json',
|
|
|
|
|
|
|
|
qs: {
|
|
|
|
|
|
|
|
...baseQuery,
|
|
|
|
|
|
|
|
_: Math.floor(Date.now() / 300000) // 5 min intervals
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
checking = false;
|
|
|
|
checking = false;
|
|
|
|
|
|
|
|
|
|
|
@ -179,10 +173,13 @@ const downloadModule = async (name, ver) => {
|
|
|
|
name
|
|
|
|
name
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const url = baseUrl + '/' + name + '/' + ver;
|
|
|
|
const url = baseUrl + '/' + name;
|
|
|
|
|
|
|
|
const path = join(downloadPath, name + '-' + ver + '.tar');
|
|
|
|
|
|
|
|
|
|
|
|
const path = join(downloadPath, name + '-' + ver + '.zip');
|
|
|
|
const stream = zlib.createBrotliDecompress();
|
|
|
|
const stream = fs.createWriteStream(path);
|
|
|
|
stream.pipe(fs.createWriteStream(path));
|
|
|
|
|
|
|
|
// const path = join(downloadPath, name + '-' + ver + '.tar.br');
|
|
|
|
|
|
|
|
// const stream = fs.createWriteStream(path);
|
|
|
|
|
|
|
|
|
|
|
|
stream.on('progress', ([ cur, total ]) => events.emit('downloading-module-progress', {
|
|
|
|
stream.on('progress', ([ cur, total ]) => events.emit('downloading-module-progress', {
|
|
|
|
name,
|
|
|
|
name,
|
|
|
@ -196,7 +193,6 @@ const downloadModule = async (name, ver) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const resp = await request.get({
|
|
|
|
const resp = await request.get({
|
|
|
|
url,
|
|
|
|
url,
|
|
|
|
qs: baseQuery,
|
|
|
|
|
|
|
|
stream
|
|
|
|
stream
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -250,43 +246,31 @@ const installModule = async (name, ver, path) => {
|
|
|
|
// Extract zip via unzip cmd line - replaces yauzl dep (speed++, size--, jank++)
|
|
|
|
// Extract zip via unzip cmd line - replaces yauzl dep (speed++, size--, jank++)
|
|
|
|
const ePath = join(basePath, name);
|
|
|
|
const ePath = join(basePath, name);
|
|
|
|
|
|
|
|
|
|
|
|
const total = await new Promise((res) => {
|
|
|
|
let total = 0;
|
|
|
|
const p = execFile('unzip', ['-l', path]);
|
|
|
|
await new Promise((res) => {
|
|
|
|
|
|
|
|
const p = execFile('tar', ['-tf', path]);
|
|
|
|
|
|
|
|
|
|
|
|
p.stdout.on('data', x => {
|
|
|
|
p.stdout.on('data', x => total += x.toString().split('\n').length);
|
|
|
|
const m = x.toString().match(/([0-9]+) files/);
|
|
|
|
p.on('close', res);
|
|
|
|
if (m) res(parseInt(m[1]));
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
p.stderr.on('data', res); // On error resolve undefined (??'d to 0)
|
|
|
|
|
|
|
|
}) ?? 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mkdirp.sync(ePath);
|
|
|
|
mkdirp.sync(ePath);
|
|
|
|
|
|
|
|
|
|
|
|
const proc = execFile('unzip', ['-o', path, '-d', ePath]);
|
|
|
|
const proc = execFile('tar', ['-xvf', path, '-C', ePath]);
|
|
|
|
|
|
|
|
|
|
|
|
proc.on('error', (err) => {
|
|
|
|
|
|
|
|
if (err.code === 'ENOENT') {
|
|
|
|
|
|
|
|
require('electron').dialog.showErrorBox('Failed Dependency', 'Please install "unzip"');
|
|
|
|
|
|
|
|
process.exit(1); // Close now
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handleErr(err);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc.on('error', handleErr);
|
|
|
|
proc.stderr.on('data', handleErr);
|
|
|
|
proc.stderr.on('data', handleErr);
|
|
|
|
|
|
|
|
|
|
|
|
let cur = 0;
|
|
|
|
let cur = 0;
|
|
|
|
proc.stdout.on('data', x => x.toString().split('\n').forEach(y => {
|
|
|
|
proc.stdout.on('data', x => {
|
|
|
|
if (!y.includes('inflating')) return;
|
|
|
|
cur += x.toString().split('\n').length;
|
|
|
|
|
|
|
|
|
|
|
|
cur++;
|
|
|
|
|
|
|
|
events.emit('installing-module-progress', {
|
|
|
|
events.emit('installing-module-progress', {
|
|
|
|
name,
|
|
|
|
name,
|
|
|
|
cur,
|
|
|
|
cur,
|
|
|
|
total
|
|
|
|
total
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
proc.on('close', () => {
|
|
|
|
proc.on('close', () => {
|
|
|
|
if (hasError) return;
|
|
|
|
if (hasError) return;
|
|
|
|