2018-01-06 23:09:25 +00:00
|
|
|
const electron = require('electron');
|
|
|
|
const remote = electron.remote;
|
|
|
|
const desktopCapturer = electron.desktopCapturer;
|
|
|
|
const electronScreen = electron.screen;
|
|
|
|
const shell = electron.shell;
|
|
|
|
const dialog = remote.dialog;
|
|
|
|
|
|
|
|
const fs = require('fs');
|
|
|
|
const os = require('os');
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
const screenshot = document.getElementById('screen-shot');
|
|
|
|
const screenshotMsg = document.getElementById('screenshot-path');
|
|
|
|
const pathButton = document.getElementById('path-button');
|
2018-01-07 07:47:34 +00:00
|
|
|
const casenameField = document.getElementById('casename');
|
2018-01-06 23:09:25 +00:00
|
|
|
|
|
|
|
var screenshotPath = '';
|
2018-01-07 07:47:34 +00:00
|
|
|
var caseName = '';
|
2018-01-06 23:09:25 +00:00
|
|
|
|
|
|
|
pathButton.addEventListener('click', function(event) {
|
|
|
|
dialog.showSaveDialog(function(fileName) {
|
|
|
|
if (fileName === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
screenshotPath = fileName;
|
|
|
|
screenshotMsg.textContent = screenshotPath;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
screenshot.addEventListener('click', function(event) {
|
|
|
|
screenshotMsg.textContent = "Gathering screenshot...";
|
|
|
|
const thumbSize = determineScreenShot();
|
|
|
|
let options = { types: ['screen'], thumbnailSize: thumbSize };
|
|
|
|
|
|
|
|
desktopCapturer.getSources(options, function(error, sources) {
|
|
|
|
if (error) return console.log(error.message);
|
|
|
|
|
|
|
|
sources.forEach(function(source) {
|
2018-01-07 07:47:34 +00:00
|
|
|
if (source.name === 'Entire Screen' || source.name === 'Entire screen' || source.name === 'Screen 1') {
|
2018-01-06 23:09:25 +00:00
|
|
|
|
2018-01-07 07:47:34 +00:00
|
|
|
caseName = casenameField.value;
|
2018-01-06 23:09:25 +00:00
|
|
|
if (screenshotPath === '') {
|
2018-01-07 07:47:34 +00:00
|
|
|
timestamp = new Date().getTime();
|
|
|
|
screenshotPath = path.join(os.tmpdir(), caseName+'-'+timestamp+'.png');
|
2018-01-06 23:09:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fs.writeFile(screenshotPath, source.thumbnail.toPng(), function(error) {
|
|
|
|
if (error) return console.log(error.message);
|
|
|
|
|
|
|
|
shell.openExternal('file://' + screenshotPath);
|
|
|
|
var message = 'Saved screenshot to: ' + screenshotPath;
|
|
|
|
screenshotMsg.textContent = message;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function determineScreenShot() {
|
|
|
|
const screenSize = electronScreen.getPrimaryDisplay().workAreaSize;
|
|
|
|
const maxDimension = Math.max(screenSize.width, screenSize.height);
|
|
|
|
return {
|
|
|
|
width: maxDimension * window.devicePixelRatio,
|
|
|
|
height: maxDimension * window.devicePixelRatio
|
|
|
|
};
|
|
|
|
}
|