-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbackground.js
33 lines (30 loc) · 1.06 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
/* Copyright (c) 2019 Parallax Inc., All Rights Reserved. */
// Register listeners to create app window upon application launch and
// to close active serial ports upon application termination
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('index.html', {
id: "BlocklyProp-Launcher",
innerBounds: {
width: 500,
height: 433
}, state: "normal",
resizable: false
}, function(win) {
win.onClosed.addListener(closeSerialPorts);
win.onClosed.addListener(closeServer);
});
});
function closeSerialPorts() {
// Close this app's active serial ports
chrome.serial.getConnections(function(activeConnections) {
activeConnections.forEach(function(port) {
chrome.serial.disconnect(port.connectionId, function() {});
});
});
}
function closeServer() {
// Close this app's active server(s)
chrome.sockets.tcpServer.getSockets(function (socketInfos) {
socketInfos.forEach(function(v) {chrome.sockets.tcpServer.close(v.socketId)});
});
}