Fix native open dialogs and attach the save packed content window as a modal

This commit is contained in:
Samuel Elliott 2019-03-28 12:32:13 +00:00
parent aa55072323
commit 3eb9105daa
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
2 changed files with 28 additions and 17 deletions

View File

@ -16,7 +16,7 @@ import { remote } from 'electron';
import Content from './content';
import Globals from './globals';
import Database from './database';
import { Utils, FileUtils, ClientLogger as Logger } from 'common';
import { Utils, FileUtils, ClientLogger as Logger, ClientIPC } from 'common';
import { SettingsSet, ErrorEvent } from 'structs';
import { Modals } from 'ui';
import Combokeys from 'combokeys';
@ -73,23 +73,23 @@ export default class {
}
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;
const filepath = await ClientIPC.send('bd-native-save', {
title: 'Save Package',
defaultPath: path,
filters: [
{
name: 'BetterDiscord Package',
extensions: ['bd']
}
]
});
asar.uncache(filepath);
asar.createPackage(contentPath, filepath, () => {
resolve(filepath);
});
if (!filepath) return;
return new Promise((resolve, reject) => {
asar.uncache(filepath);
asar.createPackage(contentPath, filepath, () => {
resolve(filepath);
});
});
}

View File

@ -82,6 +82,12 @@ class Comms {
});
});
BDIpc.on('bd-native-save', (event, options) => {
dialog.showSaveDialog(OriginalBrowserWindow.fromWebContents(event.ipcEvent.sender), options, filename => {
event.reply(filename);
});
});
BDIpc.on('bd-compileSass', (event, options) => {
if (typeof options.path === 'string' && typeof options.data === 'string') {
options.data = `${options.data} @import '${options.path.replace(/\\/g, '\\\\').replace(/'/g, '\\\'')}';`;
@ -196,6 +202,11 @@ class BrowserWindow extends OriginalBrowserWindow {
}
}
// Some Electron APIs depend on browserWindow.constructor being BrowserWindow
Object.defineProperty(BrowserWindow.prototype, 'constructor', {
value: OriginalBrowserWindow
});
export class BetterDiscord {
get comms() { return this._comms ? this._comms : (this._commas = new Comms(this)); }