Compare commits
2 Commits
remove_mod
...
metadata_d
| Author | SHA1 | Date | |
|---|---|---|---|
| f80ea86d3b | |||
| 15d7013924 |
@@ -13,10 +13,10 @@
|
||||
<form>
|
||||
<input type="text" id="casename" name="casename" placeholder="Case Name"><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>
|
||||
|
||||
<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="screen-shot" class="btn btn-primary">Take Screenshot</button>
|
||||
</div>
|
||||
|
||||
82
renderer.js
82
renderer.js
@@ -13,22 +13,30 @@ const screenshot = document.getElementById('screen-shot');
|
||||
const screenshotMsg = document.getElementById('screenshot-path');
|
||||
const pathButton = document.getElementById('path-button');
|
||||
const casenameField = document.getElementById('casename');
|
||||
const socialmediaField = document.getElementById('socialmedia');
|
||||
const incidentdescriptionField = document.getElementById('incidentdescription');
|
||||
|
||||
var screenshotPath = '';
|
||||
|
||||
var directoryPath = '';
|
||||
var caseName = '';
|
||||
var socialMedia = '';
|
||||
var incidentDescription = '';
|
||||
|
||||
pathButton.addEventListener('click', function(event) {
|
||||
dialog.showSaveDialog({
|
||||
filters: [
|
||||
{ name: 'png', extensions: ['png'] }
|
||||
dialog.showOpenDialog({
|
||||
title: 'Choose a folder for DocumentIt to save in',
|
||||
buttonLabel: 'Select Path',
|
||||
properties: [
|
||||
'openDirectory',
|
||||
'createDirectory',
|
||||
]
|
||||
},
|
||||
function(fileName) {
|
||||
if (fileName === undefined) {
|
||||
function(paths) {
|
||||
if (paths === undefined || paths.length === 0) {
|
||||
return;
|
||||
}
|
||||
screenshotPath = fileName;
|
||||
screenshotMsg.textContent = screenshotPath;
|
||||
directoryPath = paths[0]; // paths is an array, get the first (only) one
|
||||
screenshotMsg.textContent = "Path: "+directoryPath;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -38,29 +46,71 @@ screenshot.addEventListener('click', function(event) {
|
||||
let options = { types: ['screen'], thumbnailSize: thumbSize };
|
||||
|
||||
desktopCapturer.getSources(options, function(error, sources) {
|
||||
if (error) return console.log(error.message);
|
||||
if (error) return displayError(error.message);
|
||||
|
||||
sources.forEach(function(source) {
|
||||
if (source.name === 'Entire Screen' || source.name === 'Entire screen' || source.name === 'Screen 1') {
|
||||
|
||||
// get values from form
|
||||
caseName = casenameField.value;
|
||||
if (screenshotPath === '') {
|
||||
timestamp = new Date().getTime();
|
||||
screenshotPath = path.join(os.tmpdir(), caseName + '-' + timestamp + '.png');
|
||||
}
|
||||
socialMedia = socialmediaField.value;
|
||||
incidentDescription = incidentdescriptionField.value;
|
||||
|
||||
if (directoryPath === '') return displayError("Please Select a Path to save the screenshot to.");
|
||||
|
||||
timestamp = new Date().getTime();
|
||||
screenshotFilename = caseName + '-' + timestamp + '.png';
|
||||
screenshotPath = path.join(directoryPath, screenshotFilename);
|
||||
|
||||
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);
|
||||
var message = 'Saved screenshot to: ' + screenshotPath;
|
||||
screenshotMsg.textContent = message;
|
||||
screenshotMsg.textContent = 'Saved screenshot to: ' + screenshotPath;
|
||||
|
||||
// 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() {
|
||||
const screenSize = electronScreen.getPrimaryDisplay().workAreaSize;
|
||||
const maxDimension = Math.max(screenSize.width, screenSize.height);
|
||||
|
||||
Reference in New Issue
Block a user