Skip to content

Commit 0bc3c1d

Browse files
author
Alberto Iannaccone
committed
notify user when IDE new version is available
1 parent 2a3873a commit 0bc3c1d

File tree

7 files changed

+78
-5
lines changed

7 files changed

+78
-5
lines changed

Diff for: .vscode/settings.json

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"tslint.enable": true,
33
"tslint.configFile": "./tslint.json",
4-
"editor.formatOnSave": true,
54
"files.exclude": {
65
"**/lib": false
76
},

Diff for: .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",

Diff for: 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",

Diff for: arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

+7
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ import { NotificationManager } from './theia/messages/notifications-manager';
163163
import { NotificationManager as TheiaNotificationManager } from '@theia/messages/lib/browser/notifications-manager';
164164
import { NotificationsRenderer as TheiaNotificationsRenderer } from '@theia/messages/lib/browser/notifications-renderer';
165165
import { NotificationsRenderer } from './theia/messages/notifications-renderer';
166+
import { NewVersionNotification } from './contributions/new-version-notification'
167+
import { UpdatesRetriever } from './updates/updates-retriever';
166168

167169
const ElementQueries = require('css-element-queries/src/ElementQueries');
168170

@@ -448,4 +450,9 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
448450
rebind(TheiaNotificationManager).toService(NotificationManager);
449451
bind(NotificationsRenderer).toSelf().inSingletonScope();
450452
rebind(TheiaNotificationsRenderer).toService(NotificationsRenderer);
453+
454+
bind(NewVersionNotification).toSelf().inSingletonScope();
455+
bind(FrontendApplicationContribution).toService(NewVersionNotification);
456+
457+
bind(UpdatesRetriever).toSelf().inSingletonScope();
451458
});

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

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

13-
@injectable()
13+
@injectable()
1414
export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
1515

1616
@inject(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() || true) {
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)