diff options
author | 2022-11-07 06:27:57 +0530 | |
---|---|---|
committer | 2022-11-07 00:57:57 +0000 | |
commit | dd238ae7949e72e3b90235f56e14686cc5231f34 (patch) | |
tree | 4f63ef38367c9aacfe39028a68a74705bb8954fa /src/lib/Tray.ts | |
parent | Transform tray & menu files to typescript (#740) (diff) | |
download | ferdium-app-dd238ae7949e72e3b90235f56e14686cc5231f34.tar.gz ferdium-app-dd238ae7949e72e3b90235f56e14686cc5231f34.tar.zst ferdium-app-dd238ae7949e72e3b90235f56e14686cc5231f34.zip |
Remove duplicated Toggle.js component (#741)
Diffstat (limited to 'src/lib/Tray.ts')
-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`, |