diff options
| author | Andrej Mihajlov <and@codeispoetry.ru> | 2017-03-17 17:43:38 +0000 |
|---|---|---|
| committer | Andrej Mihajlov <and@codeispoetry.ru> | 2017-03-17 17:43:38 +0000 |
| commit | e1fc38b58291df6592ed4615791eb2c6511c1092 (patch) | |
| tree | f0bcb91db1249e81e82513cc806b362d8c0a68c1 /app/lib | |
| parent | 8931eedcdfaf02c30769c76db96c273cff666448 (diff) | |
| download | mullvadvpn-e1fc38b58291df6592ed4615791eb2c6511c1092.tar.xz mullvadvpn-e1fc38b58291df6592ed4615791eb2c6511c1092.zip | |
Drop spinner and update assets
Diffstat (limited to 'app/lib')
| -rw-r--r-- | app/lib/tray-icon-manager.js | 42 | ||||
| -rw-r--r-- | app/lib/tray-icon-provider.js | 95 |
2 files changed, 19 insertions, 118 deletions
diff --git a/app/lib/tray-icon-manager.js b/app/lib/tray-icon-manager.js index e22ac231f2..987698a23d 100644 --- a/app/lib/tray-icon-manager.js +++ b/app/lib/tray-icon-manager.js @@ -26,8 +26,6 @@ export default class TrayIconManager { this._iconProvider = iconProvider; this._animator = null; this._iconType = null; - - iconProvider.on(TrayIconProvider.EventType.themeChanged, this._onThemeChange); } /** @@ -40,15 +38,6 @@ export default class TrayIconManager { this._animator = null; } this._iconType = null; - this._iconProvider.removeListener(TrayIconProvider.EventType.themeChanged, this._onThemeChange); - } - - /** - * Event handler for notification when menubar theme is changed. - * @memberOf TrayIconManager - */ - _onThemeChange = () => { - this._updateType(this._iconType, true); } /** @@ -66,7 +55,7 @@ export default class TrayIconManager { * @memberOf TrayIconManager */ set iconType(type) { - this.updateIconType(type, false); + this._updateIconType(type); } /** @@ -78,12 +67,20 @@ export default class TrayIconManager { * * @memberOf TrayIconManager */ - updateIconType(type, skipAnimation) { + _updateIconType(type) { // no-op if same animator requested if(this._iconType === type) { return; } + // skip animation if: + // 1. there was no icon set before (which is usually when app starts) + // 2. unsecured -> securing + // 3. securing -> unsecured + const skip = this._iconType === null || + type === TrayIconType.securing || // unsecured -> securing + (type === TrayIconType.unsecured && this._iconType === TrayIconType.securing); // securing -> unsecured + // do not animate if setting icon for the first time - this._updateType(type, this._iconType === null || skipAnimation); + this._updateType(type, skip); } /** @@ -98,7 +95,7 @@ export default class TrayIconManager { switch(type) { case TrayIconType.secured: return this._iconProvider.lockAnimation(); case TrayIconType.unsecured: return this._iconProvider.unlockAnimation(); - case TrayIconType.securing: return this._iconProvider.spinnerAnimation(); + case TrayIconType.securing: return this._iconProvider.unlockAnimation(); } } @@ -121,19 +118,10 @@ export default class TrayIconManager { this._animator = null; } - switch(type) { - case TrayIconType.secured: - case TrayIconType.unsecured: - if(skipAnimation) { - animator.advanceToEnd(); - } else { - animator.start(); - } - break; - - case TrayIconType.securing: + if(skipAnimation) { + animator.advanceToEnd(); + } else { animator.start(); - break; } this._animator = animator; diff --git a/app/lib/tray-icon-provider.js b/app/lib/tray-icon-provider.js index 66f926a8c6..aa50a71a71 100644 --- a/app/lib/tray-icon-provider.js +++ b/app/lib/tray-icon-provider.js @@ -1,19 +1,11 @@ import path from 'path'; import { EventEmitter } from 'events'; -import { systemPreferences } from 'electron'; import TrayAnimation from './tray-animation'; import Enum from './enum'; const menubarIcons = { base: path.join(path.resolve(__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' - } + lock: 'lock-{s}.png' }; /** @@ -22,39 +14,7 @@ const menubarIcons = { * @export * @class TrayIconProvider */ -export default class TrayIconProvider extends EventEmitter { - - /** - * EventType - * @type {TrayIconProvider.EventType} - * @property {string} themeChanged - event fired when menubar theme is changed - */ - static EventType = new Enum('themeChanged'); - - /** - * Creates an instance of TrayIconProvider. - * - * @memberOf TrayIconProvider - */ - constructor() { - super(); - - this._themeChangeObserver = systemPreferences.subscribeNotification('AppleInterfaceThemeChangedNotification', () => { - this.emit(TrayIconProvider.EventType.themeChanged); - }); - } - - /** - * Destroys TrayIconProvider - * - * @memberOf TrayIconProvider - */ - destroy() { - if(this._themeChangeObserver) { - systemPreferences.unsubscribeNotification(this._themeChangeObserver); - this._themeChangeObserver = null; - } - } +export default class TrayIconProvider { /** * Get lock animation @@ -65,7 +25,8 @@ export default class TrayIconProvider extends EventEmitter { * @memberOf TrayIconProvider */ lockAnimation(isReverse = false) { - let animation = TrayAnimation.fromFileSequence(this._lockPath, [1, 9]); + let filePath = path.join(menubarIcons.base, menubarIcons.lock); + let animation = TrayAnimation.fromFileSequence(filePath, [1, 9]); animation.speed = 100; animation.reverse = isReverse; @@ -83,52 +44,4 @@ export default class TrayIconProvider extends EventEmitter { return this.lockAnimation(true); } - /** - * Get spinner animation - * - * @returns TrayIconAnimator - * - * @memberOf TrayIconProvider - */ - spinnerAnimation() { - let animation = TrayAnimation.fromFileSequence(this._spinnerPath, [1, 9]); - animation.speed = 100; - animation.repeat = true; - - return animation; - } - - /** - * Pattern to spinner animation assets based on macOS menubar theme - * - * @readonly - * - * @memberOf TrayIconProvider - */ - get _spinnerPath() { - return path.join(menubarIcons.base, menubarIcons.spinner[this._colorTheme]); - } - - /** - * Pattern to lock/unlock animation assets based on macOS menubar theme - * - * @readonly - * - * @memberOf TrayIconProvider - */ - get _lockPath() { - return path.join(menubarIcons.base, menubarIcons.lock[this._colorTheme]); - } - - /** - * Current theme name based on macOS menubar theme. - * - * @readonly - * - * @memberOf TrayIconProvider - */ - get _colorTheme() { - return systemPreferences.isDarkMode() ? 'dark' : 'light'; - } - }
\ No newline at end of file |
