[AsarUpdate] Initial Add, autoupdate after Discord startup
This commit is contained in:
parent
2b5c3c8baa
commit
b3d0d3e32b
|
@ -16,6 +16,7 @@ Below is a list in order of priority, marked as complete when finished:
|
||||||
- [ ] A bunch of specific minor fixes / features
|
- [ ] A bunch of specific minor fixes / features
|
||||||
- [X] Handle hardware acceleration
|
- [X] Handle hardware acceleration
|
||||||
- [ ] Add Discord-specific Electron flags?
|
- [ ] Add Discord-specific Electron flags?
|
||||||
|
- [ ] Asar auto-updating
|
||||||
- [ ] Multi-instance handling
|
- [ ] Multi-instance handling
|
||||||
- [ ] Auto start
|
- [ ] Auto start
|
||||||
- [ ] First run
|
- [ ] First run
|
||||||
|
@ -39,8 +40,9 @@ Custom patches are another main goal of OpenAsar, patching enhancements where ot
|
||||||
|
|
||||||
## 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, they may temporarily brick your client until you revert your changes. 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, they may temporarily brick your client until you revert your changes. The avaliable options are:
|
||||||
- `quickstart` (bool) - enables Quickstart (experimental)
|
- `quickstart` (bool, default false) - whether to use Quickstart (experimental)
|
||||||
- `skipStartupUpdateChecks` (bool) - skips startup update checking (Linux-only)
|
- `skipStartupUpdateChecks` (bool, default false) - skips startup update checking (Linux-only)
|
||||||
|
- `autoupdate` (bool, default true) - whether to autoupdate OpenAsar after Discord startup
|
||||||
|
|
||||||
An example of a settings.json with OpenAsar config:
|
An example of a settings.json with OpenAsar config:
|
||||||
```json
|
```json
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
const request = require('request');
|
||||||
|
const fs = require('original-fs'); // Use original-fs, not Electron's modified fs
|
||||||
|
const crypto = require('crypto');
|
||||||
|
const electron = require('electron');
|
||||||
|
const { join } = require('path');
|
||||||
|
|
||||||
|
const asarPath = join(require.main.filename, '..');
|
||||||
|
log('AsarUpdate', 'Asar Path:', asarPath);
|
||||||
|
|
||||||
|
const downloadUrls = {
|
||||||
|
nightly: 'https://github.com/GooseMod/OpenAsar/releases/download/nightly/openasar.asar'
|
||||||
|
};
|
||||||
|
|
||||||
|
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
|
||||||
|
log('AsarUpdate', 'Updating...');
|
||||||
|
|
||||||
|
const asarUrl = downloadUrls[channel];
|
||||||
|
log('AsarUpdate', 'Release Channel:', channel, 'Download URL:', asarUrl);
|
||||||
|
|
||||||
|
const originalHash = getAsarHash();
|
||||||
|
log('AsarUpdate', 'Original Hash:', originalHash);
|
||||||
|
|
||||||
|
const file = fs.createWriteStream(asarPath);
|
||||||
|
log('AsarUpdate', 'Opened write stream to asar');
|
||||||
|
|
||||||
|
request(asarUrl, (_err, res) => {
|
||||||
|
log('AsarUpdate', 'Piping download response to stream');
|
||||||
|
res.pipe(file);
|
||||||
|
});
|
||||||
|
|
||||||
|
file.on('finish', () => {
|
||||||
|
file.close();
|
||||||
|
log('AsarUpdate', 'Completed download');
|
||||||
|
|
||||||
|
const newHash = getAsarHash();
|
||||||
|
const changed = originalHash !== newHash;
|
||||||
|
|
||||||
|
log('AsarUpdate', `Hash Comparison:
|
||||||
|
Original Hash: ${originalHash}
|
||||||
|
New Hash: ${newHash}
|
||||||
|
Changed: ${changed}`);
|
||||||
|
|
||||||
|
if (changed) {
|
||||||
|
electron.dialog.showMessageBox(null, {
|
||||||
|
message: 'Updated OpenAsar',
|
||||||
|
detail: `New version will be used next restart.`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
|
@ -53,6 +53,18 @@ const startUpdate = () => {
|
||||||
}, () => {
|
}, () => {
|
||||||
log('Bootstrap', 'Setting main window visible');
|
log('Bootstrap', 'Setting main window visible');
|
||||||
desktopCore.setMainWindowVisible(true);
|
desktopCore.setMainWindowVisible(true);
|
||||||
|
|
||||||
|
setTimeout(() => { // Try to update our asar
|
||||||
|
if (!oaConfig.autoupdate) return; // If autoupdate disabled, don't update
|
||||||
|
|
||||||
|
const asarUpdate = require('./asarUpdate');
|
||||||
|
|
||||||
|
try {
|
||||||
|
asarUpdate();
|
||||||
|
} catch (e) {
|
||||||
|
log('AsarUpdate', 'Failed to update', e);
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue