2 Commits

2 changed files with 68 additions and 18 deletions

View File

@@ -13,10 +13,10 @@
<form> <form>
<input type="text" id="casename" name="casename" placeholder="Case Name"><br> <input type="text" id="casename" name="casename" placeholder="Case Name"><br>
<input type="text" id="socialmedia" name="socialmedia" placeholder="Social Media"><br> <input type="text" id="socialmedia" name="socialmedia" placeholder="Social Media"><br>
<textarea id="description" name="description" placeholder="Incident Description..." rows="10" cols="30"></textarea> <textarea id="incidentdescription" name="incidentdescription" 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

@@ -13,22 +13,30 @@ const screenshot = document.getElementById('screen-shot');
const screenshotMsg = document.getElementById('screenshot-path'); 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');
const socialmediaField = document.getElementById('socialmedia');
const incidentdescriptionField = document.getElementById('incidentdescription');
var screenshotPath = '';
var directoryPath = '';
var caseName = ''; var caseName = '';
var socialMedia = '';
var incidentDescription = '';
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 +46,71 @@ 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') {
// get values from form
caseName = casenameField.value; caseName = casenameField.value;
if (screenshotPath === '') { socialMedia = socialmediaField.value;
incidentDescription = incidentdescriptionField.value;
if (directoryPath === '') return displayError("Please Select a Path to save the screenshot to.");
timestamp = new Date().getTime(); timestamp = new Date().getTime();
screenshotPath = path.join(os.tmpdir(), caseName + '-' + timestamp + '.png'); screenshotFilename = caseName + '-' + timestamp + '.png';
} screenshotPath = path.join(directoryPath, screenshotFilename);
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;
// if file was written, save to db as well
updateDatabase(directoryPath, screenshotFilename, caseName, socialMedia, incidentDescription);
}) })
} }
}); });
}); });
}); });
function updateDatabase(directoryPath, screenshotFilename, caseName, socialMedia, incidentDescription) {
// open/read db
dbPath = path.join(directoryPath, "documentit-data.json");
try {
dbContents = fs.readFileSync(dbPath, {encoding: "utf8"});
} catch (err) {
console.log(err);
console.log("Unable to open database, starting new db.");
dbContents = "{}"; // file doesn't exist, create blank JSON
}
var database = JSON.parse(dbContents);
// init db if not init'd
// "cases" parent object
if (!database.hasOwnProperty('cases')) database.cases = {};
// each case is indexed by name (TODO: help users avoid typo'd case names)
if (!database.cases.hasOwnProperty(caseName)) database.cases[caseName] = {};
now = new Date(); // screenshots are indexed by unix timestamp
database.cases[caseName][now.getTime()] = {
'date': now.toLocaleString(), // human-readable duplicate of index time
'socialMedia': socialMedia,
'incidentDescription': incidentDescription,
'screenshotFilename': screenshotFilename
};
// write db. stringify with two spaces for human-readability
fs.writeFileSync(dbPath, JSON.stringify(database, null, ' '));
}
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);