Skip to content

Commit a5a6a0b

Browse files
author
Alberto Iannaccone
authored
Go to download page when automatic update fails (#871)
* add preference to set a custom update url * go to download page when update fails * fix i18n check
1 parent 2a27a14 commit a5a6a0b

File tree

5 files changed

+156
-85
lines changed

5 files changed

+156
-85
lines changed
Lines changed: 135 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { WindowService } from '@theia/core/lib/browser/window/window-service';
12
import { nls } from '@theia/core/lib/common';
23
import { shell } from 'electron';
34
import * as React from 'react';
@@ -8,6 +9,7 @@ import ProgressBar from '../../components/ProgressBar';
89

910
export type IDEUpdaterComponentProps = {
1011
updateInfo: UpdateInfo;
12+
windowService: WindowService;
1113
downloadFinished?: boolean;
1214
downloadStarted?: boolean;
1315
progress?: ProgressInfo;
@@ -22,6 +24,7 @@ export const IDEUpdaterComponent = ({
2224
updateInfo: { version, releaseNotes },
2325
downloadStarted = false,
2426
downloadFinished = false,
27+
windowService,
2528
progress,
2629
error,
2730
onDownload,
@@ -62,98 +65,147 @@ export const IDEUpdaterComponent = ({
6265
</button>
6366
);
6467

65-
return (
66-
<div className="ide-updater-dialog--content">
67-
{downloadFinished ? (
68-
<div className="ide-updater-dialog--downloaded">
69-
<div>
70-
{nls.localize(
71-
'arduino/ide-updater/versionDownloaded',
72-
'Arduino IDE {0} has been downloaded.',
73-
version
74-
)}
75-
</div>
76-
<div>
68+
const DownloadCompleted: () => React.ReactElement = () => (
69+
<div className="ide-updater-dialog--downloaded">
70+
<div>
71+
{nls.localize(
72+
'arduino/ide-updater/versionDownloaded',
73+
'Arduino IDE {0} has been downloaded.',
74+
version
75+
)}
76+
</div>
77+
<div>
78+
{nls.localize(
79+
'arduino/ide-updater/closeToInstallNotice',
80+
'Close the software and install the update on your machine.'
81+
)}
82+
</div>
83+
<div className="buttons-container">
84+
{closeButton}
85+
<button
86+
onClick={onCloseAndInstall}
87+
type="button"
88+
className="theia-button close-and-install"
89+
>
90+
{nls.localize(
91+
'arduino/ide-updater/closeAndInstallButton',
92+
'Close and Install'
93+
)}
94+
</button>
95+
</div>
96+
</div>
97+
);
98+
99+
const DownloadStarted: () => React.ReactElement = () => (
100+
<div className="ide-updater-dialog--downloading">
101+
<div>
102+
{nls.localize(
103+
'arduino/ide-updater/downloadingNotice',
104+
'Downloading the latest version of the Arduino IDE.'
105+
)}
106+
</div>
107+
<ProgressBar percent={progress?.percent} showPercentage />
108+
</div>
109+
);
110+
111+
const PreDownload: () => React.ReactElement = () => (
112+
<div className="ide-updater-dialog--pre-download">
113+
<div className="ide-updater-dialog--logo-container">
114+
<div className="ide-updater-dialog--logo"></div>
115+
</div>
116+
<div className="ide-updater-dialog--new-version-text dialogSection">
117+
<div className="dialogRow">
118+
<div className="bold">
77119
{nls.localize(
78-
'arduino/ide-updater/closeToInstallNotice',
79-
'Close the software and install the update on your machine.'
120+
'arduino/ide-updater/updateAvailable',
121+
'Update Available'
80122
)}
81123
</div>
82-
<div className="buttons-container">
83-
{closeButton}
84-
<button
85-
onClick={onCloseAndInstall}
86-
type="button"
87-
className="theia-button close-and-install"
88-
>
89-
{nls.localize(
90-
'arduino/ide-updater/closeAndInstallButton',
91-
'Close and Install'
92-
)}
93-
</button>
94-
</div>
95124
</div>
96-
) : downloadStarted ? (
97-
<div className="ide-updater-dialog--downloading">
98-
<div>
99-
{nls.localize(
100-
'arduino/ide-updater/downloadingNotice',
101-
'Downloading the latest version of the Arduino IDE.'
102-
)}
103-
</div>
104-
<ProgressBar percent={progress?.percent} showPercentage />
125+
<div className="dialogRow">
126+
{nls.localize(
127+
'arduino/ide-updater/newVersionAvailable',
128+
'A new version of Arduino IDE ({0}) is available for download.',
129+
version
130+
)}
105131
</div>
106-
) : (
107-
<div className="ide-updater-dialog--pre-download">
108-
<div className="ide-updater-dialog--logo-container">
109-
<div className="ide-updater-dialog--logo"></div>
132+
{releaseNotes && (
133+
<div className="dialogRow">
134+
<div className="changelog-container" ref={changelogDivRef} />
110135
</div>
111-
<div className="ide-updater-dialog--new-version-text dialogSection">
112-
<div className="dialogRow">
113-
<div className="bold">
114-
{nls.localize(
115-
'arduino/ide-updater/updateAvailable',
116-
'Update Available'
117-
)}
118-
</div>
119-
</div>
120-
<div className="dialogRow">
121-
{nls.localize(
122-
'arduino/ide-updater/newVersionAvailable',
123-
'A new version of Arduino IDE ({0}) is available for download.',
124-
version
125-
)}
126-
</div>
127-
{releaseNotes && (
128-
<div className="dialogRow">
129-
<div className="changelog-container" ref={changelogDivRef} />
130-
</div>
136+
)}
137+
<div className="buttons-container">
138+
<button
139+
onClick={onSkipVersion}
140+
type="button"
141+
className="theia-button secondary skip-version"
142+
>
143+
{nls.localize(
144+
'arduino/ide-updater/skipVersionButton',
145+
'Skip Version'
131146
)}
132-
<div className="buttons-container">
133-
<button
134-
onClick={onSkipVersion}
135-
type="button"
136-
className="theia-button secondary skip-version"
137-
>
138-
{nls.localize(
139-
'arduino/ide-updater/skipVersionButton',
140-
'Skip Version'
141-
)}
142-
</button>
143-
<div className="push"></div>
144-
{closeButton}
145-
<button
146-
onClick={onDownload}
147-
type="button"
148-
className="theia-button primary"
149-
>
150-
{nls.localize('arduino/ide-updater/downloadButton', 'Download')}
151-
</button>
152-
</div>
153-
</div>
147+
</button>
148+
<div className="push"></div>
149+
{closeButton}
150+
<button
151+
onClick={onDownload}
152+
type="button"
153+
className="theia-button primary"
154+
>
155+
{nls.localize('arduino/ide-updater/downloadButton', 'Download')}
156+
</button>
154157
</div>
158+
</div>
159+
</div>
160+
);
161+
162+
const onGoToDownloadClick = (
163+
event: React.SyntheticEvent<HTMLAnchorElement, Event>
164+
) => {
165+
const { target } = event.nativeEvent;
166+
if (target instanceof HTMLAnchorElement) {
167+
event.nativeEvent.preventDefault();
168+
windowService.openNewWindow(target.href, { external: true });
169+
onClose();
170+
}
171+
};
172+
173+
const GoToDownloadPage: () => React.ReactElement = () => (
174+
<div className="ide-updater-dialog--go-to-download-page">
175+
<div>
176+
{nls.localize(
177+
'arduino/ide-updater/goToDownloadPage',
178+
"An update for the Arduino IDE is available, but we're not able to download and install it automatically. Please go to the download page and download the latest version from there."
179+
)}
180+
</div>
181+
<div className="buttons-container">
182+
{closeButton}
183+
<a
184+
className="theia-button primary"
185+
href="https://www.arduino.cc/en/software#experimental-software"
186+
onClick={onGoToDownloadClick}
187+
>
188+
{nls.localize(
189+
'arduino/ide-updater/goToDownloadButton',
190+
'Go To Download'
191+
)}
192+
</a>
193+
</div>
194+
</div>
195+
);
196+
197+
return (
198+
<div className="ide-updater-dialog--content">
199+
{!!error ? (
200+
<GoToDownloadPage />
201+
) : downloadFinished ? (
202+
<DownloadCompleted />
203+
) : downloadStarted ? (
204+
<DownloadStarted />
205+
) : (
206+
<PreDownload />
155207
)}
156-
{!!error && <div className="error-container">{error}</div>}
208+
{/* {!!error && <div className="error-container">{error}</div>} */}
157209
</div>
158210
);
159211
};

arduino-ide-extension/src/browser/dialogs/ide-updater/ide-updater-dialog.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from '../../../common/protocol/ide-updater';
1616
import { LocalStorageService } from '@theia/core/lib/browser';
1717
import { SKIP_IDE_VERSION } from '../../arduino-frontend-contribution';
18+
import { WindowService } from '@theia/core/lib/browser/window/window-service';
1819

1920
@injectable()
2021
export class IDEUpdaterDialogWidget extends ReactWidget {
@@ -35,6 +36,9 @@ export class IDEUpdaterDialogWidget extends ReactWidget {
3536
@inject(LocalStorageService)
3637
protected readonly localStorageService: LocalStorageService;
3738

39+
@inject(WindowService)
40+
protected windowService: WindowService;
41+
3842
init(updateInfo: UpdateInfo, onClose: () => void): void {
3943
this.updateInfo = updateInfo;
4044
this.progressInfo = undefined;
@@ -92,9 +96,11 @@ export class IDEUpdaterDialogWidget extends ReactWidget {
9296
<form>
9397
<IDEUpdaterComponent
9498
updateInfo={this.updateInfo}
99+
windowService={this.windowService}
95100
downloadStarted={this.downloadStarted}
96101
downloadFinished={this.downloadFinished}
97102
progress={this.progressInfo}
103+
error={this.error}
98104
onClose={this.close.bind(this)}
99105
onSkipVersion={this.onSkipVersion.bind(this)}
100106
onDownload={this.onDownload.bind(this)}

arduino-ide-extension/src/browser/style/ide-updater-dialog.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@
6262
margin-top: 28px;
6363
}
6464

65+
.ide-updater-dialog .buttons-container a.theia-button {
66+
text-decoration: none;
67+
display: flex;
68+
align-items: center;
69+
justify-content: center;
70+
}
71+
72+
.ide-updater-dialog .buttons-container a.theia-button:hover {
73+
color: var(--theia-button-foreground);
74+
}
75+
6576
.ide-updater-dialog .buttons-container .push {
6677
margin-right: auto;
6778
}

arduino-ide-extension/src/electron-main/ide-updater/ide-updater-impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class IDEUpdaterImpl implements IDEUpdater {
104104
await this.updater.downloadUpdate(this.cancellationToken);
105105
} catch (e) {
106106
if (e.message === 'cancelled') return;
107-
throw e;
107+
this.clients.forEach((c) => c.notifyError(e));
108108
}
109109
}
110110

i18n/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,9 @@
264264
"updateAvailable": "Update Available",
265265
"newVersionAvailable": "A new version of Arduino IDE ({0}) is available for download.",
266266
"skipVersionButton": "Skip Version",
267-
"downloadButton": "Download"
267+
"downloadButton": "Download",
268+
"goToDownloadPage": "An update for the Arduino IDE is available, but we're not able to download and install it automatically. Please go to the download page and download the latest version from there.",
269+
"goToDownloadButton": "Go To Download"
268270
},
269271
"updater": {
270272
"ideUpdaterDialog": "Software Update"

0 commit comments

Comments
 (0)