summaryrefslogtreecommitdiffhomepage
path: root/app/lib
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@codeispoetry.ru>2017-06-06 19:02:04 +0300
committerAndrej Mihajlov <and@codeispoetry.ru>2017-06-08 23:06:53 +0300
commitd0205e776de41e87cd8d107d1ecb4e8a55e5023d (patch)
treec43aa429b8a71284f4521f28867dc763ee4ee2eb /app/lib
parent6cf1beb51454d32065f049e50c6ab4dba55ce0b7 (diff)
downloadmullvadvpn-d0205e776de41e87cd8d107d1ecb4e8a55e5023d.tar.xz
mullvadvpn-d0205e776de41e87cd8d107d1ecb4e8a55e5023d.zip
Add type annotations for TrayIconManager
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/tray-icon-manager.js88
1 files changed, 30 insertions, 58 deletions
diff --git a/app/lib/tray-icon-manager.js b/app/lib/tray-icon-manager.js
index eb242deb6b..73424cb7ef 100644
--- a/app/lib/tray-icon-manager.js
+++ b/app/lib/tray-icon-manager.js
@@ -1,85 +1,57 @@
-import assert from 'assert';
+// @flow
import path from 'path';
-import { TrayIconType } from '../enums';
import KeyframeAnimation from './keyframe-animation';
-/**
- * Tray icon manager
- *
- * @export
- * @class TrayIconManager
- */
+import type { Tray } from 'electron';
+
+export type TrayIconType = 'unsecured' | 'securing' | 'secured';
+
export default class TrayIconManager {
- /**
- * Creates an instance of TrayIconManager.
- * @param {Electron.Tray} tray
- *
- * @memberOf TrayIconManager
- */
- constructor(tray) {
- assert(tray, 'Tray icon cannot be null');
+ _animation: ?KeyframeAnimation;
+ _iconType: TrayIconType;
- const basePath = path.join(path.resolve(__dirname, '..'), 'assets/images/menubar icons');
- let filePath = path.join(basePath, 'lock-{}.png');
- let animation = KeyframeAnimation.fromFilePattern(filePath, [1, 9]);
+ constructor(tray: Tray, initialType: TrayIconType) {
+ const animation = this._createAnimation();
animation.onFrame = (img) => tray.setImage(img);
- animation.speed = 100;
+ animation.reverse = this._isReverseAnimation(initialType);
+ animation.play({ advanceTo: 'end' });
this._animation = animation;
- this._iconType = null;
+ this._iconType = initialType;
}
- /**
- * Destroy manager
- * @memberOf TrayIconManager
- */
destroy() {
if(this._animation) {
this._animation.stop();
this._animation = null;
}
- this._iconType = null;
}
- /**
- * Get current icon type
- * @type {TrayIconType}
- * @memberOf TrayIconManager
- */
- get iconType() {
- return this._iconType;
+ _createAnimation(): KeyframeAnimation {
+ const basePath = path.join(path.resolve(__dirname, '..'), 'assets/images/menubar icons');
+ const filePath = path.join(basePath, 'lock-{}.png');
+ const animation = KeyframeAnimation.fromFilePattern(filePath, [1, 9]);
+ animation.speed = 100;
+ return animation;
}
- /**
- * Set current icon type
- * @type {TrayIconType}
- * @memberOf TrayIconManager
- */
- set iconType(type) {
- assert(TrayIconType.isValid(type), 'Invalid icon type');
+ _isReverseAnimation(type: TrayIconType): bool {
+ // unsecured & securing are treated as one
+ return type !== 'secured';
+ }
- // no-op if the same type
- if(this._iconType === type) {
- return;
- }
+ get iconType(): TrayIconType {
+ return this._iconType;
+ }
- let options = { beginFromCurrentState: true };
- if(this._iconType === null) {
- options.advanceTo = 'end';
- }
+ set iconType(type: TrayIconType) {
+ if(this._iconType === type || !this._animation) { return; }
- switch(type) {
- case TrayIconType.secured:
- this._animation.reverse = false;
- break;
- case TrayIconType.securing:
- case TrayIconType.unsecured:
- this._animation.reverse = true;
- break;
- }
+ const animation = this._animation;
+ animation.reverse = this._isReverseAnimation(type);
+ animation.play({ beginFromCurrentState: true });
- this._animation.play(options);
this._iconType = type;
}