Compare commits

...

2 Commits
main ... mu

Author SHA1 Message Date
Ducko bd94cf74c9 [Updater > Module] Defer discord_voice install 2022-04-21 11:28:54 +01:00
Ducko dfba43512a [Updater > Module] Rewrite to use Mu api 2022-04-21 10:28:54 +01:00
3 changed files with 28 additions and 44 deletions

View File

@ -51,7 +51,7 @@ document.body.appendChild(el);
openasar = {}; // Define global for any mods which want to know / etc
DiscordNative.nativeModules.ensureModule('discord_voice');
setInterval(() => { // Try init themesync
try {
themesync();

View File

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

View File

@ -1,7 +1,7 @@
const request = require('request');
const nodeRequest = (opts) => new Promise((resolve, reject) => {
const { stream, timeout } = opts;
let { stream, timeout } = opts;
const req = request({ ...opts, timeout: timeout ?? 15000 });