Move packer to contentmanager

This commit is contained in:
Jiiks 2018-11-30 22:08:05 +02:00
parent f028aefab8
commit 26b1fad5a4
2 changed files with 31 additions and 22 deletions

View File

@ -12,6 +12,7 @@ import asar from 'asar';
import path, { dirname } from 'path';
import rimraf from 'rimraf';
import { remote } from 'electron';
import Content from './content';
import Globals from './globals';
import Database from './database';
@ -71,6 +72,28 @@ export default class {
return Globals.getPath(this.pathId);
}
static async packContent(path, contentPath) {
return new Promise((resolve, reject) => {
remote.dialog.showSaveDialog({
title: 'Save Package',
defaultPath: path,
filters: [
{
name: 'BetterDiscord Package',
extensions: ['bd']
}
]
}, filepath => {
if (!filepath) return;
asar.uncache(filepath);
asar.createPackage(contentPath, filepath, () => {
resolve(filepath);
});
});
});
}
/**
* Load all locally stored content.
* @param {bool} suppressErrors Suppress any errors that occur during loading of content

View File

@ -23,11 +23,8 @@
<script>
// Imports
import asar from 'asar';
import electron from 'electron';
import fs from 'fs';
import { Toasts } from 'ui';
import { Settings } from 'modules';
import { Settings, PluginManager } from 'modules';
import { ClientLogger as Logger } from 'common';
import { shell } from 'electron';
import Card from './Card.vue';
@ -45,24 +42,13 @@
MiSettings, MiRefresh, MiPencil, MiDelete, MiExtension, MiBoxDownload
},
methods: {
package() {
electron.remote.dialog.showSaveDialog({
title: 'Save Plugin Package',
defaultPath: this.plugin.name,
filters: [
{
name: 'BetterDiscord Package',
extensions: ['bd']
}
]
}, filepath => {
if (!filepath) return;
asar.uncache(filepath);
asar.createPackage(this.plugin.contentPath, filepath, () => {
Toasts.success('Plugin Packaged!');
});
});
async package() {
try {
const packagePath = await PluginManager.packContent(this.plugin.name, this.plugin.contentPath);
Toasts.success(`Plugin Packaged: ${packagePath}`);
} catch (err) {
Logger.log('PluginCard', err);
}
},
editPlugin() {
try {