added more styling to index with bootstrap, added desktopcapturer (currently non functioning) to take screenshots, added ability to choose file path to save to

This commit is contained in:
Queen Bee 2018-01-06 15:09:25 -08:00
parent eac7525b8c
commit e1ccfb95a1
2 changed files with 72 additions and 2 deletions

View File

@ -8,9 +8,17 @@
</head>
<body>
<div class="container">
<div class="container window align-content-center">
<h1>DocumentIt</h1>
<div id="output"></div>
<form>
<input type="text" name="casename" placeholder="Case Name"><br>
<input type="text" name="socialmedia" placeholder="Social Media"><br>
<textarea name="description" placeholder="Incident Description..." rows="10" cols="30"></textarea>
</form>
<label id="screenshot-path">Path:</label><br>
<button id="path-button" class="btn btn-warning">Select Path</button><br>
<button id="screen-shot" class="btn btn-primary">Take Screenshot</button>
</div>
</body>
<script>

View File

@ -0,0 +1,62 @@
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');
var screenshotPath = '';
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) {
if (source.name === 'Entire Screen' || source.name === 'Screen 1') {
if (screenshotPath === '') {
screenshotPath = path.join(os.tmpdir(), 'screenshot.png');
}
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
};
}