[AsarUpdate] Disable update prompt by default, rewrite to be async
This commit is contained in:
parent
b2413f595a
commit
f36174e55b
2 changed files with 54 additions and 41 deletions
13
README.md
13
README.md
|
@ -27,13 +27,18 @@ OpenAsar is highly stable, but still likely has a few possible minor issues. Cra
|
|||
<!-- **If using Linux it is highly recommended to disable write protection** (needing root to overwrite files) for your Discord install if you have it enabled. It is not much of a security defecit as Windows has no write protection as well. This enables updating the asar and potentially host updating further on. -->
|
||||
|
||||
## Config
|
||||
You can configure OpenAsar via `settings.json` (found in your Discord app data / user data), under a `openasar` object. Keep in mind most options are defaults for good reason. The avaliable options are:
|
||||
You can configure OpenAsar via `settings.json` (found in your Discord app data / user data), under a `openasar` object. Keep in mind most options are defaults for good reason.
|
||||
|
||||
### OpenAsar Options
|
||||
- `quickstart` (bool, default false) - whether to use Quickstart (experimental)
|
||||
- `themeSync` (bool, default true) - syncs your modded client's theme with splash theming
|
||||
- `autoupdate` (bool, default true) - whether to autoupdate OpenAsar after Discord startup
|
||||
- `multiInstance` (bool, default false) - whether to enable multi-instance
|
||||
- `ssoeAllowlist` (bool, default true) - whether to use safer custom method of opening external urls (true) or normal Discord's method (false)
|
||||
- `updatePrompt` (bool, default false) - whether to show update prompt after updating OpenAsar
|
||||
- `splashText` (bool, default true) - whether to show bottom right version info text in splash
|
||||
- `ssoeAllowlist` (bool, default true) - whether to use safer custom method of opening external urls (true) or normal Discord's method (false)
|
||||
|
||||
### Extra Discord Options
|
||||
- `multiInstance` (bool, default false) - whether to enable multi-instance
|
||||
- `skipStartupUpdateChecks` (bool, default false) - skips startup update checking (Linux-only)
|
||||
|
||||
An example of a settings.json with OpenAsar config:
|
||||
|
@ -58,4 +63,4 @@ An example of a settings.json with OpenAsar config:
|
|||
|
||||
Additionally there are some environmental variables you can use:
|
||||
- `OPENASAR_QUICKSTART` (bool, default false) - same as `quickstart` config option
|
||||
- `OPENASAR_NOSTART` (bool, default false) - if enabled halts starting after splash loads (for splash testing)
|
||||
- `OPENASAR_NOSTART` (bool, default false) - if enabled halts starting after splash loads (for splash testing)
|
|
@ -15,7 +15,7 @@ const channel = 'nightly'; // Have prod, etc. once stable / 1.0
|
|||
|
||||
const getAsarHash = () => crypto.createHash('sha512').update(fs.readFileSync(asarPath)).digest('hex');
|
||||
|
||||
module.exports = () => { // (Try) update asar
|
||||
module.exports = async () => { // (Try) update asar
|
||||
log('AsarUpdate', 'Updating...');
|
||||
|
||||
if (!oaVersion.startsWith('nightly-')) {
|
||||
|
@ -28,55 +28,63 @@ module.exports = () => { // (Try) update asar
|
|||
const originalHash = getAsarHash();
|
||||
log('AsarUpdate', 'Original Hash:', originalHash);
|
||||
|
||||
const file = fs.createWriteStream(asarPath);
|
||||
const updateSuccess = await new Promise((res) => {
|
||||
const file = fs.createWriteStream(asarPath);
|
||||
|
||||
let writeError = false;
|
||||
file.on('error', err => {
|
||||
log('AsarUpdate', 'Failed to write', err);
|
||||
file.close();
|
||||
let writeError = false;
|
||||
file.on('error', err => {
|
||||
log('AsarUpdate', 'Failed to write', err);
|
||||
file.close();
|
||||
|
||||
writeError = true;
|
||||
writeError = true;
|
||||
res(false);
|
||||
});
|
||||
|
||||
log('AsarUpdate', 'Opened write stream to asar');
|
||||
|
||||
request(asarUrl, (_err, res) => {
|
||||
if (writeError) return;
|
||||
|
||||
log('AsarUpdate', 'Piping download response to stream');
|
||||
res.pipe(file);
|
||||
});
|
||||
|
||||
file.on('finish', () => {
|
||||
file.close();
|
||||
res(true);
|
||||
});
|
||||
});
|
||||
|
||||
log('AsarUpdate', 'Opened write stream to asar');
|
||||
if (!updateSuccess) {
|
||||
log('AsarUpdate', 'Aborting rest of update due to update error');
|
||||
return;
|
||||
}
|
||||
|
||||
request(asarUrl, (_err, res) => {
|
||||
log('AsarUpdate', 'Piping download response to stream');
|
||||
res.pipe(file);
|
||||
});
|
||||
log('AsarUpdate', 'Completed download');
|
||||
|
||||
file.on('finish', async () => {
|
||||
file.close();
|
||||
log('AsarUpdate', 'Completed download');
|
||||
const newHash = getAsarHash();
|
||||
const changed = originalHash !== newHash;
|
||||
|
||||
const newHash = getAsarHash();
|
||||
const changed = originalHash !== newHash;
|
||||
|
||||
log('AsarUpdate', `Hash Comparison:
|
||||
log('AsarUpdate', `Hash Comparison:
|
||||
Original Hash: ${originalHash}
|
||||
New Hash: ${newHash}
|
||||
Changed: ${changed}`);
|
||||
|
||||
if (changed) {
|
||||
const { response } = await electron.dialog.showMessageBox(null, {
|
||||
message: 'Updated OpenAsar',
|
||||
detail: `Restart required to use new version.`,
|
||||
buttons: ['Restart Now', 'Later'],
|
||||
defaultId: 0
|
||||
});
|
||||
if (changed && oaConfig.updatePrompt === true) {
|
||||
const { response } = await electron.dialog.showMessageBox(null, {
|
||||
message: 'Updated OpenAsar',
|
||||
detail: `Restart required to use new version.`,
|
||||
buttons: ['Restart Now', 'Later'],
|
||||
defaultId: 0
|
||||
});
|
||||
|
||||
log('AsarUpdate', 'Modal response', response);
|
||||
log('AsarUpdate', 'Modal response', response);
|
||||
|
||||
if (response === 0) {
|
||||
log('AsarUpdate', 'Restarting');
|
||||
if (response === 0) {
|
||||
log('AsarUpdate', 'Restarting');
|
||||
|
||||
electron.app.relaunch();
|
||||
electron.app.exit();
|
||||
}
|
||||
electron.app.relaunch();
|
||||
electron.app.exit();
|
||||
}
|
||||
|
||||
if (writeError) {
|
||||
// Warn message?
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue