-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
53 lines (47 loc) · 1.35 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* Listens for the app launching, then creates the window.
*
* @see http://developer.chrome.com/apps/app.runtime.html
* @see http://developer.chrome.com/apps/app.window.html
*/
var webview;
var callback;
var email;
var socketId = null;
function logout(cb) {
console.log("Logout callback");
callback = cb;
}
chrome.app.runtime.onLaunched.addListener(function(launchData) {
var screenWidth = screen.availWidth;
var screenHeight = screen.availHeight;
var targetOrigin = "http://cati.kwest.co/pair";
chrome.app.window.create(
'index.html',
{
id: 'mainWindowCATI',
state: "fullscreen"
},
function(win) {
win.contentWindow.addEventListener("load", function(){
webview = win.contentWindow.document.getElementById("catiWebView");
webview.src = targetOrigin;
webview.addEventListener("loadstop", function(){
win.contentWindow.document.addEventListener("message", function() {
console.log("Window Msg ");
});
});
});
}
);
});
chrome.runtime.onSuspend.addListener(function() {
// Close the socket if closing
if (socketId) {
chrome.bluetoothSocket.disconnect(socketId);
}
// Tell the system we are closing the app
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", "http://cati.kwest.co/closing?email="+email);
xmlhttp.send();
});