Skip to content

Commit

Permalink
Merge pull request #293 from JsSucks/2.0.0-beta.4
Browse files Browse the repository at this point in the history
beta 4 to master
  • Loading branch information
Jiiks authored Mar 8, 2019
2 parents 6788cca + 33567a2 commit 3219ff7
Show file tree
Hide file tree
Showing 50 changed files with 1,210 additions and 798 deletions.
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "bdclient",
"description": "BetterDiscord client package",
"author": "Jiiks",
"version": "2.0.0-beta.3",
"version": "2.0.0-beta.4",
"homepage": "https://betterdiscord.net",
"license": "MIT",
"main": "dist/betterdiscord.client.js",
Expand Down
7 changes: 3 additions & 4 deletions client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
import { DOM, BdUI, BdMenu, Modals, Toasts, Notifications, BdContextMenu, DiscordContextMenu } from 'ui';
import BdCss from './styles/index.scss';
import { Events, Globals, Settings, Database, Updater, ModuleManager, PluginManager, ThemeManager, ExtModuleManager, Vendor, Patcher, MonkeyPatch, ReactComponents, ReactHelpers, ReactAutoPatcher, DiscordApi, BdWebApi, Connectivity, Cache, Reflection, PackageInstaller } from 'modules';
import { ClientLogger as Logger, ClientIPC, Utils } from 'common';
import { ClientLogger as Logger, ClientIPC, Utils, Axi } from 'common';
import { BuiltinManager, EmoteModule, ReactDevtoolsModule, VueDevtoolsModule, TrackingProtection, E2EE } from 'builtin';
import electron from 'electron';
import path from 'path';
import { setTimeout } from 'timers';

const tests = typeof PRODUCTION === 'undefined';
const ignoreExternal = true;
const ignoreExternal = tests && true;

class BetterDiscord {

Expand All @@ -39,7 +38,7 @@ class BetterDiscord {
BdWebApi,
Connectivity,
Cache,
Logger, ClientIPC, Utils,
Logger, ClientIPC, Utils, Axi,

plugins: PluginManager.localContent,
themes: ThemeManager.localContent,
Expand Down
2 changes: 1 addition & 1 deletion client/src/modules/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default new class extends Module {
}

get version() {
return this.config.version;
return this.config.versions.core;
}

}
2 changes: 1 addition & 1 deletion client/src/modules/imodule.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class Module {
}

setState(newState) {
const oldState = this.state;
const oldState = Object.assign({}, this.state);
Object.assign(this.state, newState);
if (this.stateChanged) this.stateChanged(oldState, newState);
}
Expand Down
216 changes: 159 additions & 57 deletions client/src/modules/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,81 +8,183 @@
* LICENSE file in the root directory of this source tree.
*/

import { Notifications } from 'ui';
import { Reflection, Globals } from 'modules';

import Events from './events';
import Globals from './globals';
import { ClientLogger as Logger } from 'common';
import request from 'request-promise-native';
import Module from './imodule';

export default new class {
export default new class extends Module {

constructor() {
this.updatesAvailable = false;
this.latestVersion = undefined;
this.error = undefined;
get updates() { return this.state.updates }
get bdUpdates() { return this.state.updates.bd }
get error() { return null; }
get updatesAvailable() { return this.state.updatesAvailable; }

this.init = this.init.bind(this);
this.checkForUpdates = this.checkForUpdates.bind(this);
constructor() {
super({
updatesAvailable: false,
error: null,
updates: { bd: [] },
updating: false
});
}

/**
* The interval to wait before checking for updates.
*/
get interval() {
return 60 * 1000 * 30;
bindings() {
this.restartNotif = this.restartNotif.bind(this);
this.reloadNotif = this.reloadNotif.bind(this);
this.startUpdate = this.startUpdate.bind(this);
this.setUpdateStatus = this.setUpdateStatus.bind(this);
this.testUi = this.testUi.bind(this);
}

init() {
this.updateInterval = setInterval(this.checkForUpdates, this.interval);
restartNotif() {
Notifications.add('Updates Finished!', 'Restart required.', [
{
text: 'Restart Later',
onClick: () => { setTimeout(this.restartNotif, 5 * 60000); return true; }
},
{
text: 'Restart Now',
onClick: () => {
try {
const { remote } = Globals.require('electron');
window.close();
Reflection.module.byProps('showToken', 'hideToken').showToken();
remote.app.relaunch();
remote.app.exit(0);
} catch (err) {
console.err(err);
return true;
}
}
}
]);
}

/**
* Installs an update.
* TODO
*/
async update() {
try {
await new Promise(resolve => setTimeout(resolve, 5000));

this.updatesAvailable = false;
this.latestVersion = Globals.version;
Events.emit('update-check-end');
} catch (err) {
this.error = err;
this.checkForUpdates();
throw err;
}
reloadNotif() {
Notifications.add('Updates Finished!', 'Reload required.', [
{
text: 'Reload Later',
onClick: () => { setTimeout(this.reloadNotif, 5 * 60000); return true; }
},
{
text: 'Reload Now',
onClick: () => {
document.location.reload();
}
}
]);
}

/**
* Checks for updates.
* @return {Promise}
*/
async checkForUpdates() {
if (this.updatesAvailable) return true;
Events.emit('update-check-start');
Logger.info('Updater', 'Checking for updates');

try {
const response = await request({
uri: 'https://rawgit.com/JsSucks/BetterDiscordApp/master/package.json',
json: true
events(ipc) {
ipc.on('updater-checkForUpdates', () => {
if (this.state.updating) return; // We're already updating. Updater should be paused anyways at this point.
Events.emit('update-check-start');
});

ipc.on('updater-noUpdates', () => {
if (this.state.updatesAvailable) return; // If for some reason we get this even though we have updates already.
this.setState({
updatesAvailable: false,
updates: {}
});
});

this.latestVersion = response.version;
Events.emit('update-check-end');
Logger.info('Updater', `Latest Version: ${response.version} - Current Version: ${Globals.version}`);
ipc.on('updater-updatesAvailable', (_, updates) => {
console.log(updates);
if (this.state.updating) return; // If for some reason we get more updates when we're already updating
updates.bd = updates.bd.map(update => {
update.text = `${update.id.charAt(0).toUpperCase()}${update.id.slice(1)}`;
update.hint = `Current: ${update.currentVersion} | Latest: ${update.version}`;
update.status = {
update: true,
updating: false,
updated: false,
error: null
};

if (this.latestVersion !== Globals.version) {
this.updatesAvailable = true;
Events.emit('updates-available');
return true;
return update;
});
this.setState({
updates,
updatesAvailable: true
});
});

ipc.on('updater-updated', (_, info) => {
const { reloadRequired, restartRequired } = info;
if (restartRequired) {
this.restartNotif();
return;
}

return false;
} catch (err) {
Events.emit('update-check-fail', err);
throw err;
if (reloadRequired) {
this.reloadNotif();
return;
}
});

ipc.on('updater-updateFinished', (_, update) => {
this.setUpdateStatus(update.id, 'updated', true);
});

ipc.on('updater-updateError', (_, update) => {
this.setUpdateStatus(update.id, 'error', update.error);
});
}

stateChanged(oldState, newState) {
if (!newState.updatesAvailable) return Events.emit('update-check-end');
if (!oldState.updatesAvailable && newState.updatesAvailable) {
Events.emit('updates-available');
Notifications.add('', 'Updates Available!', [
{
text: 'Ignore',
onClick: () => { return true; }
},
{
text: 'Show Updates',
onClick: () => {
Events.emit('bd-open-menu', 'updater');
return true;
}
}
]);
}
}

setUpdateStatus(updateId, statusChild, statusValue) {
for (const u of this.bdUpdates) {
if (u.id === updateId) {
u.status[statusChild] = statusValue;
return;
}
}
}

toggleUpdate(update) {
update.status.update = !update.status.update;
}

async startUpdate() {
console.log('start update');
const updates = { bd: [] };
for (const update of this.bdUpdates) {
if (update.status.update) {
update.status.updating = true;
updates.bd.push(update);
}
}
console.log(updates);
this.send('updater-startUpdate', updates);
}

testUi(updates) {
this.setState({
updates,
updatesAvailable: true
});
}

}
3 changes: 3 additions & 0 deletions client/src/modules/vendor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import jQuery from 'jquery';
import lodash from 'lodash';
import Vue from 'vue';
import { Axi } from 'common';

import request from 'request-promise-native';

Expand Down Expand Up @@ -40,6 +41,8 @@ export default class {
*/
static get Vue() { return Vue }

static get axios() { return Axi.axios }

static get request() { return request }

static get Combokeys() { return Combokeys }
Expand Down
9 changes: 9 additions & 0 deletions client/src/styles/partials/bdsettings/devview.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.bd-contentColumn .bd-devview {
display: grid;
grid-template-columns: 33% 33% 33%;

.bd-button {
font-size: 10px;
height: 20px;
}
}
1 change: 1 addition & 0 deletions client/src/styles/partials/bdsettings/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
@import './kvp';
@import './collection';
@import './e2ee';
@import './devview';
18 changes: 18 additions & 0 deletions client/src/styles/partials/bdsettings/updater.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,22 @@
margin: 0 0 10px;
color: #fff;
}

.bd-settingSwitch {
.bd-spinner7 {
height: 24px;
}

.bd-updaterStatus {
text-align: right;

&.bd-err {
color: $colerr;
}

&.bd-ok {
color: $colok;
}
}
}
}
Loading

0 comments on commit 3219ff7

Please sign in to comment.