-
Notifications
You must be signed in to change notification settings - Fork 32
/
eventPage.js
120 lines (101 loc) · 4.42 KB
/
eventPage.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
If an id is also specified and a window with a matching id has been shown before, the remembered bounds of the window will be used instead.
*/
'use strict';
function startApplication() {
var applicationStartTime = new Date().getTime();
chrome.app.window.create('main.html', {
id: 'main-window',
frame: 'chrome',
innerBounds: {
minWidth: 960,
minHeight: 625
}
}, function (createdWindow) {
createdWindow.contentWindow.addEventListener('load', function () {
createdWindow.contentWindow.catch_startup_time(applicationStartTime);
});
createdWindow.onClosed.addListener(function() {
// connectionId is passed from the script side through the contentWindow refference
// allowing us to automatically close the port when application shut down
// save connectionId in separate variable before main window is destroyed
var connectionId = createdWindow.contentWindow.serial.connectionId;
var operatingMode = createdWindow.contentWindow.GUI.operating_mode;
if (connectionId) {
if (operatingMode == 3) {
var bufferOut = new ArrayBuffer(6);
var bufView = new Uint8Array(bufferOut);
bufView[0] = 0x23;
bufView[1] = 0x31;
bufView[2] = 0x2C;
bufView[3] = 0x2C;
bufView[4] = 0x2C;
bufView[5] = 0x2C;
chrome.serial.send(connectionId, bufferOut, function (writeInfo) {
if (writeInfo.bytesSent > 0) {
console.log('SERIAL: Leaving scanner mode');
}
});
}
setTimeout(function () {
// We will try to "close" the CLI menu
var bufferOut = new ArrayBuffer(7);
var bufView = new Uint8Array(bufferOut);
bufView[0] = 0xB5;
bufView[1] = 0x62;
bufView[2] = 199;
bufView[3] = 0x01;
bufView[4] = 0x00;
bufView[5] = 0x01;
bufView[6] = bufView[2] ^ bufView[3] ^ bufView[4] ^ bufView[5];
// after ESC char is sent out, we close the connection
chrome.serial.send(connectionId, bufferOut, function (writeInfo) {
if (writeInfo.bytesSent > 0) {
console.log('SERIAL: Exit command send');
chrome.serial.disconnect(connectionId, function (result) {
console.log('SERIAL: Connection closed - ' + result);
});
}
});
}, 50);
}
});
});
}
chrome.app.runtime.onLaunched.addListener(startApplication);
chrome.runtime.onInstalled.addListener(function (details) {
if (details.reason == 'update') {
var previousVersionArr = details.previousVersion.split('.'),
currentVersionArr = getManifestVersion().split('.');
// only fire up notification sequence when one of the major version numbers changed
if (currentVersionArr[0] > previousVersionArr[0] || currentVersionArr[1] > previousVersionArr[1]) {
var manifest = chrome.runtime.getManifest();
var options = {
priority: 0,
type: 'basic',
title: manifest.name,
message: chrome.i18n.getMessage('notifications_app_just_updated_to_version', [getManifestVersion(manifest)]),
iconUrl: '/images/icon_128.png',
buttons: [{'title': chrome.i18n.getMessage('notifications_click_here_to_start_app')}]
};
chrome.notifications.create('openlrsng_update', options, function (notificationId) {
// empty
});
}
}
});
chrome.notifications.onButtonClicked.addListener(function (notificationId, buttonIndex) {
if (notificationId == 'openlrsng_update') {
startApplication();
}
});
function getManifestVersion(manifest) {
if (!manifest) {
manifest = chrome.runtime.getManifest();
}
var version = manifest.version_name;
if (!version) {
version = manifest.version;
}
return version;
};