add About dialog

This commit is contained in:
jjavierdguezas 2020-05-29 18:15:08 +02:00
parent d5bc371913
commit f1c92d0363
2 changed files with 57 additions and 1 deletions

View file

@ -1,5 +1,9 @@
// @flow
import {app, dialog, Menu, shell, BrowserWindow} from 'electron';
import {app, dialog, Menu, shell, BrowserWindow, clipboard} from 'electron';
import * as os from 'os';
import { pkg } from './utils/generalUtils'
const path = require('path');
export default class MenuBuilder {
mainWindow: BrowserWindow;
@ -43,6 +47,45 @@ export default class MenuBuilder {
shell.openExternal('https://twitter.com/ResponsivelyApp');
},
},
{
label: 'About',
click() {
const iconPath = path.join(__dirname, '../resources/icons/64x64.png')
const title = 'Responsively';
const description = pkg.description;
const version = pkg.version || 'Unknown';
const electron = process.versions['electron'] || 'Unknown';
const chrome = process.versions['chrome'] || 'Unknown';
const node = process.versions['node'] || 'Unknown';
const v8 = process.versions['v8'] || 'Unknown';
const osText = `${os.type()} ${os.arch()} ${os.release()}`.trim() || 'Unknown';
const usefulInfo = `Version: ${version}\nElectron: ${electron}\nChrome: ${chrome}\nNode.js: ${node}\nV8: ${v8}\nOS: ${osText}`;
const detail = description? `${description}\n\n${usefulInfo}` : usefulInfo;
let buttons = ['OK', 'Copy'];
let cancelId = 0;
let defaultId = 1;
if (process.platform === 'linux') {
buttons = ['Copy', 'OK'];
cancelId = 1;
defaultId = 0;
}
dialog.showMessageBox(BrowserWindow.getAllWindows()[0], {
type: 'none',
buttons,
title,
message: title,
detail,
noLink: true,
icon: iconPath,
cancelId,
defaultId
}).then(({response }) => {
if (response === defaultId) {
clipboard.writeText(usefulInfo, 'clipboard');
}
});
},
},
],
};

View file

@ -1,5 +1,18 @@
import {app} from 'electron';
const path = require('path');
const fs = require('fs')
const emailRE = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
export function validateEmail(email) {
return emailRE.test(String(email).toLowerCase());
}
export function getPackageJson() {
const appPath = process.env.NODE_ENV === 'production' ? app.getAppPath() : path.join(__dirname, '..', '..');
const pkgContent = fs.readFileSync(path.join(appPath, 'package.json'));
return JSON.parse(pkgContent);
}
const pkg = getPackageJson();
export { pkg };