Updater base
This commit is contained in:
parent
402acdfea9
commit
e63386e9eb
|
@ -35,7 +35,7 @@ import deepmerge from 'deepmerge';
|
||||||
import ContentSecurityPolicy from 'csp-parse';
|
import ContentSecurityPolicy from 'csp-parse';
|
||||||
import keytar from 'keytar';
|
import keytar from 'keytar';
|
||||||
|
|
||||||
import { FileUtils, BDIpc, Config, WindowUtils, CSSEditor, Editor, Database } from './modules';
|
import { FileUtils, BDIpc, Config, WindowUtils, Updater, Editor, Database } from './modules';
|
||||||
|
|
||||||
const packageJson = require(path.resolve(__dirname, 'package.json'));
|
const packageJson = require(path.resolve(__dirname, 'package.json'));
|
||||||
const sparkplug = path.resolve(__dirname, 'sparkplug.js');
|
const sparkplug = path.resolve(__dirname, 'sparkplug.js');
|
||||||
|
@ -195,6 +195,8 @@ export class BetterDiscord {
|
||||||
get config() { return this._config ? this._config : (this._config = new Config(this._args)); }
|
get config() { return this._config ? this._config : (this._config = new Config(this._args)); }
|
||||||
get window() { return this.windowUtils ? this.windowUtils.window : undefined; }
|
get window() { return this.windowUtils ? this.windowUtils.window : undefined; }
|
||||||
get editor() { return this._editor ? this._editor : (this._editor = new Editor(this, this.config.getPath('editor'))); }
|
get editor() { return this._editor ? this._editor : (this._editor = new Editor(this, this.config.getPath('editor'))); }
|
||||||
|
get updater() { return this._updater ? this._updater : (this._updater = new Updater(this)); }
|
||||||
|
get sendToDiscord() { return this.windowUtils.send; }
|
||||||
|
|
||||||
constructor(args) {
|
constructor(args) {
|
||||||
if (TESTS) args = TEST_ARGS();
|
if (TESTS) args = TEST_ARGS();
|
||||||
|
@ -230,6 +232,8 @@ export class BetterDiscord {
|
||||||
await this.waitForWindowUtils();
|
await this.waitForWindowUtils();
|
||||||
await this.ensureDirectories();
|
await this.ensureDirectories();
|
||||||
|
|
||||||
|
await this.updater.checkForUpdates();
|
||||||
|
|
||||||
this.windowUtils.on('did-finish-load', () => this.injectScripts(true));
|
this.windowUtils.on('did-finish-load', () => this.injectScripts(true));
|
||||||
|
|
||||||
this.windowUtils.on('did-navigate-in-page', (event, url, isMainFrame) => {
|
this.windowUtils.on('did-navigate-in-page', (event, url, isMainFrame) => {
|
||||||
|
|
|
@ -4,3 +4,4 @@ export { default as Config } from './config';
|
||||||
export { default as CSSEditor } from './csseditor';
|
export { default as CSSEditor } from './csseditor';
|
||||||
export { default as Editor } from './editor';
|
export { default as Editor } from './editor';
|
||||||
export { default as Database } from './database';
|
export { default as Database } from './database';
|
||||||
|
export { default as Updater } from './updater';
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
/**
|
||||||
|
* BetterDiscord Updater Module
|
||||||
|
* Copyright (c) 2015-present JsSucks - https://github.com/JsSucks
|
||||||
|
* All rights reserved.
|
||||||
|
* https://github.com/JsSucks - https://betterdiscord.net
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Module from './modulebase';
|
||||||
|
|
||||||
|
export default class Updater extends Module {
|
||||||
|
|
||||||
|
constructor(bd) {
|
||||||
|
super();
|
||||||
|
this.bd = bd;
|
||||||
|
}
|
||||||
|
|
||||||
|
bindings() {
|
||||||
|
this.checkForUpdates = this.checkForUpdates.bind(this);
|
||||||
|
this.start = this.start.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
start(interval = 15) {
|
||||||
|
this.updaterThread = setInterval(this.checkForUpdates, interval * 60 * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
async checkForUpdates() {
|
||||||
|
console.log('[BetterDiscord:Updater] Checking for updates');
|
||||||
|
this.bd.sendToDiscord('updater-checkForUpdates', '');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { coreVersion, clientVersion, editorVersion } = this.bd.config;
|
||||||
|
console.log('[BetterDiscord:Updater]', coreVersion, clientVersion, editorVersion);
|
||||||
|
return true;
|
||||||
|
} catch (err) {
|
||||||
|
console.log('[BetterDiscord:Updater]', err);
|
||||||
|
this.bd.sendToDiscord('updater-error', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue