-
-
Notifications
You must be signed in to change notification settings - Fork 431
[ATL-813] Notify user when IDE new version is available #422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { injectable, inject } from 'inversify'; | ||
import { MessageService } from '@theia/core/lib/common/message-service'; | ||
import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application'; | ||
import { UpdatesRetriever } from '../updates/updates-retriever'; | ||
import { shell } from 'electron'; | ||
|
||
const GO_TO_DOWNLOAD_PAGE = 'Go to download page...'; | ||
/** | ||
* Listens on `BoardsConfig.Config` changes, if a board is selected which does not | ||
* have the corresponding core installed, it proposes the user to install the core. | ||
*/ | ||
@injectable() | ||
export class NewVersionNotification implements FrontendApplicationContribution { | ||
@inject(UpdatesRetriever) | ||
private readonly updatesRetriever: UpdatesRetriever; | ||
|
||
@inject(MessageService) | ||
protected readonly messageService: MessageService; | ||
|
||
async onStart(): Promise<void> { | ||
if (await this.updatesRetriever.isUpdateAvailable()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fstasi @AlbyIanna |
||
this.messageService.info('New Arduino IDE version available.', GO_TO_DOWNLOAD_PAGE).then(async answer => { | ||
if (answer === GO_TO_DOWNLOAD_PAGE) { | ||
shell.openExternal('https://www.arduino.cc/en/software#experimental-software'); | ||
} | ||
}) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import axios from 'axios'; | ||
import { injectable } from 'inversify'; | ||
import * as os from 'os'; | ||
import { compare } from 'semver'; | ||
import { remote } from 'electron'; | ||
|
||
const BASE_URL = 'https://downloads.arduino.cc'; | ||
const LATEST_LOCATION_PARTIAL_URL = `${BASE_URL}/latest-location/arduino-ide/arduino-ide_latest_`; | ||
const LATEST_VERSION_PARTIAL_URL = `${BASE_URL}/arduino-ide/arduino-ide_`; | ||
|
||
@injectable() | ||
export class UpdatesRetriever { | ||
public async isUpdateAvailable(): Promise<boolean> { | ||
let filename; | ||
switch (os.type()) { | ||
case 'Linux': | ||
filename = 'Linux_64bit.zip'; | ||
break; | ||
case 'Darwin': | ||
filename = 'macOS_64bit.dmg'; | ||
break; | ||
case 'Windows_NT': | ||
filename = 'Windows_64bit.exe'; | ||
break; | ||
default: | ||
return false; | ||
} | ||
const response = await axios.head(`${LATEST_LOCATION_PARTIAL_URL}${filename}`) | ||
const location = (response.headers?.location as String); | ||
if (location && location.startsWith(LATEST_VERSION_PARTIAL_URL)) { | ||
const latestVersion = location.split('_')[1]; | ||
const version = await remote.app.getVersion(); | ||
return compare(latestVersion, version) === 1; | ||
} | ||
return false; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlbyIanna I love axios, but are we sure we want to add another dependency when we have something somehow similar? (
"request": "^2.82.0"
should be included already)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you're right. I initially decided to use axios before the API was returning 403 and using
request
I couldn't handle the response properly, but now the API is not returning 403 anymore so I can change this.