mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-01-08 07:03:28 -06:00
2b6ec2aeb8
* ELECTRON-43 - Implemented Alert settings functionality * ELECTRON-43 1. Added multiple monitor support for notifications in windows 2. Implemented a settings window to change notification position 3. Completed implementing configure alert position window * ELECTRON-43 - Refactored code and changed config data * ELECTRON-43 1. Refactored the code 2. Added modal property to browser window * ELECTRON-43 1. Resolved conflicts 2. Made config default display value to null 3. Renamed api method from 'showAlertSettings' to 'showNotificationSettings' for consistency 4. Fixed some bugs
152 lines
4.1 KiB
JavaScript
152 lines
4.1 KiB
JavaScript
'use strict';
|
|
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
const electron = require('electron');
|
|
const BrowserWindow = electron.BrowserWindow;
|
|
const app = electron.app;
|
|
const ipc = electron.ipcMain;
|
|
const log = require('../../log.js');
|
|
const logLevels = require('../../enums/logLevels.js');
|
|
const notify = require('./../electron-notify');
|
|
const eventEmitter = require('./../../eventEmitter');
|
|
|
|
const { updateConfigField } = require('../../config');
|
|
|
|
let configurationWindow;
|
|
let screens;
|
|
let position;
|
|
let display;
|
|
|
|
let windowConfig = {
|
|
width: 460,
|
|
height: 360,
|
|
show: false,
|
|
modal: true,
|
|
autoHideMenuBar: true,
|
|
resizable: false,
|
|
webPreferences: {
|
|
preload: path.join(__dirname, 'configure-notification-position-preload.js'),
|
|
sandbox: true,
|
|
nodeIntegration: false
|
|
}
|
|
};
|
|
|
|
app.on('ready', () => {
|
|
screens = electron.screen.getAllDisplays();
|
|
|
|
// if display added/removed update the list of screens
|
|
electron.screen.on('display-added', updateScreens);
|
|
electron.screen.on('display-removed', updateScreens);
|
|
});
|
|
|
|
function updateScreens() {
|
|
screens = electron.screen.getAllDisplays();
|
|
|
|
// Notifying renderer when a display is added/removed
|
|
if (configurationWindow && screens && screens.length >= 0) {
|
|
configurationWindow.webContents.send('screens', screens);
|
|
}
|
|
}
|
|
|
|
function getTemplatePath() {
|
|
let templatePath = path.join(__dirname, 'configure-notification-position.html');
|
|
try {
|
|
fs.statSync(templatePath).isFile();
|
|
} catch (err) {
|
|
log.send(logLevels.ERROR, 'configure-notification-position: Could not find template ("' + templatePath + '").');
|
|
}
|
|
return 'file://' + templatePath;
|
|
}
|
|
|
|
function openConfigurationWindow(windowName) {
|
|
let allWindows = BrowserWindow.getAllWindows();
|
|
allWindows = allWindows.find((window) => { return window.winName === windowName });
|
|
|
|
// if we couldn't find any window matching the window name
|
|
// it will render as a new window
|
|
if (allWindows) {
|
|
windowConfig.parent = allWindows;
|
|
}
|
|
|
|
configurationWindow = new BrowserWindow(windowConfig);
|
|
configurationWindow.setVisibleOnAllWorkspaces(true);
|
|
configurationWindow.loadURL(getTemplatePath());
|
|
|
|
configurationWindow.once('ready-to-show', () => {
|
|
configurationWindow.show();
|
|
});
|
|
|
|
configurationWindow.webContents.on('did-finish-load', () => {
|
|
if (screens && screens.length >= 0) {
|
|
configurationWindow.webContents.send('screens', screens);
|
|
}
|
|
configurationWindow.webContents.send('notificationSettings', {position: position, display: display});
|
|
});
|
|
|
|
configurationWindow.on('close', () => {
|
|
destroyWindow();
|
|
});
|
|
|
|
configurationWindow.on('closed', () => {
|
|
destroyWindow();
|
|
});
|
|
}
|
|
|
|
function destroyWindow() {
|
|
configurationWindow = null;
|
|
}
|
|
|
|
/**
|
|
* Method to save 'position' & 'display' to the config file
|
|
*/
|
|
function updateConfig() {
|
|
let settings = {
|
|
position: position,
|
|
display: display
|
|
};
|
|
updateConfigField('notificationSettings', settings);
|
|
updateNotification(position, display);
|
|
}
|
|
|
|
/**
|
|
* Method to update the Notification class with the new 'position' & 'screen'
|
|
* @param mPosition - position to display the notifications
|
|
* ('upper-right, upper-left, lower-right, lower-left')
|
|
* @param mDisplay - id of the selected display
|
|
*/
|
|
function updateNotification(mPosition, mDisplay) {
|
|
notify.updateConfig({position: mPosition, display: mDisplay});
|
|
notify.reset();
|
|
}
|
|
|
|
ipc.on('close-alert', function () {
|
|
configurationWindow.close();
|
|
});
|
|
|
|
ipc.on('update-config', (event, config) => {
|
|
|
|
if (config) {
|
|
if (config.position) {
|
|
position = config.position;
|
|
}
|
|
if (config.display) {
|
|
display = config.display;
|
|
}
|
|
}
|
|
|
|
updateConfig();
|
|
});
|
|
|
|
/**
|
|
* Event to read 'Position' & 'Display' from config and
|
|
* updated the configuration view
|
|
*/
|
|
eventEmitter.on('notificationSettings', (notificationSettings) => {
|
|
position = notificationSettings.position;
|
|
display = notificationSettings.display;
|
|
});
|
|
|
|
module.exports = {
|
|
openConfigurationWindow: openConfigurationWindow
|
|
}; |