-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrowser-api.html
More file actions
38 lines (33 loc) · 1 KB
/
browser-api.html
File metadata and controls
38 lines (33 loc) · 1 KB
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
<!DOCTYPE html>
<html>
<body>
<script>
const ipcRenderer = require('electron').ipcRenderer;
var updateOnlineStatus = function() {
ipcRenderer.send('online-status-changed', navigator.onLine ? 'online' : 'offline');
};
window.addEventListener('online', updateOnlineStatus);
window.addEventListener('offline', updateOnlineStatus);
updateOnlineStatus();
function gotPositionCallback(position)
{
var result = { coords: {}, timestamp: position.timestamp };
['latitude', 'longitude', 'altitude', 'accuracy', 'altitudeAccuracy', 'heading', 'speed']
.forEach(function(prop)
{
result.coords[prop] = position.coords[prop];
});
ipcRenderer.send('got-current-position', result);
}
function geolocation(fun, options)
{
return navigator.geolocation[fun](gotPositionCallback,
function(error)
{
ipcRenderer.send('error-getting-current-position', { code: error.code, message: error.message });
},
options);
};
</script>
</body>
</html>