Commit f5cdeab4 authored by Rob Nelson's avatar Rob Nelson
Browse files

Load plugins and themes from accounts.yml.

parent 1335090b
......@@ -4,7 +4,16 @@ Account1:
id: Account1
addons:
# Bandaged Better Discord. Installs using bbdctl.
bbd: {}
bbd:
# Plugins to install and autoupdate (PluginRepo and ThemeRepo are automatically included)
plugins:
CustomDiscordIcon:
name: CustomDiscordIcon
url: https://raw.githubusercontent.com/KyzaGitHub/Khub/master/Plugins/CustomDiscordIcon/CustomDiscordIcon.plugin.js
themes:
Nox:
name: Nox
url: https://raw.githubusercontent.com/rauenzi/Nox/master/release/Nox.theme.css
# Background color of the tray icon. Used in the SVG.
color: '#0095B3'
# img/{imagepack}/ - Used for tray icons.
......
import os, stat, re, json
from typing import Dict
from buildtools import os_utils, log
from discordjail.addons.framework import Addon, Addons
from discordjail.http import download_file_to
......@@ -14,6 +15,25 @@ ENABLE_BY_DEFAULT = [
'PluginRepo',
'ThemeRepo'
]
class BBDPlugin(object):
def __init__(self, _id='', url=''):
self.id: str = _id
self.name: str = _id
self.url: str = url
def deserialize(self, key: str, data: dict) -> None:
self.id = key
self.name = data.get('name', key)
self.url = data['url']
def install(self, bbd: 'BandagedBetterDiscordAddon') -> None:
download_file_to(self.url, os.path.join(bbd.plugins_dir, f'{self.id}.plugin.js'))
class BBDTheme(BBDPlugin):
def install(self, bbd: 'BandagedBetterDiscordAddon') -> None:
download_file_to(self.url, os.path.join(bbd.themes_dir, f'{self.id}.theme.css'))
class BandagedBetterDiscordAddon(Addon):
TYPEID = 'bbd'
NAME = 'Bandaged Better Discord'
......@@ -27,8 +47,20 @@ class BandagedBetterDiscordAddon(Addon):
self.plugins_dir: str = ''
self.themes_dir: str = ''
self.plugins: Dict[str, BBDPlugin] = {}
self.themes: Dict[str, BBDPlugin] = {}
self.plugins['PluginRepo'] = BBDPlugin('PluginRepo', BBD_PLUGIN_REPO)
self.plugins['ThemeRepo'] = BBDPlugin('ThemeRepo', BBD_THEME_REPO)
def deserialize(self, data: dict) -> None:
super().deserialize(data)
for k,v in data.get('plugins', {}).items():
self.plugins[k] = p = BBDPlugin()
p.deserialize(k, v)
for k,v in data.get('themes', {}).items():
self.themes[k] = t = BBDTheme()
t.deserialize(k, v)
def preexec(self):
......@@ -54,7 +86,7 @@ class BandagedBetterDiscordAddon(Addon):
with log.info('Injector not found, installing...'):
os_utils.cmd([self.bbdctl_path, 'install']+opts, show_output=True, echo=True, critical=False)
if not os_utils.cmd([self.bbdctl_path, 'update']+opts, show_output=True, echo=True, critical=False):
with log.info('Install failed, attempting reinstall...'):
with log.info('Update failed, attempting reinstall...'):
os_utils.cmd([self.bbdctl_path, 'install']+opts, show_output=True, echo=True, critical=False)
os_utils.cmd([self.bbdctl_path, 'update']+opts, show_output=True, echo=True, critical=False)
......@@ -67,8 +99,11 @@ class BandagedBetterDiscordAddon(Addon):
log.info(f'Creating {self.themes_dir}...')
os.makedirs(self.themes_dir)
download_file_to(BBD_PLUGIN_REPO, os.path.join(self.plugins_dir, 'PluginRepo.plugin.js'))
download_file_to(BBD_THEME_REPO, os.path.join(self.plugins_dir, 'ThemeRepo.plugin.js'))
for plugin in self.plugins.values():
plugin.install(self)
for theme in self.themes.values():
theme.install(self)
bdstorage = {
......
......@@ -8,8 +8,6 @@ from .http import download_file_to
from buildtools import log, http
from buildtools.twisted_utils import async_cmd
from asar import AsarFile
DISCORD_DL_API = "https://discordapp.com/api/download?platform=linux&format=tar.gz"
DISCORD_API_ENDPOINT = 'https://discordapp.com/api'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment