summaryrefslogtreecommitdiffhomepage
path: root/app/main.js
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@codeispoetry.ru>2017-03-16 17:04:21 +0000
committerAndrej Mihajlov <and@codeispoetry.ru>2017-03-16 17:04:21 +0000
commite018e522c1aaf085d5933a8b8c67fd8ea09aa26a (patch)
tree567ea4ebbeb0f30c2b8fc2bc80a0c802492936ba /app/main.js
parent62085e0ae04ae601fc8e2eb77a3ef7d8a22801b1 (diff)
downloadmullvadvpn-e018e522c1aaf085d5933a8b8c67fd8ea09aa26a.tar.xz
mullvadvpn-e018e522c1aaf085d5933a8b8c67fd8ea09aa26a.zip
Setup tray animators
Diffstat (limited to 'app/main.js')
-rw-r--r--app/main.js51
1 files changed, 46 insertions, 5 deletions
diff --git a/app/main.js b/app/main.js
index 1d5ba3f91a..582b14c68d 100644
--- a/app/main.js
+++ b/app/main.js
@@ -1,5 +1,6 @@
import path from 'path';
-import { app, crashReporter, BrowserWindow, ipcMain, Tray, Menu, nativeImage } from 'electron';
+import { app, crashReporter, BrowserWindow, ipcMain, Tray, Menu } from 'electron';
+import { TrayAnimation, TrayAnimator } from './lib/tray-animator';
// Override appData path to avoid collisions with old client
// New userData path, i.e on macOS: ~/Library/Application Support/mullvad.vpn
@@ -29,11 +30,51 @@ const stopTrayEventMonitor = () => {
}
};
+const menubarIcons = {
+ base: path.join(__dirname, 'assets/images/menubar icons'),
+ spinner: {
+ light: 'light ui/spinner/spinner-{s}-light.png',
+ dark: 'dark ui/spinner/spinner-{s}-dark.png'
+ },
+ lock: {
+ light: 'light ui/lock/lock-{s}-light.png',
+ dark: 'dark ui/lock/lock-{s}-dark.png'
+ }
+};
+
+const spinnerPath = path.join(menubarIcons.base, menubarIcons.spinner.light);
+const lockPath = path.join(menubarIcons.base, menubarIcons.lock.light);
+
+let trayAnimator = null;
+
ipcMain.on('changeTrayIcon', (event, name) => {
- const iconPath = path.join(__dirname, './assets/images/tray-icon-' + name + '.png');
- const image = nativeImage.createFromPath(iconPath);
- if(image) {
- tray.setImage(image);
+ if(!tray) { return; }
+
+ trayAnimator && trayAnimator.stop();
+ trayAnimator = null;
+
+ console.log('changeTrayIcon: ' + name);
+
+ if(name === 'securing') {
+ let animation = TrayAnimation.fromFileSequence(spinnerPath, [1, 9]);
+ animation.speed = 100;
+ animation.repeat = true;
+
+ trayAnimator = new TrayAnimator(tray, animation);
+ trayAnimator.start();
+ } else if(name === 'secured') {
+ let animation = TrayAnimation.fromFileSequence(lockPath, [1, 9]);
+ animation.speed = 100;
+
+ trayAnimator = new TrayAnimator(tray, animation);
+ trayAnimator.start();
+ } else if(name === 'unsecured') {
+ let animation = TrayAnimation.fromFileSequence(lockPath, [1, 9]);
+ animation.speed = 100;
+ animation.reverse = true;
+
+ trayAnimator = new TrayAnimator(tray, animation);
+ trayAnimator.start();
}
});