forked from khornberg/docker-indicator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
executable file
·68 lines (55 loc) · 1.53 KB
/
Copy pathmain.js
File metadata and controls
executable file
·68 lines (55 loc) · 1.53 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
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
/* jshint esnext: true */
"use strict";
var menubar = require('menubar');
var Docker = require('dockerode');
var docker = require('./src/connect');
var iconPath = __dirname + "/images/icons/";
var mb = menubar({
dir: __dirname + "/src",
preloadWindow: true,
icon: iconPath + "IconTemplate@2x.png",
supportsTrayHighlightState: true
});
var lastConnectionStatus = null;
function down() {
let NativeImage = require('electron').nativeImage;
let image = NativeImage.createFromPath(iconPath + "IconOffTemplate@2x.png");
mb.tray.setImage(image);
lastConnectionStatus = null;
}
function up(){
let NativeImage = require('electron').nativeImage;
let image = NativeImage.createFromPath(iconPath + "IconTemplate@2x.png");
mb.tray.setImage(image);
lastConnectionStatus = 'OK';
}
function setIcon() {
docker.ping((err, data) => {
if (lastConnectionStatus === null && data === null) {
down();
mb.window.webContents.send('send', 'update');
}
if (lastConnectionStatus === null && data == 'OK') {
up();
mb.window.webContents.send('send', 'new-docker');
}
if (lastConnectionStatus === 'OK' && data === null) {
down();
mb.window.webContents.send('send', 'update');
}
});
}
mb.once('show', function () {
// mb.window.openDevTools();
});
mb.on('ready', function ready () {
setIcon();
setInterval(setIcon, 5000);
});
mb.on('show', function () {
//send events to the page
if (lastConnectionStatus == 'OK') {
mb.window.webContents.send('send', 'update');
}
});
//sdg