-
-
Notifications
You must be signed in to change notification settings - Fork 446
Prevent overwriting existing libraries and platforms at first IDE start-up #1169
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
121aa67
move initialization of libs and platforms into new contribution
42283ba
use noOverwrite when install built-in libraries and platform
9236f2e
catch errors when installing platforms and libraries at first start-up
1b214e7
arduino-cli version 0.25.0-rc1
cd9719e
refine platforms and libraries initialization in case of errors
6c4482f
add trailing newline when libraries and platform installation fail
68bc78a
use regex to check error if builtin library dependencies are already …
28b5732
rename contribution
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
arduino-ide-extension/src/browser/contributions/init-libs-platforms.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { LocalStorageService } from '@theia/core/lib/browser'; | ||
import { inject, injectable } from '@theia/core/shared/inversify'; | ||
import { BoardsService, LibraryService } from '../../common/protocol'; | ||
import { Contribution } from './contribution'; | ||
|
||
@injectable() | ||
export class InitLibsPlatforms extends Contribution { | ||
@inject(LocalStorageService) | ||
private readonly localStorageService: LocalStorageService; | ||
@inject(BoardsService) | ||
private readonly boardsService: BoardsService; | ||
@inject(LibraryService) | ||
private readonly libraryService: LibraryService; | ||
|
||
override async onReady(): Promise<void> { | ||
const isFirstStartup = !(await this.localStorageService.getData( | ||
InitLibsPlatforms.INIT_LIBS_AND_PACKAGES | ||
)); | ||
if (isFirstStartup) { | ||
const avrPackage = await this.boardsService.getBoardPackage({ | ||
id: 'arduino:avr', | ||
}); | ||
const builtInLibrary = ( | ||
await this.libraryService.search({ query: 'Arduino_BuiltIn' }) | ||
)[0]; | ||
|
||
let avrPackageError: Error | undefined; | ||
let builtInLibraryError: Error | undefined; | ||
|
||
if (avrPackage) { | ||
try { | ||
await this.boardsService.install({ | ||
item: avrPackage, | ||
noOverwrite: true, // We don't want to automatically replace custom platforms the user might already have in place | ||
}); | ||
} catch (e) { | ||
// There's no error code, I need to parse the error message: https://github.com/arduino/arduino-cli/commit/ffe4232b359fcfa87238d68acf1c3b64a1621f14#diff-10ffbdde46838dd9caa881fd1f2a5326a49f8061f6cfd7c9d430b4875a6b6895R62 | ||
if ( | ||
e.message.includes( | ||
`Platform ${avrPackage.id}@${avrPackage.installedVersion} already installed` | ||
) | ||
) { | ||
// If arduino:avr installation fails because it's already installed we don't want to retry on next start-up | ||
console.error(e); | ||
} else { | ||
// But if there is any other error (e.g.: no interntet cconnection), we want to retry next time | ||
avrPackageError = e; | ||
} | ||
} | ||
} else { | ||
avrPackageError = new Error('Could not find platform.'); | ||
} | ||
|
||
if (builtInLibrary) { | ||
try { | ||
await this.libraryService.install({ | ||
item: builtInLibrary, | ||
installDependencies: true, | ||
noOverwrite: true, // We don't want to automatically replace custom libraries the user might already have in place | ||
}); | ||
} catch (e) { | ||
// There's no error code, I need to parse the error message: https://github.com/arduino/arduino-cli/commit/2ea3608453b17b1157f8a1dc892af2e13e40f4f0#diff-1de7569144d4e260f8dde0e0d00a4e2a218c57966d583da1687a70d518986649R95 | ||
if ( | ||
e.message.includes( | ||
`Library ${builtInLibrary.name} is already installed` | ||
) | ||
) { | ||
// If Arduino_BuiltIn installation fails because it's already installed we don't want to retry on next start-up | ||
console.log('error installing core', e); | ||
} else { | ||
// But if there is any other error (e.g.: no interntet cconnection), we want to retry next time | ||
builtInLibraryError = e; | ||
} | ||
} | ||
} else { | ||
builtInLibraryError = new Error('Could not find library'); | ||
} | ||
|
||
if (avrPackageError) { | ||
this.messageService.error( | ||
`Could not install Arduino AVR platform: ${avrPackageError}` | ||
); | ||
} | ||
if (builtInLibraryError) { | ||
this.messageService.error( | ||
`Could not install ${builtInLibrary.name} library: ${builtInLibraryError}` | ||
); | ||
} | ||
|
||
if (!avrPackageError && !builtInLibraryError) { | ||
await this.localStorageService.setData( | ||
InitLibsPlatforms.INIT_LIBS_AND_PACKAGES, | ||
true | ||
); | ||
} | ||
} | ||
} | ||
} | ||
export namespace InitLibsPlatforms { | ||
export const INIT_LIBS_AND_PACKAGES = 'initializedLibsAndPackages'; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.