Require path before screenshot; auto-name files within folder, no user-selected filenames.

This commit is contained in:
Will Bradley 2018-04-15 23:34:23 -07:00
parent a9e08b4451
commit 15d7013924
2 changed files with 25 additions and 16 deletions

View File

@ -16,7 +16,7 @@
<textarea id="description" name="description" placeholder="Incident Description..." rows="10" cols="30"></textarea> <textarea id="description" name="description" placeholder="Incident Description..." rows="10" cols="30"></textarea>
</form> </form>
<label id="screenshot-path">Path:</label><br> <label id="screenshot-path">Path: NONE</label><br>
<button id="path-button" class="btn btn-primary">Select Path</button><br> <button id="path-button" class="btn btn-primary">Select Path</button><br>
<button id="screen-shot" class="btn btn-primary">Take Screenshot</button> <button id="screen-shot" class="btn btn-primary">Take Screenshot</button>
</div> </div>

View File

@ -14,21 +14,24 @@ const screenshotMsg = document.getElementById('screenshot-path');
const pathButton = document.getElementById('path-button'); const pathButton = document.getElementById('path-button');
const casenameField = document.getElementById('casename'); const casenameField = document.getElementById('casename');
var screenshotPath = ''; var directoryPath = '';
var caseName = ''; var caseName = '';
pathButton.addEventListener('click', function(event) { pathButton.addEventListener('click', function(event) {
dialog.showSaveDialog({ dialog.showOpenDialog({
filters: [ title: 'Choose a folder for DocumentIt to save in',
{ name: 'png', extensions: ['png'] } buttonLabel: 'Select Path',
properties: [
'openDirectory',
'createDirectory',
] ]
}, },
function(fileName) { function(paths) {
if (fileName === undefined) { if (paths === undefined || paths.length === 0) {
return; return;
} }
screenshotPath = fileName; directoryPath = paths[0]; // paths is an array, get the first (only) one
screenshotMsg.textContent = screenshotPath; screenshotMsg.textContent = "Path: "+directoryPath;
}); });
}); });
@ -38,29 +41,35 @@ screenshot.addEventListener('click', function(event) {
let options = { types: ['screen'], thumbnailSize: thumbSize }; let options = { types: ['screen'], thumbnailSize: thumbSize };
desktopCapturer.getSources(options, function(error, sources) { desktopCapturer.getSources(options, function(error, sources) {
if (error) return console.log(error.message); if (error) return displayError(error.message);
sources.forEach(function(source) { sources.forEach(function(source) {
if (source.name === 'Entire Screen' || source.name === 'Entire screen' || source.name === 'Screen 1') { if (source.name === 'Entire Screen' || source.name === 'Entire screen' || source.name === 'Screen 1') {
caseName = casenameField.value; caseName = casenameField.value;
if (screenshotPath === '') { if (directoryPath === '') {
timestamp = new Date().getTime(); return displayError("Please Select a Path to save the screenshot to.");
screenshotPath = path.join(os.tmpdir(), caseName + '-' + timestamp + '.png');
} }
timestamp = new Date().getTime();
screenshotPath = path.join(directoryPath, caseName + '-' + timestamp + '.png');
fs.writeFile(screenshotPath, source.thumbnail.toPng(), function(error) { fs.writeFile(screenshotPath, source.thumbnail.toPng(), function(error) {
if (error) return console.log(error.message); if (error) return displayError(error.message);
shell.openExternal('file://' + screenshotPath); shell.openExternal('file://' + screenshotPath);
var message = 'Saved screenshot to: ' + screenshotPath; screenshotMsg.textContent = 'Saved screenshot to: ' + screenshotPath;
screenshotMsg.textContent = message;
}) })
} }
}); });
}); });
}); });
function displayError(message) {
screenshotMsg.textContent = "ERROR: "+message;
return console.log(message);
}
function determineScreenShot() { function determineScreenShot() {
const screenSize = electronScreen.getPrimaryDisplay().workAreaSize; const screenSize = electronScreen.getPrimaryDisplay().workAreaSize;
const maxDimension = Math.max(screenSize.width, screenSize.height); const maxDimension = Math.max(screenSize.width, screenSize.height);