Functional installer/updater. Still needs lots of work.
This commit is contained in:
parent
a040a605d4
commit
8c060314da
|
@ -12,7 +12,6 @@ import { ClientLogger as Logger } from 'common';
|
|||
import { SocketProxy, EventHook, CssEditor } from 'modules';
|
||||
import { ProfileBadges, ClassNormaliser } from 'ui';
|
||||
import Updater from './updater';
|
||||
import PackageInstaller from './packageinstaller';
|
||||
|
||||
/**
|
||||
* Module Manager initializes all modules when everything is ready
|
||||
|
@ -29,8 +28,7 @@ export default class {
|
|||
new SocketProxy(),
|
||||
new EventHook(),
|
||||
CssEditor,
|
||||
Updater,
|
||||
new PackageInstaller()
|
||||
Updater
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,3 +27,4 @@ export { default as Connectivity } from './connectivity';
|
|||
export { default as Security } from './security';
|
||||
export { default as Cache } from './cache';
|
||||
export { default as Reflection } from './reflection/index';
|
||||
export { default as PackageInstaller } from './packageinstaller';
|
||||
|
|
|
@ -1,19 +1,16 @@
|
|||
import EventListener from './eventlistener';
|
||||
import asar from 'asar';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import { Modals } from 'ui';
|
||||
import { Utils } from 'common';
|
||||
import PluginManager from './pluginmanager';
|
||||
import Globals from './globals';
|
||||
|
||||
export default class extends EventListener {
|
||||
export default class {
|
||||
|
||||
get eventBindings() {
|
||||
return [
|
||||
{ id: 'install-pkg', callback: this.installPackage }
|
||||
];
|
||||
}
|
||||
|
||||
async installPackage(pkg, upload) {
|
||||
static async installPackageEvent(pkg, upload) {
|
||||
try {
|
||||
const config = JSON.parse(asar.extractFile(pkg.path, 'config.json').toString());
|
||||
const { info, main } = config;
|
||||
|
@ -26,6 +23,8 @@ export default class extends EventListener {
|
|||
if (icon) config.iconEncoded = icon;
|
||||
const isPlugin = info.type && info.type === 'plugin' || main.endsWith('.js');
|
||||
|
||||
config.path = pkg.path;
|
||||
|
||||
/*
|
||||
config.permissions = [
|
||||
{
|
||||
|
@ -58,4 +57,23 @@ export default class extends EventListener {
|
|||
} catch (err) {}
|
||||
}
|
||||
|
||||
// TODO lots of stuff
|
||||
/**
|
||||
* Installs or updates defined package
|
||||
* @param {Byte[]|String} bytesOrPath byte array of binary or path to local file
|
||||
* @param {String} name Package name
|
||||
* @param {Boolean} update Does an older version already exist
|
||||
*/
|
||||
static async installPackage(bytesOrPath, name, update = false) {
|
||||
const bytes = typeof bytesOrPath === 'string' ? fs.readFileSync(bytesOrPath) : bytesOrPath;
|
||||
const outputPath = path.join(Globals.getPath('plugins'), `${name}.bd`);
|
||||
fs.writeFileSync(outputPath, bytes);
|
||||
|
||||
if (!update) {
|
||||
return PluginManager.preloadPackedContent(`${name}.bd`);
|
||||
}
|
||||
|
||||
return PluginManager.reloadContent(PluginManager.getPluginByName(name));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import { Utils, Filters, ClientLogger as Logger } from 'common';
|
|||
import { MonkeyPatch } from './patcher';
|
||||
import Reflection from './reflection/index';
|
||||
import DiscordApi from './discordapi';
|
||||
import Events from './events';
|
||||
import PackageInstaller from './packageinstaller';
|
||||
|
||||
class Helpers {
|
||||
static get plannedActions() {
|
||||
|
@ -514,7 +514,9 @@ export class ReactAutoPatcher {
|
|||
e.stopImmediatePropagation();
|
||||
stateNode.clearDragging();
|
||||
|
||||
Events.emit('install-pkg', e.dataTransfer.files[0], DiscordApi.currentChannel.id);
|
||||
PackageInstaller.installPackageEvent(e.dataTransfer.files[0], DiscordApi.currentChannel.id);
|
||||
|
||||
// Events.emit('install-pkg', e.dataTransfer.files[0], DiscordApi.currentChannel.id);
|
||||
};
|
||||
|
||||
// Remove their handler, add ours, then read theirs to give ours priority to stop theirs when we get a .bd file.
|
||||
|
|
|
@ -35,14 +35,14 @@
|
|||
</div>
|
||||
<div v-else slot="footer" class="bd-installModalFooter">
|
||||
<div class="bd-button bd-ok" @click="modal.confirm(0); modal.close();">Upload</div>
|
||||
<div class="bd-button bd-ok" @click="modal.confirm(); modal.close();">{{ !alreadyInstalled ? 'Install' : 'Update' }}</div>
|
||||
<div class="bd-button bd-ok" @click="install">{{ !alreadyInstalled ? 'Install' : 'Update' }}</div>
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
||||
<script>
|
||||
// Imports
|
||||
import { Modal, MiExtension } from '../../common';
|
||||
import { PluginManager, ThemeManager } from 'modules';
|
||||
import { PluginManager, ThemeManager, PackageInstaller } from 'modules';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
|
@ -73,6 +73,14 @@
|
|||
this.verifying = false;
|
||||
}, 2000);
|
||||
|
||||
},
|
||||
methods: {
|
||||
async install() {
|
||||
const installed = await PackageInstaller.installPackage(this.modal.config.path, this.modal.config.info.name, this.alreadyInstalled);
|
||||
console.log(installed);
|
||||
this.modal.confirm();
|
||||
this.modal.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue