diff options
author | Muhamed <unknown> | 2022-11-07 01:11:48 +0530 |
---|---|---|
committer | Vijay Aravamudhan <vraravam@users.noreply.github.com> | 2022-11-08 17:25:27 +0530 |
commit | a1f5e31bfce97b4bbe492e24bf7d57ec2803c31a (patch) | |
tree | 881417b8917e8212fcf94547b92bba2701592745 /src/lib | |
parent | 6.2.1-nightly.42 [skip ci] (diff) | |
download | ferdium-app-a1f5e31bfce97b4bbe492e24bf7d57ec2803c31a.tar.gz ferdium-app-a1f5e31bfce97b4bbe492e24bf7d57ec2803c31a.tar.zst ferdium-app-a1f5e31bfce97b4bbe492e24bf7d57ec2803c31a.zip |
refactor: remove toggle component's duplicate
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Tray.ts | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/src/lib/Tray.ts b/src/lib/Tray.ts index 8e489edde..dafbb68aa 100644 --- a/src/lib/Tray.ts +++ b/src/lib/Tray.ts | |||
@@ -20,7 +20,7 @@ const INDICATOR_TRAY_INDIRECT = 'tray-indirect'; | |||
20 | 20 | ||
21 | // TODO: Need to support i18n for a lot of the hard-coded strings in this file | 21 | // TODO: Need to support i18n for a lot of the hard-coded strings in this file |
22 | export default class TrayIcon { | 22 | export default class TrayIcon { |
23 | trayIcon: Tray | null = null; | 23 | tray: Tray | null = null; |
24 | 24 | ||
25 | indicator: string | number = 0; | 25 | indicator: string | number = 0; |
26 | 26 | ||
@@ -97,7 +97,9 @@ export default class TrayIcon { | |||
97 | } | 97 | } |
98 | 98 | ||
99 | _updateTrayMenu(appSettings): void { | 99 | _updateTrayMenu(appSettings): void { |
100 | if (!this.trayIcon) return; | 100 | if (!this.tray) { |
101 | return; | ||
102 | } | ||
101 | 103 | ||
102 | if (appSettings && appSettings.type === 'app') { | 104 | if (appSettings && appSettings.type === 'app') { |
103 | this.isAppMuted = appSettings.data.isAppMuted; // save current state after a change | 105 | this.isAppMuted = appSettings.data.isAppMuted; // save current state after a change |
@@ -105,7 +107,7 @@ export default class TrayIcon { | |||
105 | 107 | ||
106 | this.trayMenu = Menu.buildFromTemplate(this.trayMenuTemplate(this)); | 108 | this.trayMenu = Menu.buildFromTemplate(this.trayMenuTemplate(this)); |
107 | if (isLinux) { | 109 | if (isLinux) { |
108 | this.trayIcon.setContextMenu(this.trayMenu); | 110 | this.tray.setContextMenu(this.trayMenu); |
109 | } | 111 | } |
110 | } | 112 | } |
111 | 113 | ||
@@ -115,26 +117,26 @@ export default class TrayIcon { | |||
115 | } | 117 | } |
116 | 118 | ||
117 | _show(): void { | 119 | _show(): void { |
118 | if (this.trayIcon) { | 120 | if (this.tray) { |
119 | return; | 121 | return; |
120 | } | 122 | } |
121 | 123 | ||
122 | this.trayIcon = new Tray(this._getAsset('tray', INDICATOR_TRAY_PLAIN)); | 124 | this.tray = new Tray(this._getAsset('tray', INDICATOR_TRAY_PLAIN)); |
123 | this.trayIcon.setToolTip('Ferdium'); | 125 | this.tray.setToolTip('Ferdium'); |
124 | 126 | ||
125 | this.trayMenu = Menu.buildFromTemplate(this.trayMenuTemplate(this)); | 127 | this.trayMenu = Menu.buildFromTemplate(this.trayMenuTemplate(this)); |
126 | if (isLinux) { | 128 | if (isLinux) { |
127 | this.trayIcon.setContextMenu(this.trayMenu); | 129 | this.tray.setContextMenu(this.trayMenu); |
128 | } | 130 | } |
129 | 131 | ||
130 | this.trayIcon.on('click', () => { | 132 | this.tray.on('click', () => { |
131 | this._toggleWindow(); | 133 | this._toggleWindow(); |
132 | }); | 134 | }); |
133 | 135 | ||
134 | if (isMac || isWindows) { | 136 | if (isMac || isWindows) { |
135 | this.trayIcon.on('right-click', () => { | 137 | this.tray.on('right-click', () => { |
136 | if (this.trayIcon && this.trayMenu) { | 138 | if (this.tray && this.trayMenu) { |
137 | this.trayIcon.popUpContextMenu(this.trayMenu); | 139 | this.tray.popUpContextMenu(this.trayMenu); |
138 | } | 140 | } |
139 | }); | 141 | }); |
140 | } | 142 | } |
@@ -177,10 +179,10 @@ export default class TrayIcon { | |||
177 | } | 179 | } |
178 | 180 | ||
179 | _hide(): void { | 181 | _hide(): void { |
180 | if (!this.trayIcon) return; | 182 | if (!this.tray) return; |
181 | 183 | ||
182 | this.trayIcon.destroy(); | 184 | this.tray.destroy(); |
183 | this.trayIcon = null; | 185 | this.tray = null; |
184 | 186 | ||
185 | if (isMac && this.themeChangeSubscriberId) { | 187 | if (isMac && this.themeChangeSubscriberId) { |
186 | systemPreferences.unsubscribeNotification(this.themeChangeSubscriberId); | 188 | systemPreferences.unsubscribeNotification(this.themeChangeSubscriberId); |
@@ -216,16 +218,16 @@ export default class TrayIcon { | |||
216 | } | 218 | } |
217 | 219 | ||
218 | _refreshIcon(): void { | 220 | _refreshIcon(): void { |
219 | if (!this.trayIcon) { | 221 | if (!this.tray) { |
220 | return; | 222 | return; |
221 | } | 223 | } |
222 | 224 | ||
223 | this.trayIcon.setImage( | 225 | this.tray.setImage( |
224 | this._getAsset('tray', this._getAssetFromIndicator(this.indicator)), | 226 | this._getAsset('tray', this._getAssetFromIndicator(this.indicator)), |
225 | ); | 227 | ); |
226 | 228 | ||
227 | if (isMac && !macosVersion.isGreaterThanOrEqualTo('11')) { | 229 | if (isMac && !macosVersion.isGreaterThanOrEqualTo('11')) { |
228 | this.trayIcon.setPressedImage( | 230 | this.tray.setPressedImage( |
229 | this._getAsset( | 231 | this._getAsset( |
230 | 'tray', | 232 | 'tray', |
231 | `${this._getAssetFromIndicator(this.indicator)}-active`, | 233 | `${this._getAssetFromIndicator(this.indicator)}-active`, |