Use axios and http/https to check for updates
This commit is contained in:
parent
b6f38a73dc
commit
cd77d659a5
|
@ -478,7 +478,6 @@ export default class PluginApi {
|
|||
waitForModuleByName: this.waitForWebpackModuleByName.bind(this),
|
||||
waitForModuleByDisplayName: this.waitForWebpackModuleByDisplayName.bind(this),
|
||||
waitForModuleByRegex: this.waitForWebpackModuleByRegex.bind(this),
|
||||
waitForModulesByRegex: this.waitForWebpackModulesByRegex.bind(this),
|
||||
waitForModuleByProperties: this.waitForWebpackModuleByProperties.bind(this),
|
||||
waitForModuleByPrototypeFields: this.waitForWebpackModuleByPrototypeFields.bind(this),
|
||||
getClassName: this.getWebpackClassName.bind(this),
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
import Events from './events';
|
||||
import Globals from './globals';
|
||||
import { $ } from 'vendor';
|
||||
import { axios } from 'vendor';
|
||||
import { ClientLogger as Logger } from 'common';
|
||||
|
||||
export default new class {
|
||||
|
@ -57,40 +57,29 @@ export default new class {
|
|||
* Checks for updates.
|
||||
* @return {Promise}
|
||||
*/
|
||||
checkForUpdates() {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (this.updatesAvailable) return resolve(true);
|
||||
Events.emit('update-check-start');
|
||||
Logger.info('Updater', 'Checking for updates');
|
||||
async checkForUpdates() {
|
||||
if (this.updatesAvailable) return true;
|
||||
Events.emit('update-check-start');
|
||||
Logger.info('Updater', 'Checking for updates');
|
||||
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: 'https://rawgit.com/JsSucks/BetterDiscordApp/master/package.json',
|
||||
cache: false,
|
||||
success: e => {
|
||||
try {
|
||||
this.latestVersion = e.version;
|
||||
Events.emit('update-check-end');
|
||||
Logger.info('Updater', `Latest Version: ${e.version} - Current Version: ${Globals.version}`);
|
||||
try {
|
||||
const response = await axios.get('https://rawgit.com/JsSucks/BetterDiscordApp/master/package.json');
|
||||
|
||||
if (this.latestVersion !== Globals.version) {
|
||||
this.updatesAvailable = true;
|
||||
Events.emit('updates-available');
|
||||
resolve(true);
|
||||
}
|
||||
this.latestVersion = response.data.version;
|
||||
Events.emit('update-check-end');
|
||||
Logger.info('Updater', `Latest Version: ${response.data.version} - Current Version: ${Globals.version}`);
|
||||
|
||||
resolve(false);
|
||||
} catch (err) {
|
||||
Events.emit('update-check-fail', err);
|
||||
reject(err);
|
||||
}
|
||||
},
|
||||
fail: err => {
|
||||
Events.emit('update-check-fail', err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
if (this.latestVersion !== Globals.version) {
|
||||
this.updatesAvailable = true;
|
||||
Events.emit('updates-available');
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch (err) {
|
||||
Events.emit('update-check-fail', err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,6 +12,11 @@ import jQuery from 'jquery';
|
|||
import lodash from 'lodash';
|
||||
import Vue from 'vue';
|
||||
|
||||
import axios from 'axios';
|
||||
import axiosHttpAdapter from 'axios/lib/adapters/http';
|
||||
|
||||
axios.defaults.adapter = axiosHttpAdapter;
|
||||
|
||||
import Combokeys from 'combokeys';
|
||||
import filetype from 'file-type';
|
||||
import filewatcher from 'filewatcher';
|
||||
|
@ -38,6 +43,8 @@ export default class {
|
|||
*/
|
||||
static get Vue() { return Vue }
|
||||
|
||||
static get axios() { return axios }
|
||||
|
||||
static get Combokeys() { return Combokeys }
|
||||
static get filetype() { return filetype }
|
||||
static get filewatcher() { return filewatcher }
|
||||
|
|
|
@ -31,11 +31,6 @@ module.exports = {
|
|||
loaders: [jsLoader, vueLoader, scssLoader]
|
||||
},
|
||||
externals: {
|
||||
electron: 'require("electron")',
|
||||
fs: 'require("fs")',
|
||||
path: 'require("path")',
|
||||
util: 'require("util")',
|
||||
process: 'require("process")',
|
||||
sparkplug: 'require("../../core/dist/sparkplug")'
|
||||
},
|
||||
resolve: {
|
||||
|
@ -52,6 +47,7 @@ module.exports = {
|
|||
path.resolve('src', 'builtin')
|
||||
]
|
||||
},
|
||||
target: 'electron-renderer',
|
||||
node: {
|
||||
process: false,
|
||||
__filename: false,
|
||||
|
|
|
@ -32,11 +32,6 @@ module.exports = {
|
|||
loaders: [jsLoader, vueLoader, scssLoader]
|
||||
},
|
||||
externals: {
|
||||
electron: 'require("electron")',
|
||||
fs: 'require("fs")',
|
||||
path: 'require("path")',
|
||||
util: 'require("util")',
|
||||
process: 'require("process")',
|
||||
sparkplug: 'require("./sparkplug")'
|
||||
},
|
||||
resolve: {
|
||||
|
@ -53,6 +48,7 @@ module.exports = {
|
|||
path.resolve('src', 'builtin')
|
||||
]
|
||||
},
|
||||
target: 'electron-renderer',
|
||||
node: {
|
||||
process: false,
|
||||
__filename: false,
|
||||
|
|
|
@ -725,6 +725,16 @@
|
|||
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.6.0.tgz",
|
||||
"integrity": "sha1-g+9cqGCysy5KDe7e6MdxudtXRx4="
|
||||
},
|
||||
"axios": {
|
||||
"version": "0.18.0",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.18.0.tgz",
|
||||
"integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"follow-redirects": "1.5.1",
|
||||
"is-buffer": "1.1.6"
|
||||
}
|
||||
},
|
||||
"babel-code-frame": {
|
||||
"version": "6.26.0",
|
||||
"resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz",
|
||||
|
@ -1629,15 +1639,6 @@
|
|||
"integrity": "sha1-aN/1++YMUes3cl6p4+0xDcwed24=",
|
||||
"dev": true
|
||||
},
|
||||
"boom": {
|
||||
"version": "4.3.1",
|
||||
"resolved": "https://registry.npmjs.org/boom/-/boom-4.3.1.tgz",
|
||||
"integrity": "sha1-T4owBctKfjiJ90kDD9JbluAdLjE=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"hoek": "4.2.0"
|
||||
}
|
||||
},
|
||||
"brace-expansion": {
|
||||
"version": "1.1.11",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
||||
|
@ -2724,26 +2725,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"cryptiles": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-3.1.2.tgz",
|
||||
"integrity": "sha1-qJ+7Ig9c4l7FboxKqKT9e1sNKf4=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"boom": "5.2.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"boom": {
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/boom/-/boom-5.2.0.tgz",
|
||||
"integrity": "sha1-XdnabuOl8wIHdDYpDLcX0/SlTgI=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"hoek": "4.2.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"crypto-browserify": {
|
||||
"version": "3.12.0",
|
||||
"resolved": "https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-3.12.0.tgz",
|
||||
|
@ -4339,6 +4320,26 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"follow-redirects": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.1.tgz",
|
||||
"integrity": "sha512-v9GI1hpaqq1ZZR6pBD1+kI7O24PhDvNGNodjS3MdcEqyrahCp8zbtpv+2B/krUnSmUH80lbAS7MrdeK5IylgKg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"debug": "3.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
||||
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"for-in": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",
|
||||
|
@ -4366,9 +4367,9 @@
|
|||
"integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE="
|
||||
},
|
||||
"form-data": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.1.tgz",
|
||||
"integrity": "sha1-b7lPvXGIUwbXPRXMSX/kzE7NRL8=",
|
||||
"version": "2.3.2",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.2.tgz",
|
||||
"integrity": "sha1-SXBJi+YEwgwAXU9cI67NIda0kJk=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"asynckit": "0.4.0",
|
||||
|
@ -6803,18 +6804,6 @@
|
|||
"minimalistic-assert": "1.0.1"
|
||||
}
|
||||
},
|
||||
"hawk": {
|
||||
"version": "6.0.2",
|
||||
"resolved": "https://registry.npmjs.org/hawk/-/hawk-6.0.2.tgz",
|
||||
"integrity": "sha1-r02RTrBl+bXOTZ0RwcshJu7MMDg=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"boom": "4.3.1",
|
||||
"cryptiles": "3.1.2",
|
||||
"hoek": "4.2.0",
|
||||
"sntp": "2.1.0"
|
||||
}
|
||||
},
|
||||
"he": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz",
|
||||
|
@ -6832,12 +6821,6 @@
|
|||
"minimalistic-crypto-utils": "1.0.1"
|
||||
}
|
||||
},
|
||||
"hoek": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/hoek/-/hoek-4.2.0.tgz",
|
||||
"integrity": "sha1-ctnQdU9/4lyi0BrY+PmpRJqJUm0=",
|
||||
"dev": true
|
||||
},
|
||||
"home-or-tmp": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/home-or-tmp/-/home-or-tmp-2.0.0.tgz",
|
||||
|
@ -9180,7 +9163,7 @@
|
|||
"minimist": "1.2.0",
|
||||
"pretty-bytes": "1.0.4",
|
||||
"progress-stream": "1.2.0",
|
||||
"request": "2.83.0",
|
||||
"request": "2.87.0",
|
||||
"single-line-log": "1.1.2",
|
||||
"throttleit": "0.0.2"
|
||||
},
|
||||
|
@ -10748,9 +10731,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"qs": {
|
||||
"version": "6.5.1",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz",
|
||||
"integrity": "sha1-NJzfbu+J7EXBLX1es/wMhwNDptg=",
|
||||
"version": "6.5.2",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
|
||||
"integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==",
|
||||
"dev": true
|
||||
},
|
||||
"query-string": {
|
||||
|
@ -11210,9 +11193,9 @@
|
|||
}
|
||||
},
|
||||
"request": {
|
||||
"version": "2.83.0",
|
||||
"resolved": "https://registry.npmjs.org/request/-/request-2.83.0.tgz",
|
||||
"integrity": "sha1-ygtl2gLtYpNYh4COb1EDgQNOM1Y=",
|
||||
"version": "2.87.0",
|
||||
"resolved": "https://registry.npmjs.org/request/-/request-2.87.0.tgz",
|
||||
"integrity": "sha512-fcogkm7Az5bsS6Sl0sibkbhcKsnyon/jV1kF3ajGmF0c8HrttdKTPRT9hieOaQHA5HEq6r8OyWOo/o781C1tNw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"aws-sign2": "0.7.0",
|
||||
|
@ -11221,9 +11204,8 @@
|
|||
"combined-stream": "1.0.6",
|
||||
"extend": "3.0.1",
|
||||
"forever-agent": "0.6.1",
|
||||
"form-data": "2.3.1",
|
||||
"form-data": "2.3.2",
|
||||
"har-validator": "5.0.3",
|
||||
"hawk": "6.0.2",
|
||||
"http-signature": "1.2.0",
|
||||
"is-typedarray": "1.0.0",
|
||||
"isstream": "0.1.2",
|
||||
|
@ -11231,9 +11213,8 @@
|
|||
"mime-types": "2.1.17",
|
||||
"oauth-sign": "0.8.2",
|
||||
"performance-now": "2.1.0",
|
||||
"qs": "6.5.1",
|
||||
"qs": "6.5.2",
|
||||
"safe-buffer": "5.1.1",
|
||||
"stringstream": "0.0.5",
|
||||
"tough-cookie": "2.3.3",
|
||||
"tunnel-agent": "0.6.0",
|
||||
"uuid": "3.2.1"
|
||||
|
@ -11489,7 +11470,7 @@
|
|||
"semver": {
|
||||
"version": "5.5.0",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz",
|
||||
"integrity": "sha1-3Eu8emyp2Rbe5dQ1FvAJK1j3uKs="
|
||||
"integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA=="
|
||||
},
|
||||
"semver-greatest-satisfied-range": {
|
||||
"version": "1.1.0",
|
||||
|
@ -11752,15 +11733,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"sntp": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/sntp/-/sntp-2.1.0.tgz",
|
||||
"integrity": "sha1-LGzsFP7cIiJznK+bXD2F0cxaLMg=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"hoek": "4.2.0"
|
||||
}
|
||||
},
|
||||
"sort-keys": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/sort-keys/-/sort-keys-1.1.2.tgz",
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"archiver": "^2.1.1",
|
||||
"axios": "^0.18.0",
|
||||
"babel-core": "^6.26.3",
|
||||
"babel-loader": "^7.1.4",
|
||||
"babel-preset-env": "^1.7.0",
|
||||
|
|
Loading…
Reference in New Issue