mirror of
https://github.com/finos/SymphonyElectron.git
synced 2026-07-29 15:55:55 -05:00
Merge pull request #193 from KiranNiranjan/ELECTRON-142
Electron-142 (App version menu item)
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>About Symphony</title>
|
||||
<style>
|
||||
html, body {
|
||||
margin: 0;
|
||||
height: 100%;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
.name {
|
||||
flex: 1;
|
||||
font-size: 1.3em;
|
||||
padding: 10px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.version-text {
|
||||
flex: 1;
|
||||
font-size: 1em;
|
||||
color: #2f2f2f;
|
||||
}
|
||||
|
||||
.copyright-text {
|
||||
flex: 1;
|
||||
padding: 10px;
|
||||
font-size: 0.6em;
|
||||
color: #7f7f7f;
|
||||
}
|
||||
|
||||
.content {
|
||||
text-align: center;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding-top: 20px
|
||||
}
|
||||
|
||||
.logo {
|
||||
margin: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="content">
|
||||
<img class="logo" src="symphony-logo.png">
|
||||
<span id="app-name" class="name">Symphony</span>
|
||||
<span id="version" class="version-text"></span>
|
||||
<span id="copyright" class="copyright-text"></span>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,83 @@
|
||||
'use strict';
|
||||
|
||||
const electron = require('electron');
|
||||
const BrowserWindow = electron.BrowserWindow;
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const log = require('../log.js');
|
||||
const logLevels = require('../enums/logLevels.js');
|
||||
|
||||
let aboutWindow;
|
||||
|
||||
let windowConfig = {
|
||||
width: 350,
|
||||
height: 260,
|
||||
show: false,
|
||||
modal: true,
|
||||
autoHideMenuBar: true,
|
||||
titleBarStyle: true,
|
||||
resizable: false,
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, 'renderer.js'),
|
||||
sandbox: true,
|
||||
nodeIntegration: false
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* method to get the HTML template path
|
||||
* @returns {string}
|
||||
*/
|
||||
function getTemplatePath() {
|
||||
let templatePath = path.join(__dirname, 'about-app.html');
|
||||
try {
|
||||
fs.statSync(templatePath).isFile();
|
||||
} catch (err) {
|
||||
log.send(logLevels.ERROR, 'about-window: Could not find template ("' + templatePath + '").');
|
||||
}
|
||||
return 'file://' + templatePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the about application window for a specific window
|
||||
* @param {String} windowName - name of the window upon
|
||||
* which this window should show
|
||||
*/
|
||||
function openAboutWindow(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;
|
||||
}
|
||||
|
||||
aboutWindow = new BrowserWindow(windowConfig);
|
||||
aboutWindow.setVisibleOnAllWorkspaces(true);
|
||||
aboutWindow.loadURL(getTemplatePath());
|
||||
|
||||
aboutWindow.once('ready-to-show', () => {
|
||||
aboutWindow.show();
|
||||
});
|
||||
|
||||
aboutWindow.on('close', () => {
|
||||
destroyWindow();
|
||||
});
|
||||
|
||||
aboutWindow.on('closed', () => {
|
||||
destroyWindow();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys a window
|
||||
*/
|
||||
function destroyWindow() {
|
||||
aboutWindow = null;
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
openAboutWindow: openAboutWindow
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
const { remote } = require('electron');
|
||||
|
||||
renderDom();
|
||||
|
||||
/**
|
||||
* Method that renders application data
|
||||
*/
|
||||
function renderDom() {
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const applicationName = remote.app.getName() || 'Symphony';
|
||||
const version = remote.app.getVersion();
|
||||
let appName = document.getElementById('app-name');
|
||||
let versionText = document.getElementById('version');
|
||||
let copyright = document.getElementById('copyright');
|
||||
|
||||
appName.innerHTML = applicationName;
|
||||
versionText.innerHTML = version ? `Version ${version} (${version})` : null;
|
||||
copyright.innerHTML = `Copyright © ${new Date().getFullYear()} ${applicationName}`
|
||||
});
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.1 KiB |
@@ -7,6 +7,7 @@ const isMac = require('../utils/misc.js').isMac;
|
||||
const log = require('../log.js');
|
||||
const logLevels = require('../enums/logLevels.js');
|
||||
const eventEmitter = require('../eventEmitter');
|
||||
const aboutApp = require('../aboutApp');
|
||||
|
||||
let minimizeOnClose = false;
|
||||
let launchOnStartup = false;
|
||||
@@ -246,6 +247,15 @@ function getTemplate(app) {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
// This adds About Symphony under help menu for windows
|
||||
template[3].submenu.push({
|
||||
label: 'About Symphony',
|
||||
click(focusedWindow) {
|
||||
let windowName = focusedWindow ? focusedWindow.name : '';
|
||||
aboutApp.openAboutWindow(windowName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return template;
|
||||
|
||||
Reference in New Issue
Block a user