|
1 | 1 | import { AppUpgradeError } from '../../../../../../../../../shared/daemon-rpc-types';
|
2 | 2 | import { messages } from '../../../../../../../../../shared/gettext';
|
3 |
| -import { useAppUpgradeEvent } from '../../../../../hooks'; |
| 3 | +import { |
| 4 | + useAppUpgradeEvent, |
| 5 | + useGetHasAppUpgradeError, |
| 6 | + useIsAppUpgradeDownloaded, |
| 7 | +} from '../../../../../hooks'; |
4 | 8 |
|
5 | 9 | export const useText = () => {
|
6 |
| - const event = useAppUpgradeEvent(); |
| 10 | + const appUpgradeEvent = useAppUpgradeEvent(); |
| 11 | + const isAppUpgradeDownloaded = useIsAppUpgradeDownloaded(); |
| 12 | + const getHasAppUpgradeError = useGetHasAppUpgradeError(); |
7 | 13 |
|
8 |
| - // TODO: Handle more cases when we should present 'Install Update' and |
9 |
| - // do it better/more concise than here. |
10 |
| - if (event?.type) { |
11 |
| - if (event.type === 'APP_UPGRADE_EVENT_ERROR') { |
12 |
| - if (event.error === AppUpgradeError.startInstallerFailed) { |
13 |
| - return messages.pgettext('download-update-view', 'Install update'); |
14 |
| - } |
15 |
| - } |
16 |
| - |
17 |
| - if (event.type === 'APP_UPGRADE_EVENT_ABORTED') { |
18 |
| - const upgradeDownloaded = false; |
19 |
| - if (upgradeDownloaded) { |
20 |
| - // TRANSLATORS: Button text to install an update |
21 |
| - return messages.pgettext('download-update-view', 'Install update'); |
22 |
| - } |
| 14 | + if (isAppUpgradeDownloaded) { |
| 15 | + const appUpgradeEventAborted = appUpgradeEvent?.type === 'APP_UPGRADE_EVENT_ABORTED'; |
| 16 | + const hasErrorStartInstallerFailed = getHasAppUpgradeError( |
| 17 | + AppUpgradeError.startInstallerFailed, |
| 18 | + ); |
| 19 | + if (appUpgradeEventAborted || hasErrorStartInstallerFailed) { |
| 20 | + // TRANSLATORS: Button text to install an update |
| 21 | + return messages.pgettext('download-update-view', 'Install update'); |
23 | 22 | }
|
24 | 23 | }
|
25 | 24 |
|
26 |
| - switch (event?.type) { |
27 |
| - case 'APP_UPGRADE_EVENT_ABORTED': |
28 |
| - // TRANSLATORS: Button text to install an update |
29 |
| - return messages.pgettext('download-update-view', 'Install update'); |
30 |
| - case 'APP_UPGRADE_EVENT_STARTING_INSTALLER': |
31 |
| - case 'APP_UPGRADE_EVENT_DOWNLOAD_PROGRESS': |
32 |
| - case 'APP_UPGRADE_EVENT_DOWNLOAD_STARTED': |
33 |
| - case 'APP_UPGRADE_EVENT_VERIFYING_INSTALLER': |
34 |
| - // TRANSLATORS: Button text to cancel the download of an update |
35 |
| - return messages.pgettext('download-update-view', 'Cancel'); |
36 |
| - default: |
37 |
| - // TRANSLATORS: Button text to download and install an update |
38 |
| - return messages.pgettext('download-update-view', 'Download and install'); |
| 25 | + if (appUpgradeEvent?.type === 'APP_UPGRADE_EVENT_ERROR') { |
| 26 | + // TRANSLATORS: Button text to retry download of an update |
| 27 | + return messages.pgettext('download-update-view', 'Retry download'); |
39 | 28 | }
|
| 29 | + |
| 30 | + // TRANSLATORS: Button text to download and install an update |
| 31 | + return messages.pgettext('download-update-view', 'Download and install'); |
40 | 32 | };
|
0 commit comments