Add updater view

This commit is contained in:
Samuel Elliott 2018-03-21 22:24:23 +00:00
parent a85422f29e
commit 33adb92902
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
9 changed files with 110 additions and 16 deletions

View File

@ -16,8 +16,10 @@ import { ClientLogger as Logger } from 'common';
export default new class {
constructor() {
window.updater = this;
this.updatesAvailable = false;
this.latestVersion = undefined;
this.error = undefined;
this.init = this.init.bind(this);
this.checkForUpdates = this.checkForUpdates.bind(this);
}
@ -37,9 +39,18 @@ export default new class {
* Installs an update.
* TODO
*/
update() {
this.updatesAvailable = false;
Events.emit('update-check-end');
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;
}
}
/**
@ -58,10 +69,11 @@ export default new class {
cache: false,
success: e => {
try {
this.latestVersion = e.version;
Events.emit('update-check-end');
Logger.info('Updater', `Latest Version: ${e.version} - Current Version: ${Globals.getObject('version')}`);
Logger.info('Updater', `Latest Version: ${e.version} - Current Version: ${Globals.version}`);
if (e.version !== Globals.getObject('version')) {
if (this.latestVersion !== Globals.version) {
this.updatesAvailable = true;
Events.emit('updates-available');
resolve(true);

View File

@ -52,12 +52,12 @@
.bd-settings-button-btn {
background-image: $logoBigBw;
background-size: 100% 100%;
filter: none;
opacity: 1;
width: 130px;
height: 80px;
background-size: 100% 100%;
margin-left: 20px;
height: 43px;
margin: 18px 0 17px 20px;
cursor: default;
}
}

View File

@ -4,3 +4,4 @@
@import './card.scss';
@import './tooltips.scss';
@import './settings-schemes.scss';
@import './updater.scss';

View File

@ -0,0 +1,6 @@
.bd-updaterview {
p {
margin: 0 0 10px;
color: #ffffff;
}
}

View File

@ -8,17 +8,22 @@
* LICENSE file in the root directory of this source tree.
*/
import { Events } from 'modules';
import { Utils } from 'common';
let items = 0;
const BdMenuItems = new class {
export const BdMenuItems = new class {
constructor() {
window.bdmenu = this;
this.items = [];
const updater = this.add({category: 'Updates', contentid: 'updater', text: 'Updates available!', hidden: true});
Events.on('update-check-end', () => updater.hidden = true);
Events.on('updates-available', () => updater.hidden = false);
this.addSettingsSet('Internal', 'core', 'Core');
this.addSettingsSet('Internal', 'ui', 'UI');
this.addSettingsSet('Internal', 'emotes', 'Emotes');
@ -82,5 +87,3 @@ const BdMenuItems = new class {
}
};
export { BdMenuItems };

View File

@ -49,6 +49,7 @@
<CssEditorView v-if="item.contentid === 'css'" />
<PluginsView v-if="item.contentid === 'plugins'" />
<ThemesView v-if="item.contentid === 'themes'" />
<UpdaterView v-if="item.contentid === 'updater'" />
</div>
</ContentColumn>
</SidebarView>
@ -60,7 +61,7 @@
import { Settings } from 'modules';
import { BdMenuItems } from 'ui';
import { SidebarView, Sidebar, SidebarItem, ContentColumn } from './sidebar';
import { SettingsWrapper, SettingsPanel, CssEditorView, PluginsView, ThemesView } from './bd';
import { SettingsWrapper, SettingsPanel, CssEditorView, PluginsView, ThemesView, UpdaterView } from './bd';
import { SvgX, MiGithubCircle, MiWeb, MiClose, MiTwitterCircle } from './common';
export default {
@ -79,7 +80,7 @@
props: ['active', 'close'],
components: {
SidebarView, Sidebar, SidebarItem, ContentColumn,
SettingsWrapper, SettingsPanel, CssEditorView, PluginsView, ThemesView,
SettingsWrapper, SettingsPanel, CssEditorView, PluginsView, ThemesView, UpdaterView,
MiGithubCircle, MiWeb, MiClose, MiTwitterCircle
},
computed: {

View File

@ -11,9 +11,9 @@
<template>
<SettingsWrapper headertext="CSS Editor">
<div class="bd-css-editor">
<div v-if="CssEditor.error" class="bd-form-item">
<div v-if="error" class="bd-form-item">
<h5 style="margin-bottom: 10px;">Compiler error</h5>
<div class="bd-err bd-pre-wrap"><div class="bd-pre">{{ CssEditor.error.formatted }}</div></div>
<div class="bd-err bd-pre-wrap"><div class="bd-pre">{{ error.formatted }}</div></div>
<div class="bd-form-divider"></div>
</div>

View File

@ -0,0 +1,70 @@
/**
* BetterDiscord Updater View Component
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
* All rights reserved.
* 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.
*/
<template>
<SettingsWrapper headertext="Updates">
<div class="bd-flex bd-flex-col bd-updaterview">
<div v-if="error" class="bd-form-item">
<h5 style="margin-bottom: 10px;">Error installing updates</h5>
<div class="bd-err bd-pre-wrap"><div class="bd-pre">{{ error.formatted }}</div></div>
<div class="bd-form-divider"></div>
</div>
<template v-if="updatesAvailable">
<p>Version {{ newVersion }} is available. You are currently running version {{ currentVersion }}.</p>
<FormButton :onClick="install" :loading="updating">Install</FormButton>
</template>
<template v-else>
<p>You're all up to date!</p>
</template>
</div>
</SettingsWrapper>
</template>
<script>
import { Globals, Updater } from 'modules';
import { ClientLogger as Logger } from 'common';
import SettingsWrapper from './SettingsWrapper.vue';
import { FormButton } from '../common';
export default {
data() {
return {
currentVersion: Globals.version,
updating: false,
updater: Updater
};
},
components: {
SettingsWrapper,
FormButton
},
computed: {
updatesAvailable() {
return this.updater.updatesAvailable;
},
newVersion() {
return this.updater.latestVersion;
},
error() {
return this.updater.error;
}
},
methods: {
async install() {
this.updating = true;
try {
await this.updater.update();
} catch (err) {}
this.updating = false;
}
}
}
</script>

View File

@ -3,5 +3,6 @@ export { default as SettingsPanel } from './SettingsPanel.vue';
export { default as CssEditorView } from './CssEditor.vue';
export { default as PluginsView } from './PluginsView.vue';
export { default as ThemesView } from './ThemesView.vue';
export { default as UpdaterView } from './UpdaterView.vue';
export { default as BdBadge } from './BdBadge.vue';
export { default as BdMessageBadge } from './BdMessageBadge.vue';