mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-11-28 19:53:53 -06:00
cda34b1d70
* added idea and coverage directories under gitignore * electron-24: implemented handlers to process protocol actions * electron-17: implemented use case for opening app if it is not open and handle the protocol url * electron-24: added code and documentation comments * electron-24: added unit tests for the protocol handler * added npm-debug log to gitignore * electron-24: added protocol handler support for windows * electron-24: made changes as per comments on the PR * electron-16: added more comments and further refactoring
81 lines
2.0 KiB
JavaScript
81 lines
2.0 KiB
JavaScript
const path = require('path');
|
|
const EventEmitter = require('events');
|
|
|
|
let ipcEmitter = new EventEmitter();
|
|
|
|
// use config provided by test framework
|
|
function pathToConfigDir() {
|
|
return path.join(__dirname, '/../fixtures');
|
|
}
|
|
|
|
// electron app mock...
|
|
const app = {
|
|
getAppPath: pathToConfigDir,
|
|
getPath: function(type) {
|
|
if (type === 'exe') {
|
|
return path.join(pathToConfigDir(), '/Symphony.exe');
|
|
}
|
|
return pathToConfigDir();
|
|
},
|
|
on: function() {
|
|
// no-op
|
|
}
|
|
};
|
|
|
|
// simple ipc mocks for render and main process ipc using
|
|
// nodes' EventEmitter
|
|
const ipcMain = {
|
|
on: function(event, cb) {
|
|
ipcEmitter.on(event, cb);
|
|
},
|
|
send: function (event, args) {
|
|
var senderEvent = {
|
|
sender: {
|
|
send: function (event, arg) {
|
|
ipcEmitter.emit(event, arg);
|
|
}
|
|
}
|
|
};
|
|
ipcEmitter.emit(event, senderEvent, args);
|
|
},
|
|
};
|
|
|
|
const ipcRenderer = {
|
|
sendSync: function(event, args) {
|
|
let listeners = ipcEmitter.listeners(event);
|
|
if (listeners.length > 0) {
|
|
let listener = listeners[0];
|
|
var eventArg = {};
|
|
listener(eventArg, args);
|
|
return eventArg.returnValue;
|
|
}
|
|
return null;
|
|
},
|
|
send: function(event, args) {
|
|
var senderEvent = {
|
|
sender: {
|
|
send: function(event, arg) {
|
|
ipcEmitter.emit(event, arg);
|
|
}
|
|
}
|
|
};
|
|
ipcEmitter.emit(event, senderEvent, args);
|
|
},
|
|
on: function(eventName, cb) {
|
|
ipcEmitter.on(eventName, cb);
|
|
},
|
|
removeListener: function(eventName, cb) {
|
|
ipcEmitter.removeListener(eventName, cb);
|
|
}
|
|
};
|
|
|
|
module.exports = {
|
|
require: jest.genMockFunction(),
|
|
match: jest.genMockFunction(),
|
|
app: jest.genMockFunction(),
|
|
ipcMain: ipcMain,
|
|
ipcRenderer: ipcRenderer,
|
|
remote: jest.genMockFunction(),
|
|
dialog: jest.genMockFunction()
|
|
};
|