handle focus event, fix whitespace

This commit is contained in:
Tor Hveem 2016-04-03 13:47:38 +02:00
parent 1d52986bc6
commit 382a5dc5c0

View file

@ -1,27 +1,32 @@
<!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="utf-8">
<script> <script>
onload = function() { onload = function() {
const ipc= require('electron').ipcRenderer; const ipc= require('electron').ipcRenderer;
const remote = require('electron').remote;
const nativeImage = require('electron').nativeImage;
var webview = document.getElementById("glowingbear"); var webview = document.getElementById("glowingbear");
var handleconsole = function(e) { var handleconsole = function(e) {
if(e.message.substring(0,7) == "badge: ") { console.log("webview: " + e.message);
ipc.send('badge', e.message.substring(7));
}else{
console.log("webview: " + e.message);
} }
} var handlenewwindow = function(e) {
var handlenewwindow = function(e) { require('shell').openExternal(e.url);
require('shell').openExternal(e.url); }
} var handletitleset = function(e) {
var handletitleset = function(e) { document.title = e.title;
document.title = e.title; }
} webview.addEventListener("console-message", handleconsole);
webview.addEventListener("console-message", handleconsole); webview.addEventListener("new-window", handlenewwindow);
webview.addEventListener("new-window", handlenewwindow); webview.addEventListener("page-title-set", handletitleset);
webview.addEventListener("page-title-set", handletitleset);
ipc.on('browser-window-focus', function() {
setTimeout(function() { webview.focus(); }, 0);
setTimeout(function() { webview.executeJavaScript("document.getElementById(\"sendMessage\").focus();") }, 0);
});
} }
</script> </script>
</head> </head>