[AsarUpdate] Disable update prompt by default, rewrite to be async
This commit is contained in:
parent
b2413f595a
commit
f36174e55b
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. -->
|
<!-- **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
|
## 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)
|
- `quickstart` (bool, default false) - whether to use Quickstart (experimental)
|
||||||
- `themeSync` (bool, default true) - syncs your modded client's theme with splash theming
|
- `themeSync` (bool, default true) - syncs your modded client's theme with splash theming
|
||||||
- `autoupdate` (bool, default true) - whether to autoupdate OpenAsar after Discord startup
|
- `autoupdate` (bool, default true) - whether to autoupdate OpenAsar after Discord startup
|
||||||
- `multiInstance` (bool, default false) - whether to enable multi-instance
|
- `updatePrompt` (bool, default false) - whether to show update prompt after updating OpenAsar
|
||||||
- `ssoeAllowlist` (bool, default true) - whether to use safer custom method of opening external urls (true) or normal Discord's method (false)
|
|
||||||
- `splashText` (bool, default true) - whether to show bottom right version info text in splash
|
- `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)
|
- `skipStartupUpdateChecks` (bool, default false) - skips startup update checking (Linux-only)
|
||||||
|
|
||||||
An example of a settings.json with OpenAsar config:
|
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:
|
Additionally there are some environmental variables you can use:
|
||||||
- `OPENASAR_QUICKSTART` (bool, default false) - same as `quickstart` config option
|
- `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');
|
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...');
|
log('AsarUpdate', 'Updating...');
|
||||||
|
|
||||||
if (!oaVersion.startsWith('nightly-')) {
|
if (!oaVersion.startsWith('nightly-')) {
|
||||||
|
@ -28,55 +28,63 @@ module.exports = () => { // (Try) update asar
|
||||||
const originalHash = getAsarHash();
|
const originalHash = getAsarHash();
|
||||||
log('AsarUpdate', 'Original Hash:', originalHash);
|
log('AsarUpdate', 'Original Hash:', originalHash);
|
||||||
|
|
||||||
const file = fs.createWriteStream(asarPath);
|
const updateSuccess = await new Promise((res) => {
|
||||||
|
const file = fs.createWriteStream(asarPath);
|
||||||
|
|
||||||
let writeError = false;
|
let writeError = false;
|
||||||
file.on('error', err => {
|
file.on('error', err => {
|
||||||
log('AsarUpdate', 'Failed to write', err);
|
log('AsarUpdate', 'Failed to write', err);
|
||||||
file.close();
|
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', 'Completed download');
|
||||||
log('AsarUpdate', 'Piping download response to stream');
|
|
||||||
res.pipe(file);
|
|
||||||
});
|
|
||||||
|
|
||||||
file.on('finish', async () => {
|
const newHash = getAsarHash();
|
||||||
file.close();
|
const changed = originalHash !== newHash;
|
||||||
log('AsarUpdate', 'Completed download');
|
|
||||||
|
|
||||||
const newHash = getAsarHash();
|
log('AsarUpdate', `Hash Comparison:
|
||||||
const changed = originalHash !== newHash;
|
|
||||||
|
|
||||||
log('AsarUpdate', `Hash Comparison:
|
|
||||||
Original Hash: ${originalHash}
|
Original Hash: ${originalHash}
|
||||||
New Hash: ${newHash}
|
New Hash: ${newHash}
|
||||||
Changed: ${changed}`);
|
Changed: ${changed}`);
|
||||||
|
|
||||||
if (changed) {
|
if (changed && oaConfig.updatePrompt === true) {
|
||||||
const { response } = await electron.dialog.showMessageBox(null, {
|
const { response } = await electron.dialog.showMessageBox(null, {
|
||||||
message: 'Updated OpenAsar',
|
message: 'Updated OpenAsar',
|
||||||
detail: `Restart required to use new version.`,
|
detail: `Restart required to use new version.`,
|
||||||
buttons: ['Restart Now', 'Later'],
|
buttons: ['Restart Now', 'Later'],
|
||||||
defaultId: 0
|
defaultId: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
log('AsarUpdate', 'Modal response', response);
|
log('AsarUpdate', 'Modal response', response);
|
||||||
|
|
||||||
if (response === 0) {
|
if (response === 0) {
|
||||||
log('AsarUpdate', 'Restarting');
|
log('AsarUpdate', 'Restarting');
|
||||||
|
|
||||||
electron.app.relaunch();
|
electron.app.relaunch();
|
||||||
electron.app.exit();
|
electron.app.exit();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (writeError) {
|
|
||||||
// Warn message?
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
Loading…
Reference in New Issue