2018-01-10 17:02:29 +01:00
|
|
|
'use strict';
|
|
|
|
|
2018-01-10 21:48:10 +01:00
|
|
|
/**
|
|
|
|
* BetterDiscord IPC Module
|
|
|
|
* Copyright (c) 2015-present JsSucks - https://github.com/JsSucks
|
|
|
|
* All rights reserved.
|
|
|
|
* https://github.com/JsSucks - https://betterdiscord.net
|
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*/
|
|
|
|
const { Module } = require('./modulebase');
|
|
|
|
|
2018-01-10 17:02:29 +01:00
|
|
|
const { ipcMain } = require('electron');
|
|
|
|
|
2018-01-10 21:48:10 +01:00
|
|
|
class BDIpcEvent extends Module {
|
2018-01-10 17:02:29 +01:00
|
|
|
|
|
|
|
constructor(event, args) {
|
2018-01-10 21:48:10 +01:00
|
|
|
super(args);
|
2018-01-10 17:02:29 +01:00
|
|
|
this.ipcEvent = event;
|
|
|
|
}
|
|
|
|
|
|
|
|
bindings() {
|
|
|
|
this.send = this.send.bind(this);
|
|
|
|
this.reply = this.reply.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
send(message) {
|
2018-01-10 21:48:10 +01:00
|
|
|
this.ipcEvent.sender.send(this.args.__eid, message);
|
2018-01-10 17:02:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
reply(message) {
|
|
|
|
this.send(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class BDIpc {
|
|
|
|
|
|
|
|
static on(channel, cb) {
|
|
|
|
ipcMain.on(channel, (event, args) => cb(new BDIpcEvent(event, args)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { BDIpc };
|