BetterDiscordApp-v2/client/src/ui/components/bd/PluginsView.vue

100 lines
3.5 KiB
Vue
Raw Normal View History

2018-01-30 16:59:27 +01:00
/**
* BetterDiscord Plugins 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="Plugins">
<div class="bd-tabbar" slot="header">
<div class="bd-button" :class="{'bd-active': local}" @click="showLocal">
<h3>Installed</h3>
2018-02-19 19:10:09 +01:00
<div class="bd-material-button" v-if="local" @click="refreshLocal"><MiRefresh /></div>
</div>
<div class="bd-button" :class="{'bd-active': !local}" @click="showOnline">
<h3>Browse</h3>
2018-02-19 19:10:09 +01:00
<div class="bd-material-button" v-if="!local" @click="refreshOnline"><MiRefresh /></div>
2018-01-30 16:59:27 +01:00
</div>
</div>
2018-03-01 20:00:24 +01:00
<div class="bd-flex bd-flex-col bd-pluginsview">
2018-01-30 16:59:27 +01:00
<div v-if="local" class="bd-flex bd-flex-grow bd-flex-col bd-plugins-container bd-local-plugins">
2018-02-21 18:46:27 +01:00
<PluginCard v-for="plugin in localPlugins" :plugin="plugin" :key="plugin.id" :togglePlugin="() => togglePlugin(plugin)" :reloadPlugin="() => reloadPlugin(plugin)" :deletePlugin="e => deletePlugin(plugin, e.shiftKey)" :showSettings="() => showSettings(plugin)" />
2018-01-30 16:59:27 +01:00
</div>
2018-03-05 04:01:29 +01:00
<div v-if="!local" class="bd-online-ph">
<h3>Coming Soon</h3>
<a href="https://v2.betterdiscord.net/plugins" target="_new">Website Browser</a>
2018-01-30 16:59:27 +01:00
</div>
</div>
</SettingsWrapper>
</template>
<script>
// Imports
import { PluginManager } from 'modules';
import { Modals } from 'ui';
2018-01-30 16:59:27 +01:00
import { SettingsWrapper } from './';
import PluginCard from './PluginCard.vue';
2018-02-03 22:52:56 +01:00
import { MiRefresh } from '../common';
2018-01-30 16:59:27 +01:00
export default {
data() {
return {
local: true,
2018-01-31 09:32:20 +01:00
localPlugins: PluginManager.localPlugins
2018-01-30 16:59:27 +01:00
}
},
components: {
SettingsWrapper, PluginCard,
2018-02-03 22:52:56 +01:00
MiRefresh
2018-01-30 16:59:27 +01:00
},
methods: {
2018-01-30 23:21:06 +01:00
showLocal() {
this.local = true;
},
showOnline() {
this.local = false;
},
2018-02-19 19:10:09 +01:00
async refreshLocal() {
await PluginManager.refreshPlugins();
2018-01-31 12:29:19 +01:00
},
2018-02-19 19:10:09 +01:00
async refreshOnline() {
},
async togglePlugin(plugin) {
2018-01-31 09:32:20 +01:00
// TODO Display error if plugin fails to start/stop
try {
2018-02-21 18:46:27 +01:00
await plugin.enabled ? PluginManager.stopPlugin(plugin) : PluginManager.startPlugin(plugin);
this.$forceUpdate();
2018-01-31 09:32:20 +01:00
} catch (err) {
console.log(err);
}
},
2018-02-19 19:10:09 +01:00
async reloadPlugin(plugin) {
try {
await PluginManager.reloadPlugin(plugin);
this.$forceUpdate();
} catch (err) {
console.log(err);
}
2018-01-31 09:17:15 +01:00
},
2018-02-21 18:46:27 +01:00
async deletePlugin(plugin, unload) {
try {
if (unload) await PluginManager.unloadPlugin(plugin);
else await PluginManager.deletePlugin(plugin);
this.$forceUpdate();
} catch (err) {
console.error(err);
}
},
2018-01-31 12:35:38 +01:00
showSettings(plugin) {
return Modals.contentSettings(plugin);
2018-01-31 12:35:38 +01:00
}
2018-01-30 16:59:27 +01:00
}
}
</script>