diff options
Diffstat (limited to 'src/components/layout/Sidebar.tsx')
-rw-r--r-- | src/components/layout/Sidebar.tsx | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/components/layout/Sidebar.tsx b/src/components/layout/Sidebar.tsx index 6fd911a24..498ae4696 100644 --- a/src/components/layout/Sidebar.tsx +++ b/src/components/layout/Sidebar.tsx | |||
@@ -1,3 +1,4 @@ | |||
1 | import { ipcRenderer } from 'electron'; | ||
1 | import { Component } from 'react'; | 2 | import { Component } from 'react'; |
2 | import { Tooltip as ReactTooltip } from 'react-tooltip'; | 3 | import { Tooltip as ReactTooltip } from 'react-tooltip'; |
3 | import { defineMessages, injectIntl, WrappedComponentProps } from 'react-intl'; | 4 | import { defineMessages, injectIntl, WrappedComponentProps } from 'react-intl'; |
@@ -14,8 +15,10 @@ import { | |||
14 | mdiPlusBox, | 15 | mdiPlusBox, |
15 | mdiViewGrid, | 16 | mdiViewGrid, |
16 | mdiViewSplitVertical, | 17 | mdiViewSplitVertical, |
18 | mdiCancel, | ||
17 | } from '@mdi/js'; | 19 | } from '@mdi/js'; |
18 | 20 | ||
21 | import { Circle } from 'rc-progress'; | ||
19 | import Tabbar from '../services/tabs/Tabbar'; | 22 | import Tabbar from '../services/tabs/Tabbar'; |
20 | import { | 23 | import { |
21 | addNewServiceShortcutKey, | 24 | addNewServiceShortcutKey, |
@@ -112,6 +115,10 @@ interface IProps extends WrappedComponentProps { | |||
112 | 115 | ||
113 | interface IState { | 116 | interface IState { |
114 | tooltipEnabled: boolean; | 117 | tooltipEnabled: boolean; |
118 | downloadProgress: { | ||
119 | progress: number; | ||
120 | total: number; | ||
121 | } | null; | ||
115 | } | 122 | } |
116 | 123 | ||
117 | @inject('stores', 'actions') | 124 | @inject('stores', 'actions') |
@@ -122,7 +129,33 @@ class Sidebar extends Component<IProps, IState> { | |||
122 | 129 | ||
123 | this.state = { | 130 | this.state = { |
124 | tooltipEnabled: true, | 131 | tooltipEnabled: true, |
132 | downloadProgress: null, | ||
125 | }; | 133 | }; |
134 | |||
135 | ipcRenderer.on('download-progress', this.handleDownloadProgress); | ||
136 | ipcRenderer.on('download-done', this.handleDownloadDone); | ||
137 | } | ||
138 | |||
139 | handleDownloadProgress = (_event, data) => { | ||
140 | this.setState({ | ||
141 | downloadProgress: { | ||
142 | progress: data.item.receivedBytes, | ||
143 | total: data.item.totalBytes, | ||
144 | }, | ||
145 | }); | ||
146 | }; | ||
147 | |||
148 | handleDownloadDone = (_event, _data) => { | ||
149 | this.setState({ | ||
150 | downloadProgress: null, | ||
151 | }); | ||
152 | }; | ||
153 | |||
154 | componentWillUnmount() { | ||
155 | ipcRenderer.removeListener( | ||
156 | 'download-progress', | ||
157 | this.handleDownloadProgress, | ||
158 | ); | ||
126 | } | 159 | } |
127 | 160 | ||
128 | enableToolTip() { | 161 | enableToolTip() { |
@@ -180,6 +213,13 @@ class Sidebar extends Component<IProps, IState> { | |||
180 | 213 | ||
181 | const { isMenuCollapsed } = stores!.settings.all.app; | 214 | const { isMenuCollapsed } = stores!.settings.all.app; |
182 | 215 | ||
216 | const { downloadProgress } = this.state; | ||
217 | |||
218 | const downloadPercentage = | ||
219 | downloadProgress === null | ||
220 | ? 0 | ||
221 | : (downloadProgress.progress / downloadProgress.total) * 100; | ||
222 | |||
183 | return ( | 223 | return ( |
184 | <div className="sidebar"> | 224 | <div className="sidebar"> |
185 | <Tabbar | 225 | <Tabbar |
@@ -361,6 +401,49 @@ class Sidebar extends Component<IProps, IState> { | |||
361 | )} | 401 | )} |
362 | </button> | 402 | </button> |
363 | ) : null} | 403 | ) : null} |
404 | {downloadProgress !== null && ( | ||
405 | <div | ||
406 | className="download-progress" | ||
407 | style={{ | ||
408 | width: '-webkit-fill-available', | ||
409 | height: 'fit-content', | ||
410 | display: 'flex', | ||
411 | justifyContent: 'center', | ||
412 | margin: 5, | ||
413 | }} | ||
414 | > | ||
415 | <Circle | ||
416 | percent={downloadPercentage} | ||
417 | strokeWidth={10} | ||
418 | strokeColor="#008000" | ||
419 | trailColor="grey" | ||
420 | /> | ||
421 | </div> | ||
422 | )} | ||
423 | <button | ||
424 | type="button" | ||
425 | onClick={() => { | ||
426 | ipcRenderer.send('stop-download'); | ||
427 | this.setState({ | ||
428 | downloadProgress: null, | ||
429 | }); | ||
430 | }} | ||
431 | className="sidebar__button sidebar__button--settings" | ||
432 | data-tooltip-id="tooltip-sidebar-button" | ||
433 | data-tooltip-content={`${intl.formatMessage( | ||
434 | globalMessages.settings, | ||
435 | )} (${settingsShortcutKey(false)})`} | ||
436 | > | ||
437 | <Icon icon={mdiCancel} size={1.5} /> | ||
438 | {stores!.settings.app.automaticUpdates && | ||
439 | (stores!.app.updateStatus === | ||
440 | stores!.app.updateStatusTypes.AVAILABLE || | ||
441 | stores!.app.updateStatus === | ||
442 | stores!.app.updateStatusTypes.DOWNLOADED || | ||
443 | this.props.showServicesUpdatedInfoBar) && ( | ||
444 | <span className="update-available">•</span> | ||
445 | )} | ||
446 | </button> | ||
364 | </div> | 447 | </div> |
365 | ); | 448 | ); |
366 | } | 449 | } |