From e63386e9eb06e2931505d9c5dc221cabafea1787 Mon Sep 17 00:00:00 2001 From: Jiiks Date: Tue, 5 Mar 2019 12:53:08 +0200 Subject: [PATCH] Updater base --- core/src/main.js | 6 +++++- core/src/modules/index.js | 1 + core/src/modules/updater.js | 43 +++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 core/src/modules/updater.js diff --git a/core/src/main.js b/core/src/main.js index 58cbfa66..4fade163 100644 --- a/core/src/main.js +++ b/core/src/main.js @@ -35,7 +35,7 @@ import deepmerge from 'deepmerge'; import ContentSecurityPolicy from 'csp-parse'; 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 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 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 updater() { return this._updater ? this._updater : (this._updater = new Updater(this)); } + get sendToDiscord() { return this.windowUtils.send; } constructor(args) { if (TESTS) args = TEST_ARGS(); @@ -230,6 +232,8 @@ export class BetterDiscord { await this.waitForWindowUtils(); await this.ensureDirectories(); + await this.updater.checkForUpdates(); + this.windowUtils.on('did-finish-load', () => this.injectScripts(true)); this.windowUtils.on('did-navigate-in-page', (event, url, isMainFrame) => { diff --git a/core/src/modules/index.js b/core/src/modules/index.js index 4a56e948..2b98833e 100644 --- a/core/src/modules/index.js +++ b/core/src/modules/index.js @@ -4,3 +4,4 @@ export { default as Config } from './config'; export { default as CSSEditor } from './csseditor'; export { default as Editor } from './editor'; export { default as Database } from './database'; +export { default as Updater } from './updater'; diff --git a/core/src/modules/updater.js b/core/src/modules/updater.js new file mode 100644 index 00000000..3277f240 --- /dev/null +++ b/core/src/modules/updater.js @@ -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); + } + } + +}