Skip to content

Commit a2b5bb1

Browse files
author
Alberto Iannaccone
committed
notify user when IDE new version is available
1 parent 0592199 commit a2b5bb1

File tree

6 files changed

+78
-4
lines changed

6 files changed

+78
-4
lines changed

.vscode/tasks.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"panel": "new",
3636
"clear": false
3737
}
38-
}
38+
},
3939
{
4040
"label": "Arduino IDE - Watch Browser App",
4141
"type": "shell",

arduino-ide-extension/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"@theia/monaco": "next",
2929
"@theia/navigator": "next",
3030
"@theia/outline-view": "next",
31-
"@theia/preferences": "next",
3231
"@theia/output": "next",
32+
"@theia/preferences": "next",
3333
"@theia/search-in-workspace": "next",
3434
"@theia/terminal": "next",
3535
"@theia/workspace": "next",
@@ -48,14 +48,15 @@
4848
"@types/which": "^1.3.1",
4949
"ajv": "^6.5.3",
5050
"async-mutex": "^0.3.0",
51+
"axios": "^0.21.1",
5152
"css-element-queries": "^1.2.0",
5253
"dateformat": "^3.0.3",
5354
"deepmerge": "^4.2.2",
5455
"fuzzy": "^0.1.3",
5556
"glob": "^7.1.6",
5657
"google-protobuf": "^3.11.4",
57-
"lodash.debounce": "^4.0.8",
5858
"js-yaml": "^3.13.1",
59+
"lodash.debounce": "^4.0.8",
5960
"ncp": "^2.0.0",
6061
"p-queue": "^5.0.0",
6162
"ps-tree": "^1.2.0",

arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

+7
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ import { NotificationManager } from './theia/messages/notifications-manager';
217217
import { NotificationManager as TheiaNotificationManager } from '@theia/messages/lib/browser/notifications-manager';
218218
import { NotificationsRenderer as TheiaNotificationsRenderer } from '@theia/messages/lib/browser/notifications-renderer';
219219
import { NotificationsRenderer } from './theia/messages/notifications-renderer';
220+
import { NewVersionNotification } from './contributions/new-version-notification'
221+
import { UpdatesRetriever } from './updates/updates-retriever';
220222

221223
const ElementQueries = require('css-element-queries/src/ElementQueries');
222224

@@ -653,4 +655,9 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
653655
rebind(TheiaNotificationManager).toService(NotificationManager);
654656
bind(NotificationsRenderer).toSelf().inSingletonScope();
655657
rebind(TheiaNotificationsRenderer).toService(NotificationsRenderer);
658+
659+
bind(NewVersionNotification).toSelf().inSingletonScope();
660+
bind(FrontendApplicationContribution).toService(NewVersionNotification);
661+
662+
bind(UpdatesRetriever).toSelf().inSingletonScope();
656663
});

arduino-ide-extension/src/browser/boards/boards-data-menu-updater.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { BoardsDataStore } from './boards-data-store';
1313
import { MainMenuManager } from '../../common/main-menu-manager';
1414
import { ArduinoMenus, unregisterSubmenu } from '../menu/arduino-menus';
1515

16-
@injectable()
16+
@injectable()
1717
export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
1818
@inject(CommandRegistry)
1919
protected readonly commandRegistry: CommandRegistry;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { injectable, inject } from 'inversify';
2+
import { MessageService } from '@theia/core/lib/common/message-service';
3+
import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application';
4+
import { UpdatesRetriever } from '../updates/updates-retriever';
5+
import { shell } from 'electron';
6+
7+
const GO_TO_DOWNLOAD_PAGE = 'Go to download page...';
8+
/**
9+
* Listens on `BoardsConfig.Config` changes, if a board is selected which does not
10+
* have the corresponding core installed, it proposes the user to install the core.
11+
*/
12+
@injectable()
13+
export class NewVersionNotification implements FrontendApplicationContribution {
14+
@inject(UpdatesRetriever)
15+
private readonly updatesRetriever: UpdatesRetriever;
16+
17+
@inject(MessageService)
18+
protected readonly messageService: MessageService;
19+
20+
async onStart(): Promise<void> {
21+
if (await this.updatesRetriever.isUpdateAvailable()) {
22+
this.messageService.info('New Arduino IDE version available.', GO_TO_DOWNLOAD_PAGE).then(async answer => {
23+
if (answer === GO_TO_DOWNLOAD_PAGE) {
24+
shell.openExternal('https://www.arduino.cc/en/software#experimental-software');
25+
}
26+
})
27+
}
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import axios from 'axios';
2+
import { injectable } from 'inversify';
3+
import * as os from 'os';
4+
import { compare } from 'semver';
5+
import { remote } from 'electron';
6+
7+
const BASE_URL = 'https://downloads.arduino.cc';
8+
const LATEST_LOCATION_PARTIAL_URL = `${BASE_URL}/latest-location/arduino-ide/arduino-ide_latest_`;
9+
const LATEST_VERSION_PARTIAL_URL = `${BASE_URL}/arduino-ide/arduino-ide_`;
10+
11+
@injectable()
12+
export class UpdatesRetriever {
13+
public async isUpdateAvailable(): Promise<boolean> {
14+
let filename;
15+
switch (os.type()) {
16+
case 'Linux':
17+
filename = 'Linux_64bit.zip';
18+
break;
19+
case 'Darwin':
20+
filename = 'macOS_64bit.dmg';
21+
break;
22+
case 'Windows_NT':
23+
filename = 'Windows_64bit.exe';
24+
break;
25+
default:
26+
return false;
27+
}
28+
const response = await axios.head(`${LATEST_LOCATION_PARTIAL_URL}${filename}`)
29+
const location = (response.headers?.location as String);
30+
if (location && location.startsWith(LATEST_VERSION_PARTIAL_URL)) {
31+
const latestVersion = location.split('_')[1];
32+
const version = await remote.app.getVersion();
33+
return compare(latestVersion, version) === 1;
34+
}
35+
return false;
36+
}
37+
}

0 commit comments

Comments
 (0)