Skip to content

Instantly share code, notes, and snippets.

@candidosales
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save candidosales/0381112ea350612a3261 to your computer and use it in GitHub Desktop.
Save candidosales/0381112ea350612a3261 to your computer and use it in GitHub Desktop.
var app = require('app'), // Module to control application life.
BrowserWindow = require('browser-window'); // Module to create native browser window.
path = require('path'),
ipc = require('ipc'),
hashes = require('jshashes'),
mime = require('mime'),
fs = require('fs'),
exec = require('child_process').exec;
userName = process.env.USERNAME,
domain = process.env.USERDOMAIN,
palitagemRef = process.env.PALITAGEM_REF || '172.30.5.123';
//
// SHA512 = new hashes.SHA512,
// loginId = path.join(domain,userName),
// loginSHA = SHA512.hex(loginId);
// Report crashes to our server.
require('crash-reporter').start();
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the javascript object is GCed.
var mainWindow = null;
// Quit when all windows are closed.
app.on('window-all-closed', function() {
if (process.platform != 'darwin')
app.quit();
});
// Desabilitar http cache
app.commandLine.appendSwitch('disable-http-cache');
// This method will be called when Electron has done everything
// initialization and ready for creating browser windows.
app.on('ready', function() {
// Create the browser window.
mainWindow = new BrowserWindow({width: 400, height: 650 });
mainWindow.loadUrl('file://' + __dirname + '/index.html');
mainWindow.openDevTools();
//mainWindow.loadUrl('http://' + palitagemRef + '/registro-chamadas/autenticacao?u=' + userName + '&d=' + domain + '&_t=' + Date.now());
ipc.on('screenshot.electron', function(event, arg) {
console.log('electron screenshot', arg);
var pathPhoto = __dirname + '\\evidencia-' + arg + '.png';
var prevTitle = mainWindow.getTitle(), tempTitle = "____PALITAGEM" + Date.now();
mainWindow.setTitle(tempTitle);
exec('nircmd.exe win trans ititle "' + tempTitle + '" 0', function () {
exec('nircmd.exe savescreenshot ' + pathPhoto, function () {
if (fs.existsSync(pathPhoto)) {
console.log("Init SS");
// var photo = { mimeType: mime.lookup(pathPhoto), base64: null };
fs.readFile(pathPhoto, function (err, original) {
console.log("FileRead DONE");
if (!err) {
//photo.base64 = original.toString('base64');
mainWindow.webContents.send('screenshot.final', original.toString('base64'), 'evidencia-' + arg + '.png', mime.lookup(pathPhoto));
}
else {
console.log("Sending event screenshot.error...");
mainWindow.webContents.send('screenshot.error', err);
}
});
}
exec('nircmd.exe win trans ititle "' + tempTitle + '" 255', function () {
mainWindow.setTitle(prevTitle);
});
});
});
});
// Emitted when the window is closed.
mainWindow.on('closed', function() {
mainWindow = null;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment