2018-08-29 05:19:18 +02:00
|
|
|
import EventListener from './eventlistener';
|
|
|
|
import asar from 'asar';
|
|
|
|
|
|
|
|
import { Modals } from 'ui';
|
|
|
|
import { Utils } from 'common';
|
2018-08-29 22:02:41 +02:00
|
|
|
import PluginManager from './pluginmanager';
|
2018-08-29 05:19:18 +02:00
|
|
|
|
|
|
|
export default class extends EventListener {
|
|
|
|
|
|
|
|
get eventBindings() {
|
|
|
|
return [
|
|
|
|
{ id: 'install-pkg', callback: this.installPackage }
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
async installPackage(pkg, upload) {
|
|
|
|
try {
|
|
|
|
const config = JSON.parse(asar.extractFile(pkg.path, 'config.json').toString());
|
|
|
|
const { info, main } = config;
|
|
|
|
|
|
|
|
let icon = null;
|
|
|
|
if (info.icon && info.icon_type) {
|
|
|
|
const extractIcon = asar.extractFile(pkg.path, info.icon);
|
|
|
|
icon = `data:${info.icon_type};base64,${Utils.arrayBufferToBase64(extractIcon)}`;
|
|
|
|
}
|
|
|
|
if (icon) config.iconEncoded = icon;
|
|
|
|
const isPlugin = info.type && info.type === 'plugin' || main.endsWith('.js');
|
|
|
|
|
|
|
|
/*
|
|
|
|
config.permissions = [
|
|
|
|
{
|
|
|
|
HEADER: 'Test Permission Header',
|
|
|
|
BODY: 'Test Permission Body'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
HEADER: 'Test Permission Header',
|
|
|
|
BODY: 'Test Permission Body'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
HEADER: 'Test Permission Header',
|
|
|
|
BODY: 'Test Permission Body'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
HEADER: 'Test Permission Header',
|
|
|
|
BODY: 'Test Permission Body'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
*/
|
|
|
|
// Show install modal
|
2018-08-29 22:02:41 +02:00
|
|
|
const modalResult = await Modals.installModal(isPlugin ? 'plugin' : 'theme', config).promise;
|
2018-08-29 05:19:18 +02:00
|
|
|
|
|
|
|
if (modalResult === 0) {
|
|
|
|
// Upload it instead
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(modalResult);
|
|
|
|
|
|
|
|
} catch (err) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|