Load icon from package

This commit is contained in:
Jiiks 2018-12-07 03:32:49 +02:00
parent 683299735f
commit 02a0d92b9a
2 changed files with 9 additions and 48 deletions

View File

@ -107,57 +107,12 @@ export default class PackageInstaller {
* @param {String} remoteLocation Remote resource location
*/
static async installRemotePackage(remoteLocation) {
let outputPath = null;
try {
const modalResult = await Modals.remoteInstallModal(remoteLocation).promise;
console.log(modalResult);
await this.dragAndDropHandler(modalResult);
} catch (err) {
throw err;
}
return;
try {
const { hostname } = Object.assign(document.createElement('a'), { href: remoteLocation });
if (hostname !== 'api.github.com' && hostname !== 'secretbdapi') throw 'Invalid host!';
const options = {
uri: remoteLocation,
encoding: null,
headers: {
'User-Agent': 'BetterDiscordClient',
'Accept': 'application/octet-stream'
}
};
const response = await request.get(options);
outputPath = path.join(Globals.getPath('tmp'), Security.hash('sha256', response, 'hex'));
fs.writeFileSync(outputPath, response);
const config = JSON.parse(asar.extractFile(outputPath, 'config.json').toString());
const { info, main } = config;
let icon = null;
if (info.icon && info.icon_type) {
const extractIcon = asar.extractFile(outputPath, info.icon);
icon = `data:${info.icon_type};base64,${Utils.arrayBufferToBase64(extractIcon)}`;
}
const isPlugin = info.type && info.type === 'plugin' || main.endsWith('.js');
// Show install modal
const modalResult = await Modals.installModal(isPlugin ? 'plugin' : 'theme', config, filePath, icon).promise;
} catch (err) {
throw err;
} finally {
if (!outputPath) return;
rimraf(outputPath, err => {
if (err) console.log(err);
});
}
}
static async downloadRemotePackage(remoteLocation) {

View File

@ -37,7 +37,8 @@
<script>
// Imports
import { FileUtils, ClientLogger as Logger } from 'common';
import asar from 'asar';
import { Utils, FileUtils, ClientLogger as Logger } from 'common';
import path from 'path';
import { MiExtension } from '../common';
import ContentAuthor from './ContentAuthor.vue';
@ -58,9 +59,14 @@
async getIconURL() {
if (!this.item.icon) return;
if (this.item.icon.substr(0, 5) === 'data:') {
return `url(${this.item.icon})`;
}
try {
if (this.item.icon.substr(0, 5) === 'data:') {
return `url(${this.item.icon})`;
if (this.item.packed) {
const icon = asar.extractFile(this.item.paths.packagePath, this.item.icon);
return `url(data:${this.item.info.icon_type || 'image/svg+xml'};base64,${Utils.arrayBufferToBase64(icon)})`;
}
const iconPath = path.join(this.item.contentPath, this.item.icon);