mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-10-27 20:18:35 +00:00
Compare commits
105 Commits
2.0.0-beta
...
2.0.0-beta
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7d5381bbde | ||
|
|
302fb7b6af | ||
|
|
6233e1fa98 | ||
|
|
2cb9889fe4 | ||
|
|
bed6e0b741 | ||
|
|
302f0109dd | ||
|
|
735d3733e2 | ||
|
|
4b36852f57 | ||
|
|
b84b6c921d | ||
|
|
289f07f187 | ||
|
|
b9c777a5c3 | ||
|
|
92af4bef26 | ||
|
|
167f059163 | ||
|
|
93515fc906 | ||
|
|
20c2e1c67e | ||
|
|
65152731f9 | ||
|
|
57b9eb95bb | ||
|
|
64dc124a53 | ||
|
|
38d372e2d5 | ||
|
|
5897f379a4 | ||
|
|
d790266cc8 | ||
|
|
4da5d573e4 | ||
|
|
4e6f9ae75d | ||
|
|
e10f0f1683 | ||
|
|
40a73af82b | ||
|
|
461ca06445 | ||
|
|
773675e3c5 | ||
|
|
4c536ec8fc | ||
|
|
e6cbefb880 | ||
|
|
0592199858 | ||
|
|
2a3873a923 | ||
|
|
05c0505228 | ||
|
|
8c4e66f536 | ||
|
|
cd0f1b3163 | ||
|
|
4fa2024266 | ||
|
|
852bf9b73e | ||
|
|
db48ed616b | ||
|
|
0dd1e45233 | ||
|
|
2a55ddd757 | ||
|
|
3240bf7f3d | ||
|
|
0d0ad9efae | ||
|
|
9aff90b0af | ||
|
|
8071298598 | ||
|
|
c86d82d273 | ||
|
|
fa9334eb7a | ||
|
|
c50d45c663 | ||
|
|
c20f832ddf | ||
|
|
cb2ef78c0a | ||
|
|
68af4c38fe | ||
|
|
a8df2444a9 | ||
|
|
d45dd6beef | ||
|
|
1ab5634789 | ||
|
|
80bddc238d | ||
|
|
8a692d0ce5 | ||
|
|
98671225ac | ||
|
|
f106c97f1e | ||
|
|
369a8f4307 | ||
|
|
4e7f8291e8 | ||
|
|
26a1db3cf8 | ||
|
|
a3f7b795a0 | ||
|
|
b422fc5298 | ||
|
|
ab320eb0b0 | ||
|
|
b17b7a6de7 | ||
|
|
562b77aec3 | ||
|
|
cdd5cfdfc1 | ||
|
|
f712ec986f | ||
|
|
c75b954041 | ||
|
|
3fb087f1ad | ||
|
|
27292774d7 | ||
|
|
da424f34cc | ||
|
|
f6e623ca9c | ||
|
|
1e0f52bbdd | ||
|
|
6dadd1775a | ||
|
|
067cc8766a | ||
|
|
15b0564212 | ||
|
|
e90fa27ebf | ||
|
|
ef03d3f583 | ||
|
|
5c8669d699 | ||
|
|
9cd91464e3 | ||
|
|
5a262d42c1 | ||
|
|
eadc993854 | ||
|
|
c64ac48fe3 | ||
|
|
ac502053d7 | ||
|
|
1d8eb0d544 | ||
|
|
e94702349b | ||
|
|
d648159f43 | ||
|
|
acbd98d0f8 | ||
|
|
22e02e19b8 | ||
|
|
7ee6d5ad8f | ||
|
|
19aa3dd8a5 | ||
|
|
de4ae232fa | ||
|
|
5a57576320 | ||
|
|
8e1feb36ff | ||
|
|
cdadda85e5 | ||
|
|
596d54a102 | ||
|
|
e1b36c6c56 | ||
|
|
86be874bb0 | ||
|
|
057904d38d | ||
|
|
0aef4b328f | ||
|
|
79b1a306a1 | ||
|
|
709baaca98 | ||
|
|
a06a69dff9 | ||
|
|
561d5fbbd3 | ||
|
|
df0aafd928 | ||
|
|
ad2cfc8894 |
65
.eslintrc.js
Normal file
65
.eslintrc.js
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
module.exports = {
|
||||||
|
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
|
||||||
|
parserOptions: {
|
||||||
|
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
|
||||||
|
sourceType: 'module', // Allows for the use of imports
|
||||||
|
ecmaFeatures: {
|
||||||
|
jsx: true, // Allows for the parsing of JSX
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ignorePatterns: [
|
||||||
|
'node_modules/*',
|
||||||
|
'**/node_modules/*',
|
||||||
|
'.node_modules/*',
|
||||||
|
'.github/*',
|
||||||
|
'.browser_modules/*',
|
||||||
|
'docs/*',
|
||||||
|
'scripts/*',
|
||||||
|
'electron/*',
|
||||||
|
'electron-app/*',
|
||||||
|
'browser-app/*',
|
||||||
|
'plugins/*',
|
||||||
|
'arduino-ide-extension/src/node/cli-protocol',
|
||||||
|
],
|
||||||
|
settings: {
|
||||||
|
react: {
|
||||||
|
version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use
|
||||||
|
},
|
||||||
|
},
|
||||||
|
extends: [
|
||||||
|
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
|
||||||
|
'plugin:react/recommended', // Uses the recommended rules from @eslint-plugin-react
|
||||||
|
'plugin:react-hooks/recommended', // Uses recommended rules from react hooks
|
||||||
|
'plugin:prettier/recommended',
|
||||||
|
'prettier', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
|
||||||
|
],
|
||||||
|
plugins: ['prettier', 'unused-imports'],
|
||||||
|
rules: {
|
||||||
|
'@typescript-eslint/no-unused-expressions': 'off',
|
||||||
|
'@typescript-eslint/no-namespace': 'off',
|
||||||
|
'@typescript-eslint/no-var-requires': 'off',
|
||||||
|
'@typescript-eslint/no-empty-function': 'warn',
|
||||||
|
'@typescript-eslint/no-empty-interface': 'warn',
|
||||||
|
'no-unused-vars': 'off',
|
||||||
|
'unused-imports/no-unused-imports': 'error',
|
||||||
|
'unused-imports/no-unused-vars': [
|
||||||
|
'warn',
|
||||||
|
{
|
||||||
|
vars: 'all',
|
||||||
|
varsIgnorePattern: '^_',
|
||||||
|
args: 'after-used',
|
||||||
|
argsIgnorePattern: '^_',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'react/display-name': 'warn',
|
||||||
|
eqeqeq: ['error', 'smart'],
|
||||||
|
'guard-for-in': 'off',
|
||||||
|
'id-blacklist': 'off',
|
||||||
|
'id-match': 'off',
|
||||||
|
'no-underscore-dangle': 'off',
|
||||||
|
'no-unused-expressions': 'off',
|
||||||
|
'no-var': 'error',
|
||||||
|
radix: 'error',
|
||||||
|
'prettier/prettier': 'warn',
|
||||||
|
},
|
||||||
|
};
|
||||||
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -2,7 +2,7 @@
|
|||||||
name: Bug report
|
name: Bug report
|
||||||
about: Create a report to help us improve
|
about: Create a report to help us improve
|
||||||
title: ''
|
title: ''
|
||||||
labels: bug
|
labels: 'type: bug'
|
||||||
assignees: ''
|
assignees: ''
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
2
.github/ISSUE_TEMPLATE/feature_request.md
vendored
2
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@@ -2,7 +2,7 @@
|
|||||||
name: Feature request
|
name: Feature request
|
||||||
about: Suggest an idea for this project
|
about: Suggest an idea for this project
|
||||||
title: ''
|
title: ''
|
||||||
labels: enhancement
|
labels: 'type: enhancement'
|
||||||
assignees: ''
|
assignees: ''
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
106
.github/workflows/build.yml
vendored
106
.github/workflows/build.yml
vendored
@@ -13,14 +13,18 @@ on:
|
|||||||
schedule:
|
schedule:
|
||||||
- cron: '0 3 * * *' # run every day at 3AM (https://docs.github.com/en/actions/reference/events-that-trigger-workflows#scheduled-events-schedule)
|
- cron: '0 3 * * *' # run every day at 3AM (https://docs.github.com/en/actions/reference/events-that-trigger-workflows#scheduled-events-schedule)
|
||||||
|
|
||||||
|
env:
|
||||||
|
JOB_TRANSFER_ARTIFACT: build-artifacts
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
build:
|
build:
|
||||||
|
if: github.repository == 'arduino/arduino-ide'
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
config:
|
config:
|
||||||
- os: windows-latest
|
- os: windows-latest
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-18.04 # https://github.com/arduino/arduino-ide/issues/259
|
||||||
- os: macos-latest
|
- os: macos-latest
|
||||||
runs-on: ${{ matrix.config.os }}
|
runs-on: ${{ matrix.config.os }}
|
||||||
timeout-minutes: 90
|
timeout-minutes: 90
|
||||||
@@ -50,21 +54,26 @@ jobs:
|
|||||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||||
IS_NIGHTLY: ${{ github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main') }}
|
IS_NIGHTLY: ${{ github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main') }}
|
||||||
IS_RELEASE: ${{ startsWith(github.ref, 'refs/tags/') }}
|
IS_RELEASE: ${{ startsWith(github.ref, 'refs/tags/') }}
|
||||||
|
IS_FORK: ${{ github.event.pull_request.head.repo.fork == true }}
|
||||||
run: |
|
run: |
|
||||||
# See: https://www.electron.build/code-signing
|
# See: https://www.electron.build/code-signing
|
||||||
if [ "${{ runner.OS }}" = "macOS" ]; then
|
if [ $IS_FORK = true ]; then
|
||||||
export CSC_LINK="${{ runner.temp }}/signing_certificate.p12"
|
echo "Skipping the app signing: building from a fork."
|
||||||
# APPLE_SIGNING_CERTIFICATE_P12 secret was produced by following the procedure from:
|
else
|
||||||
# https://www.kencochrane.com/2020/08/01/build-and-sign-golang-binaries-for-macos-with-github-actions/#exporting-the-developer-certificate
|
if [ "${{ runner.OS }}" = "macOS" ]; then
|
||||||
echo "${{ secrets.APPLE_SIGNING_CERTIFICATE_P12 }}" | base64 --decode > "$CSC_LINK"
|
export CSC_LINK="${{ runner.temp }}/signing_certificate.p12"
|
||||||
|
# APPLE_SIGNING_CERTIFICATE_P12 secret was produced by following the procedure from:
|
||||||
|
# https://www.kencochrane.com/2020/08/01/build-and-sign-golang-binaries-for-macos-with-github-actions/#exporting-the-developer-certificate
|
||||||
|
echo "${{ secrets.APPLE_SIGNING_CERTIFICATE_P12 }}" | base64 --decode > "$CSC_LINK"
|
||||||
|
|
||||||
export CSC_KEY_PASSWORD="${{ secrets.KEYCHAIN_PASSWORD }}"
|
export CSC_KEY_PASSWORD="${{ secrets.KEYCHAIN_PASSWORD }}"
|
||||||
|
|
||||||
elif [ "${{ runner.OS }}" = "Windows" ]; then
|
elif [ "${{ runner.OS }}" = "Windows" ]; then
|
||||||
export CSC_LINK="${{ runner.temp }}/signing_certificate.pfx"
|
export CSC_LINK="${{ runner.temp }}/signing_certificate.pfx"
|
||||||
echo "${{ secrets.WINDOWS_SIGNING_CERTIFICATE_PFX }}" | base64 --decode > "$CSC_LINK"
|
echo "${{ secrets.WINDOWS_SIGNING_CERTIFICATE_PFX }}" | base64 --decode > "$CSC_LINK"
|
||||||
|
|
||||||
export CSC_KEY_PASSWORD="${{ secrets.WINDOWS_SIGNING_CERTIFICATE_PASSWORD }}"
|
export CSC_KEY_PASSWORD="${{ secrets.WINDOWS_SIGNING_CERTIFICATE_PASSWORD }}"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
yarn --cwd ./electron/packager/
|
yarn --cwd ./electron/packager/
|
||||||
@@ -73,9 +82,42 @@ jobs:
|
|||||||
- name: Upload [GitHub Actions]
|
- name: Upload [GitHub Actions]
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v2
|
||||||
with:
|
with:
|
||||||
name: build-artifacts
|
name: ${{ env.JOB_TRANSFER_ARTIFACT }}
|
||||||
path: electron/build/dist/build-artifacts/
|
path: electron/build/dist/build-artifacts/
|
||||||
|
|
||||||
|
artifacts:
|
||||||
|
name: ${{ matrix.artifact.name }} artifact
|
||||||
|
needs: build
|
||||||
|
if: always() && needs.build.result != 'skipped'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
artifact:
|
||||||
|
- path: "*Linux_64bit.zip"
|
||||||
|
name: Linux_X86-64
|
||||||
|
- path: "*macOS_64bit.dmg"
|
||||||
|
name: macOS
|
||||||
|
- path: "*Windows_64bit.exe"
|
||||||
|
name: Windows_X86-64_interactive_installer
|
||||||
|
- path: "*Windows_64bit.msi"
|
||||||
|
name: Windows_X86-64_MSI
|
||||||
|
- path: "*Windows_64bit.zip"
|
||||||
|
name: Windows_X86-64_zip
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Download job transfer artifact
|
||||||
|
uses: actions/download-artifact@v2
|
||||||
|
with:
|
||||||
|
name: ${{ env.JOB_TRANSFER_ARTIFACT }}
|
||||||
|
path: ${{ env.JOB_TRANSFER_ARTIFACT }}
|
||||||
|
|
||||||
|
- name: Upload tester build artifact
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: ${{ matrix.artifact.name }}
|
||||||
|
path: ${{ env.JOB_TRANSFER_ARTIFACT }}/${{ matrix.artifact.path }}
|
||||||
|
|
||||||
changelog:
|
changelog:
|
||||||
needs: build
|
needs: build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -115,25 +157,25 @@ jobs:
|
|||||||
if: github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main')
|
if: github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main')
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v2
|
||||||
with:
|
with:
|
||||||
name: build-artifacts
|
name: ${{ env.JOB_TRANSFER_ARTIFACT }}
|
||||||
path: CHANGELOG.txt
|
path: CHANGELOG.txt
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
needs: changelog
|
needs: changelog
|
||||||
if: github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main')
|
if: github.repository == 'arduino/arduino-ide' && (github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main'))
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Download [GitHub Actions]
|
- name: Download [GitHub Actions]
|
||||||
uses: actions/download-artifact@v2
|
uses: actions/download-artifact@v2
|
||||||
with:
|
with:
|
||||||
name: build-artifacts
|
name: ${{ env.JOB_TRANSFER_ARTIFACT }}
|
||||||
path: build-artifacts
|
path: ${{ env.JOB_TRANSFER_ARTIFACT }}
|
||||||
|
|
||||||
- name: Publish Nightly [S3]
|
- name: Publish Nightly [S3]
|
||||||
uses: docker://plugins/s3
|
uses: docker://plugins/s3
|
||||||
env:
|
env:
|
||||||
PLUGIN_SOURCE: "build-artifacts/*"
|
PLUGIN_SOURCE: "${{ env.JOB_TRANSFER_ARTIFACT }}/*"
|
||||||
PLUGIN_STRIP_PREFIX: "build-artifacts/"
|
PLUGIN_STRIP_PREFIX: "${{ env.JOB_TRANSFER_ARTIFACT }}/"
|
||||||
PLUGIN_TARGET: "/arduino-ide/nightly"
|
PLUGIN_TARGET: "/arduino-ide/nightly"
|
||||||
PLUGIN_BUCKET: ${{ secrets.DOWNLOADS_BUCKET }}
|
PLUGIN_BUCKET: ${{ secrets.DOWNLOADS_BUCKET }}
|
||||||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||||
@@ -141,14 +183,14 @@ jobs:
|
|||||||
|
|
||||||
release:
|
release:
|
||||||
needs: changelog
|
needs: changelog
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: github.repository == 'arduino/arduino-ide' && startsWith(github.ref, 'refs/tags/')
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Download [GitHub Actions]
|
- name: Download [GitHub Actions]
|
||||||
uses: actions/download-artifact@v2
|
uses: actions/download-artifact@v2
|
||||||
with:
|
with:
|
||||||
name: build-artifacts
|
name: ${{ env.JOB_TRANSFER_ARTIFACT }}
|
||||||
path: build-artifacts
|
path: ${{ env.JOB_TRANSFER_ARTIFACT }}
|
||||||
|
|
||||||
- name: Get Tag
|
- name: Get Tag
|
||||||
id: tag_name
|
id: tag_name
|
||||||
@@ -160,7 +202,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
release_name: ${{ steps.tag_name.outputs.TAG_NAME }}
|
release_name: ${{ steps.tag_name.outputs.TAG_NAME }}
|
||||||
file: build-artifacts/*
|
file: ${{ env.JOB_TRANSFER_ARTIFACT }}/*
|
||||||
tag: ${{ github.ref }}
|
tag: ${{ github.ref }}
|
||||||
file_glob: true
|
file_glob: true
|
||||||
body: ${{ needs.changelog.outputs.BODY }}
|
body: ${{ needs.changelog.outputs.BODY }}
|
||||||
@@ -168,9 +210,25 @@ jobs:
|
|||||||
- name: Publish Release [S3]
|
- name: Publish Release [S3]
|
||||||
uses: docker://plugins/s3
|
uses: docker://plugins/s3
|
||||||
env:
|
env:
|
||||||
PLUGIN_SOURCE: "build-artifacts/*"
|
PLUGIN_SOURCE: "${{ env.JOB_TRANSFER_ARTIFACT }}/*"
|
||||||
PLUGIN_STRIP_PREFIX: "build-artifacts/"
|
PLUGIN_STRIP_PREFIX: "${{ env.JOB_TRANSFER_ARTIFACT }}/"
|
||||||
PLUGIN_TARGET: "/arduino-ide"
|
PLUGIN_TARGET: "/arduino-ide"
|
||||||
PLUGIN_BUCKET: ${{ secrets.DOWNLOADS_BUCKET }}
|
PLUGIN_BUCKET: ${{ secrets.DOWNLOADS_BUCKET }}
|
||||||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||||
|
|
||||||
|
clean:
|
||||||
|
# This job must run after all jobs that use the transfer artifact.
|
||||||
|
needs:
|
||||||
|
- build
|
||||||
|
- publish
|
||||||
|
- release
|
||||||
|
- artifacts
|
||||||
|
if: always() && needs.build.result != 'skipped'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Remove unneeded job transfer artifact
|
||||||
|
uses: geekyeggo/delete-artifact@v1
|
||||||
|
with:
|
||||||
|
name: ${{ env.JOB_TRANSFER_ARTIFACT }}
|
||||||
|
|||||||
48
.github/workflows/check-certificates.yml
vendored
48
.github/workflows/check-certificates.yml
vendored
@@ -1,30 +1,41 @@
|
|||||||
name: Check for issues with signing certificates
|
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-certificates.md
|
||||||
|
name: Check Certificates
|
||||||
|
|
||||||
|
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
|
||||||
on:
|
on:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- '.github/workflows/check-certificates.ya?ml'
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- '.github/workflows/check-certificates.ya?ml'
|
||||||
schedule:
|
schedule:
|
||||||
# run every 10 hours
|
# Run every 10 hours.
|
||||||
- cron: "0 */10 * * *"
|
- cron: '0 */10 * * *'
|
||||||
# workflow_dispatch event allows the workflow to be triggered manually.
|
|
||||||
# This could be used to run an immediate check after updating certificate secrets.
|
|
||||||
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_dispatch
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
repository_dispatch:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
# Begin notifications when there are less than this many days remaining before expiration
|
# Begin notifications when there are less than this many days remaining before expiration.
|
||||||
EXPIRATION_WARNING_PERIOD: 30
|
EXPIRATION_WARNING_PERIOD: 30
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check-certificates:
|
check-certificates:
|
||||||
|
name: ${{ matrix.certificate.identifier }}
|
||||||
|
# Only run when the workflow will have access to the certificate secrets.
|
||||||
|
if: >
|
||||||
|
(github.event_name != 'pull_request' && github.repository == 'arduino/arduino-ide') ||
|
||||||
|
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'arduino/arduino-ide')
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
certificate:
|
certificate:
|
||||||
- identifier: macOS signing certificate # Text used to identify the certificate in notifications
|
# Additional certificate definitions can be added to this list.
|
||||||
certificate-secret: APPLE_SIGNING_CERTIFICATE_P12 # The name of the secret that contains the certificate
|
- identifier: macOS signing certificate # Text used to identify certificate in notifications.
|
||||||
password-secret: KEYCHAIN_PASSWORD # The name of the secret that contains the certificate password
|
certificate-secret: APPLE_SIGNING_CERTIFICATE_P12 # Name of the secret that contains the certificate.
|
||||||
|
password-secret: KEYCHAIN_PASSWORD # Name of the secret that contains the certificate password.
|
||||||
- identifier: Windows signing certificate
|
- identifier: Windows signing certificate
|
||||||
certificate-secret: WINDOWS_SIGNING_CERTIFICATE_PFX
|
certificate-secret: WINDOWS_SIGNING_CERTIFICATE_PFX
|
||||||
password-secret: WINDOWS_SIGNING_CERTIFICATE_PASSWORD
|
password-secret: WINDOWS_SIGNING_CERTIFICATE_PASSWORD
|
||||||
@@ -32,7 +43,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Set certificate path environment variable
|
- name: Set certificate path environment variable
|
||||||
run: |
|
run: |
|
||||||
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
|
# See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
|
||||||
echo "CERTIFICATE_PATH=${{ runner.temp }}/certificate.p12" >> "$GITHUB_ENV"
|
echo "CERTIFICATE_PATH=${{ runner.temp }}/certificate.p12" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
- name: Decode certificate
|
- name: Decode certificate
|
||||||
@@ -54,18 +65,17 @@ jobs:
|
|||||||
exit 1
|
exit 1
|
||||||
)
|
)
|
||||||
|
|
||||||
# See: https://github.com/rtCamp/action-slack-notify
|
|
||||||
- name: Slack notification of certificate verification failure
|
- name: Slack notification of certificate verification failure
|
||||||
if: failure()
|
if: failure()
|
||||||
uses: rtCamp/action-slack-notify@v2.1.0
|
|
||||||
env:
|
env:
|
||||||
SLACK_WEBHOOK: ${{ secrets.TEAM_TOOLING_CHANNEL_SLACK_WEBHOOK }}
|
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
|
||||||
SLACK_MESSAGE: |
|
SLACK_MESSAGE: |
|
||||||
:warning::warning::warning::warning:
|
:warning::warning::warning::warning:
|
||||||
WARNING: ${{ github.repository }} ${{ matrix.certificate.identifier }} verification failed!!!
|
WARNING: ${{ github.repository }} ${{ matrix.certificate.identifier }} verification failed!!!
|
||||||
:warning::warning::warning::warning:
|
:warning::warning::warning::warning:
|
||||||
SLACK_COLOR: danger
|
SLACK_COLOR: danger
|
||||||
MSG_MINIMAL: true
|
MSG_MINIMAL: true
|
||||||
|
uses: rtCamp/action-slack-notify@v2
|
||||||
|
|
||||||
- name: Get days remaining before certificate expiration date
|
- name: Get days remaining before certificate expiration date
|
||||||
env:
|
env:
|
||||||
@@ -94,7 +104,7 @@ jobs:
|
|||||||
|
|
||||||
DAYS_BEFORE_EXPIRATION="$((($(date --utc --date="$EXPIRATION_DATE" +%s) - $(date --utc +%s)) / 60 / 60 / 24))"
|
DAYS_BEFORE_EXPIRATION="$((($(date --utc --date="$EXPIRATION_DATE" +%s) - $(date --utc +%s)) / 60 / 60 / 24))"
|
||||||
|
|
||||||
# Display the expiration information in the log
|
# Display the expiration information in the log.
|
||||||
echo "Certificate expiration date: $EXPIRATION_DATE"
|
echo "Certificate expiration date: $EXPIRATION_DATE"
|
||||||
echo "Days remaining before expiration: $DAYS_BEFORE_EXPIRATION"
|
echo "Days remaining before expiration: $DAYS_BEFORE_EXPIRATION"
|
||||||
|
|
||||||
@@ -109,14 +119,14 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Slack notification of pending certificate expiration
|
- name: Slack notification of pending certificate expiration
|
||||||
# Don't send spurious expiration notification if verification fails
|
# Don't send spurious expiration notification if verification fails.
|
||||||
if: failure() && steps.check-expiration.outcome == 'failure'
|
if: failure() && steps.check-expiration.outcome == 'failure'
|
||||||
uses: rtCamp/action-slack-notify@v2.1.0
|
|
||||||
env:
|
env:
|
||||||
SLACK_WEBHOOK: ${{ secrets.TEAM_TOOLING_CHANNEL_SLACK_WEBHOOK }}
|
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
|
||||||
SLACK_MESSAGE: |
|
SLACK_MESSAGE: |
|
||||||
:warning::warning::warning::warning:
|
:warning::warning::warning::warning:
|
||||||
WARNING: ${{ github.repository }} ${{ matrix.certificate.identifier }} will expire in ${{ steps.get-days-before-expiration.outputs.days }} days!!!
|
WARNING: ${{ github.repository }} ${{ matrix.certificate.identifier }} will expire in ${{ steps.get-days-before-expiration.outputs.days }} days!!!
|
||||||
:warning::warning::warning::warning:
|
:warning::warning::warning::warning:
|
||||||
SLACK_COLOR: danger
|
SLACK_COLOR: danger
|
||||||
MSG_MINIMAL: true
|
MSG_MINIMAL: true
|
||||||
|
uses: rtCamp/action-slack-notify@v2
|
||||||
|
|||||||
6
.prettierrc
Normal file
6
.prettierrc
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"singleQuote": true,
|
||||||
|
"tabWidth": 2,
|
||||||
|
"useTabs": false,
|
||||||
|
"printWidth": 80
|
||||||
|
}
|
||||||
35
.vscode/launch.json
vendored
35
.vscode/launch.json
vendored
@@ -1,22 +1,6 @@
|
|||||||
{
|
{
|
||||||
// Use IntelliSense to learn about possible attributes.
|
|
||||||
// Hover to view descriptions of existing attributes.
|
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
|
||||||
"type": "node",
|
|
||||||
"request": "attach",
|
|
||||||
"name": "Attach by Process ID",
|
|
||||||
"processId": "${command:PickProcess}"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"name": "Electron Packager",
|
|
||||||
"program": "${workspaceRoot}/electron/packager/index.js",
|
|
||||||
"cwd": "${workspaceFolder}/electron/packager"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"type": "node",
|
"type": "node",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
@@ -29,15 +13,17 @@
|
|||||||
"NODE_PRESERVE_SYMLINKS": "1"
|
"NODE_PRESERVE_SYMLINKS": "1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"program": "${workspaceRoot}/electron-app/src-gen/frontend/electron-main.js",
|
"cwd": "${workspaceFolder}/electron-app",
|
||||||
"protocol": "inspector",
|
"protocol": "inspector",
|
||||||
"args": [
|
"args": [
|
||||||
|
".",
|
||||||
"--log-level=debug",
|
"--log-level=debug",
|
||||||
"--hostname=localhost",
|
"--hostname=localhost",
|
||||||
"--no-cluster",
|
"--no-cluster",
|
||||||
|
"--app-project-path=${workspaceRoot}/electron-app",
|
||||||
"--remote-debugging-port=9222",
|
"--remote-debugging-port=9222",
|
||||||
"--no-app-auto-install",
|
"--no-app-auto-install",
|
||||||
"--plugins=local-dir:plugins"
|
"--plugins=local-dir:../plugins"
|
||||||
],
|
],
|
||||||
"env": {
|
"env": {
|
||||||
"NODE_ENV": "development"
|
"NODE_ENV": "development"
|
||||||
@@ -104,6 +90,19 @@
|
|||||||
"smartStep": true,
|
"smartStep": true,
|
||||||
"internalConsoleOptions": "openOnSessionStart",
|
"internalConsoleOptions": "openOnSessionStart",
|
||||||
"outputCapture": "std"
|
"outputCapture": "std"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "attach",
|
||||||
|
"name": "Attach by Process ID",
|
||||||
|
"processId": "${command:PickProcess}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Electron Packager",
|
||||||
|
"program": "${workspaceRoot}/electron/packager/index.js",
|
||||||
|
"cwd": "${workspaceFolder}/electron/packager"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
18
.vscode/settings.json
vendored
18
.vscode/settings.json
vendored
@@ -1,21 +1,9 @@
|
|||||||
{
|
{
|
||||||
"tslint.enable": true,
|
|
||||||
"tslint.configFile": "./tslint.json",
|
|
||||||
"editor.formatOnSave": true,
|
|
||||||
"files.exclude": {
|
"files.exclude": {
|
||||||
"**/lib": false
|
"**/lib": false
|
||||||
},
|
},
|
||||||
"editor.insertSpaces": true,
|
"typescript.tsdk": "node_modules/typescript/lib",
|
||||||
"editor.detectIndentation": false,
|
"editor.codeActionsOnSave": {
|
||||||
"[typescript]": {
|
"source.fixAll.eslint": true
|
||||||
"editor.tabSize": 4
|
|
||||||
},
|
},
|
||||||
"[json]": {
|
|
||||||
"editor.tabSize": 2
|
|
||||||
},
|
|
||||||
"[jsonc]": {
|
|
||||||
"editor.tabSize": 2
|
|
||||||
},
|
|
||||||
"files.insertFinalNewline": true,
|
|
||||||
"typescript.tsdk": "node_modules/typescript/lib"
|
|
||||||
}
|
}
|
||||||
|
|||||||
4
.vscode/tasks.json
vendored
4
.vscode/tasks.json
vendored
@@ -1,6 +1,4 @@
|
|||||||
{
|
{
|
||||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
|
||||||
// for the documentation about the tasks.json format
|
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"tasks": [
|
"tasks": [
|
||||||
{
|
{
|
||||||
@@ -35,7 +33,7 @@
|
|||||||
"panel": "new",
|
"panel": "new",
|
||||||
"clear": false
|
"clear": false
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
{
|
{
|
||||||
"label": "Arduino IDE - Watch Browser App",
|
"label": "Arduino IDE - Watch Browser App",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
|
|||||||
136
BUILDING.md
Normal file
136
BUILDING.md
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
# Development
|
||||||
|
|
||||||
|
This page includes technical documentation for developers who want to build the IDE locally and contribute to the project.
|
||||||
|
|
||||||
|
## Architecture overview
|
||||||
|
|
||||||
|
The IDE consists of three major parts:
|
||||||
|
- the _Electron main_ process,
|
||||||
|
- the _backend_, and
|
||||||
|
- the _frontend_.
|
||||||
|
|
||||||
|
The _Electron main_ process is responsible for:
|
||||||
|
- creating the application,
|
||||||
|
- managing the application lifecycle via listeners, and
|
||||||
|
- creating and managing the web pages for the app.
|
||||||
|
|
||||||
|
In Electron, the process that runs the main entry JavaScript file is called the main process. The _Electron main_ process can display a GUI by creating web pages. An Electron app always has exactly one main process.
|
||||||
|
|
||||||
|
By default, whenever the _Electron main_ process creates a web page, it will instantiate a new `BrowserWindow` instance. Since Electron uses Chromium for displaying web pages, Chromium's multi-process architecture is also used. Each web page in Electron runs in its own process, which is called the renderer process. Each `BrowserWindow` instance runs the web page in its own renderer process. When a `BrowserWindow` instance is destroyed, the corresponding renderer process is also terminated. The main process manages all web pages and their corresponding renderer processes. Each renderer process is isolated and only cares about the web page running in it.<sup>[[1]]</sup>
|
||||||
|
|
||||||
|
In normal browsers, web pages usually run in a sandboxed environment, and accessing native resources are disallowed. However, Electron has the power to use Node.js APIs in the web pages allowing lower-level OS interactions. Due to security reasons, accessing native resources is an undesired behavior in the IDE. So by convention, we do not use Node.js APIs. (Note: the Node.js integration is [not yet disabled](https://github.com/eclipse-theia/theia/issues/2018) although it is not used). In the IDE, only the _backend_ allows OS interaction.
|
||||||
|
|
||||||
|
The _backend_ process is responsible for:
|
||||||
|
- providing access to the filesystem,
|
||||||
|
- communicating with the [Arduino CLI](https://github.com/arduino/arduino-cli) via gRPC,
|
||||||
|
- running your terminal,
|
||||||
|
- exposing additional RESTful APIs,
|
||||||
|
- performing the Git commands in the local repositories,
|
||||||
|
- hosting and running any VS Code extensions, or
|
||||||
|
- executing VS Code tasks<sup>[[2]]</sup>.
|
||||||
|
|
||||||
|
The _Electron main_ process spawns the _backend_ process. There is always exactly one _backend_ process. However, due to performance considerations, the _backend_ spawns several sub-processes for the filesystem watching, Git repository discovery, etc. The communication between the _backend_ process and its sub-processes is established via IPC. Besides spawning sub-processes, the _backend_ will start an HTTP server on a random available port, and serves the web application as static content. When the sub-processes are up and running, and the HTTP server is also listening, the _backend_ process sends the HTTP server port to the _Electron main_ process via IPC. The _Electron main_ process will load the _backend_'s endpoint in the `BrowserWindow`.
|
||||||
|
|
||||||
|
The _frontend_ is running as an Electron renderer process and can invoke services implemented on the _backend_. The communication between the _backend_ and the _frontend_ is done via JSON-RPC over a websocket connection. This means, the services running in the _frontend_ are all proxies, and will ask the corresponding service implementation on the _backend_.
|
||||||
|
|
||||||
|
[1]: https://www.electronjs.org/docs/tutorial/application-architecture#differences-between-main-process-and-renderer-process
|
||||||
|
[2]: https://code.visualstudio.com/Docs/editor/tasks
|
||||||
|
|
||||||
|
|
||||||
|
## Build from source
|
||||||
|
|
||||||
|
If you’re familiar with TypeScript, the [Theia IDE](https://theia-ide.org/), and if you want to contribute to the
|
||||||
|
project, you should be able to build the Arduino IDE locally. Please refer to the [Theia IDE prerequisites](https://github.com/theia-ide/theia/blob/master/doc/) documentation for the setup instructions.
|
||||||
|
|
||||||
|
### Build
|
||||||
|
```sh
|
||||||
|
yarn
|
||||||
|
```
|
||||||
|
|
||||||
|
### Rebuild the native dependencies
|
||||||
|
```sh
|
||||||
|
yarn rebuild:electron
|
||||||
|
```
|
||||||
|
|
||||||
|
### Start
|
||||||
|
```sh
|
||||||
|
yarn start
|
||||||
|
```
|
||||||
|
|
||||||
|
### CI
|
||||||
|
|
||||||
|
This project is built on [GitHub Actions](https://github.com/arduino/arduino-ide/actions).
|
||||||
|
|
||||||
|
- _Snapshot_ builds run when changes are pushed to the `main` branch, or when a PR is created against the `main` branch. For the sake of the review and verification process, the build artifacts for each operating system can be downloaded from the GitHub Actions page.
|
||||||
|
- _Nightly_ builds run every day at 03:00 GMT from the `main` branch.
|
||||||
|
- _Release_ builds run when a new tag is pushed to the remote. The tag must follow the [semver](https://semver.org/). For instance, `1.2.3` is a correct tag, but `v2.3.4` won't work. Steps to trigger a new release build:
|
||||||
|
- Create a local tag:
|
||||||
|
```sh
|
||||||
|
git tag -a 1.2.3 -m "Creating a new tag for the `1.2.3` release."
|
||||||
|
```
|
||||||
|
- Push it to the remote:
|
||||||
|
```sh
|
||||||
|
git push origin 1.2.3
|
||||||
|
```
|
||||||
|
|
||||||
|
## Notes for macOS contributors
|
||||||
|
Beginning in macOS 10.14.5, the software [must be notarized to run](https://developer.apple.com/documentation/xcode/notarizing_macos_software_before_distribution). The signing and notarization processes for the Arduino IDE are managed by our Continuous Integration (CI) workflows, implemented with GitHub Actions. On every push and pull request, the Arduino IDE is built and saved to a workflow artifact. These artifacts can be used by contributors and beta testers who don't want to set up a build system locally.
|
||||||
|
For security reasons, signing and notarization are disabled for workflow runs for pull requests from forks of this repository. This means that macOS will block you from running those artifacts.
|
||||||
|
Due to this limitation, Mac users have two options for testing contributions from forks:
|
||||||
|
|
||||||
|
### The Safe approach (recommended)
|
||||||
|
|
||||||
|
Follow [the instructions above](#build-from-source) to create the build environment locally, then build the code you want to test.
|
||||||
|
|
||||||
|
### The Risky approach
|
||||||
|
|
||||||
|
*Please note that this approach is risky as you are lowering the security on your system, therefore we strongly discourage you from following it.*
|
||||||
|
1. Use [this guide](https://help.apple.com/xcode/mac/10.2/index.html?localePath=en.lproj#/dev9b7736b0e), in order to disable Gatekeeper (at your own risk!).
|
||||||
|
1. Download the unsigned artifact provided by the CI workflow run related to the Pull Request at each push.
|
||||||
|
1. Re-enable Gatekeeper after tests are done, following the guide linked above.
|
||||||
|
|
||||||
|
### Creating a release
|
||||||
|
|
||||||
|
You will not need to create a new release yourself as the Arduino team takes care of this on a regular basis, but we are documenting the process here. Let's assume the current version is `0.1.3` and you want to release `0.2.0`.
|
||||||
|
|
||||||
|
- Make sure the `main` state represents what you want to release and you're on `main`.
|
||||||
|
- Prepare a release-candidate build on a branch:
|
||||||
|
```bash
|
||||||
|
git branch 0.2.0-rc \
|
||||||
|
&& git checkout 0.2.0-rc
|
||||||
|
```
|
||||||
|
- Bump up the version number. It must be a valid [semver](https://semver.org/) and must be greater than the current one:
|
||||||
|
```bash
|
||||||
|
yarn update:version 0.2.0
|
||||||
|
```
|
||||||
|
- This should generate multiple outgoing changes with the version update.
|
||||||
|
- Commit your changes and push to the remote:
|
||||||
|
```bash
|
||||||
|
git add . \
|
||||||
|
&& git commit -s -m "Updated versions to 0.2.0" \
|
||||||
|
&& git push
|
||||||
|
```
|
||||||
|
- Create the GH PR the workflow starts automatically.
|
||||||
|
- Once you're happy with the RC, merge the changes to the `main`.
|
||||||
|
- Create a tag and push it:
|
||||||
|
```bash
|
||||||
|
git tag -a 0.2.0 -m "0.2.0" \
|
||||||
|
&& git push origin 0.2.0
|
||||||
|
```
|
||||||
|
- The release build starts automatically and uploads the artifacts with the changelog to the [release page](https://github.com/arduino/arduino-ide/releases).
|
||||||
|
- If you do not want to release the `EXE` and `MSI` installers, wipe them manually.
|
||||||
|
- If you do not like the generated changelog, modify it and update the GH release.
|
||||||
|
|
||||||
|
## FAQ
|
||||||
|
|
||||||
|
* *Can I manually change the version of the [`arduino-cli`](https://github.com/arduino/arduino-cli/) used by the IDE?*
|
||||||
|
|
||||||
|
Yes. It is possible but not recommended. The CLI exposes a set of functionality via [gRPC](https://github.com/arduino/arduino-cli/tree/master/rpc) and the IDE uses this API to communicate with the CLI. Before we build a new version of IDE, we pin a specific version of CLI and use the corresponding `proto` files to generate TypeScript modules for gRPC. This means, a particular version of IDE is compliant only with the pinned version of CLI. Mismatching IDE and CLI versions might not be able to communicate with each other. This could cause unpredictable IDE behavior.
|
||||||
|
|
||||||
|
* *I have understood that not all versions of the CLI are compatible with my version of IDE but how can I manually update the `arduino-cli` inside the IDE?*
|
||||||
|
|
||||||
|
[Get](https://arduino.github.io/arduino-cli/installation) the desired version of `arduino-cli` for your platform and manually replace the one inside the IDE. The CLI can be found inside the IDE at:
|
||||||
|
- Windows: `C:\path\to\Arduino IDE\resources\app\node_modules\arduino-ide-extension\build\arduino-cli.exe`,
|
||||||
|
- macOS: `/path/to/Arduino IDE.app/Contents/Resources/app/node_modules/arduino-ide-extension/build/arduino-cli`, and
|
||||||
|
- Linux: `/path/to/Arduino IDE/resources/app/node_modules/arduino-ide-extension/build/arduino-cli`.
|
||||||
|
|
||||||
19
Dockerfile
19
Dockerfile
@@ -1,19 +0,0 @@
|
|||||||
FROM gitpod/workspace-full-vnc
|
|
||||||
|
|
||||||
USER root
|
|
||||||
RUN apt-get update -q --fix-missing && \
|
|
||||||
apt-get install -y -q software-properties-common && \
|
|
||||||
apt-get install -y -q --no-install-recommends \
|
|
||||||
build-essential \
|
|
||||||
libssl-dev \
|
|
||||||
golang-go \
|
|
||||||
libxkbfile-dev \
|
|
||||||
libnss3-dev
|
|
||||||
|
|
||||||
RUN set -ex && \
|
|
||||||
tmpdir=$(mktemp -d) && \
|
|
||||||
curl -L -o $tmpdir/protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protoc-3.6.1-linux-x86_64.zip && \
|
|
||||||
mkdir -p /usr/lib/protoc && cd /usr/lib/protoc && unzip $tmpdir/protoc.zip && \
|
|
||||||
chmod -R 755 /usr/lib/protoc/include/google && \
|
|
||||||
ln -s /usr/lib/protoc/bin/* /usr/bin && \
|
|
||||||
rm $tmpdir/protoc.zip
|
|
||||||
661
LICENSE.txt
Normal file
661
LICENSE.txt
Normal file
@@ -0,0 +1,661 @@
|
|||||||
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU Affero General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works, specifically designed to ensure
|
||||||
|
cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
our General Public Licenses are intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
Developers that use our General Public Licenses protect your rights
|
||||||
|
with two steps: (1) assert copyright on the software, and (2) offer
|
||||||
|
you this License which gives you legal permission to copy, distribute
|
||||||
|
and/or modify the software.
|
||||||
|
|
||||||
|
A secondary benefit of defending all users' freedom is that
|
||||||
|
improvements made in alternate versions of the program, if they
|
||||||
|
receive widespread use, become available for other developers to
|
||||||
|
incorporate. Many developers of free software are heartened and
|
||||||
|
encouraged by the resulting cooperation. However, in the case of
|
||||||
|
software used on network servers, this result may fail to come about.
|
||||||
|
The GNU General Public License permits making a modified version and
|
||||||
|
letting the public access it on a server without ever releasing its
|
||||||
|
source code to the public.
|
||||||
|
|
||||||
|
The GNU Affero General Public License is designed specifically to
|
||||||
|
ensure that, in such cases, the modified source code becomes available
|
||||||
|
to the community. It requires the operator of a network server to
|
||||||
|
provide the source code of the modified version running there to the
|
||||||
|
users of that server. Therefore, public use of a modified version, on
|
||||||
|
a publicly accessible server, gives the public access to the source
|
||||||
|
code of the modified version.
|
||||||
|
|
||||||
|
An older license, called the Affero General Public License and
|
||||||
|
published by Affero, was designed to accomplish similar goals. This is
|
||||||
|
a different license, not a version of the Affero GPL, but Affero has
|
||||||
|
released a new version of the Affero GPL which permits relicensing under
|
||||||
|
this license.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, if you modify the
|
||||||
|
Program, your modified version must prominently offer all users
|
||||||
|
interacting with it remotely through a computer network (if your version
|
||||||
|
supports such interaction) an opportunity to receive the Corresponding
|
||||||
|
Source of your version by providing access to the Corresponding Source
|
||||||
|
from a network server at no charge, through some standard or customary
|
||||||
|
means of facilitating copying of software. This Corresponding Source
|
||||||
|
shall include the Corresponding Source for any work covered by version 3
|
||||||
|
of the GNU General Public License that is incorporated pursuant to the
|
||||||
|
following paragraph.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the work with which it is combined will remain governed by version
|
||||||
|
3 of the GNU General Public License.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU Affero General Public License from time to time. Such new versions
|
||||||
|
will be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU Affero General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU Affero General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU Affero General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If your software can interact with users remotely through a computer
|
||||||
|
network, you should also make sure that it provides a way for users to
|
||||||
|
get its source. For example, if your program is a web application, its
|
||||||
|
interface could display a "Source" link that leads users to an archive
|
||||||
|
of the code. There are many ways you could offer source, and different
|
||||||
|
solutions will be better for different programs; see section 13 for the
|
||||||
|
specific requirements.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
156
README.md
156
README.md
@@ -1,36 +1,24 @@
|
|||||||
# Arduino IDE
|
<img src="https://content.arduino.cc/website/Arduino_logo_teal.svg" height="100" align="right" />
|
||||||
|
|
||||||
|
# Arduino IDE 2.x (beta)
|
||||||
|
|
||||||
[](https://github.com/arduino/arduino-ide/actions?query=workflow%3A%22Arduino+IDE%22)
|
[](https://github.com/arduino/arduino-ide/actions?query=workflow%3A%22Arduino+IDE%22)
|
||||||
|
|
||||||
### Download
|
This repository contains the source code of the Arduino IDE 2.x, which is currently in beta stage. If you're looking for the stable IDE, go to the repository of the 1.x version at https://github.com/arduino/Arduino.
|
||||||
|
|
||||||
You can download the latest version of the Arduino IDE application for the supported platforms from the [GitHub release page](https://github.com/arduino/arduino-ide/releases) or following the links in the following table.
|
The Arduino IDE 2.x is a major rewrite, sharing no code with the IDE 1.x. It is based on the [Theia IDE](https://theia-ide.org/) framework and built with [Electron](https://www.electronjs.org/). The backend operations such as compilation and uploading are offloaded to an [arduino-cli](https://github.com/arduino/arduino-cli) instance running in daemon mode. This new IDE was developed with the goal of preserving the same interface and user experience of the previous major version in order to provide a frictionless upgrade.
|
||||||
|
|
||||||
#### Latest version
|
> ⚠️ This is **beta** software. Help us test it!
|
||||||
|
|
||||||
Platform | 32 bit | 64 bit |
|

|
||||||
--------- | ------------------------ | ------------------------------------------------------------------------------ |
|
|
||||||
Linux | | [Linux 64 bit] |
|
|
||||||
Linux ARM | [🚧 Work in progress...] | [🚧 Work in progress...] |
|
|
||||||
Windows | | [Windows 64 bit installer]<br />[Windows 64 bit MSI]<br />[Windows 64 bit ZIP] |
|
|
||||||
macOS | | [macOS 64 bit] |
|
|
||||||
|
|
||||||
[🚧 Work in progress...]: https://github.com/arduino/arduino-ide/issues/287
|
## Download
|
||||||
[Linux 64 bit]: https://downloads.arduino.cc/arduino-ide/arduino-ide_latest_Linux_64bit.zip
|
|
||||||
[Windows 64 bit installer]: https://downloads.arduino.cc/arduino-ide/arduino-ide_latest_Windows_64bit.exe
|
|
||||||
[Windows 64 bit MSI]: https://downloads.arduino.cc/arduino-ide/arduino-ide_latest_Windows_64bit.msi
|
|
||||||
[Windows 64 bit ZIP]: https://downloads.arduino.cc/arduino-ide/arduino-ide_latest_Windows_64bit.zip
|
|
||||||
[macOS 64 bit]: https://downloads.arduino.cc/arduino-ide/arduino-ide_latest_macOS_64bit.dmg
|
|
||||||
|
|
||||||
#### Previous versions
|
You can download the latest version from the [software download page on the Arduino website](https://www.arduino.cc/en/software#experimental-software).
|
||||||
|
### Nightly builds
|
||||||
These are available from the [GitHub releases page](https://github.com/arduino/arduino-ide/releases).
|
|
||||||
|
|
||||||
#### Nightly builds
|
|
||||||
|
|
||||||
These builds are generated every day at 03:00 GMT from the `main` branch and
|
These builds are generated every day at 03:00 GMT from the `main` branch and
|
||||||
should be considered unstable. In order to get the latest nightly build
|
should be considered unstable:
|
||||||
available for the supported platform, use the following links:
|
|
||||||
|
|
||||||
Platform | 32 bit | 64 bit |
|
Platform | 32 bit | 64 bit |
|
||||||
--------- | ------------------------ | ------------------------------------------------------------------------------------------------------ |
|
--------- | ------------------------ | ------------------------------------------------------------------------------------------------------ |
|
||||||
@@ -39,7 +27,7 @@ Linux ARM | [🚧 Work in progress...] | [🚧 Work in progress...]
|
|||||||
Windows | | [Nightly Windows 64 bit installer]<br />[Nightly Windows 64 bit MSI]<br />[Nightly Windows 64 bit ZIP] |
|
Windows | | [Nightly Windows 64 bit installer]<br />[Nightly Windows 64 bit MSI]<br />[Nightly Windows 64 bit ZIP] |
|
||||||
macOS | | [Nightly macOS 64 bit] |
|
macOS | | [Nightly macOS 64 bit] |
|
||||||
|
|
||||||
[🚧 Work in progress...]: https://github.com/arduino/arduino-ide/issues/287
|
[🚧 Work in progress...]: https://github.com/arduino/arduino-ide/issues/107
|
||||||
[Nightly Linux 64 bit]: https://downloads.arduino.cc/arduino-ide/nightly/arduino-ide_nightly-latest_Linux_64bit.zip
|
[Nightly Linux 64 bit]: https://downloads.arduino.cc/arduino-ide/nightly/arduino-ide_nightly-latest_Linux_64bit.zip
|
||||||
[Nightly Windows 64 bit installer]: https://downloads.arduino.cc/arduino-ide/nightly/arduino-ide_nightly-latest_Windows_64bit.exe
|
[Nightly Windows 64 bit installer]: https://downloads.arduino.cc/arduino-ide/nightly/arduino-ide_nightly-latest_Windows_64bit.exe
|
||||||
[Nightly Windows 64 bit MSI]: https://downloads.arduino.cc/arduino-ide/nightly/arduino-ide_nightly-latest_Windows_64bit.msi
|
[Nightly Windows 64 bit MSI]: https://downloads.arduino.cc/arduino-ide/nightly/arduino-ide_nightly-latest_Windows_64bit.msi
|
||||||
@@ -49,117 +37,41 @@ macOS | | [Nightly macOS 64 bit]
|
|||||||
> These links return an HTTP `302: Found` response, redirecting to latest
|
> These links return an HTTP `302: Found` response, redirecting to latest
|
||||||
generated builds by replacing `latest` with the latest available build
|
generated builds by replacing `latest` with the latest available build
|
||||||
date, using the format YYYYMMDD (i.e for 2019/Aug/06 `latest` is
|
date, using the format YYYYMMDD (i.e for 2019/Aug/06 `latest` is
|
||||||
replaced with `20190806` )
|
replaced with `20190806`)
|
||||||
|
|
||||||
### Build from source
|
## Support
|
||||||
|
|
||||||
If you’re familiar with TypeScript, the [Theia IDE](https://theia-ide.org/), and if you want to contribute to the
|
If you need assistance, see the [Help Center](https://support.arduino.cc/hc/en-us/categories/360002212660-Software-and-Downloads) and browse the [forum](https://forum.arduino.cc/index.php?board=150.0).
|
||||||
project, you should be able to build the Arduino IDE locally. Please refer to the [Theia IDE prerequisites](https://github.com/theia-ide/theia/blob/master/doc/) documentation for the setup instructions.
|
|
||||||
|
|
||||||
### Build
|
## Bugs & Issues
|
||||||
```sh
|
|
||||||
yarn
|
|
||||||
```
|
|
||||||
|
|
||||||
### Rebuild the native dependencies
|
If you want to report an issue, you can submit it to the [issue tracker](https://github.com/arduino/arduino-ide/issues) of this repository. A few rules apply:
|
||||||
```sh
|
|
||||||
yarn rebuild:electron
|
|
||||||
```
|
|
||||||
|
|
||||||
### Start
|
* Before posting, please check if the same problem has been already reported by someone else to avoid duplicates.
|
||||||
```sh
|
* Remember to include as much detail as you can about your hardware set-up, code and steps for reproducing the issue. Make sure you're using an original Arduino board.
|
||||||
yarn start
|
|
||||||
```
|
|
||||||
|
|
||||||
### CI
|
### Security
|
||||||
|
|
||||||
This project is built on [GitHub Actions](https://github.com/bcmi-labs/arduino-editor/actions?query=workflow%3A%22Arduino+Pro+IDE%22).
|
If you think you found a vulnerability or other security-related bug in this project, please read our
|
||||||
|
[security policy](https://github.com/arduino/arduino-ide/security/policy) and report the bug to our Security Team 🛡️
|
||||||
|
Thank you!
|
||||||
|
|
||||||
- _Snapshot_ builds run when changes are pushed to the `main` branch, or when a PR is created against the `main` branch. For the sake of the review and verification process, the build artifacts can be downloaded from the GitHub Actions page. Note: [due to a limitation](https://github.com/actions/upload-artifact/issues/80#issuecomment-630030144) with the GH Actions UI, you cannot download a particular build, but you have to get all together inside the `build-artifacts.zip`.
|
e-mail contact: security@arduino.cc
|
||||||
- _Nightly_ builds run every day at 03:00 GMT from the `main` branch.
|
|
||||||
- _Release_ builds run when a new tag is pushed to the remote. The tag must follow the [semver](https://semver.org/). For instance, `1.2.3` is a correct tag, but `v2.3.4` won't work. Steps to trigger a new release build:
|
|
||||||
- Create a local tag:
|
|
||||||
```sh
|
|
||||||
git tag -a 1.2.3 -m "Creating a new tag for the `1.2.3` release."
|
|
||||||
```
|
|
||||||
- Push it to the remote:
|
|
||||||
```sh
|
|
||||||
git push origin 1.2.3
|
|
||||||
```
|
|
||||||
|
|
||||||
### Creating a GH release
|
## Contributions and development
|
||||||
This section guides you through how to create a new release. Let's assume the current version is `0.1.3` and you want to release `0.2.0`.
|
|
||||||
|
|
||||||
- Make sure the `main` state represents what you want to release and you're on `main`.
|
Contributions are very welcome! You can browse the list of open issues to see what's needed and then you can submit your code using a Pull Request. Please provide detailed descriptions. We also appreciate any help in testing issues and patches contributed by other users.
|
||||||
- Prepare a release-candidate build on a branch:
|
|
||||||
```bash
|
|
||||||
git branch 0.2.0-rc \
|
|
||||||
&& git checkout 0.2.0-rc
|
|
||||||
```
|
|
||||||
- Bump up the version number. It must be a valid [semver](https://semver.org/) and must be greater than the current one:
|
|
||||||
```bash
|
|
||||||
yarn update:version 0.2.0
|
|
||||||
```
|
|
||||||
- This should generate multiple outgoing changes with the version update.
|
|
||||||
- Commit your changes and push to the remote:
|
|
||||||
```bash
|
|
||||||
git add . \
|
|
||||||
&& git commit -s -m "Updated versions to 0.2.0" \
|
|
||||||
&& git push
|
|
||||||
```
|
|
||||||
- Create the GH PR the workflow starts automatically.
|
|
||||||
- Once you're happy with the RC, merge the changes to the `main`.
|
|
||||||
- Create a tag and push it:
|
|
||||||
```bash
|
|
||||||
git tag -a 0.2.0 -m "0.2.0" \
|
|
||||||
&& git push origin 0.2.0
|
|
||||||
```
|
|
||||||
- The release build starts automatically and uploads the artifacts with the changelog to the Pro IDE [release page](https://github.com/arduino/arduino-ide/releases).
|
|
||||||
- If you do not want to release the `EXE` and `MSI` installers, wipe them manually.
|
|
||||||
- If you do not like the generated changelog, modify it and update the GH release.
|
|
||||||
|
|
||||||
|
This repository contains the main code, but two more repositories are included during the build process:
|
||||||
|
|
||||||
### FAQ
|
* [vscode-arduino-tools](https://github.com/arduino/vscode-arduino-tools): provides support for the language server and the debugger
|
||||||
|
* [arduino-language-server](https://github.com/arduino/arduino-language-server): provides the language server that parses Arduino code
|
||||||
|
|
||||||
- Q: Can I manually change the version of the [`arduino-cli`](https://github.com/arduino/arduino-cli/) used by the IDE?
|
See the [BUILDING.md](BUILDING.md) for a technical overview of the application and instructions for building the code.
|
||||||
- A: Yes. It is possible but not recommended. The CLI exposes a set of functionality via [gRPC](https://github.com/arduino/arduino-cli/tree/master/rpc) and the IDE uses this API to communicate with the CLI. Before we build a new version of IDE, we pin a specific version of CLI and use the corresponding `proto` files to generate TypeScript modules for gRPC. This means, a particular version of IDE is compliant only with the pinned version of CLI. Mismatching IDE and CLI versions might not be able to communicate with each other. This could cause unpredictable IDE behavior.
|
## Donations
|
||||||
|
|
||||||
- Q: I have understood that not all versions of the CLI is compatible with my version of IDE but how can I manually update the `arduino-cli` inside the IDE?
|
This open source code was written by the Arduino team and is maintained on a daily basis with the help of the community. We invest a considerable amount of time in development, testing and optimization. Please consider [donating](https://www.arduino.cc/en/donate/) or [sponsoring](https://github.com/sponsors/arduino) to support our work, as well as [buying original Arduino boards](https://store.arduino.cc/) which is the best way to make sure our effort can continue in the long term.
|
||||||
- A: [Get](https://arduino.github.io/arduino-cli/installation) the desired version of `arduino-cli` for your platform and manually replace the one inside the IDE. The CLI can be found inside the IDE at:
|
|
||||||
- Windows: `C:\path\to\Arduino IDE\resources\app\node_modules\arduino-ide-extension\build\arduino-cli.exe`,
|
|
||||||
- macOS: `/path/to/Arduino IDE.app/Contents/Resources/app/node_modules/arduino-ide-extension/build/arduino-cli`, and
|
|
||||||
- Linux: `/path/to/Arduino IDE/resources/app/node_modules/arduino-ide-extension/build/arduino-cli`.
|
|
||||||
|
|
||||||
### Architecture overview
|
## License
|
||||||
|
|
||||||
The Pro IDE consists of three major parts:
|
The code contained in this repository and the executable distributions are licensed under the terms of the GNU AGPLv3. The executable distributions contain third-party code licensed under other compatible licenses such as GPLv2, MIT and BSD-3. If you have questions about licensing please contact us at [license@arduino.cc](mailto:license@arduino.cc).
|
||||||
- the _Electron main_ process,
|
|
||||||
- the _backend_, and
|
|
||||||
- the _frontend_.
|
|
||||||
|
|
||||||
The _Electron main_ process is responsible for:
|
|
||||||
- creating the application,
|
|
||||||
- managing the application lifecycle via listeners, and
|
|
||||||
- creating and managing the web pages for the app.
|
|
||||||
|
|
||||||
In Electron, the process that runs the main entry JavaScript file is called the main process. The _Electron main_ process can display a GUI by creating web pages. An Electron app always has exactly on main process.
|
|
||||||
|
|
||||||
By default, whenever the _Electron main_ process creates a web page, it will instantiate a new `BrowserWindow` instance. Since Electron uses Chromium for displaying web pages, Chromium's multi-process architecture is also used. Each web page in Electron runs in its own process, which is called the renderer process. Each `BrowserWindow` instance runs the web page in its own renderer process. When a `BrowserWindow` instance is destroyed, the corresponding renderer process is also terminated. The main process manages all web pages and their corresponding renderer processes. Each renderer process is isolated and only cares about the web page running in it.<sup>[[1]]</sup>
|
|
||||||
|
|
||||||
In normal browsers, web pages usually run in a sandboxed environment, and accessing native resources are disallowed. However, Electron has the power to use Node.js APIs in the web pages allowing lower-level OS interactions. Due to security reasons, accessing native resources is an undesired behavior in the Pro IDE. So by convention, we do not use Node.js APIs. (Note: the Node.js integration is [not yet disabled](https://github.com/eclipse-theia/theia/issues/2018) although it is not used). In the Pro IDE, only the _backend_ allows OS interaction.
|
|
||||||
|
|
||||||
The _backend_ process is responsible for:
|
|
||||||
- providing access to the filesystem,
|
|
||||||
- communicating with the Arduino CLI via gRPC,
|
|
||||||
- running your terminal,
|
|
||||||
- exposing additional RESTful APIs,
|
|
||||||
- performing the Git commands in the local repositories,
|
|
||||||
- hosting and running any VS Code extensions, or
|
|
||||||
- executing VS Code tasks<sup>[[2]]</sup>.
|
|
||||||
|
|
||||||
The _Electron main_ process spawns the _backend_ process. There is always exactly one _backend_ process. However, due to performance considerations, the _backend_ spawns several sub-processes for the filesystem watching, Git repository discovery, etc. The communication between the _backend_ process and its sub-processes is established via IPC. Besides spawning sub-processes, the _backend_ will start an HTTP server on a random available port, and serves the web application as static content. When the sub-processes are up and running, and the HTTP server is also listening, the _backend_ process sends the HTTP server port to the _Electron main_ process via IPC. The _Electron main_ process will load the _backend_'s endpoint in the `BrowserWindow`.
|
|
||||||
|
|
||||||
The _frontend_ is running as an Electron renderer process and can invoke services implemented on the _backend_. The communication between the _backend_ and the _frontend_ is done via JSON-RPC over a websocket connection. This means, the services running in the _frontend_ are all proxies, and will ask the corresponding service implementation on the _backend_.
|
|
||||||
|
|
||||||
[1]: https://www.electronjs.org/docs/tutorial/application-architecture#differences-between-main-process-and-renderer-process
|
|
||||||
[2]: https://code.visualstudio.com/Docs/editor/tasks
|
|
||||||
|
|||||||
@@ -54,3 +54,17 @@ The Config Service knows about your system, like for example the default sketch
|
|||||||
### `"arduino"` configuration in the `package.json`:
|
### `"arduino"` configuration in the `package.json`:
|
||||||
- `"cli"`:
|
- `"cli"`:
|
||||||
- `"version"` type `string` | `{ owner: string, repo: string, commitish?: string }`: if the type is a `string` and is a valid semver, it will get the corresponding [released](https://github.com/arduino/arduino-cli/releases) CLI. If the type is `string` and is a [date in `YYYYMMDD`](https://arduino.github.io/arduino-cli/latest/installation/#nightly-builds) format, it will get a nightly CLI. If the type is an object, a CLI, build from the sources in the `owner/repo` will be used. If `commitish` is not defined, the HEAD of the default branch will be used. In any other cases an error is thrown.
|
- `"version"` type `string` | `{ owner: string, repo: string, commitish?: string }`: if the type is a `string` and is a valid semver, it will get the corresponding [released](https://github.com/arduino/arduino-cli/releases) CLI. If the type is `string` and is a [date in `YYYYMMDD`](https://arduino.github.io/arduino-cli/latest/installation/#nightly-builds) format, it will get a nightly CLI. If the type is an object, a CLI, build from the sources in the `owner/repo` will be used. If `commitish` is not defined, the HEAD of the default branch will be used. In any other cases an error is thrown.
|
||||||
|
|
||||||
|
#### Rebuild gRPC protocol interfaces
|
||||||
|
- Some CLI updates can bring changes to the gRPC interfaces, as the API might change. gRPC interfaces can be updated running the command
|
||||||
|
`yarn --cwd arduino-ide-extension generate-protocol`
|
||||||
|
|
||||||
|
### Customize Icons
|
||||||
|
ArduinoIde uses a customized version of FontAwesome.
|
||||||
|
In order to update/replace icons follow the following steps:
|
||||||
|
- import the file `arduino-icons.json` in [Icomoon](https://icomoon.io/app/#/projects)
|
||||||
|
- load it
|
||||||
|
- edit the icons as needed
|
||||||
|
- !! download the **new** `arduino-icons.json` file and put it in this repo
|
||||||
|
- Click on "Generate Font" in Icomoon, then download
|
||||||
|
- place the updated fonts in the `src/style/fonts` directory
|
||||||
|
|||||||
15709
arduino-ide-extension/arduino-icons.json
Normal file
15709
arduino-ide-extension/arduino-icons.json
Normal file
File diff suppressed because one or more lines are too long
@@ -1,16 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "arduino-ide-extension",
|
"name": "arduino-ide-extension",
|
||||||
"version": "2.0.0-beta.2",
|
"version": "2.0.0-beta.11",
|
||||||
"description": "An extension for Theia building the Arduino IDE",
|
"description": "An extension for Theia building the Arduino IDE",
|
||||||
"license": "MIT",
|
"license": "AGPL-3.0-or-later",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepare": "yarn download-cli && yarn download-ls && yarn clean && yarn download-examples && yarn build",
|
"prepare": "yarn download-cli && yarn download-fwuploader && yarn download-ls && yarn clean && yarn download-examples && yarn build",
|
||||||
"clean": "rimraf lib",
|
"clean": "rimraf lib",
|
||||||
"download-cli": "node ./scripts/download-cli.js",
|
"download-cli": "node ./scripts/download-cli.js",
|
||||||
|
"download-fwuploader": "node ./scripts/download-fwuploader.js",
|
||||||
"download-ls": "node ./scripts/download-ls.js",
|
"download-ls": "node ./scripts/download-ls.js",
|
||||||
"download-examples": "node ./scripts/download-examples.js",
|
"download-examples": "node ./scripts/download-examples.js",
|
||||||
"generate-protocol": "node ./scripts/generate-protocol.js",
|
"generate-protocol": "node ./scripts/generate-protocol.js",
|
||||||
"lint": "tslint -c ./tslint.json --project ./tsconfig.json",
|
"lint": "eslint",
|
||||||
"build": "tsc && ncp ./src/node/cli-protocol/ ./lib/node/cli-protocol/ && yarn lint",
|
"build": "tsc && ncp ./src/node/cli-protocol/ ./lib/node/cli-protocol/ && yarn lint",
|
||||||
"watch": "tsc -w",
|
"watch": "tsc -w",
|
||||||
"test": "mocha \"./lib/test/**/*.test.js\"",
|
"test": "mocha \"./lib/test/**/*.test.js\"",
|
||||||
@@ -23,22 +24,29 @@
|
|||||||
"@theia/editor": "next",
|
"@theia/editor": "next",
|
||||||
"@theia/filesystem": "next",
|
"@theia/filesystem": "next",
|
||||||
"@theia/git": "next",
|
"@theia/git": "next",
|
||||||
|
"@theia/keymaps": "next",
|
||||||
"@theia/markers": "next",
|
"@theia/markers": "next",
|
||||||
"@theia/monaco": "next",
|
"@theia/monaco": "next",
|
||||||
"@theia/navigator": "next",
|
"@theia/navigator": "next",
|
||||||
"@theia/outline-view": "next",
|
"@theia/outline-view": "next",
|
||||||
"@theia/preferences": "next",
|
|
||||||
"@theia/output": "next",
|
"@theia/output": "next",
|
||||||
|
"@theia/preferences": "next",
|
||||||
"@theia/search-in-workspace": "next",
|
"@theia/search-in-workspace": "next",
|
||||||
"@theia/terminal": "next",
|
"@theia/terminal": "next",
|
||||||
"@theia/workspace": "next",
|
"@theia/workspace": "next",
|
||||||
|
"@tippyjs/react": "^4.2.5",
|
||||||
|
"@types/atob": "^2.1.2",
|
||||||
|
"@types/auth0-js": "^9.14.0",
|
||||||
|
"@types/btoa": "^1.2.3",
|
||||||
"@types/dateformat": "^3.0.1",
|
"@types/dateformat": "^3.0.1",
|
||||||
"@types/deepmerge": "^2.2.0",
|
"@types/deepmerge": "^2.2.0",
|
||||||
"@types/glob": "^5.0.35",
|
"@types/glob": "^5.0.35",
|
||||||
"@types/google-protobuf": "^3.7.2",
|
"@types/google-protobuf": "^3.7.2",
|
||||||
"@types/js-yaml": "^3.12.2",
|
"@types/js-yaml": "^3.12.2",
|
||||||
|
"@types/keytar": "^4.4.0",
|
||||||
"@types/lodash.debounce": "^4.0.6",
|
"@types/lodash.debounce": "^4.0.6",
|
||||||
"@types/ncp": "^2.0.4",
|
"@types/ncp": "^2.0.4",
|
||||||
|
"@types/node-fetch": "^2.5.7",
|
||||||
"@types/ps-tree": "^1.1.0",
|
"@types/ps-tree": "^1.1.0",
|
||||||
"@types/react-select": "^3.0.0",
|
"@types/react-select": "^3.0.0",
|
||||||
"@types/react-tabs": "^2.3.2",
|
"@types/react-tabs": "^2.3.2",
|
||||||
@@ -46,15 +54,25 @@
|
|||||||
"@types/temp": "^0.8.34",
|
"@types/temp": "^0.8.34",
|
||||||
"@types/which": "^1.3.1",
|
"@types/which": "^1.3.1",
|
||||||
"ajv": "^6.5.3",
|
"ajv": "^6.5.3",
|
||||||
|
"async-mutex": "^0.3.0",
|
||||||
|
"atob": "^2.1.2",
|
||||||
|
"auth0-js": "^9.14.0",
|
||||||
|
"btoa": "^1.2.1",
|
||||||
"css-element-queries": "^1.2.0",
|
"css-element-queries": "^1.2.0",
|
||||||
"dateformat": "^3.0.3",
|
"dateformat": "^3.0.3",
|
||||||
"deepmerge": "^4.2.2",
|
"deepmerge": "2.0.1",
|
||||||
"fuzzy": "^0.1.3",
|
"fuzzy": "^0.1.3",
|
||||||
"glob": "^7.1.6",
|
"glob": "^7.1.6",
|
||||||
"google-protobuf": "^3.11.4",
|
"google-protobuf": "^3.11.4",
|
||||||
"lodash.debounce": "^4.0.8",
|
"hash.js": "^1.1.7",
|
||||||
|
"is-valid-path": "^0.1.1",
|
||||||
"js-yaml": "^3.13.1",
|
"js-yaml": "^3.13.1",
|
||||||
|
"jwt-decode": "^3.1.2",
|
||||||
|
"keytar": "7.2.0",
|
||||||
|
"lodash.debounce": "^4.0.8",
|
||||||
"ncp": "^2.0.0",
|
"ncp": "^2.0.0",
|
||||||
|
"node-fetch": "^2.6.1",
|
||||||
|
"open": "^8.0.6",
|
||||||
"p-queue": "^5.0.0",
|
"p-queue": "^5.0.0",
|
||||||
"ps-tree": "^1.2.0",
|
"ps-tree": "^1.2.0",
|
||||||
"react-disable": "^0.1.0",
|
"react-disable": "^0.1.0",
|
||||||
@@ -114,16 +132,16 @@
|
|||||||
"frontend": "lib/browser/theia/core/browser-menu-module",
|
"frontend": "lib/browser/theia/core/browser-menu-module",
|
||||||
"frontendElectron": "lib/electron-browser/theia/core/electron-menu-module"
|
"frontendElectron": "lib/electron-browser/theia/core/electron-menu-module"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"frontend": "lib/browser/boards/quick-open/boards-quick-open-module"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"electronMain": "lib/electron-main/arduino-electron-main-module"
|
"electronMain": "lib/electron-main/arduino-electron-main-module"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"arduino": {
|
"arduino": {
|
||||||
"cli": {
|
"cli": {
|
||||||
"version": "0.16.0"
|
"version": "0.18.3"
|
||||||
|
},
|
||||||
|
"fwuploader": {
|
||||||
|
"version": "2.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
// The version to use.
|
// The version to use.
|
||||||
const version = '1.9.0';
|
const version = '1.9.1';
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|
||||||
|
|||||||
166
arduino-ide-extension/scripts/download-fwuploader.js
Executable file
166
arduino-ide-extension/scripts/download-fwuploader.js
Executable file
@@ -0,0 +1,166 @@
|
|||||||
|
// @ts-check
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const temp = require('temp');
|
||||||
|
const shell = require('shelljs');
|
||||||
|
const semver = require('semver');
|
||||||
|
const downloader = require('./downloader');
|
||||||
|
|
||||||
|
const version = (() => {
|
||||||
|
const pkg = require(path.join(__dirname, '..', 'package.json'));
|
||||||
|
if (!pkg) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { arduino } = pkg;
|
||||||
|
if (!arduino) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { fwuploader } = arduino;
|
||||||
|
if (!fwuploader) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { version } = fwuploader;
|
||||||
|
return version;
|
||||||
|
})();
|
||||||
|
|
||||||
|
if (!version) {
|
||||||
|
shell.echo(
|
||||||
|
`Could not retrieve Firmware Uploader version info from the 'package.json'.`
|
||||||
|
);
|
||||||
|
shell.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { platform, arch } = process;
|
||||||
|
const buildFolder = path.join(__dirname, '..', 'build');
|
||||||
|
const fwuploderName = `arduino-fwuploader${
|
||||||
|
platform === 'win32' ? '.exe' : ''
|
||||||
|
}`;
|
||||||
|
const destinationPath = path.join(buildFolder, fwuploderName);
|
||||||
|
|
||||||
|
if (typeof version === 'string') {
|
||||||
|
const suffix = (() => {
|
||||||
|
switch (platform) {
|
||||||
|
case 'darwin':
|
||||||
|
return 'macOS_64bit.tar.gz';
|
||||||
|
case 'win32':
|
||||||
|
return 'Windows_64bit.zip';
|
||||||
|
case 'linux': {
|
||||||
|
switch (arch) {
|
||||||
|
case 'arm':
|
||||||
|
return 'Linux_ARMv7.tar.gz';
|
||||||
|
case 'arm64':
|
||||||
|
return 'Linux_ARM64.tar.gz';
|
||||||
|
case 'x64':
|
||||||
|
return 'Linux_64bit.tar.gz';
|
||||||
|
default:
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
if (!suffix) {
|
||||||
|
shell.echo(
|
||||||
|
`The Firmware Uploader is not available for ${platform} ${arch}.`
|
||||||
|
);
|
||||||
|
shell.exit(1);
|
||||||
|
}
|
||||||
|
if (semver.valid(version)) {
|
||||||
|
const url = `https://downloads.arduino.cc/arduino-fwuploader/arduino-fwuploader_${version}_${suffix}`;
|
||||||
|
shell.echo(
|
||||||
|
`📦 Identified released version of the Firmware Uploader. Downloading version ${version} from '${url}'`
|
||||||
|
);
|
||||||
|
await downloader.downloadUnzipFile(
|
||||||
|
url,
|
||||||
|
destinationPath,
|
||||||
|
'arduino-fwuploader'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
shell.echo(`🔥 Could not interpret 'version': ${version}`);
|
||||||
|
shell.exit(1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// We assume an object with `owner`, `repo`, commitish?` properties.
|
||||||
|
const { owner, repo, commitish } = version;
|
||||||
|
if (!owner) {
|
||||||
|
shell.echo(`Could not retrieve 'owner' from ${JSON.stringify(version)}`);
|
||||||
|
shell.exit(1);
|
||||||
|
}
|
||||||
|
if (!repo) {
|
||||||
|
shell.echo(`Could not retrieve 'repo' from ${JSON.stringify(version)}`);
|
||||||
|
shell.exit(1);
|
||||||
|
}
|
||||||
|
const url = `https://github.com/${owner}/${repo}.git`;
|
||||||
|
shell.echo(
|
||||||
|
`Building Firmware Uploader from ${url}. Commitish: ${
|
||||||
|
commitish ? commitish : 'HEAD'
|
||||||
|
}`
|
||||||
|
);
|
||||||
|
|
||||||
|
if (fs.existsSync(destinationPath)) {
|
||||||
|
shell.echo(
|
||||||
|
`Skipping the Firmware Uploader build because it already exists: ${destinationPath}`
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shell.mkdir('-p', buildFolder).code !== 0) {
|
||||||
|
shell.echo('Could not create build folder.');
|
||||||
|
shell.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const tempRepoPath = temp.mkdirSync();
|
||||||
|
shell.echo(`>>> Cloning Firmware Uploader source to ${tempRepoPath}...`);
|
||||||
|
if (shell.exec(`git clone ${url} ${tempRepoPath}`).code !== 0) {
|
||||||
|
shell.exit(1);
|
||||||
|
}
|
||||||
|
shell.echo('<<< Cloned Firmware Uploader repo.');
|
||||||
|
|
||||||
|
if (commitish) {
|
||||||
|
shell.echo(`>>> Checking out ${commitish}...`);
|
||||||
|
if (
|
||||||
|
shell.exec(`git -C ${tempRepoPath} checkout ${commitish}`).code !== 0
|
||||||
|
) {
|
||||||
|
shell.exit(1);
|
||||||
|
}
|
||||||
|
shell.echo(`<<< Checked out ${commitish}.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
shell.echo(`>>> Building the Firmware Uploader...`);
|
||||||
|
if (shell.exec('go build', { cwd: tempRepoPath }).code !== 0) {
|
||||||
|
shell.exit(1);
|
||||||
|
}
|
||||||
|
shell.echo('<<< Firmware Uploader build done.');
|
||||||
|
|
||||||
|
if (!fs.existsSync(path.join(tempRepoPath, fwuploderName))) {
|
||||||
|
shell.echo(
|
||||||
|
`Could not find the Firmware Uploader at ${path.join(
|
||||||
|
tempRepoPath,
|
||||||
|
fwuploderName
|
||||||
|
)}.`
|
||||||
|
);
|
||||||
|
shell.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const builtFwUploaderPath = path.join(tempRepoPath, fwuploderName);
|
||||||
|
shell.echo(
|
||||||
|
`>>> Copying Firmware Uploader from ${builtFwUploaderPath} to ${destinationPath}...`
|
||||||
|
);
|
||||||
|
if (shell.cp(builtFwUploaderPath, destinationPath).code !== 0) {
|
||||||
|
shell.exit(1);
|
||||||
|
}
|
||||||
|
shell.echo(`<<< Copied the Firmware Uploader.`);
|
||||||
|
|
||||||
|
shell.echo('<<< Verifying Firmware Uploader...');
|
||||||
|
if (!fs.existsSync(destinationPath)) {
|
||||||
|
shell.exit(1);
|
||||||
|
}
|
||||||
|
shell.echo('>>> Verified Firmware Uploader.');
|
||||||
|
}
|
||||||
|
})();
|
||||||
@@ -4,20 +4,18 @@ import { Command } from '@theia/core/lib/common/command';
|
|||||||
* @deprecated all these commands should go under contributions and have their command, menu, keybinding, and toolbar contributions.
|
* @deprecated all these commands should go under contributions and have their command, menu, keybinding, and toolbar contributions.
|
||||||
*/
|
*/
|
||||||
export namespace ArduinoCommands {
|
export namespace ArduinoCommands {
|
||||||
|
export const TOGGLE_COMPILE_FOR_DEBUG: Command = {
|
||||||
|
id: 'arduino-toggle-compile-for-debug',
|
||||||
|
};
|
||||||
|
|
||||||
export const TOGGLE_COMPILE_FOR_DEBUG: Command = {
|
/**
|
||||||
id: 'arduino-toggle-compile-for-debug'
|
* Unlike `OPEN_SKETCH`, it opens all files from a sketch folder. (ino, cpp, etc...)
|
||||||
};
|
*/
|
||||||
|
export const OPEN_SKETCH_FILES: Command = {
|
||||||
/**
|
id: 'arduino-open-sketch-files',
|
||||||
* Unlike `OPEN_SKETCH`, it opens all files from a sketch folder. (ino, cpp, etc...)
|
};
|
||||||
*/
|
|
||||||
export const OPEN_SKETCH_FILES: Command = {
|
|
||||||
id: 'arduino-open-sketch-files'
|
|
||||||
};
|
|
||||||
|
|
||||||
export const OPEN_BOARDS_DIALOG: Command = {
|
|
||||||
id: 'arduino-open-boards-dialog'
|
|
||||||
};
|
|
||||||
|
|
||||||
|
export const OPEN_BOARDS_DIALOG: Command = {
|
||||||
|
id: 'arduino-open-boards-dialog',
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,38 @@
|
|||||||
const debounce = require('lodash.debounce');
|
import { Mutex } from 'async-mutex';
|
||||||
import { MAIN_MENU_BAR, MenuContribution, MenuModelRegistry, SelectionService, ILogger } from '@theia/core';
|
|
||||||
import {
|
import {
|
||||||
ContextMenuRenderer,
|
MAIN_MENU_BAR,
|
||||||
FrontendApplication, FrontendApplicationContribution,
|
MenuContribution,
|
||||||
OpenerService, StatusBar, StatusBarAlignment
|
MenuModelRegistry,
|
||||||
|
SelectionService,
|
||||||
|
ILogger,
|
||||||
|
DisposableCollection,
|
||||||
|
} from '@theia/core';
|
||||||
|
import {
|
||||||
|
ContextMenuRenderer,
|
||||||
|
FrontendApplication,
|
||||||
|
FrontendApplicationContribution,
|
||||||
|
OpenerService,
|
||||||
|
StatusBar,
|
||||||
|
StatusBarAlignment,
|
||||||
} from '@theia/core/lib/browser';
|
} from '@theia/core/lib/browser';
|
||||||
import { ColorContribution } from '@theia/core/lib/browser/color-application-contribution';
|
import { ColorContribution } from '@theia/core/lib/browser/color-application-contribution';
|
||||||
import { ColorRegistry } from '@theia/core/lib/browser/color-registry';
|
import { ColorRegistry } from '@theia/core/lib/browser/color-registry';
|
||||||
import { CommonMenus } from '@theia/core/lib/browser/common-frontend-contribution';
|
import { CommonMenus } from '@theia/core/lib/browser/common-frontend-contribution';
|
||||||
import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
|
import {
|
||||||
import { CommandContribution, CommandRegistry } from '@theia/core/lib/common/command';
|
TabBarToolbarContribution,
|
||||||
|
TabBarToolbarRegistry,
|
||||||
|
} from '@theia/core/lib/browser/shell/tab-bar-toolbar';
|
||||||
|
import {
|
||||||
|
CommandContribution,
|
||||||
|
CommandRegistry,
|
||||||
|
} from '@theia/core/lib/common/command';
|
||||||
import { MessageService } from '@theia/core/lib/common/message-service';
|
import { MessageService } from '@theia/core/lib/common/message-service';
|
||||||
import URI from '@theia/core/lib/common/uri';
|
import URI from '@theia/core/lib/common/uri';
|
||||||
import { EditorMainMenu, EditorManager } from '@theia/editor/lib/browser';
|
import {
|
||||||
|
EditorMainMenu,
|
||||||
|
EditorManager,
|
||||||
|
EditorOpenerOptions,
|
||||||
|
} from '@theia/editor/lib/browser';
|
||||||
import { FileDialogService } from '@theia/filesystem/lib/browser/file-dialog';
|
import { FileDialogService } from '@theia/filesystem/lib/browser/file-dialog';
|
||||||
import { ProblemContribution } from '@theia/markers/lib/browser/problem/problem-contribution';
|
import { ProblemContribution } from '@theia/markers/lib/browser/problem/problem-contribution';
|
||||||
import { MonacoMenus } from '@theia/monaco/lib/browser/monaco-menu';
|
import { MonacoMenus } from '@theia/monaco/lib/browser/monaco-menu';
|
||||||
@@ -26,7 +46,14 @@ import { inject, injectable, postConstruct } from 'inversify';
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { remote } from 'electron';
|
import { remote } from 'electron';
|
||||||
import { MainMenuManager } from '../common/main-menu-manager';
|
import { MainMenuManager } from '../common/main-menu-manager';
|
||||||
import { BoardsService, CoreService, Port, SketchesService, ExecutableService } from '../common/protocol';
|
import {
|
||||||
|
BoardsService,
|
||||||
|
CoreService,
|
||||||
|
Port,
|
||||||
|
SketchesService,
|
||||||
|
ExecutableService,
|
||||||
|
Sketch,
|
||||||
|
} from '../common/protocol';
|
||||||
import { ArduinoDaemon } from '../common/protocol/arduino-daemon';
|
import { ArduinoDaemon } from '../common/protocol/arduino-daemon';
|
||||||
import { ConfigService } from '../common/protocol/config-service';
|
import { ConfigService } from '../common/protocol/config-service';
|
||||||
import { FileSystemExt } from '../common/protocol/filesystem-ext';
|
import { FileSystemExt } from '../common/protocol/filesystem-ext';
|
||||||
@@ -44,367 +71,523 @@ import { WorkspaceService } from './theia/workspace/workspace-service';
|
|||||||
import { ArduinoToolbar } from './toolbar/arduino-toolbar';
|
import { ArduinoToolbar } from './toolbar/arduino-toolbar';
|
||||||
import { HostedPluginSupport } from '@theia/plugin-ext/lib/hosted/browser/hosted-plugin';
|
import { HostedPluginSupport } from '@theia/plugin-ext/lib/hosted/browser/hosted-plugin';
|
||||||
import { FileService } from '@theia/filesystem/lib/browser/file-service';
|
import { FileService } from '@theia/filesystem/lib/browser/file-service';
|
||||||
import { OutputService } from '../common/protocol/output-service';
|
import { ResponseService } from '../common/protocol/response-service';
|
||||||
import { ArduinoPreferences } from './arduino-preferences';
|
import { ArduinoPreferences } from './arduino-preferences';
|
||||||
import { SketchesServiceClientImpl } from '../common/protocol/sketches-service-client-impl';
|
import { SketchesServiceClientImpl } from '../common/protocol/sketches-service-client-impl';
|
||||||
import { SaveAsSketch } from './contributions/save-as-sketch';
|
import { SaveAsSketch } from './contributions/save-as-sketch';
|
||||||
|
import { FileChangeType } from '@theia/filesystem/lib/browser';
|
||||||
|
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
|
||||||
|
import { SketchbookWidgetContribution } from './widgets/sketchbook/sketchbook-widget-contribution';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class ArduinoFrontendContribution implements FrontendApplicationContribution,
|
export class ArduinoFrontendContribution
|
||||||
TabBarToolbarContribution, CommandContribution, MenuContribution, ColorContribution {
|
implements
|
||||||
|
FrontendApplicationContribution,
|
||||||
|
TabBarToolbarContribution,
|
||||||
|
CommandContribution,
|
||||||
|
MenuContribution,
|
||||||
|
ColorContribution
|
||||||
|
{
|
||||||
|
@inject(ILogger)
|
||||||
|
protected logger: ILogger;
|
||||||
|
|
||||||
@inject(ILogger)
|
@inject(MessageService)
|
||||||
protected logger: ILogger;
|
protected readonly messageService: MessageService;
|
||||||
|
|
||||||
@inject(MessageService)
|
@inject(BoardsService)
|
||||||
protected readonly messageService: MessageService;
|
protected readonly boardsService: BoardsService;
|
||||||
|
|
||||||
@inject(BoardsService)
|
@inject(CoreService)
|
||||||
protected readonly boardsService: BoardsService;
|
protected readonly coreService: CoreService;
|
||||||
|
|
||||||
@inject(CoreService)
|
@inject(BoardsServiceProvider)
|
||||||
protected readonly coreService: CoreService;
|
protected readonly boardsServiceClientImpl: BoardsServiceProvider;
|
||||||
|
|
||||||
@inject(BoardsServiceProvider)
|
@inject(SelectionService)
|
||||||
protected readonly boardsServiceClientImpl: BoardsServiceProvider;
|
protected readonly selectionService: SelectionService;
|
||||||
|
|
||||||
@inject(SelectionService)
|
@inject(EditorManager)
|
||||||
protected readonly selectionService: SelectionService;
|
protected readonly editorManager: EditorManager;
|
||||||
|
|
||||||
@inject(EditorManager)
|
@inject(ContextMenuRenderer)
|
||||||
protected readonly editorManager: EditorManager;
|
protected readonly contextMenuRenderer: ContextMenuRenderer;
|
||||||
|
|
||||||
@inject(ContextMenuRenderer)
|
@inject(FileDialogService)
|
||||||
protected readonly contextMenuRenderer: ContextMenuRenderer;
|
protected readonly fileDialogService: FileDialogService;
|
||||||
|
|
||||||
@inject(FileDialogService)
|
@inject(FileService)
|
||||||
protected readonly fileDialogService: FileDialogService;
|
protected readonly fileService: FileService;
|
||||||
|
|
||||||
@inject(FileService)
|
@inject(SketchesService)
|
||||||
protected readonly fileSystem: FileService;
|
protected readonly sketchService: SketchesService;
|
||||||
|
|
||||||
@inject(SketchesService)
|
@inject(BoardsConfigDialog)
|
||||||
protected readonly sketchService: SketchesService;
|
protected readonly boardsConfigDialog: BoardsConfigDialog;
|
||||||
|
|
||||||
@inject(BoardsConfigDialog)
|
@inject(MenuModelRegistry)
|
||||||
protected readonly boardsConfigDialog: BoardsConfigDialog;
|
protected readonly menuRegistry: MenuModelRegistry;
|
||||||
|
|
||||||
@inject(MenuModelRegistry)
|
@inject(CommandRegistry)
|
||||||
protected readonly menuRegistry: MenuModelRegistry;
|
protected readonly commandRegistry: CommandRegistry;
|
||||||
|
|
||||||
@inject(CommandRegistry)
|
@inject(StatusBar)
|
||||||
protected readonly commandRegistry: CommandRegistry;
|
protected readonly statusBar: StatusBar;
|
||||||
|
|
||||||
@inject(StatusBar)
|
@inject(WorkspaceService)
|
||||||
protected readonly statusBar: StatusBar;
|
protected readonly workspaceService: WorkspaceService;
|
||||||
|
|
||||||
@inject(WorkspaceService)
|
@inject(MonitorConnection)
|
||||||
protected readonly workspaceService: WorkspaceService;
|
protected readonly monitorConnection: MonitorConnection;
|
||||||
|
|
||||||
@inject(MonitorConnection)
|
@inject(FileNavigatorContribution)
|
||||||
protected readonly monitorConnection: MonitorConnection;
|
protected readonly fileNavigatorContributions: FileNavigatorContribution;
|
||||||
|
|
||||||
@inject(FileNavigatorContribution)
|
@inject(OutputContribution)
|
||||||
protected readonly fileNavigatorContributions: FileNavigatorContribution;
|
protected readonly outputContribution: OutputContribution;
|
||||||
|
|
||||||
@inject(OutputContribution)
|
@inject(OutlineViewContribution)
|
||||||
protected readonly outputContribution: OutputContribution;
|
protected readonly outlineContribution: OutlineViewContribution;
|
||||||
|
|
||||||
@inject(OutlineViewContribution)
|
@inject(ProblemContribution)
|
||||||
protected readonly outlineContribution: OutlineViewContribution;
|
protected readonly problemContribution: ProblemContribution;
|
||||||
|
|
||||||
@inject(ProblemContribution)
|
@inject(ScmContribution)
|
||||||
protected readonly problemContribution: ProblemContribution;
|
protected readonly scmContribution: ScmContribution;
|
||||||
|
|
||||||
@inject(ScmContribution)
|
@inject(SearchInWorkspaceFrontendContribution)
|
||||||
protected readonly scmContribution: ScmContribution;
|
protected readonly siwContribution: SearchInWorkspaceFrontendContribution;
|
||||||
|
|
||||||
@inject(SearchInWorkspaceFrontendContribution)
|
@inject(SketchbookWidgetContribution)
|
||||||
protected readonly siwContribution: SearchInWorkspaceFrontendContribution;
|
protected readonly sketchbookWidgetContribution: SketchbookWidgetContribution;
|
||||||
|
|
||||||
@inject(EditorMode)
|
@inject(EditorMode)
|
||||||
protected readonly editorMode: EditorMode;
|
protected readonly editorMode: EditorMode;
|
||||||
|
|
||||||
@inject(ArduinoDaemon)
|
@inject(ArduinoDaemon)
|
||||||
protected readonly daemon: ArduinoDaemon;
|
protected readonly daemon: ArduinoDaemon;
|
||||||
|
|
||||||
@inject(OpenerService)
|
@inject(OpenerService)
|
||||||
protected readonly openerService: OpenerService;
|
protected readonly openerService: OpenerService;
|
||||||
|
|
||||||
@inject(ConfigService)
|
@inject(ConfigService)
|
||||||
protected readonly configService: ConfigService;
|
protected readonly configService: ConfigService;
|
||||||
|
|
||||||
@inject(BoardsDataStore)
|
@inject(BoardsDataStore)
|
||||||
protected readonly boardsDataStore: BoardsDataStore;
|
protected readonly boardsDataStore: BoardsDataStore;
|
||||||
|
|
||||||
@inject(MainMenuManager)
|
@inject(MainMenuManager)
|
||||||
protected readonly mainMenuManager: MainMenuManager;
|
protected readonly mainMenuManager: MainMenuManager;
|
||||||
|
|
||||||
@inject(FileSystemExt)
|
@inject(FileSystemExt)
|
||||||
protected readonly fileSystemExt: FileSystemExt;
|
protected readonly fileSystemExt: FileSystemExt;
|
||||||
|
|
||||||
@inject(HostedPluginSupport)
|
@inject(HostedPluginSupport)
|
||||||
protected hostedPluginSupport: HostedPluginSupport;
|
protected hostedPluginSupport: HostedPluginSupport;
|
||||||
|
|
||||||
@inject(ExecutableService)
|
@inject(ExecutableService)
|
||||||
protected executableService: ExecutableService;
|
protected executableService: ExecutableService;
|
||||||
|
|
||||||
@inject(OutputService)
|
@inject(ResponseService)
|
||||||
protected readonly outputService: OutputService;
|
protected readonly responseService: ResponseService;
|
||||||
|
|
||||||
@inject(ArduinoPreferences)
|
@inject(ArduinoPreferences)
|
||||||
protected readonly arduinoPreferences: ArduinoPreferences;
|
protected readonly arduinoPreferences: ArduinoPreferences;
|
||||||
|
|
||||||
@inject(SketchesServiceClientImpl)
|
@inject(SketchesServiceClientImpl)
|
||||||
protected readonly sketchServiceClient: SketchesServiceClientImpl;
|
protected readonly sketchServiceClient: SketchesServiceClientImpl;
|
||||||
|
|
||||||
protected invalidConfigPopup: Promise<void | 'No' | 'Yes' | undefined> | undefined;
|
@inject(FrontendApplicationStateService)
|
||||||
|
protected readonly appStateService: FrontendApplicationStateService;
|
||||||
|
|
||||||
@postConstruct()
|
protected invalidConfigPopup:
|
||||||
protected async init(): Promise<void> {
|
| Promise<void | 'No' | 'Yes' | undefined>
|
||||||
if (!window.navigator.onLine) {
|
| undefined;
|
||||||
// tslint:disable-next-line:max-line-length
|
protected toDisposeOnStop = new DisposableCollection();
|
||||||
this.messageService.warn('You appear to be offline. Without an Internet connection, the Arduino CLI might not be able to download the required resources and could cause malfunction. Please connect to the Internet and restart the application.');
|
|
||||||
}
|
@postConstruct()
|
||||||
const updateStatusBar = ({ selectedBoard, selectedPort }: BoardsConfig.Config) => {
|
protected async init(): Promise<void> {
|
||||||
this.statusBar.setElement('arduino-selected-board', {
|
if (!window.navigator.onLine) {
|
||||||
alignment: StatusBarAlignment.RIGHT,
|
// tslint:disable-next-line:max-line-length
|
||||||
text: selectedBoard ? `$(microchip) ${selectedBoard.name}` : '$(close) no board selected',
|
this.messageService.warn(
|
||||||
className: 'arduino-selected-board'
|
'You appear to be offline. Without an Internet connection, the Arduino CLI might not be able to download the required resources and could cause malfunction. Please connect to the Internet and restart the application.'
|
||||||
});
|
);
|
||||||
if (selectedBoard) {
|
|
||||||
this.statusBar.setElement('arduino-selected-port', {
|
|
||||||
alignment: StatusBarAlignment.RIGHT,
|
|
||||||
text: selectedPort ? `on ${Port.toString(selectedPort)}` : '[not connected]',
|
|
||||||
className: 'arduino-selected-port'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.boardsServiceClientImpl.onBoardsConfigChanged(updateStatusBar);
|
|
||||||
updateStatusBar(this.boardsServiceClientImpl.boardsConfig);
|
|
||||||
}
|
}
|
||||||
|
const updateStatusBar = ({
|
||||||
onStart(app: FrontendApplication): void {
|
selectedBoard,
|
||||||
// Initialize all `pro-mode` widgets. This is a NOOP if in normal mode.
|
selectedPort,
|
||||||
for (const viewContribution of [
|
}: BoardsConfig.Config) => {
|
||||||
this.fileNavigatorContributions,
|
this.statusBar.setElement('arduino-selected-board', {
|
||||||
this.outputContribution,
|
alignment: StatusBarAlignment.RIGHT,
|
||||||
this.outlineContribution,
|
text: selectedBoard
|
||||||
this.problemContribution,
|
? `$(microchip) ${selectedBoard.name}`
|
||||||
this.scmContribution,
|
: '$(close) no board selected',
|
||||||
this.siwContribution] as Array<FrontendApplicationContribution>) {
|
className: 'arduino-selected-board',
|
||||||
if (viewContribution.initializeLayout) {
|
});
|
||||||
viewContribution.initializeLayout(app);
|
if (selectedBoard) {
|
||||||
}
|
this.statusBar.setElement('arduino-selected-port', {
|
||||||
}
|
alignment: StatusBarAlignment.RIGHT,
|
||||||
const start = async ({ selectedBoard }: BoardsConfig.Config) => {
|
text: selectedPort
|
||||||
if (selectedBoard) {
|
? `on ${Port.toString(selectedPort)}`
|
||||||
const { name, fqbn } = selectedBoard;
|
: '[not connected]',
|
||||||
if (fqbn) {
|
className: 'arduino-selected-port',
|
||||||
await this.hostedPluginSupport.didStart;
|
});
|
||||||
this.startLanguageServer(fqbn, name);
|
}
|
||||||
|
};
|
||||||
|
this.boardsServiceClientImpl.onBoardsConfigChanged(updateStatusBar);
|
||||||
|
updateStatusBar(this.boardsServiceClientImpl.boardsConfig);
|
||||||
|
this.appStateService.reachedState('ready').then(async () => {
|
||||||
|
const sketch = await this.sketchServiceClient.currentSketch();
|
||||||
|
if (sketch && !(await this.sketchService.isTemp(sketch))) {
|
||||||
|
this.toDisposeOnStop.push(this.fileService.watch(new URI(sketch.uri)));
|
||||||
|
this.toDisposeOnStop.push(
|
||||||
|
this.fileService.onDidFilesChange(async (event) => {
|
||||||
|
for (const { type, resource } of event.changes) {
|
||||||
|
if (
|
||||||
|
type === FileChangeType.ADDED &&
|
||||||
|
resource.parent.toString() === sketch.uri
|
||||||
|
) {
|
||||||
|
const reloadedSketch = await this.sketchService.loadSketch(
|
||||||
|
sketch.uri
|
||||||
|
);
|
||||||
|
if (Sketch.isInSketch(resource, reloadedSketch)) {
|
||||||
|
this.ensureOpened(resource.toString(), true, {
|
||||||
|
mode: 'open',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
})
|
||||||
this.boardsServiceClientImpl.onBoardsConfigChanged(start);
|
);
|
||||||
this.arduinoPreferences.onPreferenceChanged(event => {
|
}
|
||||||
if (event.preferenceName === 'arduino.language.log' && event.newValue !== event.oldValue) {
|
});
|
||||||
start(this.boardsServiceClientImpl.boardsConfig);
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
this.arduinoPreferences.ready.then(() => {
|
|
||||||
const webContents = remote.getCurrentWebContents();
|
|
||||||
const zoomLevel = this.arduinoPreferences.get('arduino.window.zoomLevel');
|
|
||||||
webContents.setZoomLevel(zoomLevel);
|
|
||||||
});
|
|
||||||
this.arduinoPreferences.onPreferenceChanged(event => {
|
|
||||||
if (event.preferenceName === 'arduino.window.zoomLevel' && typeof event.newValue === 'number' && event.newValue !== event.oldValue) {
|
|
||||||
const webContents = remote.getCurrentWebContents();
|
|
||||||
webContents.setZoomLevel(event.newValue || 0);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected startLanguageServer = debounce((fqbn: string, name: string | undefined) => this.doStartLanguageServer(fqbn, name));
|
onStart(app: FrontendApplication): void {
|
||||||
protected async doStartLanguageServer(fqbn: string, name: string | undefined): Promise<void> {
|
// Initialize all `pro-mode` widgets. This is a NOOP if in normal mode.
|
||||||
this.logger.info(`Starting language server: ${fqbn}`);
|
for (const viewContribution of [
|
||||||
const log = this.arduinoPreferences.get('arduino.language.log');
|
this.fileNavigatorContributions,
|
||||||
let currentSketchPath: string | undefined = undefined;
|
this.outputContribution,
|
||||||
if (log) {
|
this.outlineContribution,
|
||||||
const currentSketch = await this.sketchServiceClient.currentSketch();
|
this.problemContribution,
|
||||||
if (currentSketch) {
|
this.scmContribution,
|
||||||
currentSketchPath = await this.fileSystem.fsPath(new URI(currentSketch.uri));
|
this.siwContribution,
|
||||||
}
|
this.sketchbookWidgetContribution,
|
||||||
|
] as Array<FrontendApplicationContribution>) {
|
||||||
|
if (viewContribution.initializeLayout) {
|
||||||
|
viewContribution.initializeLayout(app);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const start = async ({ selectedBoard }: BoardsConfig.Config) => {
|
||||||
|
if (selectedBoard) {
|
||||||
|
const { name, fqbn } = selectedBoard;
|
||||||
|
if (fqbn) {
|
||||||
|
this.startLanguageServer(fqbn, name);
|
||||||
}
|
}
|
||||||
const { clangdUri, cliUri, lsUri } = await this.executableService.list();
|
}
|
||||||
const [clangdPath, cliPath, lsPath] = await Promise.all([
|
};
|
||||||
this.fileSystem.fsPath(new URI(clangdUri)),
|
this.boardsServiceClientImpl.onBoardsConfigChanged(start);
|
||||||
this.fileSystem.fsPath(new URI(cliUri)),
|
this.arduinoPreferences.onPreferenceChanged((event) => {
|
||||||
this.fileSystem.fsPath(new URI(lsUri)),
|
if (
|
||||||
]);
|
event.preferenceName === 'arduino.language.log' &&
|
||||||
this.commandRegistry.executeCommand('arduino.languageserver.start', {
|
event.newValue !== event.oldValue
|
||||||
|
) {
|
||||||
|
start(this.boardsServiceClientImpl.boardsConfig);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.arduinoPreferences.ready.then(() => {
|
||||||
|
const webContents = remote.getCurrentWebContents();
|
||||||
|
const zoomLevel = this.arduinoPreferences.get('arduino.window.zoomLevel');
|
||||||
|
webContents.setZoomLevel(zoomLevel);
|
||||||
|
});
|
||||||
|
this.arduinoPreferences.onPreferenceChanged((event) => {
|
||||||
|
if (
|
||||||
|
event.preferenceName === 'arduino.window.zoomLevel' &&
|
||||||
|
typeof event.newValue === 'number' &&
|
||||||
|
event.newValue !== event.oldValue
|
||||||
|
) {
|
||||||
|
const webContents = remote.getCurrentWebContents();
|
||||||
|
webContents.setZoomLevel(event.newValue || 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
app.shell.leftPanelHandler.removeMenu('settings-menu');
|
||||||
|
}
|
||||||
|
|
||||||
|
onStop(): void {
|
||||||
|
this.toDisposeOnStop.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected languageServerFqbn?: string;
|
||||||
|
protected languageServerStartMutex = new Mutex();
|
||||||
|
protected async startLanguageServer(
|
||||||
|
fqbn: string,
|
||||||
|
name: string | undefined
|
||||||
|
): Promise<void> {
|
||||||
|
const release = await this.languageServerStartMutex.acquire();
|
||||||
|
try {
|
||||||
|
await this.hostedPluginSupport.didStart;
|
||||||
|
const details = await this.boardsService.getBoardDetails({ fqbn });
|
||||||
|
if (!details) {
|
||||||
|
// Core is not installed for the selected board.
|
||||||
|
console.info(
|
||||||
|
`Could not start language server for ${fqbn}. The core is not installed for the board.`
|
||||||
|
);
|
||||||
|
if (this.languageServerFqbn) {
|
||||||
|
try {
|
||||||
|
await this.commandRegistry.executeCommand(
|
||||||
|
'arduino.languageserver.stop'
|
||||||
|
);
|
||||||
|
console.info(
|
||||||
|
`Stopped language server process for ${this.languageServerFqbn}.`
|
||||||
|
);
|
||||||
|
this.languageServerFqbn = undefined;
|
||||||
|
} catch (e) {
|
||||||
|
console.error(
|
||||||
|
`Failed to start language server process for ${this.languageServerFqbn}`,
|
||||||
|
e
|
||||||
|
);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (fqbn === this.languageServerFqbn) {
|
||||||
|
// NOOP
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.logger.info(`Starting language server: ${fqbn}`);
|
||||||
|
const log = this.arduinoPreferences.get('arduino.language.log');
|
||||||
|
let currentSketchPath: string | undefined = undefined;
|
||||||
|
if (log) {
|
||||||
|
const currentSketch = await this.sketchServiceClient.currentSketch();
|
||||||
|
if (currentSketch) {
|
||||||
|
currentSketchPath = await this.fileService.fsPath(
|
||||||
|
new URI(currentSketch.uri)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const { clangdUri, cliUri, lsUri } = await this.executableService.list();
|
||||||
|
const [clangdPath, cliPath, lsPath, cliConfigPath] = await Promise.all([
|
||||||
|
this.fileService.fsPath(new URI(clangdUri)),
|
||||||
|
this.fileService.fsPath(new URI(cliUri)),
|
||||||
|
this.fileService.fsPath(new URI(lsUri)),
|
||||||
|
this.fileService.fsPath(
|
||||||
|
new URI(await this.configService.getCliConfigFileUri())
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
this.languageServerFqbn = await Promise.race([
|
||||||
|
new Promise<undefined>((_, reject) =>
|
||||||
|
setTimeout(
|
||||||
|
() => reject(new Error(`Timeout after ${20_000} ms.`)),
|
||||||
|
20_000
|
||||||
|
)
|
||||||
|
),
|
||||||
|
this.commandRegistry.executeCommand<string>(
|
||||||
|
'arduino.languageserver.start',
|
||||||
|
{
|
||||||
lsPath,
|
lsPath,
|
||||||
cliPath,
|
cliPath,
|
||||||
clangdPath,
|
clangdPath,
|
||||||
log: currentSketchPath ? currentSketchPath : log,
|
log: currentSketchPath ? currentSketchPath : log,
|
||||||
|
cliConfigPath,
|
||||||
board: {
|
board: {
|
||||||
fqbn,
|
fqbn,
|
||||||
name: name ? `"${name}"` : undefined
|
name: name ? `"${name}"` : undefined,
|
||||||
}
|
},
|
||||||
});
|
}
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(`Failed to start language server for ${fqbn}`, e);
|
||||||
|
this.languageServerFqbn = undefined;
|
||||||
|
} finally {
|
||||||
|
release();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
registerToolbarItems(registry: TabBarToolbarRegistry): void {
|
registerToolbarItems(registry: TabBarToolbarRegistry): void {
|
||||||
registry.registerItem({
|
registry.registerItem({
|
||||||
id: BoardsToolBarItem.TOOLBAR_ID,
|
id: BoardsToolBarItem.TOOLBAR_ID,
|
||||||
render: () => <BoardsToolBarItem
|
render: () => (
|
||||||
key='boardsToolbarItem'
|
<BoardsToolBarItem
|
||||||
commands={this.commandRegistry}
|
key="boardsToolbarItem"
|
||||||
boardsServiceClient={this.boardsServiceClientImpl} />,
|
commands={this.commandRegistry}
|
||||||
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
|
boardsServiceClient={this.boardsServiceClientImpl}
|
||||||
priority: 7
|
/>
|
||||||
});
|
),
|
||||||
registry.registerItem({
|
isVisible: (widget) =>
|
||||||
id: 'toggle-serial-monitor',
|
ArduinoToolbar.is(widget) && widget.side === 'left',
|
||||||
command: MonitorViewContribution.TOGGLE_SERIAL_MONITOR_TOOLBAR,
|
priority: 7,
|
||||||
tooltip: 'Serial Monitor'
|
});
|
||||||
});
|
registry.registerItem({
|
||||||
}
|
id: 'toggle-serial-monitor',
|
||||||
|
command: MonitorViewContribution.TOGGLE_SERIAL_MONITOR_TOOLBAR,
|
||||||
|
tooltip: 'Serial Monitor',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
registerCommands(registry: CommandRegistry): void {
|
registerCommands(registry: CommandRegistry): void {
|
||||||
registry.registerCommand(ArduinoCommands.TOGGLE_COMPILE_FOR_DEBUG, {
|
registry.registerCommand(ArduinoCommands.TOGGLE_COMPILE_FOR_DEBUG, {
|
||||||
execute: () => this.editorMode.toggleCompileForDebug(),
|
execute: () => this.editorMode.toggleCompileForDebug(),
|
||||||
isToggled: () => this.editorMode.compileForDebug
|
isToggled: () => this.editorMode.compileForDebug,
|
||||||
});
|
});
|
||||||
registry.registerCommand(ArduinoCommands.OPEN_SKETCH_FILES, {
|
registry.registerCommand(ArduinoCommands.OPEN_SKETCH_FILES, {
|
||||||
execute: async (uri: URI) => {
|
execute: async (uri: URI) => {
|
||||||
this.openSketchFiles(uri);
|
this.openSketchFiles(uri);
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
registry.registerCommand(ArduinoCommands.OPEN_BOARDS_DIALOG, {
|
registry.registerCommand(ArduinoCommands.OPEN_BOARDS_DIALOG, {
|
||||||
execute: async (query?: string | undefined) => {
|
execute: async (query?: string | undefined) => {
|
||||||
const boardsConfig = await this.boardsConfigDialog.open(query);
|
const boardsConfig = await this.boardsConfigDialog.open(query);
|
||||||
if (boardsConfig) {
|
if (boardsConfig) {
|
||||||
this.boardsServiceClientImpl.boardsConfig = boardsConfig;
|
this.boardsServiceClientImpl.boardsConfig = boardsConfig;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerMenus(registry: MenuModelRegistry) {
|
||||||
|
const menuId = (menuPath: string[]): string => {
|
||||||
|
const index = menuPath.length - 1;
|
||||||
|
const menuId = menuPath[index];
|
||||||
|
return menuId;
|
||||||
|
};
|
||||||
|
registry.getMenu(MAIN_MENU_BAR).removeNode(menuId(MonacoMenus.SELECTION));
|
||||||
|
registry.getMenu(MAIN_MENU_BAR).removeNode(menuId(EditorMainMenu.GO));
|
||||||
|
registry.getMenu(MAIN_MENU_BAR).removeNode(menuId(TerminalMenus.TERMINAL));
|
||||||
|
registry.getMenu(MAIN_MENU_BAR).removeNode(menuId(CommonMenus.VIEW));
|
||||||
|
|
||||||
|
registry.registerSubmenu(ArduinoMenus.SKETCH, 'Sketch');
|
||||||
|
registry.registerSubmenu(ArduinoMenus.TOOLS, 'Tools');
|
||||||
|
registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, {
|
||||||
|
commandId: ArduinoCommands.TOGGLE_COMPILE_FOR_DEBUG.id,
|
||||||
|
label: 'Optimize for Debugging',
|
||||||
|
order: '4',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async openSketchFiles(uri: URI): Promise<void> {
|
||||||
|
try {
|
||||||
|
const sketch = await this.sketchService.loadSketch(uri.toString());
|
||||||
|
const { mainFileUri, rootFolderFileUris } = sketch;
|
||||||
|
for (const uri of [mainFileUri, ...rootFolderFileUris]) {
|
||||||
|
await this.ensureOpened(uri);
|
||||||
|
}
|
||||||
|
await this.ensureOpened(mainFileUri, true);
|
||||||
|
if (mainFileUri.endsWith('.pde')) {
|
||||||
|
const message = `The '${sketch.name}' still uses the old \`.pde\` format. Do you want to switch to the new \`.ino\` extension?`;
|
||||||
|
this.messageService
|
||||||
|
.info(message, 'Later', 'Yes')
|
||||||
|
.then(async (answer) => {
|
||||||
|
if (answer === 'Yes') {
|
||||||
|
this.commandRegistry.executeCommand(
|
||||||
|
SaveAsSketch.Commands.SAVE_AS_SKETCH.id,
|
||||||
|
{
|
||||||
|
execOnlyIfTemp: false,
|
||||||
|
openAfterMove: true,
|
||||||
|
wipeOriginal: false,
|
||||||
}
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
const message = e instanceof Error ? e.message : JSON.stringify(e);
|
||||||
|
this.messageService.error(message);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
registerMenus(registry: MenuModelRegistry) {
|
protected async ensureOpened(
|
||||||
const menuId = (menuPath: string[]): string => {
|
uri: string,
|
||||||
const index = menuPath.length - 1;
|
forceOpen = false,
|
||||||
const menuId = menuPath[index];
|
options?: EditorOpenerOptions | undefined
|
||||||
return menuId;
|
): Promise<any> {
|
||||||
}
|
const widget = this.editorManager.all.find(
|
||||||
registry.getMenu(MAIN_MENU_BAR).removeNode(menuId(MonacoMenus.SELECTION));
|
(widget) => widget.editor.uri.toString() === uri
|
||||||
registry.getMenu(MAIN_MENU_BAR).removeNode(menuId(EditorMainMenu.GO));
|
);
|
||||||
registry.getMenu(MAIN_MENU_BAR).removeNode(menuId(TerminalMenus.TERMINAL));
|
if (!widget || forceOpen) {
|
||||||
registry.getMenu(MAIN_MENU_BAR).removeNode(menuId(CommonMenus.VIEW));
|
return this.editorManager.open(new URI(uri), options);
|
||||||
|
|
||||||
registry.registerSubmenu(ArduinoMenus.SKETCH, 'Sketch');
|
|
||||||
registry.registerSubmenu(ArduinoMenus.TOOLS, 'Tools');
|
|
||||||
registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, {
|
|
||||||
commandId: ArduinoCommands.TOGGLE_COMPILE_FOR_DEBUG.id,
|
|
||||||
label: 'Optimize for Debugging',
|
|
||||||
order: '4'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async openSketchFiles(uri: URI): Promise<void> {
|
|
||||||
try {
|
|
||||||
const sketch = await this.sketchService.loadSketch(uri.toString());
|
|
||||||
const { mainFileUri, rootFolderFileUris } = sketch;
|
|
||||||
for (const uri of [mainFileUri, ...rootFolderFileUris]) {
|
|
||||||
await this.ensureOpened(uri);
|
|
||||||
}
|
|
||||||
await this.ensureOpened(mainFileUri, true);
|
|
||||||
if (mainFileUri.endsWith('.pde')) {
|
|
||||||
const message = `The '${sketch.name}' still uses the old \`.pde\` format. Do you want to switch to the new \`.ino\` extension?`;
|
|
||||||
this.messageService.info(message, 'Later', 'Yes').then(async answer => {
|
|
||||||
if (answer === 'Yes') {
|
|
||||||
this.commandRegistry.executeCommand(SaveAsSketch.Commands.SAVE_AS_SKETCH.id, { execOnlyIfTemp: false, openAfterMove: true, wipeOriginal: false });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
const message = e instanceof Error ? e.message : JSON.stringify(e);
|
|
||||||
this.messageService.error(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async ensureOpened(uri: string, forceOpen: boolean = false): Promise<any> {
|
|
||||||
const widget = this.editorManager.all.find(widget => widget.editor.uri.toString() === uri);
|
|
||||||
if (!widget || forceOpen) {
|
|
||||||
return this.editorManager.open(new URI(uri));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
registerColors(colors: ColorRegistry): void {
|
|
||||||
colors.register(
|
|
||||||
{
|
|
||||||
id: 'arduino.branding.primary',
|
|
||||||
defaults: {
|
|
||||||
dark: 'statusBar.background',
|
|
||||||
light: 'statusBar.background'
|
|
||||||
},
|
|
||||||
description: 'The primary branding color, such as dialog titles, library, and board manager list labels.'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'arduino.branding.secondary',
|
|
||||||
defaults: {
|
|
||||||
dark: 'statusBar.background',
|
|
||||||
light: 'statusBar.background'
|
|
||||||
},
|
|
||||||
description: 'Secondary branding color for list selections, dropdowns, and widget borders.'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'arduino.foreground',
|
|
||||||
defaults: {
|
|
||||||
dark: 'editorWidget.background',
|
|
||||||
light: 'editorWidget.background',
|
|
||||||
hc: 'editorWidget.background'
|
|
||||||
},
|
|
||||||
description: 'Color of the Arduino IDE foreground which is used for dialogs, such as the Select Board dialog.'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'arduino.toolbar.background',
|
|
||||||
defaults: {
|
|
||||||
dark: 'button.background',
|
|
||||||
light: 'button.background',
|
|
||||||
hc: 'activityBar.inactiveForeground'
|
|
||||||
},
|
|
||||||
description: 'Background color of the toolbar items. Such as Upload, Verify, etc.'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'arduino.toolbar.hoverBackground',
|
|
||||||
defaults: {
|
|
||||||
dark: 'button.hoverBackground',
|
|
||||||
light: 'button.hoverBackground',
|
|
||||||
hc: 'activityBar.inactiveForeground'
|
|
||||||
},
|
|
||||||
description: 'Background color of the toolbar items when hovering over them. Such as Upload, Verify, etc.'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'arduino.output.foreground',
|
|
||||||
defaults: {
|
|
||||||
dark: 'editor.foreground',
|
|
||||||
light: 'editor.foreground',
|
|
||||||
hc: 'editor.foreground'
|
|
||||||
},
|
|
||||||
description: 'Color of the text in the Output view.'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'arduino.output.background',
|
|
||||||
defaults: {
|
|
||||||
dark: 'editor.background',
|
|
||||||
light: 'editor.background',
|
|
||||||
hc: 'editor.background'
|
|
||||||
},
|
|
||||||
description: 'Background color of the Output view.'
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
registerColors(colors: ColorRegistry): void {
|
||||||
|
colors.register(
|
||||||
|
{
|
||||||
|
id: 'arduino.branding.primary',
|
||||||
|
defaults: {
|
||||||
|
dark: 'statusBar.background',
|
||||||
|
light: 'statusBar.background',
|
||||||
|
},
|
||||||
|
description:
|
||||||
|
'The primary branding color, such as dialog titles, library, and board manager list labels.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'arduino.branding.secondary',
|
||||||
|
defaults: {
|
||||||
|
dark: 'statusBar.background',
|
||||||
|
light: 'statusBar.background',
|
||||||
|
},
|
||||||
|
description:
|
||||||
|
'Secondary branding color for list selections, dropdowns, and widget borders.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'arduino.foreground',
|
||||||
|
defaults: {
|
||||||
|
dark: 'editorWidget.background',
|
||||||
|
light: 'editorWidget.background',
|
||||||
|
hc: 'editorWidget.background',
|
||||||
|
},
|
||||||
|
description:
|
||||||
|
'Color of the Arduino IDE foreground which is used for dialogs, such as the Select Board dialog.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'arduino.toolbar.background',
|
||||||
|
defaults: {
|
||||||
|
dark: 'button.background',
|
||||||
|
light: 'button.background',
|
||||||
|
hc: 'activityBar.inactiveForeground',
|
||||||
|
},
|
||||||
|
description:
|
||||||
|
'Background color of the toolbar items. Such as Upload, Verify, etc.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'arduino.toolbar.hoverBackground',
|
||||||
|
defaults: {
|
||||||
|
dark: 'button.hoverBackground',
|
||||||
|
light: 'button.foreground',
|
||||||
|
hc: 'textLink.foreground',
|
||||||
|
},
|
||||||
|
description:
|
||||||
|
'Background color of the toolbar items when hovering over them. Such as Upload, Verify, etc.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'arduino.toolbar.toggleBackground',
|
||||||
|
defaults: {
|
||||||
|
dark: 'editor.selectionBackground',
|
||||||
|
light: 'editor.selectionBackground',
|
||||||
|
hc: 'textPreformat.foreground',
|
||||||
|
},
|
||||||
|
description:
|
||||||
|
'Toggle color of the toolbar items when they are currently toggled (the command is in progress)',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'arduino.output.foreground',
|
||||||
|
defaults: {
|
||||||
|
dark: 'editor.foreground',
|
||||||
|
light: 'editor.foreground',
|
||||||
|
hc: 'editor.foreground',
|
||||||
|
},
|
||||||
|
description: 'Color of the text in the Output view.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'arduino.output.background',
|
||||||
|
defaults: {
|
||||||
|
dark: 'editor.background',
|
||||||
|
light: 'editor.background',
|
||||||
|
hc: 'editor.background',
|
||||||
|
},
|
||||||
|
description: 'Background color of the Output view.',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,29 @@ import { ContainerModule } from 'inversify';
|
|||||||
import { WidgetFactory } from '@theia/core/lib/browser/widget-manager';
|
import { WidgetFactory } from '@theia/core/lib/browser/widget-manager';
|
||||||
import { CommandContribution } from '@theia/core/lib/common/command';
|
import { CommandContribution } from '@theia/core/lib/common/command';
|
||||||
import { bindViewContribution } from '@theia/core/lib/browser/shell/view-contribution';
|
import { bindViewContribution } from '@theia/core/lib/browser/shell/view-contribution';
|
||||||
import { TabBarToolbarContribution, TabBarToolbarFactory } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
|
import {
|
||||||
|
TabBarToolbarContribution,
|
||||||
|
TabBarToolbarFactory,
|
||||||
|
} from '@theia/core/lib/browser/shell/tab-bar-toolbar';
|
||||||
import { WebSocketConnectionProvider } from '@theia/core/lib/browser/messaging/ws-connection-provider';
|
import { WebSocketConnectionProvider } from '@theia/core/lib/browser/messaging/ws-connection-provider';
|
||||||
import { FrontendApplicationContribution, FrontendApplication as TheiaFrontendApplication } from '@theia/core/lib/browser/frontend-application'
|
import {
|
||||||
|
FrontendApplicationContribution,
|
||||||
|
FrontendApplication as TheiaFrontendApplication,
|
||||||
|
} from '@theia/core/lib/browser/frontend-application';
|
||||||
import { LibraryListWidget } from './library/library-list-widget';
|
import { LibraryListWidget } from './library/library-list-widget';
|
||||||
import { ArduinoFrontendContribution } from './arduino-frontend-contribution';
|
import { ArduinoFrontendContribution } from './arduino-frontend-contribution';
|
||||||
import { LibraryService, LibraryServicePath } from '../common/protocol/library-service';
|
import {
|
||||||
import { BoardsService, BoardsServicePath } from '../common/protocol/boards-service';
|
LibraryService,
|
||||||
import { SketchesService, SketchesServicePath } from '../common/protocol/sketches-service';
|
LibraryServicePath,
|
||||||
|
} from '../common/protocol/library-service';
|
||||||
|
import {
|
||||||
|
BoardsService,
|
||||||
|
BoardsServicePath,
|
||||||
|
} from '../common/protocol/boards-service';
|
||||||
|
import {
|
||||||
|
SketchesService,
|
||||||
|
SketchesServicePath,
|
||||||
|
} from '../common/protocol/sketches-service';
|
||||||
import { SketchesServiceClientImpl } from '../common/protocol/sketches-service-client-impl';
|
import { SketchesServiceClientImpl } from '../common/protocol/sketches-service-client-impl';
|
||||||
import { CoreService, CoreServicePath } from '../common/protocol/core-service';
|
import { CoreService, CoreServicePath } from '../common/protocol/core-service';
|
||||||
import { BoardsListWidget } from './boards/boards-list-widget';
|
import { BoardsListWidget } from './boards/boards-list-widget';
|
||||||
@@ -24,23 +39,30 @@ import { ProblemContribution as TheiaProblemContribution } from '@theia/markers/
|
|||||||
import { ProblemContribution } from './theia/markers/problem-contribution';
|
import { ProblemContribution } from './theia/markers/problem-contribution';
|
||||||
import { FileNavigatorContribution } from './theia/navigator/navigator-contribution';
|
import { FileNavigatorContribution } from './theia/navigator/navigator-contribution';
|
||||||
import { FileNavigatorContribution as TheiaFileNavigatorContribution } from '@theia/navigator/lib/browser/navigator-contribution';
|
import { FileNavigatorContribution as TheiaFileNavigatorContribution } from '@theia/navigator/lib/browser/navigator-contribution';
|
||||||
|
import { KeymapsFrontendContribution } from './theia/keymaps/keymaps-frontend-contribution';
|
||||||
|
import { KeymapsFrontendContribution as TheiaKeymapsFrontendContribution } from '@theia/keymaps/lib/browser/keymaps-frontend-contribution';
|
||||||
import { ArduinoToolbarContribution } from './toolbar/arduino-toolbar-contribution';
|
import { ArduinoToolbarContribution } from './toolbar/arduino-toolbar-contribution';
|
||||||
import { EditorContribution as TheiaEditorContribution } from '@theia/editor/lib/browser/editor-contribution';
|
import { EditorContribution as TheiaEditorContribution } from '@theia/editor/lib/browser/editor-contribution';
|
||||||
import { EditorContribution } from './theia/editor/editor-contribution';
|
import { EditorContribution } from './theia/editor/editor-contribution';
|
||||||
import { MonacoStatusBarContribution as TheiaMonacoStatusBarContribution } from '@theia/monaco/lib/browser/monaco-status-bar-contribution';
|
import { MonacoStatusBarContribution as TheiaMonacoStatusBarContribution } from '@theia/monaco/lib/browser/monaco-status-bar-contribution';
|
||||||
import { MonacoStatusBarContribution } from './theia/monaco/monaco-status-bar-contribution';
|
import { MonacoStatusBarContribution } from './theia/monaco/monaco-status-bar-contribution';
|
||||||
import {
|
import {
|
||||||
ApplicationShell as TheiaApplicationShell,
|
ApplicationShell as TheiaApplicationShell,
|
||||||
ShellLayoutRestorer as TheiaShellLayoutRestorer,
|
ShellLayoutRestorer as TheiaShellLayoutRestorer,
|
||||||
CommonFrontendContribution as TheiaCommonFrontendContribution,
|
CommonFrontendContribution as TheiaCommonFrontendContribution,
|
||||||
KeybindingRegistry as TheiaKeybindingRegistry,
|
KeybindingRegistry as TheiaKeybindingRegistry,
|
||||||
TabBarRendererFactory,
|
TabBarRendererFactory,
|
||||||
ContextMenuRenderer
|
ContextMenuRenderer,
|
||||||
|
createTreeContainer,
|
||||||
|
TreeWidget,
|
||||||
} from '@theia/core/lib/browser';
|
} from '@theia/core/lib/browser';
|
||||||
import { MenuContribution } from '@theia/core/lib/common/menu';
|
import { MenuContribution } from '@theia/core/lib/common/menu';
|
||||||
import { ApplicationShell } from './theia/core/application-shell';
|
import { ApplicationShell } from './theia/core/application-shell';
|
||||||
import { FrontendApplication } from './theia/core/frontend-application';
|
import { FrontendApplication } from './theia/core/frontend-application';
|
||||||
import { BoardsConfigDialog, BoardsConfigDialogProps } from './boards/boards-config-dialog';
|
import {
|
||||||
|
BoardsConfigDialog,
|
||||||
|
BoardsConfigDialogProps,
|
||||||
|
} from './boards/boards-config-dialog';
|
||||||
import { BoardsConfigDialogWidget } from './boards/boards-config-dialog-widget';
|
import { BoardsConfigDialogWidget } from './boards/boards-config-dialog-widget';
|
||||||
import { ScmContribution as TheiaScmContribution } from '@theia/scm/lib/browser/scm-contribution';
|
import { ScmContribution as TheiaScmContribution } from '@theia/scm/lib/browser/scm-contribution';
|
||||||
import { ScmContribution } from './theia/scm/scm-contribution';
|
import { ScmContribution } from './theia/scm/scm-contribution';
|
||||||
@@ -48,8 +70,15 @@ import { SearchInWorkspaceFrontendContribution as TheiaSearchInWorkspaceFrontend
|
|||||||
import { SearchInWorkspaceFrontendContribution } from './theia/search-in-workspace/search-in-workspace-frontend-contribution';
|
import { SearchInWorkspaceFrontendContribution } from './theia/search-in-workspace/search-in-workspace-frontend-contribution';
|
||||||
import { LibraryListWidgetFrontendContribution } from './library/library-widget-frontend-contribution';
|
import { LibraryListWidgetFrontendContribution } from './library/library-widget-frontend-contribution';
|
||||||
import { MonitorServiceClientImpl } from './monitor/monitor-service-client-impl';
|
import { MonitorServiceClientImpl } from './monitor/monitor-service-client-impl';
|
||||||
import { MonitorServicePath, MonitorService, MonitorServiceClient } from '../common/protocol/monitor-service';
|
import {
|
||||||
import { ConfigService, ConfigServicePath } from '../common/protocol/config-service';
|
MonitorServicePath,
|
||||||
|
MonitorService,
|
||||||
|
MonitorServiceClient,
|
||||||
|
} from '../common/protocol/monitor-service';
|
||||||
|
import {
|
||||||
|
ConfigService,
|
||||||
|
ConfigServicePath,
|
||||||
|
} from '../common/protocol/config-service';
|
||||||
import { MonitorWidget } from './monitor/monitor-widget';
|
import { MonitorWidget } from './monitor/monitor-widget';
|
||||||
import { MonitorViewContribution } from './monitor/monitor-view-contribution';
|
import { MonitorViewContribution } from './monitor/monitor-view-contribution';
|
||||||
import { MonitorConnection } from './monitor/monitor-connection';
|
import { MonitorConnection } from './monitor/monitor-connection';
|
||||||
@@ -64,24 +93,35 @@ import { EditorMode } from './editor-mode';
|
|||||||
import { ListItemRenderer } from './widgets/component-list/list-item-renderer';
|
import { ListItemRenderer } from './widgets/component-list/list-item-renderer';
|
||||||
import { ColorContribution } from '@theia/core/lib/browser/color-application-contribution';
|
import { ColorContribution } from '@theia/core/lib/browser/color-application-contribution';
|
||||||
import { MonacoThemingService } from '@theia/monaco/lib/browser/monaco-theming-service';
|
import { MonacoThemingService } from '@theia/monaco/lib/browser/monaco-theming-service';
|
||||||
import { ArduinoDaemonPath, ArduinoDaemon } from '../common/protocol/arduino-daemon';
|
|
||||||
import { EditorManager as TheiaEditorManager, EditorCommandContribution as TheiaEditorCommandContribution } from '@theia/editor/lib/browser';
|
|
||||||
import { EditorManager } from './theia/editor/editor-manager';
|
|
||||||
import { FrontendConnectionStatusService, ApplicationConnectionStatusContribution } from './theia/core/connection-status-service';
|
|
||||||
import {
|
import {
|
||||||
FrontendConnectionStatusService as TheiaFrontendConnectionStatusService,
|
ArduinoDaemonPath,
|
||||||
ApplicationConnectionStatusContribution as TheiaApplicationConnectionStatusContribution
|
ArduinoDaemon,
|
||||||
|
} from '../common/protocol/arduino-daemon';
|
||||||
|
import { EditorCommandContribution as TheiaEditorCommandContribution } from '@theia/editor/lib/browser';
|
||||||
|
import {
|
||||||
|
FrontendConnectionStatusService,
|
||||||
|
ApplicationConnectionStatusContribution,
|
||||||
|
} from './theia/core/connection-status-service';
|
||||||
|
import {
|
||||||
|
FrontendConnectionStatusService as TheiaFrontendConnectionStatusService,
|
||||||
|
ApplicationConnectionStatusContribution as TheiaApplicationConnectionStatusContribution,
|
||||||
} from '@theia/core/lib/browser/connection-status-service';
|
} from '@theia/core/lib/browser/connection-status-service';
|
||||||
import { BoardsDataMenuUpdater } from './boards/boards-data-menu-updater';
|
import { BoardsDataMenuUpdater } from './boards/boards-data-menu-updater';
|
||||||
import { BoardsDataStore } from './boards/boards-data-store';
|
import { BoardsDataStore } from './boards/boards-data-store';
|
||||||
import { ILogger } from '@theia/core';
|
import { ILogger } from '@theia/core';
|
||||||
import { FileSystemExt, FileSystemExtPath } from '../common/protocol/filesystem-ext';
|
|
||||||
import {
|
import {
|
||||||
WorkspaceFrontendContribution as TheiaWorkspaceFrontendContribution,
|
FileSystemExt,
|
||||||
FileMenuContribution as TheiaFileMenuContribution,
|
FileSystemExtPath,
|
||||||
WorkspaceCommandContribution as TheiaWorkspaceCommandContribution
|
} from '../common/protocol/filesystem-ext';
|
||||||
|
import {
|
||||||
|
WorkspaceFrontendContribution as TheiaWorkspaceFrontendContribution,
|
||||||
|
FileMenuContribution as TheiaFileMenuContribution,
|
||||||
|
WorkspaceCommandContribution as TheiaWorkspaceCommandContribution,
|
||||||
} from '@theia/workspace/lib/browser';
|
} from '@theia/workspace/lib/browser';
|
||||||
import { WorkspaceFrontendContribution, ArduinoFileMenuContribution } from './theia/workspace/workspace-frontend-contribution';
|
import {
|
||||||
|
WorkspaceFrontendContribution,
|
||||||
|
ArduinoFileMenuContribution,
|
||||||
|
} from './theia/workspace/workspace-frontend-contribution';
|
||||||
import { Contribution } from './contributions/contribution';
|
import { Contribution } from './contributions/contribution';
|
||||||
import { NewSketch } from './contributions/new-sketch';
|
import { NewSketch } from './contributions/new-sketch';
|
||||||
import { OpenSketch } from './contributions/open-sketch';
|
import { OpenSketch } from './contributions/open-sketch';
|
||||||
@@ -108,19 +148,31 @@ import { EditorWidgetFactory } from './theia/editor/editor-widget-factory';
|
|||||||
import { OutputWidget as TheiaOutputWidget } from '@theia/output/lib/browser/output-widget';
|
import { OutputWidget as TheiaOutputWidget } from '@theia/output/lib/browser/output-widget';
|
||||||
import { OutputWidget } from './theia/output/output-widget';
|
import { OutputWidget } from './theia/output/output-widget';
|
||||||
import { BurnBootloader } from './contributions/burn-bootloader';
|
import { BurnBootloader } from './contributions/burn-bootloader';
|
||||||
import { ExamplesServicePath, ExamplesService } from '../common/protocol/examples-service';
|
import {
|
||||||
|
ExamplesServicePath,
|
||||||
|
ExamplesService,
|
||||||
|
} from '../common/protocol/examples-service';
|
||||||
import { BuiltInExamples, LibraryExamples } from './contributions/examples';
|
import { BuiltInExamples, LibraryExamples } from './contributions/examples';
|
||||||
import { IncludeLibrary } from './contributions/include-library';
|
import { IncludeLibrary } from './contributions/include-library';
|
||||||
import { OutputChannelManager as TheiaOutputChannelManager } from '@theia/output/lib/common/output-channel';
|
import { OutputChannelManager as TheiaOutputChannelManager } from '@theia/output/lib/common/output-channel';
|
||||||
import { OutputChannelManager } from './theia/output/output-channel';
|
import { OutputChannelManager } from './theia/output/output-channel';
|
||||||
import { OutputChannelRegistryMainImpl as TheiaOutputChannelRegistryMainImpl, OutputChannelRegistryMainImpl } from './theia/plugin-ext/output-channel-registry-main';
|
import {
|
||||||
|
OutputChannelRegistryMainImpl as TheiaOutputChannelRegistryMainImpl,
|
||||||
|
OutputChannelRegistryMainImpl,
|
||||||
|
} from './theia/plugin-ext/output-channel-registry-main';
|
||||||
import { ExecutableService, ExecutableServicePath } from '../common/protocol';
|
import { ExecutableService, ExecutableServicePath } from '../common/protocol';
|
||||||
import { MonacoTextModelService as TheiaMonacoTextModelService } from '@theia/monaco/lib/browser/monaco-text-model-service';
|
import { MonacoTextModelService as TheiaMonacoTextModelService } from '@theia/monaco/lib/browser/monaco-text-model-service';
|
||||||
import { MonacoTextModelService } from './theia/monaco/monaco-text-model-service';
|
import { MonacoTextModelService } from './theia/monaco/monaco-text-model-service';
|
||||||
import { OutputServiceImpl } from './output-service-impl';
|
import { ResponseServiceImpl } from './response-service-impl';
|
||||||
import { OutputServicePath, OutputService } from '../common/protocol/output-service';
|
import {
|
||||||
|
ResponseServicePath,
|
||||||
|
ResponseService,
|
||||||
|
} from '../common/protocol/response-service';
|
||||||
import { NotificationCenter } from './notification-center';
|
import { NotificationCenter } from './notification-center';
|
||||||
import { NotificationServicePath, NotificationServiceServer } from '../common/protocol';
|
import {
|
||||||
|
NotificationServicePath,
|
||||||
|
NotificationServiceServer,
|
||||||
|
} from '../common/protocol';
|
||||||
import { About } from './contributions/about';
|
import { About } from './contributions/about';
|
||||||
import { IconThemeService } from '@theia/core/lib/browser/icon-theme-service';
|
import { IconThemeService } from '@theia/core/lib/browser/icon-theme-service';
|
||||||
import { TabBarRenderer } from './theia/core/tab-bars';
|
import { TabBarRenderer } from './theia/core/tab-bars';
|
||||||
@@ -136,268 +188,568 @@ import { DebugFrontendApplicationContribution as TheiaDebugFrontendApplicationCo
|
|||||||
import { BoardSelection } from './contributions/board-selection';
|
import { BoardSelection } from './contributions/board-selection';
|
||||||
import { OpenRecentSketch } from './contributions/open-recent-sketch';
|
import { OpenRecentSketch } from './contributions/open-recent-sketch';
|
||||||
import { Help } from './contributions/help';
|
import { Help } from './contributions/help';
|
||||||
import { bindArduinoPreferences } from './arduino-preferences'
|
import { bindArduinoPreferences } from './arduino-preferences';
|
||||||
import { SettingsService, SettingsDialog, SettingsWidget, SettingsDialogProps } from './settings';
|
import {
|
||||||
|
SettingsService,
|
||||||
|
SettingsDialog,
|
||||||
|
SettingsWidget,
|
||||||
|
SettingsDialogProps,
|
||||||
|
} from './settings';
|
||||||
import { AddFile } from './contributions/add-file';
|
import { AddFile } from './contributions/add-file';
|
||||||
import { ArchiveSketch } from './contributions/archive-sketch';
|
import { ArchiveSketch } from './contributions/archive-sketch';
|
||||||
import { OutputToolbarContribution as TheiaOutputToolbarContribution } from '@theia/output/lib/browser/output-toolbar-contribution';
|
import { OutputToolbarContribution as TheiaOutputToolbarContribution } from '@theia/output/lib/browser/output-toolbar-contribution';
|
||||||
import { OutputToolbarContribution } from './theia/output/output-toolbar-contribution';
|
import { OutputToolbarContribution } from './theia/output/output-toolbar-contribution';
|
||||||
|
import { AddZipLibrary } from './contributions/add-zip-library';
|
||||||
|
import { WorkspaceVariableContribution as TheiaWorkspaceVariableContribution } from '@theia/workspace/lib/browser/workspace-variable-contribution';
|
||||||
|
import { WorkspaceVariableContribution } from './theia/workspace/workspace-variable-contribution';
|
||||||
|
import { DebugConfigurationManager } from './theia/debug/debug-configuration-manager';
|
||||||
|
import { DebugConfigurationManager as TheiaDebugConfigurationManager } from '@theia/debug/lib/browser/debug-configuration-manager';
|
||||||
|
import { SearchInWorkspaceWidget as TheiaSearchInWorkspaceWidget } from '@theia/search-in-workspace/lib/browser/search-in-workspace-widget';
|
||||||
|
import { SearchInWorkspaceWidget } from './theia/search-in-workspace/search-in-workspace-widget';
|
||||||
|
import { SearchInWorkspaceResultTreeWidget as TheiaSearchInWorkspaceResultTreeWidget } from '@theia/search-in-workspace/lib/browser/search-in-workspace-result-tree-widget';
|
||||||
|
import { SearchInWorkspaceResultTreeWidget } from './theia/search-in-workspace/search-in-workspace-result-tree-widget';
|
||||||
|
import { MonacoEditorProvider } from './theia/monaco/monaco-editor-provider';
|
||||||
|
import { MonacoEditorProvider as TheiaMonacoEditorProvider } from '@theia/monaco/lib/browser/monaco-editor-provider';
|
||||||
|
import { DebugEditorModel } from './theia/debug/debug-editor-model';
|
||||||
|
import { DebugEditorModelFactory } from '@theia/debug/lib/browser/editor/debug-editor-model';
|
||||||
|
import { StorageWrapper } from './storage-wrapper';
|
||||||
|
import { NotificationManager } from './theia/messages/notifications-manager';
|
||||||
|
import { NotificationManager as TheiaNotificationManager } from '@theia/messages/lib/browser/notifications-manager';
|
||||||
|
import { NotificationsRenderer as TheiaNotificationsRenderer } from '@theia/messages/lib/browser/notifications-renderer';
|
||||||
|
import { NotificationsRenderer } from './theia/messages/notifications-renderer';
|
||||||
|
import { SketchbookWidgetContribution } from './widgets/sketchbook/sketchbook-widget-contribution';
|
||||||
|
import { LocalCacheFsProvider } from './local-cache/local-cache-fs-provider';
|
||||||
|
import { CloudSketchbookWidget } from './widgets/cloud-sketchbook/cloud-sketchbook-widget';
|
||||||
|
import { CloudSketchbookTreeWidget } from './widgets/cloud-sketchbook/cloud-sketchbook-tree-widget';
|
||||||
|
import { createCloudSketchbookTreeWidget } from './widgets/cloud-sketchbook/cloud-sketchbook-tree-container';
|
||||||
|
import { CreateApi } from './create/create-api';
|
||||||
|
import { ShareSketchDialog } from './dialogs/cloud-share-sketch-dialog';
|
||||||
|
import { AuthenticationClientService } from './auth/authentication-client-service';
|
||||||
|
import {
|
||||||
|
AuthenticationService,
|
||||||
|
AuthenticationServicePath,
|
||||||
|
} from '../common/protocol/authentication-service';
|
||||||
|
import { CreateFsProvider } from './create/create-fs-provider';
|
||||||
|
import { FileServiceContribution } from '@theia/filesystem/lib/browser/file-service';
|
||||||
|
import { CloudSketchbookContribution } from './widgets/cloud-sketchbook/cloud-sketchbook-contributions';
|
||||||
|
import { CloudSketchbookCompositeWidget } from './widgets/cloud-sketchbook/cloud-sketchbook-composite-widget';
|
||||||
|
import { SketchbookWidget } from './widgets/sketchbook/sketchbook-widget';
|
||||||
|
import { SketchbookTreeWidget } from './widgets/sketchbook/sketchbook-tree-widget';
|
||||||
|
import { createSketchbookTreeWidget } from './widgets/sketchbook/sketchbook-tree-container';
|
||||||
|
import { SketchCache } from './widgets/cloud-sketchbook/cloud-sketch-cache';
|
||||||
|
import { UploadFirmware } from './contributions/upload-firmware';
|
||||||
|
import {
|
||||||
|
UploadFirmwareDialog,
|
||||||
|
UploadFirmwareDialogProps,
|
||||||
|
UploadFirmwareDialogWidget,
|
||||||
|
} from './dialogs/firmware-uploader/firmware-uploader-dialog';
|
||||||
|
|
||||||
|
import { UploadCertificate } from './contributions/upload-certificate';
|
||||||
|
import {
|
||||||
|
ArduinoFirmwareUploader,
|
||||||
|
ArduinoFirmwareUploaderPath,
|
||||||
|
} from '../common/protocol/arduino-firmware-uploader';
|
||||||
|
import {
|
||||||
|
UploadCertificateDialog,
|
||||||
|
UploadCertificateDialogProps,
|
||||||
|
UploadCertificateDialogWidget,
|
||||||
|
} from './dialogs/certificate-uploader/certificate-uploader-dialog';
|
||||||
|
|
||||||
const ElementQueries = require('css-element-queries/src/ElementQueries');
|
const ElementQueries = require('css-element-queries/src/ElementQueries');
|
||||||
|
|
||||||
MonacoThemingService.register({
|
MonacoThemingService.register({
|
||||||
id: 'arduino-theme',
|
id: 'arduino-theme',
|
||||||
label: 'Light (Arduino)',
|
label: 'Light (Arduino)',
|
||||||
uiTheme: 'vs',
|
uiTheme: 'vs',
|
||||||
json: require('../../src/browser/data/arduino.color-theme.json')
|
json: require('../../src/browser/data/arduino.color-theme.json'),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
||||||
ElementQueries.listen();
|
ElementQueries.listen();
|
||||||
ElementQueries.init();
|
ElementQueries.init();
|
||||||
|
|
||||||
// Commands and toolbar items
|
// Commands and toolbar items
|
||||||
bind(ArduinoFrontendContribution).toSelf().inSingletonScope();
|
bind(ArduinoFrontendContribution).toSelf().inSingletonScope();
|
||||||
bind(CommandContribution).toService(ArduinoFrontendContribution);
|
bind(CommandContribution).toService(ArduinoFrontendContribution);
|
||||||
bind(MenuContribution).toService(ArduinoFrontendContribution);
|
bind(MenuContribution).toService(ArduinoFrontendContribution);
|
||||||
bind(TabBarToolbarContribution).toService(ArduinoFrontendContribution);
|
bind(TabBarToolbarContribution).toService(ArduinoFrontendContribution);
|
||||||
bind(FrontendApplicationContribution).toService(ArduinoFrontendContribution);
|
bind(FrontendApplicationContribution).toService(ArduinoFrontendContribution);
|
||||||
bind(ColorContribution).toService(ArduinoFrontendContribution);
|
bind(ColorContribution).toService(ArduinoFrontendContribution);
|
||||||
|
|
||||||
bind(ArduinoToolbarContribution).toSelf().inSingletonScope();
|
bind(ArduinoToolbarContribution).toSelf().inSingletonScope();
|
||||||
bind(FrontendApplicationContribution).toService(ArduinoToolbarContribution);
|
bind(FrontendApplicationContribution).toService(ArduinoToolbarContribution);
|
||||||
|
|
||||||
// Renderer for both the library and the core widgets.
|
// Renderer for both the library and the core widgets.
|
||||||
bind(ListItemRenderer).toSelf().inSingletonScope();
|
bind(ListItemRenderer).toSelf().inSingletonScope();
|
||||||
|
|
||||||
// Library service
|
// Library service
|
||||||
bind(LibraryService).toDynamicValue(context => WebSocketConnectionProvider.createProxy(context.container, LibraryServicePath)).inSingletonScope();
|
bind(LibraryService)
|
||||||
|
.toDynamicValue((context) =>
|
||||||
|
WebSocketConnectionProvider.createProxy(
|
||||||
|
context.container,
|
||||||
|
LibraryServicePath
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.inSingletonScope();
|
||||||
|
|
||||||
// Library list widget
|
// Library list widget
|
||||||
bind(LibraryListWidget).toSelf();
|
bind(LibraryListWidget).toSelf();
|
||||||
bindViewContribution(bind, LibraryListWidgetFrontendContribution);
|
bindViewContribution(bind, LibraryListWidgetFrontendContribution);
|
||||||
bind(WidgetFactory).toDynamicValue(context => ({
|
bind(WidgetFactory).toDynamicValue((context) => ({
|
||||||
id: LibraryListWidget.WIDGET_ID,
|
id: LibraryListWidget.WIDGET_ID,
|
||||||
createWidget: () => context.container.get(LibraryListWidget)
|
createWidget: () => context.container.get(LibraryListWidget),
|
||||||
}));
|
}));
|
||||||
bind(FrontendApplicationContribution).toService(LibraryListWidgetFrontendContribution);
|
bind(FrontendApplicationContribution).toService(
|
||||||
|
LibraryListWidgetFrontendContribution
|
||||||
|
);
|
||||||
|
|
||||||
// Sketch list service
|
// Sketch list service
|
||||||
bind(SketchesService).toDynamicValue(context => WebSocketConnectionProvider.createProxy(context.container, SketchesServicePath)).inSingletonScope();
|
bind(SketchesService)
|
||||||
bind(SketchesServiceClientImpl).toSelf().inSingletonScope();
|
.toDynamicValue((context) =>
|
||||||
bind(FrontendApplicationContribution).toService(SketchesServiceClientImpl);
|
WebSocketConnectionProvider.createProxy(
|
||||||
|
context.container,
|
||||||
|
SketchesServicePath
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.inSingletonScope();
|
||||||
|
bind(SketchesServiceClientImpl).toSelf().inSingletonScope();
|
||||||
|
bind(FrontendApplicationContribution).toService(SketchesServiceClientImpl);
|
||||||
|
|
||||||
// Config service
|
// Config service
|
||||||
bind(ConfigService).toDynamicValue(context => WebSocketConnectionProvider.createProxy(context.container, ConfigServicePath)).inSingletonScope();
|
bind(ConfigService)
|
||||||
|
.toDynamicValue((context) =>
|
||||||
|
WebSocketConnectionProvider.createProxy(
|
||||||
|
context.container,
|
||||||
|
ConfigServicePath
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.inSingletonScope();
|
||||||
|
|
||||||
// Boards service
|
// Boards service
|
||||||
bind(BoardsService).toDynamicValue(context => WebSocketConnectionProvider.createProxy(context.container, BoardsServicePath)).inSingletonScope();
|
bind(BoardsService)
|
||||||
// Boards service client to receive and delegate notifications from the backend.
|
.toDynamicValue((context) =>
|
||||||
bind(BoardsServiceProvider).toSelf().inSingletonScope();
|
WebSocketConnectionProvider.createProxy(
|
||||||
bind(FrontendApplicationContribution).toService(BoardsServiceProvider);
|
context.container,
|
||||||
|
BoardsServicePath
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.inSingletonScope();
|
||||||
|
// Boards service client to receive and delegate notifications from the backend.
|
||||||
|
bind(BoardsServiceProvider).toSelf().inSingletonScope();
|
||||||
|
bind(FrontendApplicationContribution).toService(BoardsServiceProvider);
|
||||||
|
|
||||||
// To be able to track, and update the menu based on the core settings (aka. board details) of the currently selected board.
|
// To be able to track, and update the menu based on the core settings (aka. board details) of the currently selected board.
|
||||||
bind(FrontendApplicationContribution).to(BoardsDataMenuUpdater).inSingletonScope();
|
bind(FrontendApplicationContribution)
|
||||||
bind(BoardsDataStore).toSelf().inSingletonScope();
|
.to(BoardsDataMenuUpdater)
|
||||||
bind(FrontendApplicationContribution).toService(BoardsDataStore);
|
.inSingletonScope();
|
||||||
// Logger for the Arduino daemon
|
bind(BoardsDataStore).toSelf().inSingletonScope();
|
||||||
bind(ILogger).toDynamicValue(ctx => {
|
bind(FrontendApplicationContribution).toService(BoardsDataStore);
|
||||||
const parentLogger = ctx.container.get<ILogger>(ILogger);
|
// Logger for the Arduino daemon
|
||||||
return parentLogger.child('store');
|
bind(ILogger)
|
||||||
}).inSingletonScope().whenTargetNamed('store');
|
.toDynamicValue((ctx) => {
|
||||||
|
const parentLogger = ctx.container.get<ILogger>(ILogger);
|
||||||
// Boards auto-installer
|
return parentLogger.child('store');
|
||||||
bind(BoardsAutoInstaller).toSelf().inSingletonScope();
|
|
||||||
bind(FrontendApplicationContribution).toService(BoardsAutoInstaller);
|
|
||||||
|
|
||||||
// Boards list widget
|
|
||||||
bind(BoardsListWidget).toSelf();
|
|
||||||
bindViewContribution(bind, BoardsListWidgetFrontendContribution);
|
|
||||||
bind(WidgetFactory).toDynamicValue(context => ({
|
|
||||||
id: BoardsListWidget.WIDGET_ID,
|
|
||||||
createWidget: () => context.container.get(BoardsListWidget)
|
|
||||||
}));
|
|
||||||
bind(FrontendApplicationContribution).toService(BoardsListWidgetFrontendContribution);
|
|
||||||
|
|
||||||
// Board select dialog
|
|
||||||
bind(BoardsConfigDialogWidget).toSelf().inSingletonScope();
|
|
||||||
bind(BoardsConfigDialog).toSelf().inSingletonScope();
|
|
||||||
bind(BoardsConfigDialogProps).toConstantValue({
|
|
||||||
title: 'Select Board'
|
|
||||||
})
|
})
|
||||||
|
.inSingletonScope()
|
||||||
|
.whenTargetNamed('store');
|
||||||
|
|
||||||
// Core service
|
// Boards auto-installer
|
||||||
bind(CoreService).toDynamicValue(context => WebSocketConnectionProvider.createProxy(context.container, CoreServicePath)).inSingletonScope();
|
bind(BoardsAutoInstaller).toSelf().inSingletonScope();
|
||||||
|
bind(FrontendApplicationContribution).toService(BoardsAutoInstaller);
|
||||||
|
|
||||||
// Serial monitor
|
// Boards list widget
|
||||||
bind(MonitorModel).toSelf().inSingletonScope();
|
bind(BoardsListWidget).toSelf();
|
||||||
bind(FrontendApplicationContribution).toService(MonitorModel);
|
bindViewContribution(bind, BoardsListWidgetFrontendContribution);
|
||||||
bind(MonitorWidget).toSelf();
|
bind(WidgetFactory).toDynamicValue((context) => ({
|
||||||
bindViewContribution(bind, MonitorViewContribution);
|
id: BoardsListWidget.WIDGET_ID,
|
||||||
bind(TabBarToolbarContribution).toService(MonitorViewContribution);
|
createWidget: () => context.container.get(BoardsListWidget),
|
||||||
bind(WidgetFactory).toDynamicValue(context => ({
|
}));
|
||||||
id: MonitorWidget.ID,
|
bind(FrontendApplicationContribution).toService(
|
||||||
createWidget: () => context.container.get(MonitorWidget)
|
BoardsListWidgetFrontendContribution
|
||||||
}));
|
);
|
||||||
// Frontend binding for the serial monitor service
|
|
||||||
bind(MonitorService).toDynamicValue(context => {
|
|
||||||
const connection = context.container.get(WebSocketConnectionProvider);
|
|
||||||
const client = context.container.get(MonitorServiceClientImpl);
|
|
||||||
return connection.createProxy(MonitorServicePath, client);
|
|
||||||
}).inSingletonScope();
|
|
||||||
bind(MonitorConnection).toSelf().inSingletonScope();
|
|
||||||
// Serial monitor service client to receive and delegate notifications from the backend.
|
|
||||||
bind(MonitorServiceClientImpl).toSelf().inSingletonScope();
|
|
||||||
bind(MonitorServiceClient).toDynamicValue(context => {
|
|
||||||
const client = context.container.get(MonitorServiceClientImpl);
|
|
||||||
WebSocketConnectionProvider.createProxy(context.container, MonitorServicePath, client);
|
|
||||||
return client;
|
|
||||||
}).inSingletonScope();
|
|
||||||
|
|
||||||
bind(WorkspaceService).toSelf().inSingletonScope();
|
// Board select dialog
|
||||||
rebind(TheiaWorkspaceService).toService(WorkspaceService);
|
bind(BoardsConfigDialogWidget).toSelf().inSingletonScope();
|
||||||
|
bind(BoardsConfigDialog).toSelf().inSingletonScope();
|
||||||
|
bind(BoardsConfigDialogProps).toConstantValue({
|
||||||
|
title: 'Select Board',
|
||||||
|
});
|
||||||
|
|
||||||
// Customizing default Theia layout based on the editor mode: `pro-mode` or `classic`.
|
// Core service
|
||||||
bind(EditorMode).toSelf().inSingletonScope();
|
bind(CoreService)
|
||||||
bind(FrontendApplicationContribution).toService(EditorMode);
|
.toDynamicValue((context) =>
|
||||||
|
WebSocketConnectionProvider.createProxy(
|
||||||
|
context.container,
|
||||||
|
CoreServicePath
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.inSingletonScope();
|
||||||
|
|
||||||
// Layout and shell customizations.
|
// Serial monitor
|
||||||
rebind(TheiaOutlineViewContribution).to(OutlineViewContribution).inSingletonScope();
|
bind(MonitorModel).toSelf().inSingletonScope();
|
||||||
rebind(TheiaProblemContribution).to(ProblemContribution).inSingletonScope();
|
bind(FrontendApplicationContribution).toService(MonitorModel);
|
||||||
rebind(TheiaFileNavigatorContribution).to(FileNavigatorContribution).inSingletonScope();
|
bind(MonitorWidget).toSelf();
|
||||||
rebind(TheiaEditorContribution).to(EditorContribution).inSingletonScope();
|
bindViewContribution(bind, MonitorViewContribution);
|
||||||
rebind(TheiaMonacoStatusBarContribution).to(MonacoStatusBarContribution).inSingletonScope();
|
bind(TabBarToolbarContribution).toService(MonitorViewContribution);
|
||||||
rebind(TheiaApplicationShell).to(ApplicationShell).inSingletonScope();
|
bind(WidgetFactory).toDynamicValue((context) => ({
|
||||||
rebind(TheiaScmContribution).to(ScmContribution).inSingletonScope();
|
id: MonitorWidget.ID,
|
||||||
rebind(TheiaSearchInWorkspaceFrontendContribution).to(SearchInWorkspaceFrontendContribution).inSingletonScope();
|
createWidget: () => context.container.get(MonitorWidget),
|
||||||
rebind(TheiaFrontendApplication).to(FrontendApplication).inSingletonScope();
|
}));
|
||||||
rebind(TheiaWorkspaceFrontendContribution).to(WorkspaceFrontendContribution).inSingletonScope();
|
// Frontend binding for the serial monitor service
|
||||||
rebind(TheiaFileMenuContribution).to(ArduinoFileMenuContribution).inSingletonScope();
|
bind(MonitorService)
|
||||||
rebind(TheiaCommonFrontendContribution).to(CommonFrontendContribution).inSingletonScope();
|
.toDynamicValue((context) => {
|
||||||
rebind(TheiaPreferencesContribution).to(PreferencesContribution).inSingletonScope();
|
const connection = context.container.get(WebSocketConnectionProvider);
|
||||||
rebind(TheiaKeybindingRegistry).to(KeybindingRegistry).inSingletonScope();
|
const client = context.container.get(MonitorServiceClientImpl);
|
||||||
rebind(TheiaWorkspaceCommandContribution).to(WorkspaceCommandContribution).inSingletonScope();
|
return connection.createProxy(MonitorServicePath, client);
|
||||||
rebind(TheiaWorkspaceDeleteHandler).to(WorkspaceDeleteHandler).inSingletonScope();
|
})
|
||||||
rebind(TheiaEditorWidgetFactory).to(EditorWidgetFactory).inSingletonScope();
|
.inSingletonScope();
|
||||||
rebind(TabBarToolbarFactory).toFactory(({ container: parentContainer }) => () => {
|
bind(MonitorConnection).toSelf().inSingletonScope();
|
||||||
|
// Serial monitor service client to receive and delegate notifications from the backend.
|
||||||
|
bind(MonitorServiceClientImpl).toSelf().inSingletonScope();
|
||||||
|
bind(MonitorServiceClient)
|
||||||
|
.toDynamicValue((context) => {
|
||||||
|
const client = context.container.get(MonitorServiceClientImpl);
|
||||||
|
WebSocketConnectionProvider.createProxy(
|
||||||
|
context.container,
|
||||||
|
MonitorServicePath,
|
||||||
|
client
|
||||||
|
);
|
||||||
|
return client;
|
||||||
|
})
|
||||||
|
.inSingletonScope();
|
||||||
|
|
||||||
|
bind(WorkspaceService).toSelf().inSingletonScope();
|
||||||
|
rebind(TheiaWorkspaceService).toService(WorkspaceService);
|
||||||
|
bind(WorkspaceVariableContribution).toSelf().inSingletonScope();
|
||||||
|
rebind(TheiaWorkspaceVariableContribution).toService(
|
||||||
|
WorkspaceVariableContribution
|
||||||
|
);
|
||||||
|
|
||||||
|
// Customizing default Theia layout based on the editor mode: `pro-mode` or `classic`.
|
||||||
|
bind(EditorMode).toSelf().inSingletonScope();
|
||||||
|
bind(FrontendApplicationContribution).toService(EditorMode);
|
||||||
|
|
||||||
|
// Layout and shell customizations.
|
||||||
|
rebind(TheiaOutlineViewContribution)
|
||||||
|
.to(OutlineViewContribution)
|
||||||
|
.inSingletonScope();
|
||||||
|
rebind(TheiaProblemContribution).to(ProblemContribution).inSingletonScope();
|
||||||
|
rebind(TheiaFileNavigatorContribution)
|
||||||
|
.to(FileNavigatorContribution)
|
||||||
|
.inSingletonScope();
|
||||||
|
rebind(TheiaKeymapsFrontendContribution)
|
||||||
|
.to(KeymapsFrontendContribution)
|
||||||
|
.inSingletonScope();
|
||||||
|
rebind(TheiaEditorContribution).to(EditorContribution).inSingletonScope();
|
||||||
|
rebind(TheiaMonacoStatusBarContribution)
|
||||||
|
.to(MonacoStatusBarContribution)
|
||||||
|
.inSingletonScope();
|
||||||
|
rebind(TheiaApplicationShell).to(ApplicationShell).inSingletonScope();
|
||||||
|
rebind(TheiaScmContribution).to(ScmContribution).inSingletonScope();
|
||||||
|
rebind(TheiaSearchInWorkspaceFrontendContribution)
|
||||||
|
.to(SearchInWorkspaceFrontendContribution)
|
||||||
|
.inSingletonScope();
|
||||||
|
rebind(TheiaFrontendApplication).to(FrontendApplication).inSingletonScope();
|
||||||
|
rebind(TheiaWorkspaceFrontendContribution)
|
||||||
|
.to(WorkspaceFrontendContribution)
|
||||||
|
.inSingletonScope();
|
||||||
|
rebind(TheiaFileMenuContribution)
|
||||||
|
.to(ArduinoFileMenuContribution)
|
||||||
|
.inSingletonScope();
|
||||||
|
rebind(TheiaCommonFrontendContribution)
|
||||||
|
.to(CommonFrontendContribution)
|
||||||
|
.inSingletonScope();
|
||||||
|
rebind(TheiaPreferencesContribution)
|
||||||
|
.to(PreferencesContribution)
|
||||||
|
.inSingletonScope();
|
||||||
|
rebind(TheiaKeybindingRegistry).to(KeybindingRegistry).inSingletonScope();
|
||||||
|
rebind(TheiaWorkspaceCommandContribution)
|
||||||
|
.to(WorkspaceCommandContribution)
|
||||||
|
.inSingletonScope();
|
||||||
|
rebind(TheiaWorkspaceDeleteHandler)
|
||||||
|
.to(WorkspaceDeleteHandler)
|
||||||
|
.inSingletonScope();
|
||||||
|
rebind(TheiaEditorWidgetFactory).to(EditorWidgetFactory).inSingletonScope();
|
||||||
|
rebind(TabBarToolbarFactory).toFactory(
|
||||||
|
({ container: parentContainer }) =>
|
||||||
|
() => {
|
||||||
const container = parentContainer.createChild();
|
const container = parentContainer.createChild();
|
||||||
container.bind(TabBarToolbar).toSelf().inSingletonScope();
|
container.bind(TabBarToolbar).toSelf().inSingletonScope();
|
||||||
return container.get(TabBarToolbar);
|
return container.get(TabBarToolbar);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
bind(OutputWidget).toSelf().inSingletonScope();
|
||||||
|
rebind(TheiaOutputWidget).toService(OutputWidget);
|
||||||
|
bind(OutputChannelManager).toSelf().inSingletonScope();
|
||||||
|
rebind(TheiaOutputChannelManager).toService(OutputChannelManager);
|
||||||
|
bind(OutputChannelRegistryMainImpl).toSelf().inTransientScope();
|
||||||
|
rebind(TheiaOutputChannelRegistryMainImpl).toService(
|
||||||
|
OutputChannelRegistryMainImpl
|
||||||
|
);
|
||||||
|
bind(MonacoTextModelService).toSelf().inSingletonScope();
|
||||||
|
rebind(TheiaMonacoTextModelService).toService(MonacoTextModelService);
|
||||||
|
bind(MonacoEditorProvider).toSelf().inSingletonScope();
|
||||||
|
rebind(TheiaMonacoEditorProvider).toService(MonacoEditorProvider);
|
||||||
|
|
||||||
|
bind(SearchInWorkspaceWidget).toSelf();
|
||||||
|
rebind(TheiaSearchInWorkspaceWidget).toService(SearchInWorkspaceWidget);
|
||||||
|
rebind(TheiaSearchInWorkspaceResultTreeWidget).toDynamicValue(
|
||||||
|
({ container }) => {
|
||||||
|
const childContainer = createTreeContainer(container);
|
||||||
|
childContainer.bind(SearchInWorkspaceResultTreeWidget).toSelf();
|
||||||
|
childContainer
|
||||||
|
.rebind(TreeWidget)
|
||||||
|
.toService(SearchInWorkspaceResultTreeWidget);
|
||||||
|
return childContainer.get(SearchInWorkspaceResultTreeWidget);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Show a disconnected status bar, when the daemon is not available
|
||||||
|
bind(ApplicationConnectionStatusContribution).toSelf().inSingletonScope();
|
||||||
|
rebind(TheiaApplicationConnectionStatusContribution).toService(
|
||||||
|
ApplicationConnectionStatusContribution
|
||||||
|
);
|
||||||
|
bind(FrontendConnectionStatusService).toSelf().inSingletonScope();
|
||||||
|
rebind(TheiaFrontendConnectionStatusService).toService(
|
||||||
|
FrontendConnectionStatusService
|
||||||
|
);
|
||||||
|
|
||||||
|
// Decorator customizations
|
||||||
|
bind(TabBarDecoratorService).toSelf().inSingletonScope();
|
||||||
|
rebind(TheiaTabBarDecoratorService).toService(TabBarDecoratorService);
|
||||||
|
|
||||||
|
// Problem markers
|
||||||
|
bind(ProblemManager).toSelf().inSingletonScope();
|
||||||
|
rebind(TheiaProblemManager).toService(ProblemManager);
|
||||||
|
|
||||||
|
// Customized layout restorer that can restore the state in async way: https://github.com/eclipse-theia/theia/issues/6579
|
||||||
|
bind(ShellLayoutRestorer).toSelf().inSingletonScope();
|
||||||
|
rebind(TheiaShellLayoutRestorer).toService(ShellLayoutRestorer);
|
||||||
|
|
||||||
|
// No dropdown for the _Output_ view.
|
||||||
|
bind(OutputToolbarContribution).toSelf().inSingletonScope();
|
||||||
|
rebind(TheiaOutputToolbarContribution).toService(OutputToolbarContribution);
|
||||||
|
|
||||||
|
bind(ArduinoDaemon)
|
||||||
|
.toDynamicValue((context) =>
|
||||||
|
WebSocketConnectionProvider.createProxy(
|
||||||
|
context.container,
|
||||||
|
ArduinoDaemonPath
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.inSingletonScope();
|
||||||
|
|
||||||
|
bind(ArduinoFirmwareUploader)
|
||||||
|
.toDynamicValue((context) =>
|
||||||
|
WebSocketConnectionProvider.createProxy(
|
||||||
|
context.container,
|
||||||
|
ArduinoFirmwareUploaderPath
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.inSingletonScope();
|
||||||
|
|
||||||
|
// File-system extension
|
||||||
|
bind(FileSystemExt)
|
||||||
|
.toDynamicValue((context) =>
|
||||||
|
WebSocketConnectionProvider.createProxy(
|
||||||
|
context.container,
|
||||||
|
FileSystemExtPath
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.inSingletonScope();
|
||||||
|
|
||||||
|
// Examples service@
|
||||||
|
bind(ExamplesService)
|
||||||
|
.toDynamicValue((context) =>
|
||||||
|
WebSocketConnectionProvider.createProxy(
|
||||||
|
context.container,
|
||||||
|
ExamplesServicePath
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.inSingletonScope();
|
||||||
|
|
||||||
|
// Executable URIs known by the backend
|
||||||
|
bind(ExecutableService)
|
||||||
|
.toDynamicValue((context) =>
|
||||||
|
WebSocketConnectionProvider.createProxy(
|
||||||
|
context.container,
|
||||||
|
ExecutableServicePath
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.inSingletonScope();
|
||||||
|
|
||||||
|
Contribution.configure(bind, NewSketch);
|
||||||
|
Contribution.configure(bind, OpenSketch);
|
||||||
|
Contribution.configure(bind, Close);
|
||||||
|
Contribution.configure(bind, SaveSketch);
|
||||||
|
Contribution.configure(bind, SaveAsSketch);
|
||||||
|
Contribution.configure(bind, VerifySketch);
|
||||||
|
Contribution.configure(bind, UploadSketch);
|
||||||
|
Contribution.configure(bind, OpenSketchExternal);
|
||||||
|
Contribution.configure(bind, EditContributions);
|
||||||
|
Contribution.configure(bind, QuitApp);
|
||||||
|
Contribution.configure(bind, SketchControl);
|
||||||
|
Contribution.configure(bind, Settings);
|
||||||
|
Contribution.configure(bind, BurnBootloader);
|
||||||
|
Contribution.configure(bind, BuiltInExamples);
|
||||||
|
Contribution.configure(bind, LibraryExamples);
|
||||||
|
Contribution.configure(bind, IncludeLibrary);
|
||||||
|
Contribution.configure(bind, About);
|
||||||
|
Contribution.configure(bind, Debug);
|
||||||
|
Contribution.configure(bind, Sketchbook);
|
||||||
|
Contribution.configure(bind, UploadFirmware);
|
||||||
|
Contribution.configure(bind, UploadCertificate);
|
||||||
|
Contribution.configure(bind, BoardSelection);
|
||||||
|
Contribution.configure(bind, OpenRecentSketch);
|
||||||
|
Contribution.configure(bind, Help);
|
||||||
|
Contribution.configure(bind, AddFile);
|
||||||
|
Contribution.configure(bind, ArchiveSketch);
|
||||||
|
Contribution.configure(bind, AddZipLibrary);
|
||||||
|
|
||||||
|
bind(ResponseServiceImpl)
|
||||||
|
.toSelf()
|
||||||
|
.inSingletonScope()
|
||||||
|
.onActivation(({ container }, responseService) => {
|
||||||
|
WebSocketConnectionProvider.createProxy(
|
||||||
|
container,
|
||||||
|
ResponseServicePath,
|
||||||
|
responseService
|
||||||
|
);
|
||||||
|
return responseService;
|
||||||
});
|
});
|
||||||
bind(OutputWidget).toSelf().inSingletonScope();
|
bind(ResponseService).toService(ResponseServiceImpl);
|
||||||
rebind(TheiaOutputWidget).toService(OutputWidget);
|
|
||||||
bind(OutputChannelManager).toSelf().inSingletonScope();
|
|
||||||
rebind(TheiaOutputChannelManager).toService(OutputChannelManager);
|
|
||||||
bind(OutputChannelRegistryMainImpl).toSelf().inTransientScope();
|
|
||||||
rebind(TheiaOutputChannelRegistryMainImpl).toService(OutputChannelRegistryMainImpl);
|
|
||||||
bind(MonacoTextModelService).toSelf().inSingletonScope();
|
|
||||||
rebind(TheiaMonacoTextModelService).toService(MonacoTextModelService);
|
|
||||||
|
|
||||||
// Show a disconnected status bar, when the daemon is not available
|
bind(NotificationCenter).toSelf().inSingletonScope();
|
||||||
bind(ApplicationConnectionStatusContribution).toSelf().inSingletonScope();
|
bind(FrontendApplicationContribution).toService(NotificationCenter);
|
||||||
rebind(TheiaApplicationConnectionStatusContribution).toService(ApplicationConnectionStatusContribution);
|
bind(NotificationServiceServer)
|
||||||
bind(FrontendConnectionStatusService).toSelf().inSingletonScope();
|
.toDynamicValue((context) =>
|
||||||
rebind(TheiaFrontendConnectionStatusService).toService(FrontendConnectionStatusService);
|
WebSocketConnectionProvider.createProxy(
|
||||||
|
context.container,
|
||||||
|
NotificationServicePath
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.inSingletonScope();
|
||||||
|
|
||||||
// Editor customizations. Sets the editor to `readOnly` if under the data dir.
|
// Enable the dirty indicator on uncloseable widgets.
|
||||||
bind(EditorManager).toSelf().inSingletonScope();
|
rebind(TabBarRendererFactory).toFactory((context) => () => {
|
||||||
rebind(TheiaEditorManager).toService(EditorManager);
|
const contextMenuRenderer =
|
||||||
|
context.container.get<ContextMenuRenderer>(ContextMenuRenderer);
|
||||||
|
const decoratorService = context.container.get<TabBarDecoratorService>(
|
||||||
|
TabBarDecoratorService
|
||||||
|
);
|
||||||
|
const iconThemeService =
|
||||||
|
context.container.get<IconThemeService>(IconThemeService);
|
||||||
|
return new TabBarRenderer(
|
||||||
|
contextMenuRenderer,
|
||||||
|
decoratorService,
|
||||||
|
iconThemeService
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
// Decorator customizations
|
// Workaround for https://github.com/eclipse-theia/theia/issues/8722
|
||||||
bind(TabBarDecoratorService).toSelf().inSingletonScope();
|
// Do not trigger a save on IDE startup if `"editor.autoSave": "on"` was set as a preference.
|
||||||
rebind(TheiaTabBarDecoratorService).toService(TabBarDecoratorService);
|
bind(EditorCommandContribution).toSelf().inSingletonScope();
|
||||||
|
rebind(TheiaEditorCommandContribution).toService(EditorCommandContribution);
|
||||||
|
|
||||||
// Problem markers
|
// Silent the badge decoration in the Explorer view.
|
||||||
bind(ProblemManager).toSelf().inSingletonScope();
|
bind(NavigatorTabBarDecorator).toSelf().inSingletonScope();
|
||||||
rebind(TheiaProblemManager).toService(ProblemManager);
|
rebind(TheiaNavigatorTabBarDecorator).toService(NavigatorTabBarDecorator);
|
||||||
|
|
||||||
// Customized layout restorer that can restore the state in async way: https://github.com/eclipse-theia/theia/issues/6579
|
// To avoid running `Save All` when there are no dirty editors before starting the debug session.
|
||||||
bind(ShellLayoutRestorer).toSelf().inSingletonScope();
|
bind(DebugSessionManager).toSelf().inSingletonScope();
|
||||||
rebind(TheiaShellLayoutRestorer).toService(ShellLayoutRestorer);
|
rebind(TheiaDebugSessionManager).toService(DebugSessionManager);
|
||||||
|
// To remove the `Run` menu item from the application menu.
|
||||||
|
bind(DebugFrontendApplicationContribution).toSelf().inSingletonScope();
|
||||||
|
rebind(TheiaDebugFrontendApplicationContribution).toService(
|
||||||
|
DebugFrontendApplicationContribution
|
||||||
|
);
|
||||||
|
// To be able to use a `launch.json` from outside of the workspace.
|
||||||
|
bind(DebugConfigurationManager).toSelf().inSingletonScope();
|
||||||
|
rebind(TheiaDebugConfigurationManager).toService(DebugConfigurationManager);
|
||||||
|
|
||||||
// No dropdown for the _Output_ view.
|
// Patch for the debug hover: https://github.com/eclipse-theia/theia/pull/9256/
|
||||||
bind(OutputToolbarContribution).toSelf().inSingletonScope();
|
rebind(DebugEditorModelFactory)
|
||||||
rebind(TheiaOutputToolbarContribution).toService(OutputToolbarContribution);
|
.toDynamicValue(
|
||||||
|
({ container }) =>
|
||||||
|
<DebugEditorModelFactory>(
|
||||||
|
((editor) => DebugEditorModel.createModel(container, editor))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.inSingletonScope();
|
||||||
|
|
||||||
bind(ArduinoDaemon).toDynamicValue(context => WebSocketConnectionProvider.createProxy(context.container, ArduinoDaemonPath)).inSingletonScope();
|
// Preferences
|
||||||
|
bindArduinoPreferences(bind);
|
||||||
|
|
||||||
// File-system extension
|
// Settings wrapper for the preferences and the CLI config.
|
||||||
bind(FileSystemExt).toDynamicValue(context => WebSocketConnectionProvider.createProxy(context.container, FileSystemExtPath)).inSingletonScope();
|
bind(SettingsService).toSelf().inSingletonScope();
|
||||||
|
// Settings dialog and widget
|
||||||
|
bind(SettingsWidget).toSelf().inSingletonScope();
|
||||||
|
bind(SettingsDialog).toSelf().inSingletonScope();
|
||||||
|
bind(SettingsDialogProps).toConstantValue({
|
||||||
|
title: 'Preferences',
|
||||||
|
});
|
||||||
|
|
||||||
// Examples service@
|
bind(StorageWrapper).toSelf().inSingletonScope();
|
||||||
bind(ExamplesService).toDynamicValue(context => WebSocketConnectionProvider.createProxy(context.container, ExamplesServicePath)).inSingletonScope();
|
bind(CommandContribution).toService(StorageWrapper);
|
||||||
|
|
||||||
// Executable URIs known by the backend
|
bind(NotificationManager).toSelf().inSingletonScope();
|
||||||
bind(ExecutableService).toDynamicValue(context => WebSocketConnectionProvider.createProxy(context.container, ExecutableServicePath)).inSingletonScope();
|
rebind(TheiaNotificationManager).toService(NotificationManager);
|
||||||
|
bind(NotificationsRenderer).toSelf().inSingletonScope();
|
||||||
|
rebind(TheiaNotificationsRenderer).toService(NotificationsRenderer);
|
||||||
|
|
||||||
Contribution.configure(bind, NewSketch);
|
// UI for the Sketchbook
|
||||||
Contribution.configure(bind, OpenSketch);
|
bind(SketchbookWidget).toSelf();
|
||||||
Contribution.configure(bind, Close);
|
bind(SketchbookTreeWidget).toDynamicValue(({ container }) =>
|
||||||
Contribution.configure(bind, SaveSketch);
|
createSketchbookTreeWidget(container)
|
||||||
Contribution.configure(bind, SaveAsSketch);
|
);
|
||||||
Contribution.configure(bind, VerifySketch);
|
bindViewContribution(bind, SketchbookWidgetContribution);
|
||||||
Contribution.configure(bind, UploadSketch);
|
bind(FrontendApplicationContribution).toService(SketchbookWidgetContribution);
|
||||||
Contribution.configure(bind, OpenSketchExternal);
|
bind(WidgetFactory).toDynamicValue(({ container }) => ({
|
||||||
Contribution.configure(bind, EditContributions);
|
id: 'arduino-sketchbook-widget',
|
||||||
Contribution.configure(bind, QuitApp);
|
createWidget: () => container.get(SketchbookWidget),
|
||||||
Contribution.configure(bind, SketchControl);
|
}));
|
||||||
Contribution.configure(bind, Settings);
|
|
||||||
Contribution.configure(bind, BurnBootloader);
|
|
||||||
Contribution.configure(bind, BuiltInExamples);
|
|
||||||
Contribution.configure(bind, LibraryExamples);
|
|
||||||
Contribution.configure(bind, IncludeLibrary);
|
|
||||||
Contribution.configure(bind, About);
|
|
||||||
Contribution.configure(bind, Debug);
|
|
||||||
Contribution.configure(bind, Sketchbook);
|
|
||||||
Contribution.configure(bind, BoardSelection);
|
|
||||||
Contribution.configure(bind, OpenRecentSketch);
|
|
||||||
Contribution.configure(bind, Help);
|
|
||||||
Contribution.configure(bind, AddFile);
|
|
||||||
Contribution.configure(bind, ArchiveSketch);
|
|
||||||
|
|
||||||
bind(OutputServiceImpl).toSelf().inSingletonScope().onActivation(({ container }, outputService) => {
|
bind(CloudSketchbookWidget).toSelf();
|
||||||
WebSocketConnectionProvider.createProxy(container, OutputServicePath, outputService);
|
rebind(SketchbookWidget).toService(CloudSketchbookWidget);
|
||||||
return outputService;
|
bind(CloudSketchbookTreeWidget).toDynamicValue(({ container }) =>
|
||||||
});
|
createCloudSketchbookTreeWidget(container)
|
||||||
bind(OutputService).toService(OutputServiceImpl);
|
);
|
||||||
|
bind(CreateApi).toSelf().inSingletonScope();
|
||||||
|
bind(SketchCache).toSelf().inSingletonScope();
|
||||||
|
|
||||||
bind(NotificationCenter).toSelf().inSingletonScope();
|
bind(ShareSketchDialog).toSelf().inSingletonScope();
|
||||||
bind(FrontendApplicationContribution).toService(NotificationCenter);
|
bind(AuthenticationClientService).toSelf().inSingletonScope();
|
||||||
bind(NotificationServiceServer).toDynamicValue(context => WebSocketConnectionProvider.createProxy(context.container, NotificationServicePath)).inSingletonScope();
|
bind(CommandContribution).toService(AuthenticationClientService);
|
||||||
|
bind(FrontendApplicationContribution).toService(AuthenticationClientService);
|
||||||
|
bind(AuthenticationService)
|
||||||
|
.toDynamicValue((context) =>
|
||||||
|
WebSocketConnectionProvider.createProxy(
|
||||||
|
context.container,
|
||||||
|
AuthenticationServicePath
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.inSingletonScope();
|
||||||
|
bind(CreateFsProvider).toSelf().inSingletonScope();
|
||||||
|
bind(FrontendApplicationContribution).toService(CreateFsProvider);
|
||||||
|
bind(FileServiceContribution).toService(CreateFsProvider);
|
||||||
|
bind(CloudSketchbookContribution).toSelf().inSingletonScope();
|
||||||
|
bind(CommandContribution).toService(CloudSketchbookContribution);
|
||||||
|
bind(LocalCacheFsProvider).toSelf().inSingletonScope();
|
||||||
|
bind(FileServiceContribution).toService(LocalCacheFsProvider);
|
||||||
|
bind(CloudSketchbookCompositeWidget).toSelf();
|
||||||
|
bind<WidgetFactory>(WidgetFactory).toDynamicValue((ctx) => ({
|
||||||
|
id: 'cloud-sketchbook-composite-widget',
|
||||||
|
createWidget: () => ctx.container.get(CloudSketchbookCompositeWidget),
|
||||||
|
}));
|
||||||
|
|
||||||
// Enable the dirty indicator on uncloseable widgets.
|
bind(UploadFirmwareDialogWidget).toSelf().inSingletonScope();
|
||||||
rebind(TabBarRendererFactory).toFactory(context => () => {
|
bind(UploadFirmwareDialog).toSelf().inSingletonScope();
|
||||||
const contextMenuRenderer = context.container.get<ContextMenuRenderer>(ContextMenuRenderer);
|
bind(UploadFirmwareDialogProps).toConstantValue({
|
||||||
const decoratorService = context.container.get<TabBarDecoratorService>(TabBarDecoratorService);
|
title: 'UploadFirmware',
|
||||||
const iconThemeService = context.container.get<IconThemeService>(IconThemeService);
|
});
|
||||||
return new TabBarRenderer(contextMenuRenderer, decoratorService, iconThemeService);
|
bind(UploadCertificateDialogWidget).toSelf().inSingletonScope();
|
||||||
});
|
bind(UploadCertificateDialog).toSelf().inSingletonScope();
|
||||||
|
bind(UploadCertificateDialogProps).toConstantValue({
|
||||||
// Workaround for https://github.com/eclipse-theia/theia/issues/8722
|
title: 'UploadCertificate',
|
||||||
// Do not trigger a save on IDE startup if `"editor.autoSave": "on"` was set as a preference.
|
});
|
||||||
bind(EditorCommandContribution).toSelf().inSingletonScope();
|
|
||||||
rebind(TheiaEditorCommandContribution).toService(EditorCommandContribution);
|
|
||||||
|
|
||||||
// Silent the badge decoration in the Explorer view.
|
|
||||||
bind(NavigatorTabBarDecorator).toSelf().inSingletonScope();
|
|
||||||
rebind(TheiaNavigatorTabBarDecorator).toService(NavigatorTabBarDecorator);
|
|
||||||
|
|
||||||
// To avoid running `Save All` when there are no dirty editors before starting the debug session.
|
|
||||||
bind(DebugSessionManager).toSelf().inSingletonScope();
|
|
||||||
rebind(TheiaDebugSessionManager).toService(DebugSessionManager);
|
|
||||||
// To remove the `Run` menu item from the application menu.
|
|
||||||
bind(DebugFrontendApplicationContribution).toSelf().inSingletonScope();
|
|
||||||
rebind(TheiaDebugFrontendApplicationContribution).toService(DebugFrontendApplicationContribution);
|
|
||||||
|
|
||||||
// Preferences
|
|
||||||
bindArduinoPreferences(bind);
|
|
||||||
|
|
||||||
// Settings wrapper for the preferences and the CLI config.
|
|
||||||
bind(SettingsService).toSelf().inSingletonScope();
|
|
||||||
// Settings dialog and widget
|
|
||||||
bind(SettingsWidget).toSelf().inSingletonScope();
|
|
||||||
bind(SettingsDialog).toSelf().inSingletonScope();
|
|
||||||
bind(SettingsDialogProps).toConstantValue({
|
|
||||||
title: 'Preferences'
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,73 +1,161 @@
|
|||||||
import { interfaces } from 'inversify';
|
import { interfaces } from 'inversify';
|
||||||
import {
|
import {
|
||||||
createPreferenceProxy,
|
createPreferenceProxy,
|
||||||
PreferenceProxy,
|
PreferenceProxy,
|
||||||
PreferenceService,
|
PreferenceService,
|
||||||
PreferenceContribution,
|
PreferenceContribution,
|
||||||
PreferenceSchema
|
PreferenceSchema,
|
||||||
} from '@theia/core/lib/browser/preferences';
|
} from '@theia/core/lib/browser/preferences';
|
||||||
|
import { CompilerWarningLiterals, CompilerWarnings } from '../common/protocol';
|
||||||
|
|
||||||
export const ArduinoConfigSchema: PreferenceSchema = {
|
export const ArduinoConfigSchema: PreferenceSchema = {
|
||||||
'type': 'object',
|
type: 'object',
|
||||||
'properties': {
|
properties: {
|
||||||
'arduino.language.log': {
|
'arduino.language.log': {
|
||||||
'type': 'boolean',
|
type: 'boolean',
|
||||||
'description': "True if the Arduino Language Server should generate log files into the sketch folder. Otherwise, false. It's false by default.",
|
description:
|
||||||
'default': false
|
"True if the Arduino Language Server should generate log files into the sketch folder. Otherwise, false. It's false by default.",
|
||||||
},
|
default: false,
|
||||||
'arduino.compile.verbose': {
|
},
|
||||||
'type': 'boolean',
|
'arduino.compile.verbose': {
|
||||||
'description': 'True for verbose compile output. False by default',
|
type: 'boolean',
|
||||||
'default': false
|
description: 'True for verbose compile output. False by default',
|
||||||
},
|
default: false,
|
||||||
'arduino.upload.verbose': {
|
},
|
||||||
'type': 'boolean',
|
'arduino.compile.warnings': {
|
||||||
'description': 'True for verbose upload output. False by default.',
|
enum: [...CompilerWarningLiterals],
|
||||||
'default': false
|
description:
|
||||||
},
|
"Tells gcc which warning level to use. It's 'None' by default",
|
||||||
'arduino.upload.verify': {
|
default: 'None',
|
||||||
'type': 'boolean',
|
},
|
||||||
'default': false
|
'arduino.upload.verbose': {
|
||||||
},
|
type: 'boolean',
|
||||||
'arduino.window.autoScale': {
|
description: 'True for verbose upload output. False by default.',
|
||||||
'type': 'boolean',
|
default: false,
|
||||||
'description': 'True if the user interface automatically scales with the font size.',
|
},
|
||||||
'default': true
|
'arduino.upload.verify': {
|
||||||
},
|
type: 'boolean',
|
||||||
'arduino.window.zoomLevel': {
|
default: false,
|
||||||
'type': 'number',
|
},
|
||||||
'description': 'Adjust the zoom level of the window. The original size is 0 and each increment above (e.g. 1) or below (e.g. -1) represents zooming 20% larger or smaller. You can also enter decimals to adjust the zoom level with a finer granularity.',
|
'arduino.window.autoScale': {
|
||||||
'default': 0
|
type: 'boolean',
|
||||||
},
|
description:
|
||||||
'arduino.ide.autoUpdate': {
|
'True if the user interface automatically scales with the font size.',
|
||||||
'type': 'boolean',
|
default: true,
|
||||||
'description': 'True to enable automatic update checks. The IDE will check for updates automatically and periodically.',
|
},
|
||||||
'default': true
|
'arduino.window.zoomLevel': {
|
||||||
}
|
type: 'number',
|
||||||
}
|
description:
|
||||||
|
'Adjust the zoom level of the window. The original size is 0 and each increment above (e.g. 1) or below (e.g. -1) represents zooming 20% larger or smaller. You can also enter decimals to adjust the zoom level with a finer granularity.',
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
|
'arduino.ide.autoUpdate': {
|
||||||
|
type: 'boolean',
|
||||||
|
description:
|
||||||
|
'True to enable automatic update checks. The IDE will check for updates automatically and periodically.',
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
'arduino.board.certificates': {
|
||||||
|
type: 'string',
|
||||||
|
description: 'List of certificates that can be uploaded to boards',
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
'arduino.sketchbook.showAllFiles': {
|
||||||
|
type: 'boolean',
|
||||||
|
description:
|
||||||
|
'True to show all sketch files inside the sketch. It is false by default.',
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
'arduino.cloud.enabled': {
|
||||||
|
type: 'boolean',
|
||||||
|
description:
|
||||||
|
'True if the sketch sync functions are enabled. Defaults to true.',
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
'arduino.cloud.pull.warn': {
|
||||||
|
type: 'boolean',
|
||||||
|
description:
|
||||||
|
'True if users should be warned before pulling a cloud sketch. Defaults to true.',
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
'arduino.cloud.push.warn': {
|
||||||
|
type: 'boolean',
|
||||||
|
description:
|
||||||
|
'True if users should be warned before pushing a cloud sketch. Defaults to true.',
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
'arduino.cloud.pushpublic.warn': {
|
||||||
|
type: 'boolean',
|
||||||
|
description:
|
||||||
|
'True if users should be warned before pushing a public sketch to the cloud. Defaults to true.',
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
'arduino.cloud.sketchSyncEnpoint': {
|
||||||
|
type: 'string',
|
||||||
|
description:
|
||||||
|
'The endpoint used to push and pull sketches from a backend. By default it points to Arduino Cloud API.',
|
||||||
|
default: 'https://api2.arduino.cc/create',
|
||||||
|
},
|
||||||
|
'arduino.auth.clientID': {
|
||||||
|
type: 'string',
|
||||||
|
description: 'The OAuth2 client ID.',
|
||||||
|
default: 'C34Ya6ex77jTNxyKWj01lCe1vAHIaPIo',
|
||||||
|
},
|
||||||
|
'arduino.auth.domain': {
|
||||||
|
type: 'string',
|
||||||
|
description: 'The OAuth2 domain.',
|
||||||
|
default: 'login.arduino.cc',
|
||||||
|
},
|
||||||
|
'arduino.auth.audience': {
|
||||||
|
type: 'string',
|
||||||
|
description: 'The 0Auth2 audience.',
|
||||||
|
default: 'https://api.arduino.cc',
|
||||||
|
},
|
||||||
|
'arduino.auth.registerUri': {
|
||||||
|
type: 'string',
|
||||||
|
description: 'The URI used to register a new user.',
|
||||||
|
default: 'https://auth.arduino.cc/login#/register',
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface ArduinoConfiguration {
|
export interface ArduinoConfiguration {
|
||||||
'arduino.language.log': boolean;
|
'arduino.language.log': boolean;
|
||||||
'arduino.compile.verbose': boolean;
|
'arduino.compile.verbose': boolean;
|
||||||
'arduino.upload.verbose': boolean;
|
'arduino.compile.warnings': CompilerWarnings;
|
||||||
'arduino.upload.verify': boolean;
|
'arduino.upload.verbose': boolean;
|
||||||
'arduino.window.autoScale': boolean;
|
'arduino.upload.verify': boolean;
|
||||||
'arduino.window.zoomLevel': number;
|
'arduino.window.autoScale': boolean;
|
||||||
'arduino.ide.autoUpdate': boolean;
|
'arduino.window.zoomLevel': number;
|
||||||
|
'arduino.ide.autoUpdate': boolean;
|
||||||
|
'arduino.board.certificates': string;
|
||||||
|
'arduino.sketchbook.showAllFiles': boolean;
|
||||||
|
'arduino.cloud.enabled': boolean;
|
||||||
|
'arduino.cloud.pull.warn': boolean;
|
||||||
|
'arduino.cloud.push.warn': boolean;
|
||||||
|
'arduino.cloud.pushpublic.warn': boolean;
|
||||||
|
'arduino.cloud.sketchSyncEnpoint': string;
|
||||||
|
'arduino.auth.clientID': string;
|
||||||
|
'arduino.auth.domain': string;
|
||||||
|
'arduino.auth.audience': string;
|
||||||
|
'arduino.auth.registerUri': string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ArduinoPreferences = Symbol('ArduinoPreferences');
|
export const ArduinoPreferences = Symbol('ArduinoPreferences');
|
||||||
export type ArduinoPreferences = PreferenceProxy<ArduinoConfiguration>;
|
export type ArduinoPreferences = PreferenceProxy<ArduinoConfiguration>;
|
||||||
|
|
||||||
export function createArduinoPreferences(preferences: PreferenceService): ArduinoPreferences {
|
export function createArduinoPreferences(
|
||||||
return createPreferenceProxy(preferences, ArduinoConfigSchema);
|
preferences: PreferenceService
|
||||||
|
): ArduinoPreferences {
|
||||||
|
return createPreferenceProxy(preferences, ArduinoConfigSchema);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function bindArduinoPreferences(bind: interfaces.Bind): void {
|
export function bindArduinoPreferences(bind: interfaces.Bind): void {
|
||||||
bind(ArduinoPreferences).toDynamicValue(ctx => {
|
bind(ArduinoPreferences).toDynamicValue((ctx) => {
|
||||||
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
|
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
|
||||||
return createArduinoPreferences(preferences);
|
return createArduinoPreferences(preferences);
|
||||||
});
|
});
|
||||||
bind(PreferenceContribution).toConstantValue({ schema: ArduinoConfigSchema });
|
bind(PreferenceContribution).toConstantValue({
|
||||||
|
schema: ArduinoConfigSchema,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,49 +20,54 @@ import { MaybePromise } from '@theia/core/lib/common/types';
|
|||||||
* - `try open recent workspace roots`, then `try open last modified sketches`, finally `create new sketch`.
|
* - `try open recent workspace roots`, then `try open last modified sketches`, finally `create new sketch`.
|
||||||
*/
|
*/
|
||||||
namespace ArduinoWorkspaceRootResolver {
|
namespace ArduinoWorkspaceRootResolver {
|
||||||
export interface InitOptions {
|
export interface InitOptions {
|
||||||
readonly isValid: (uri: string) => MaybePromise<boolean>;
|
readonly isValid: (uri: string) => MaybePromise<boolean>;
|
||||||
}
|
}
|
||||||
export interface ResolveOptions {
|
export interface ResolveOptions {
|
||||||
readonly hash?: string
|
readonly hash?: string;
|
||||||
readonly recentWorkspaces: string[];
|
readonly recentWorkspaces: string[];
|
||||||
// Gathered from the default sketch folder. The default sketch folder is defined by the CLI.
|
// Gathered from the default sketch folder. The default sketch folder is defined by the CLI.
|
||||||
readonly recentSketches: string[];
|
readonly recentSketches: string[];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export class ArduinoWorkspaceRootResolver {
|
export class ArduinoWorkspaceRootResolver {
|
||||||
|
constructor(protected options: ArduinoWorkspaceRootResolver.InitOptions) {}
|
||||||
|
|
||||||
constructor(protected options: ArduinoWorkspaceRootResolver.InitOptions) {
|
async resolve(
|
||||||
|
options: ArduinoWorkspaceRootResolver.ResolveOptions
|
||||||
|
): Promise<{ uri: string } | undefined> {
|
||||||
|
const { hash, recentWorkspaces, recentSketches } = options;
|
||||||
|
for (const uri of [
|
||||||
|
this.hashToUri(hash),
|
||||||
|
...recentWorkspaces,
|
||||||
|
...recentSketches,
|
||||||
|
].filter(notEmpty)) {
|
||||||
|
const valid = await this.isValid(uri);
|
||||||
|
if (valid) {
|
||||||
|
return { uri };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
async resolve(options: ArduinoWorkspaceRootResolver.ResolveOptions): Promise<{ uri: string } | undefined> {
|
protected isValid(uri: string): MaybePromise<boolean> {
|
||||||
const { hash, recentWorkspaces, recentSketches } = options;
|
return this.options.isValid(uri);
|
||||||
for (const uri of [this.hashToUri(hash), ...recentWorkspaces, ...recentSketches].filter(notEmpty)) {
|
}
|
||||||
const valid = await this.isValid(uri);
|
|
||||||
if (valid) {
|
// Note: here, the `hash` was defined as new `URI(yourValidFsPath).path` so we have to map it to a valid FS path first.
|
||||||
return { uri };
|
// This is important for Windows only and a NOOP on POSIX.
|
||||||
}
|
// Note: we set the `new URI(myValidUri).path.toString()` as the `hash`. See:
|
||||||
}
|
// - https://github.com/eclipse-theia/theia/blob/8196e9dcf9c8de8ea0910efeb5334a974f426966/packages/workspace/src/browser/workspace-service.ts#L143 and
|
||||||
return undefined;
|
// - https://github.com/eclipse-theia/theia/blob/8196e9dcf9c8de8ea0910efeb5334a974f426966/packages/workspace/src/browser/workspace-service.ts#L423
|
||||||
|
protected hashToUri(hash: string | undefined): string | undefined {
|
||||||
|
if (hash && hash.length > 1 && hash.startsWith('#')) {
|
||||||
|
const path = hash.slice(1); // Trim the leading `#`.
|
||||||
|
return new URI(
|
||||||
|
toUnix(path.slice(isWindows && hash.startsWith('/') ? 1 : 0))
|
||||||
|
)
|
||||||
|
.withScheme('file')
|
||||||
|
.toString();
|
||||||
}
|
}
|
||||||
|
return undefined;
|
||||||
protected isValid(uri: string): MaybePromise<boolean> {
|
}
|
||||||
return this.options.isValid(uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: here, the `hash` was defined as new `URI(yourValidFsPath).path` so we have to map it to a valid FS path first.
|
|
||||||
// This is important for Windows only and a NOOP on POSIX.
|
|
||||||
// Note: we set the `new URI(myValidUri).path.toString()` as the `hash`. See:
|
|
||||||
// - https://github.com/eclipse-theia/theia/blob/8196e9dcf9c8de8ea0910efeb5334a974f426966/packages/workspace/src/browser/workspace-service.ts#L143 and
|
|
||||||
// - https://github.com/eclipse-theia/theia/blob/8196e9dcf9c8de8ea0910efeb5334a974f426966/packages/workspace/src/browser/workspace-service.ts#L423
|
|
||||||
protected hashToUri(hash: string | undefined): string | undefined {
|
|
||||||
if (hash
|
|
||||||
&& hash.length > 1
|
|
||||||
&& hash.startsWith('#')) {
|
|
||||||
const path = hash.slice(1); // Trim the leading `#`.
|
|
||||||
return new URI(toUnix(path.slice(isWindows && hash.startsWith('/') ? 1 : 0))).withScheme('file').toString();
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
import { inject, injectable } from 'inversify';
|
||||||
|
import { Emitter } from '@theia/core/lib/common/event';
|
||||||
|
import { JsonRpcProxy } from '@theia/core/lib/common/messaging/proxy-factory';
|
||||||
|
import { WindowService } from '@theia/core/lib/browser/window/window-service';
|
||||||
|
import { DisposableCollection } from '@theia/core/lib/common/disposable';
|
||||||
|
import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application';
|
||||||
|
import {
|
||||||
|
CommandRegistry,
|
||||||
|
CommandContribution,
|
||||||
|
} from '@theia/core/lib/common/command';
|
||||||
|
import {
|
||||||
|
AuthenticationService,
|
||||||
|
AuthenticationServiceClient,
|
||||||
|
AuthenticationSession,
|
||||||
|
} from '../../common/protocol/authentication-service';
|
||||||
|
import { CloudUserCommands } from './cloud-user-commands';
|
||||||
|
import { serverPort } from '../../node/auth/authentication-server';
|
||||||
|
import { AuthOptions } from '../../node/auth/types';
|
||||||
|
import { ArduinoPreferences } from '../arduino-preferences';
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class AuthenticationClientService
|
||||||
|
implements
|
||||||
|
FrontendApplicationContribution,
|
||||||
|
CommandContribution,
|
||||||
|
AuthenticationServiceClient
|
||||||
|
{
|
||||||
|
@inject(AuthenticationService)
|
||||||
|
protected readonly service: JsonRpcProxy<AuthenticationService>;
|
||||||
|
|
||||||
|
@inject(WindowService)
|
||||||
|
protected readonly windowService: WindowService;
|
||||||
|
|
||||||
|
@inject(ArduinoPreferences)
|
||||||
|
protected readonly arduinoPreferences: ArduinoPreferences;
|
||||||
|
|
||||||
|
protected authOptions: AuthOptions;
|
||||||
|
protected _session: AuthenticationSession | undefined;
|
||||||
|
protected readonly toDispose = new DisposableCollection();
|
||||||
|
protected readonly onSessionDidChangeEmitter = new Emitter<
|
||||||
|
AuthenticationSession | undefined
|
||||||
|
>();
|
||||||
|
|
||||||
|
readonly onSessionDidChange = this.onSessionDidChangeEmitter.event;
|
||||||
|
|
||||||
|
onStart(): void {
|
||||||
|
this.toDispose.push(this.onSessionDidChangeEmitter);
|
||||||
|
this.service.setClient(this);
|
||||||
|
this.service
|
||||||
|
.session()
|
||||||
|
.then((session) => this.notifySessionDidChange(session));
|
||||||
|
this.setOptions();
|
||||||
|
this.arduinoPreferences.onPreferenceChanged((event) => {
|
||||||
|
if (event.preferenceName.startsWith('arduino.auth.')) {
|
||||||
|
this.setOptions();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setOptions(): void {
|
||||||
|
this.service.setOptions({
|
||||||
|
redirectUri: `http://localhost:${serverPort}/callback`,
|
||||||
|
responseType: 'code',
|
||||||
|
clientID: this.arduinoPreferences['arduino.auth.clientID'],
|
||||||
|
domain: this.arduinoPreferences['arduino.auth.domain'],
|
||||||
|
audience: this.arduinoPreferences['arduino.auth.audience'],
|
||||||
|
registerUri: this.arduinoPreferences['arduino.auth.registerUri'],
|
||||||
|
scopes: ['openid', 'profile', 'email', 'offline_access'],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected updateSession(session?: AuthenticationSession | undefined) {
|
||||||
|
this._session = session;
|
||||||
|
this.onSessionDidChangeEmitter.fire(this._session);
|
||||||
|
}
|
||||||
|
|
||||||
|
get session(): AuthenticationSession | undefined {
|
||||||
|
return this._session;
|
||||||
|
}
|
||||||
|
|
||||||
|
registerCommands(registry: CommandRegistry): void {
|
||||||
|
registry.registerCommand(CloudUserCommands.LOGIN, {
|
||||||
|
execute: () => this.service.login(),
|
||||||
|
});
|
||||||
|
registry.registerCommand(CloudUserCommands.LOGOUT, {
|
||||||
|
execute: () => this.service.logout(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
notifySessionDidChange(session: AuthenticationSession | undefined): void {
|
||||||
|
this.updateSession(session);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { Command } from '@theia/core/lib/common/command';
|
||||||
|
|
||||||
|
export namespace CloudUserCommands {
|
||||||
|
export const LOGIN: Command = {
|
||||||
|
id: 'arduino-cloud--login',
|
||||||
|
label: 'Sign in',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const LOGOUT: Command = {
|
||||||
|
id: 'arduino-cloud--logout',
|
||||||
|
label: 'Sign Out',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const OPEN_PROFILE_CONTEXT_MENU: Command = {
|
||||||
|
id: 'arduino-cloud-sketchbook--open-profile-menu',
|
||||||
|
label: 'Contextual menu',
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,11 +1,16 @@
|
|||||||
import { injectable, inject } from 'inversify';
|
import { injectable, inject } from 'inversify';
|
||||||
import { MessageService } from '@theia/core/lib/common/message-service';
|
import { MessageService } from '@theia/core/lib/common/message-service';
|
||||||
import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application';
|
import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application';
|
||||||
import { BoardsService, BoardsPackage } from '../../common/protocol/boards-service';
|
import {
|
||||||
|
BoardsService,
|
||||||
|
BoardsPackage,
|
||||||
|
Board,
|
||||||
|
} from '../../common/protocol/boards-service';
|
||||||
import { BoardsServiceProvider } from './boards-service-provider';
|
import { BoardsServiceProvider } from './boards-service-provider';
|
||||||
import { BoardsListWidgetFrontendContribution } from './boards-widget-frontend-contribution';
|
import { BoardsListWidgetFrontendContribution } from './boards-widget-frontend-contribution';
|
||||||
import { InstallationProgressDialog } from '../widgets/progress-dialog';
|
|
||||||
import { BoardsConfig } from './boards-config';
|
import { BoardsConfig } from './boards-config';
|
||||||
|
import { Installable } from '../../common/protocol';
|
||||||
|
import { ResponseServiceImpl } from '../response-service-impl';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listens on `BoardsConfig.Config` changes, if a board is selected which does not
|
* Listens on `BoardsConfig.Config` changes, if a board is selected which does not
|
||||||
@@ -13,50 +18,103 @@ import { BoardsConfig } from './boards-config';
|
|||||||
*/
|
*/
|
||||||
@injectable()
|
@injectable()
|
||||||
export class BoardsAutoInstaller implements FrontendApplicationContribution {
|
export class BoardsAutoInstaller implements FrontendApplicationContribution {
|
||||||
|
@inject(MessageService)
|
||||||
|
protected readonly messageService: MessageService;
|
||||||
|
|
||||||
@inject(MessageService)
|
@inject(BoardsService)
|
||||||
protected readonly messageService: MessageService;
|
protected readonly boardsService: BoardsService;
|
||||||
|
|
||||||
@inject(BoardsService)
|
@inject(BoardsServiceProvider)
|
||||||
protected readonly boardsService: BoardsService;
|
protected readonly boardsServiceClient: BoardsServiceProvider;
|
||||||
|
|
||||||
@inject(BoardsServiceProvider)
|
@inject(ResponseServiceImpl)
|
||||||
protected readonly boardsServiceClient: BoardsServiceProvider;
|
protected readonly responseService: ResponseServiceImpl;
|
||||||
|
|
||||||
@inject(BoardsListWidgetFrontendContribution)
|
@inject(BoardsListWidgetFrontendContribution)
|
||||||
protected readonly boardsManagerFrontendContribution: BoardsListWidgetFrontendContribution;
|
protected readonly boardsManagerFrontendContribution: BoardsListWidgetFrontendContribution;
|
||||||
|
|
||||||
onStart(): void {
|
// Workaround for https://github.com/eclipse-theia/theia/issues/9349
|
||||||
this.boardsServiceClient.onBoardsConfigChanged(this.ensureCoreExists.bind(this));
|
protected notifications: Board[] = [];
|
||||||
this.ensureCoreExists(this.boardsServiceClient.boardsConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ensureCoreExists(config: BoardsConfig.Config): void {
|
onStart(): void {
|
||||||
const { selectedBoard } = config;
|
this.boardsServiceClient.onBoardsConfigChanged(
|
||||||
if (selectedBoard) {
|
this.ensureCoreExists.bind(this)
|
||||||
this.boardsService.search({}).then(packages => {
|
);
|
||||||
const candidates = packages
|
this.ensureCoreExists(this.boardsServiceClient.boardsConfig);
|
||||||
.filter(pkg => BoardsPackage.contains(selectedBoard, pkg))
|
}
|
||||||
.filter(({ installable, installedVersion }) => installable && !installedVersion);
|
|
||||||
for (const candidate of candidates) {
|
protected ensureCoreExists(config: BoardsConfig.Config): void {
|
||||||
// tslint:disable-next-line:max-line-length
|
const { selectedBoard } = config;
|
||||||
this.messageService.info(`The \`"${candidate.name}"\` core has to be installed for the currently selected \`"${selectedBoard.name}"\` board. Do you want to install it now?`, 'Install Manually', 'Yes').then(async answer => {
|
if (
|
||||||
if (answer === 'Yes') {
|
selectedBoard &&
|
||||||
const dialog = new InstallationProgressDialog(candidate.name, candidate.availableVersions[0]);
|
!this.notifications.find((board) => Board.sameAs(board, selectedBoard))
|
||||||
dialog.open();
|
) {
|
||||||
try {
|
this.notifications.push(selectedBoard);
|
||||||
await this.boardsService.install({ item: candidate });
|
this.boardsService.search({}).then((packages) => {
|
||||||
} finally {
|
// filter packagesForBoard selecting matches from the cli (installed packages)
|
||||||
dialog.close();
|
// and matches based on the board name
|
||||||
}
|
// NOTE: this ensures the Deprecated & new packages are all in the array
|
||||||
}
|
// so that we can check if any of the valid packages is already installed
|
||||||
if (answer) {
|
const packagesForBoard = packages.filter(
|
||||||
this.boardsManagerFrontendContribution.openView({ reveal: true }).then(widget => widget.refresh(candidate.name.toLocaleLowerCase()));
|
(pkg) =>
|
||||||
}
|
BoardsPackage.contains(selectedBoard, pkg) ||
|
||||||
});
|
pkg.boards.some((board) => board.name === selectedBoard.name)
|
||||||
}
|
);
|
||||||
})
|
|
||||||
|
// check if one of the packages for the board is already installed. if so, no hint
|
||||||
|
if (
|
||||||
|
packagesForBoard.some(({ installedVersion }) => !!installedVersion)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
// filter the installable (not installed) packages,
|
||||||
|
// CLI returns the packages already sorted with the deprecated ones at the end of the list
|
||||||
|
// in order to ensure the new ones are preferred
|
||||||
|
const candidates = packagesForBoard.filter(
|
||||||
|
({ installable, installedVersion }) =>
|
||||||
|
installable && !installedVersion
|
||||||
|
);
|
||||||
|
|
||||||
|
const candidate = candidates[0];
|
||||||
|
if (candidate) {
|
||||||
|
const version = candidate.availableVersions[0]
|
||||||
|
? `[v ${candidate.availableVersions[0]}]`
|
||||||
|
: '';
|
||||||
|
// tslint:disable-next-line:max-line-length
|
||||||
|
this.messageService
|
||||||
|
.info(
|
||||||
|
`The \`"${candidate.name} ${version}"\` core has to be installed for the currently selected \`"${selectedBoard.name}"\` board. Do you want to install it now?`,
|
||||||
|
'Install Manually',
|
||||||
|
'Yes'
|
||||||
|
)
|
||||||
|
.then(async (answer) => {
|
||||||
|
const index = this.notifications.findIndex((board) =>
|
||||||
|
Board.sameAs(board, selectedBoard)
|
||||||
|
);
|
||||||
|
if (index !== -1) {
|
||||||
|
this.notifications.splice(index, 1);
|
||||||
|
}
|
||||||
|
if (answer === 'Yes') {
|
||||||
|
await Installable.installWithProgress({
|
||||||
|
installable: this.boardsService,
|
||||||
|
item: candidate,
|
||||||
|
messageService: this.messageService,
|
||||||
|
responseService: this.responseService,
|
||||||
|
version: candidate.availableVersions[0],
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (answer) {
|
||||||
|
this.boardsManagerFrontendContribution
|
||||||
|
.openView({ reveal: true })
|
||||||
|
.then((widget) =>
|
||||||
|
widget.refresh(candidate.name.toLocaleLowerCase())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,60 +9,62 @@ import { NotificationCenter } from '../notification-center';
|
|||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class BoardsConfigDialogWidget extends ReactWidget {
|
export class BoardsConfigDialogWidget extends ReactWidget {
|
||||||
|
@inject(BoardsService)
|
||||||
|
protected readonly boardsService: BoardsService;
|
||||||
|
|
||||||
@inject(BoardsService)
|
@inject(BoardsServiceProvider)
|
||||||
protected readonly boardsService: BoardsService;
|
protected readonly boardsServiceClient: BoardsServiceProvider;
|
||||||
|
|
||||||
@inject(BoardsServiceProvider)
|
@inject(NotificationCenter)
|
||||||
protected readonly boardsServiceClient: BoardsServiceProvider;
|
protected readonly notificationCenter: NotificationCenter;
|
||||||
|
|
||||||
@inject(NotificationCenter)
|
protected readonly onFilterTextDidChangeEmitter = new Emitter<string>();
|
||||||
protected readonly notificationCenter: NotificationCenter;
|
protected readonly onBoardConfigChangedEmitter =
|
||||||
|
new Emitter<BoardsConfig.Config>();
|
||||||
|
readonly onBoardConfigChanged = this.onBoardConfigChangedEmitter.event;
|
||||||
|
|
||||||
protected readonly onFilterTextDidChangeEmitter = new Emitter<string>();
|
protected focusNode: HTMLElement | undefined;
|
||||||
protected readonly onBoardConfigChangedEmitter = new Emitter<BoardsConfig.Config>();
|
|
||||||
readonly onBoardConfigChanged = this.onBoardConfigChangedEmitter.event;
|
|
||||||
|
|
||||||
protected focusNode: HTMLElement | undefined;
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.id = 'select-board-dialog';
|
||||||
|
this.toDispose.pushAll([
|
||||||
|
this.onBoardConfigChangedEmitter,
|
||||||
|
this.onFilterTextDidChangeEmitter,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
constructor() {
|
search(query: string): void {
|
||||||
super();
|
this.onFilterTextDidChangeEmitter.fire(query);
|
||||||
this.id = 'select-board-dialog';
|
}
|
||||||
this.toDispose.pushAll([
|
|
||||||
this.onBoardConfigChangedEmitter,
|
protected fireConfigChanged = (config: BoardsConfig.Config) => {
|
||||||
this.onFilterTextDidChangeEmitter
|
this.onBoardConfigChangedEmitter.fire(config);
|
||||||
]);
|
};
|
||||||
|
|
||||||
|
protected setFocusNode = (element: HTMLElement | undefined) => {
|
||||||
|
this.focusNode = element;
|
||||||
|
};
|
||||||
|
|
||||||
|
protected render(): React.ReactNode {
|
||||||
|
return (
|
||||||
|
<div className="selectBoardContainer">
|
||||||
|
<BoardsConfig
|
||||||
|
boardsServiceProvider={this.boardsServiceClient}
|
||||||
|
notificationCenter={this.notificationCenter}
|
||||||
|
onConfigChange={this.fireConfigChanged}
|
||||||
|
onFocusNodeSet={this.setFocusNode}
|
||||||
|
onFilteredTextDidChangeEvent={this.onFilterTextDidChangeEmitter.event}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected onActivateRequest(msg: Message): void {
|
||||||
|
super.onActivateRequest(msg);
|
||||||
|
if (this.focusNode instanceof HTMLInputElement) {
|
||||||
|
this.focusNode.select();
|
||||||
}
|
}
|
||||||
|
(this.focusNode || this.node).focus();
|
||||||
search(query: string): void {
|
}
|
||||||
this.onFilterTextDidChangeEmitter.fire(query);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected fireConfigChanged = (config: BoardsConfig.Config) => {
|
|
||||||
this.onBoardConfigChangedEmitter.fire(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected setFocusNode = (element: HTMLElement | undefined) => {
|
|
||||||
this.focusNode = element;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected render(): React.ReactNode {
|
|
||||||
return <div className='selectBoardContainer'>
|
|
||||||
<BoardsConfig
|
|
||||||
boardsServiceProvider={this.boardsServiceClient}
|
|
||||||
notificationCenter={this.notificationCenter}
|
|
||||||
onConfigChange={this.fireConfigChanged}
|
|
||||||
onFocusNodeSet={this.setFocusNode}
|
|
||||||
onFilteredTextDidChangeEvent={this.onFilterTextDidChangeEmitter.event} />
|
|
||||||
</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected onActivateRequest(msg: Message): void {
|
|
||||||
super.onActivateRequest(msg);
|
|
||||||
if (this.focusNode instanceof HTMLInputElement) {
|
|
||||||
this.focusNode.select();
|
|
||||||
}
|
|
||||||
(this.focusNode || this.node).focus();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,123 +1,134 @@
|
|||||||
import { injectable, inject, postConstruct } from 'inversify';
|
import { injectable, inject, postConstruct } from 'inversify';
|
||||||
import { Message } from '@phosphor/messaging';
|
import { Message } from '@phosphor/messaging';
|
||||||
import { AbstractDialog, DialogProps, Widget, DialogError } from '@theia/core/lib/browser';
|
import {
|
||||||
|
AbstractDialog,
|
||||||
|
DialogProps,
|
||||||
|
Widget,
|
||||||
|
DialogError,
|
||||||
|
} from '@theia/core/lib/browser';
|
||||||
import { BoardsConfig } from './boards-config';
|
import { BoardsConfig } from './boards-config';
|
||||||
import { BoardsService } from '../../common/protocol/boards-service';
|
import { BoardsService } from '../../common/protocol/boards-service';
|
||||||
import { BoardsServiceProvider } from './boards-service-provider';
|
import { BoardsServiceProvider } from './boards-service-provider';
|
||||||
import { BoardsConfigDialogWidget } from './boards-config-dialog-widget';
|
import { BoardsConfigDialogWidget } from './boards-config-dialog-widget';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class BoardsConfigDialogProps extends DialogProps {
|
export class BoardsConfigDialogProps extends DialogProps {}
|
||||||
}
|
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class BoardsConfigDialog extends AbstractDialog<BoardsConfig.Config> {
|
export class BoardsConfigDialog extends AbstractDialog<BoardsConfig.Config> {
|
||||||
|
@inject(BoardsConfigDialogWidget)
|
||||||
|
protected readonly widget: BoardsConfigDialogWidget;
|
||||||
|
|
||||||
@inject(BoardsConfigDialogWidget)
|
@inject(BoardsService)
|
||||||
protected readonly widget: BoardsConfigDialogWidget;
|
protected readonly boardService: BoardsService;
|
||||||
|
|
||||||
@inject(BoardsService)
|
@inject(BoardsServiceProvider)
|
||||||
protected readonly boardService: BoardsService;
|
protected readonly boardsServiceClient: BoardsServiceProvider;
|
||||||
|
|
||||||
@inject(BoardsServiceProvider)
|
protected config: BoardsConfig.Config = {};
|
||||||
protected readonly boardsServiceClient: BoardsServiceProvider;
|
|
||||||
|
|
||||||
protected config: BoardsConfig.Config = {};
|
constructor(
|
||||||
|
@inject(BoardsConfigDialogProps)
|
||||||
|
protected readonly props: BoardsConfigDialogProps
|
||||||
|
) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
constructor(@inject(BoardsConfigDialogProps) protected readonly props: BoardsConfigDialogProps) {
|
this.contentNode.classList.add('select-board-dialog');
|
||||||
super(props);
|
this.contentNode.appendChild(this.createDescription());
|
||||||
|
|
||||||
this.contentNode.classList.add('select-board-dialog');
|
this.appendCloseButton('CANCEL');
|
||||||
this.contentNode.appendChild(this.createDescription());
|
this.appendAcceptButton('OK');
|
||||||
|
}
|
||||||
|
|
||||||
this.appendCloseButton('CANCEL');
|
@postConstruct()
|
||||||
this.appendAcceptButton('OK');
|
protected init(): void {
|
||||||
}
|
this.toDispose.push(
|
||||||
|
this.boardsServiceClient.onBoardsConfigChanged((config) => {
|
||||||
@postConstruct()
|
this.config = config;
|
||||||
protected init(): void {
|
|
||||||
this.toDispose.push(this.boardsServiceClient.onBoardsConfigChanged(config => {
|
|
||||||
this.config = config;
|
|
||||||
this.update();
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pass in an empty string if you want to reset the search term. Using `undefined` has no effect.
|
|
||||||
*/
|
|
||||||
async open(query: string | undefined = undefined): Promise<BoardsConfig.Config | undefined> {
|
|
||||||
if (typeof query === 'string') {
|
|
||||||
this.widget.search(query);
|
|
||||||
}
|
|
||||||
return super.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected createDescription(): HTMLElement {
|
|
||||||
const head = document.createElement('div');
|
|
||||||
head.classList.add('head');
|
|
||||||
|
|
||||||
const title = document.createElement('div');
|
|
||||||
title.textContent = 'Select Other Board & Port';
|
|
||||||
title.classList.add('title');
|
|
||||||
head.appendChild(title);
|
|
||||||
|
|
||||||
const text = document.createElement('div');
|
|
||||||
text.classList.add('text');
|
|
||||||
head.appendChild(text);
|
|
||||||
|
|
||||||
for (const paragraph of [
|
|
||||||
'Select both a Board and a Port if you want to upload a sketch.',
|
|
||||||
'If you only select a Board you will be able just to compile, but not to upload your sketch.'
|
|
||||||
]) {
|
|
||||||
const p = document.createElement('p');
|
|
||||||
p.textContent = paragraph;
|
|
||||||
text.appendChild(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
return head;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected onAfterAttach(msg: Message): void {
|
|
||||||
if (this.widget.isAttached) {
|
|
||||||
Widget.detach(this.widget);
|
|
||||||
}
|
|
||||||
Widget.attach(this.widget, this.contentNode);
|
|
||||||
this.toDisposeOnDetach.push(this.widget.onBoardConfigChanged(config => {
|
|
||||||
this.config = config;
|
|
||||||
this.update();
|
|
||||||
}));
|
|
||||||
super.onAfterAttach(msg);
|
|
||||||
this.update();
|
this.update();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pass in an empty string if you want to reset the search term. Using `undefined` has no effect.
|
||||||
|
*/
|
||||||
|
async open(
|
||||||
|
query: string | undefined = undefined
|
||||||
|
): Promise<BoardsConfig.Config | undefined> {
|
||||||
|
if (typeof query === 'string') {
|
||||||
|
this.widget.search(query);
|
||||||
|
}
|
||||||
|
return super.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected createDescription(): HTMLElement {
|
||||||
|
const head = document.createElement('div');
|
||||||
|
head.classList.add('head');
|
||||||
|
|
||||||
|
const title = document.createElement('div');
|
||||||
|
title.textContent = 'Select Other Board & Port';
|
||||||
|
title.classList.add('title');
|
||||||
|
head.appendChild(title);
|
||||||
|
|
||||||
|
const text = document.createElement('div');
|
||||||
|
text.classList.add('text');
|
||||||
|
head.appendChild(text);
|
||||||
|
|
||||||
|
for (const paragraph of [
|
||||||
|
'Select both a Board and a Port if you want to upload a sketch.',
|
||||||
|
'If you only select a Board you will be able just to compile, but not to upload your sketch.',
|
||||||
|
]) {
|
||||||
|
const p = document.createElement('div');
|
||||||
|
p.textContent = paragraph;
|
||||||
|
text.appendChild(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected onUpdateRequest(msg: Message) {
|
return head;
|
||||||
super.onUpdateRequest(msg);
|
}
|
||||||
this.widget.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected onActivateRequest(msg: Message): void {
|
protected onAfterAttach(msg: Message): void {
|
||||||
super.onActivateRequest(msg);
|
if (this.widget.isAttached) {
|
||||||
this.widget.activate();
|
Widget.detach(this.widget);
|
||||||
}
|
}
|
||||||
|
Widget.attach(this.widget, this.contentNode);
|
||||||
|
this.toDisposeOnDetach.push(
|
||||||
|
this.widget.onBoardConfigChanged((config) => {
|
||||||
|
this.config = config;
|
||||||
|
this.update();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
super.onAfterAttach(msg);
|
||||||
|
this.update();
|
||||||
|
}
|
||||||
|
|
||||||
protected handleEnter(event: KeyboardEvent): boolean | void {
|
protected onUpdateRequest(msg: Message) {
|
||||||
if (event.target instanceof HTMLTextAreaElement) {
|
super.onUpdateRequest(msg);
|
||||||
return false;
|
this.widget.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected onActivateRequest(msg: Message): void {
|
||||||
|
super.onActivateRequest(msg);
|
||||||
|
this.widget.activate();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected handleEnter(event: KeyboardEvent): boolean | void {
|
||||||
|
if (event.target instanceof HTMLTextAreaElement) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected isValid(value: BoardsConfig.Config): DialogError {
|
protected isValid(value: BoardsConfig.Config): DialogError {
|
||||||
if (!value.selectedBoard) {
|
if (!value.selectedBoard) {
|
||||||
if (value.selectedPort) {
|
if (value.selectedPort) {
|
||||||
return 'Please pick a board connected to the port you have selected.';
|
return 'Please pick a board connected to the port you have selected.';
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
get value(): BoardsConfig.Config {
|
|
||||||
return this.config;
|
|
||||||
}
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
get value(): BoardsConfig.Config {
|
||||||
|
return this.config;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,284 +3,397 @@ import { Event } from '@theia/core/lib/common/event';
|
|||||||
import { notEmpty } from '@theia/core/lib/common/objects';
|
import { notEmpty } from '@theia/core/lib/common/objects';
|
||||||
import { MaybePromise } from '@theia/core/lib/common/types';
|
import { MaybePromise } from '@theia/core/lib/common/types';
|
||||||
import { DisposableCollection } from '@theia/core/lib/common/disposable';
|
import { DisposableCollection } from '@theia/core/lib/common/disposable';
|
||||||
import { Board, Port, AttachedBoardsChangeEvent, BoardWithPackage } from '../../common/protocol/boards-service';
|
import {
|
||||||
|
Board,
|
||||||
|
Port,
|
||||||
|
AttachedBoardsChangeEvent,
|
||||||
|
BoardWithPackage,
|
||||||
|
} from '../../common/protocol/boards-service';
|
||||||
import { NotificationCenter } from '../notification-center';
|
import { NotificationCenter } from '../notification-center';
|
||||||
import { BoardsServiceProvider } from './boards-service-provider';
|
import { BoardsServiceProvider } from './boards-service-provider';
|
||||||
|
|
||||||
export namespace BoardsConfig {
|
export namespace BoardsConfig {
|
||||||
|
export interface Config {
|
||||||
|
selectedBoard?: Board;
|
||||||
|
selectedPort?: Port;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Config {
|
export interface Props {
|
||||||
selectedBoard?: Board;
|
readonly boardsServiceProvider: BoardsServiceProvider;
|
||||||
selectedPort?: Port;
|
readonly notificationCenter: NotificationCenter;
|
||||||
}
|
readonly onConfigChange: (config: Config) => void;
|
||||||
|
readonly onFocusNodeSet: (element: HTMLElement | undefined) => void;
|
||||||
export interface Props {
|
readonly onFilteredTextDidChangeEvent: Event<string>;
|
||||||
readonly boardsServiceProvider: BoardsServiceProvider;
|
}
|
||||||
readonly notificationCenter: NotificationCenter;
|
|
||||||
readonly onConfigChange: (config: Config) => void;
|
|
||||||
readonly onFocusNodeSet: (element: HTMLElement | undefined) => void;
|
|
||||||
readonly onFilteredTextDidChangeEvent: Event<string>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface State extends Config {
|
|
||||||
searchResults: Array<BoardWithPackage>;
|
|
||||||
knownPorts: Port[];
|
|
||||||
showAllPorts: boolean;
|
|
||||||
query: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
export interface State extends Config {
|
||||||
|
searchResults: Array<BoardWithPackage>;
|
||||||
|
knownPorts: Port[];
|
||||||
|
showAllPorts: boolean;
|
||||||
|
query: string;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export abstract class Item<T> extends React.Component<{
|
export abstract class Item<T> extends React.Component<{
|
||||||
item: T,
|
item: T;
|
||||||
label: string,
|
label: string;
|
||||||
selected: boolean,
|
selected: boolean;
|
||||||
onClick: (item: T) => void,
|
onClick: (item: T) => void;
|
||||||
missing?: boolean,
|
missing?: boolean;
|
||||||
details?: string
|
details?: string;
|
||||||
}> {
|
}> {
|
||||||
|
render(): React.ReactNode {
|
||||||
render(): React.ReactNode {
|
const { selected, label, missing, details } = this.props;
|
||||||
const { selected, label, missing, details } = this.props;
|
const classNames = ['item'];
|
||||||
const classNames = ['item'];
|
if (selected) {
|
||||||
if (selected) {
|
classNames.push('selected');
|
||||||
classNames.push('selected');
|
|
||||||
}
|
|
||||||
if (missing === true) {
|
|
||||||
classNames.push('missing')
|
|
||||||
}
|
|
||||||
return <div onClick={this.onClick} className={classNames.join(' ')} title={`${label}${!details ? '' : details}`}>
|
|
||||||
<div className='label'>
|
|
||||||
{label}
|
|
||||||
</div>
|
|
||||||
{!details ? '' : <div className='details'>{details}</div>}
|
|
||||||
{!selected ? '' : <div className='selected-icon'><i className='fa fa-check' /></div>}
|
|
||||||
</div>;
|
|
||||||
}
|
}
|
||||||
|
if (missing === true) {
|
||||||
protected onClick = () => {
|
classNames.push('missing');
|
||||||
this.props.onClick(this.props.item);
|
|
||||||
}
|
}
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
onClick={this.onClick}
|
||||||
|
className={classNames.join(' ')}
|
||||||
|
title={`${label}${!details ? '' : details}`}
|
||||||
|
>
|
||||||
|
<div className="label">{label}</div>
|
||||||
|
{!details ? '' : <div className="details">{details}</div>}
|
||||||
|
{!selected ? (
|
||||||
|
''
|
||||||
|
) : (
|
||||||
|
<div className="selected-icon">
|
||||||
|
<i className="fa fa-check" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected onClick = () => {
|
||||||
|
this.props.onClick(this.props.item);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BoardsConfig extends React.Component<BoardsConfig.Props, BoardsConfig.State> {
|
export class BoardsConfig extends React.Component<
|
||||||
|
BoardsConfig.Props,
|
||||||
|
BoardsConfig.State
|
||||||
|
> {
|
||||||
|
protected toDispose = new DisposableCollection();
|
||||||
|
|
||||||
protected toDispose = new DisposableCollection();
|
constructor(props: BoardsConfig.Props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
constructor(props: BoardsConfig.Props) {
|
const { boardsConfig } = props.boardsServiceProvider;
|
||||||
super(props);
|
this.state = {
|
||||||
|
searchResults: [],
|
||||||
|
knownPorts: [],
|
||||||
|
showAllPorts: false,
|
||||||
|
query: '',
|
||||||
|
...boardsConfig,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const { boardsConfig } = props.boardsServiceProvider;
|
componentDidMount() {
|
||||||
this.state = {
|
this.updateBoards();
|
||||||
searchResults: [],
|
this.updatePorts(
|
||||||
knownPorts: [],
|
this.props.boardsServiceProvider.availableBoards
|
||||||
showAllPorts: false,
|
.map(({ port }) => port)
|
||||||
query: '',
|
.filter(notEmpty)
|
||||||
...boardsConfig
|
);
|
||||||
|
this.toDispose.pushAll([
|
||||||
|
this.props.notificationCenter.onAttachedBoardsChanged((event) =>
|
||||||
|
this.updatePorts(
|
||||||
|
event.newState.ports,
|
||||||
|
AttachedBoardsChangeEvent.diff(event).detached.ports
|
||||||
|
)
|
||||||
|
),
|
||||||
|
this.props.boardsServiceProvider.onBoardsConfigChanged(
|
||||||
|
({ selectedBoard, selectedPort }) => {
|
||||||
|
this.setState({ selectedBoard, selectedPort }, () =>
|
||||||
|
this.fireConfigChanged()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
),
|
||||||
|
this.props.notificationCenter.onPlatformInstalled(() =>
|
||||||
|
this.updateBoards(this.state.query)
|
||||||
|
),
|
||||||
|
this.props.notificationCenter.onPlatformUninstalled(() =>
|
||||||
|
this.updateBoards(this.state.query)
|
||||||
|
),
|
||||||
|
this.props.notificationCenter.onIndexUpdated(() =>
|
||||||
|
this.updateBoards(this.state.query)
|
||||||
|
),
|
||||||
|
this.props.notificationCenter.onDaemonStarted(() =>
|
||||||
|
this.updateBoards(this.state.query)
|
||||||
|
),
|
||||||
|
this.props.notificationCenter.onDaemonStopped(() =>
|
||||||
|
this.setState({ searchResults: [] })
|
||||||
|
),
|
||||||
|
this.props.onFilteredTextDidChangeEvent((query) =>
|
||||||
|
this.setState({ query }, () => this.updateBoards(this.state.query))
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount(): void {
|
||||||
|
this.toDispose.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fireConfigChanged() {
|
||||||
|
const { selectedBoard, selectedPort } = this.state;
|
||||||
|
this.props.onConfigChange({ selectedBoard, selectedPort });
|
||||||
|
}
|
||||||
|
|
||||||
|
protected updateBoards = (
|
||||||
|
eventOrQuery: React.ChangeEvent<HTMLInputElement> | string = ''
|
||||||
|
) => {
|
||||||
|
const query =
|
||||||
|
typeof eventOrQuery === 'string'
|
||||||
|
? eventOrQuery
|
||||||
|
: eventOrQuery.target.value.toLowerCase();
|
||||||
|
this.setState({ query });
|
||||||
|
this.queryBoards({ query }).then((searchResults) =>
|
||||||
|
this.setState({ searchResults })
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
protected updatePorts = (ports: Port[] = [], removedPorts: Port[] = []) => {
|
||||||
|
this.queryPorts(Promise.resolve(ports)).then(({ knownPorts }) => {
|
||||||
|
let { selectedPort } = this.state;
|
||||||
|
// If the currently selected port is not available anymore, unset the selected port.
|
||||||
|
if (removedPorts.some((port) => Port.equals(port, selectedPort))) {
|
||||||
|
selectedPort = undefined;
|
||||||
|
}
|
||||||
|
this.setState({ knownPorts, selectedPort }, () =>
|
||||||
|
this.fireConfigChanged()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
protected queryBoards = (
|
||||||
|
options: { query?: string } = {}
|
||||||
|
): Promise<Array<BoardWithPackage>> => {
|
||||||
|
return this.props.boardsServiceProvider.searchBoards(options);
|
||||||
|
};
|
||||||
|
|
||||||
|
protected get availablePorts(): MaybePromise<Port[]> {
|
||||||
|
return this.props.boardsServiceProvider.availableBoards
|
||||||
|
.map(({ port }) => port)
|
||||||
|
.filter(notEmpty);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected queryPorts = async (
|
||||||
|
availablePorts: MaybePromise<Port[]> = this.availablePorts
|
||||||
|
) => {
|
||||||
|
const ports = await availablePorts;
|
||||||
|
return { knownPorts: ports.sort(Port.compare) };
|
||||||
|
};
|
||||||
|
|
||||||
|
protected toggleFilterPorts = () => {
|
||||||
|
this.setState({ showAllPorts: !this.state.showAllPorts });
|
||||||
|
};
|
||||||
|
|
||||||
|
protected selectPort = (selectedPort: Port | undefined) => {
|
||||||
|
this.setState({ selectedPort }, () => this.fireConfigChanged());
|
||||||
|
};
|
||||||
|
|
||||||
|
protected selectBoard = (selectedBoard: BoardWithPackage | undefined) => {
|
||||||
|
this.setState({ selectedBoard }, () => this.fireConfigChanged());
|
||||||
|
};
|
||||||
|
|
||||||
|
protected focusNodeSet = (element: HTMLElement | null) => {
|
||||||
|
this.props.onFocusNodeSet(element || undefined);
|
||||||
|
};
|
||||||
|
|
||||||
|
render(): React.ReactNode {
|
||||||
|
return (
|
||||||
|
<div className="body">
|
||||||
|
{this.renderContainer('boards', this.renderBoards.bind(this))}
|
||||||
|
{this.renderContainer(
|
||||||
|
'ports',
|
||||||
|
this.renderPorts.bind(this),
|
||||||
|
this.renderPortsFooter.bind(this)
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected renderContainer(
|
||||||
|
title: string,
|
||||||
|
contentRenderer: () => React.ReactNode,
|
||||||
|
footerRenderer?: () => React.ReactNode
|
||||||
|
): React.ReactNode {
|
||||||
|
return (
|
||||||
|
<div className="container">
|
||||||
|
<div className="content">
|
||||||
|
<div className="title">{title}</div>
|
||||||
|
{contentRenderer()}
|
||||||
|
<div className="footer">{footerRenderer ? footerRenderer() : ''}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected renderBoards(): React.ReactNode {
|
||||||
|
const { selectedBoard, searchResults, query } = this.state;
|
||||||
|
// Board names are not unique per core https://github.com/arduino/arduino-pro-ide/issues/262#issuecomment-661019560
|
||||||
|
// It is tricky when the core is not yet installed, no FQBNs are available.
|
||||||
|
const distinctBoards = new Map<string, Board.Detailed>();
|
||||||
|
const toKey = ({ name, packageName, fqbn }: Board.Detailed) =>
|
||||||
|
!!fqbn ? `${name}-${packageName}-${fqbn}` : `${name}-${packageName}`;
|
||||||
|
for (const board of Board.decorateBoards(selectedBoard, searchResults)) {
|
||||||
|
const key = toKey(board);
|
||||||
|
if (!distinctBoards.has(key)) {
|
||||||
|
distinctBoards.set(key, board);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
return (
|
||||||
this.updateBoards();
|
<React.Fragment>
|
||||||
this.updatePorts(this.props.boardsServiceProvider.availableBoards.map(({ port }) => port).filter(notEmpty));
|
<div className="search">
|
||||||
this.toDispose.pushAll([
|
<input
|
||||||
this.props.notificationCenter.onAttachedBoardsChanged(event => this.updatePorts(event.newState.ports, AttachedBoardsChangeEvent.diff(event).detached.ports)),
|
type="search"
|
||||||
this.props.boardsServiceProvider.onBoardsConfigChanged(({ selectedBoard, selectedPort }) => {
|
value={query}
|
||||||
this.setState({ selectedBoard, selectedPort }, () => this.fireConfigChanged());
|
className="theia-input"
|
||||||
}),
|
placeholder="SEARCH BOARD"
|
||||||
this.props.notificationCenter.onPlatformInstalled(() => this.updateBoards(this.state.query)),
|
onChange={this.updateBoards}
|
||||||
this.props.notificationCenter.onPlatformUninstalled(() => this.updateBoards(this.state.query)),
|
ref={this.focusNodeSet}
|
||||||
this.props.notificationCenter.onIndexUpdated(() => this.updateBoards(this.state.query)),
|
/>
|
||||||
this.props.notificationCenter.onDaemonStarted(() => this.updateBoards(this.state.query)),
|
<i className="fa fa-search"></i>
|
||||||
this.props.notificationCenter.onDaemonStopped(() => this.setState({ searchResults: [] })),
|
</div>
|
||||||
this.props.onFilteredTextDidChangeEvent(query => this.setState({ query }, () => this.updateBoards(this.state.query)))
|
<div className="boards list">
|
||||||
]);
|
{Array.from(distinctBoards.values()).map((board) => (
|
||||||
}
|
<Item<BoardWithPackage>
|
||||||
|
key={`${board.name}-${board.packageName}`}
|
||||||
|
item={board}
|
||||||
|
label={board.name}
|
||||||
|
details={board.details}
|
||||||
|
selected={board.selected}
|
||||||
|
onClick={this.selectBoard}
|
||||||
|
missing={board.missing}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
componentWillUnmount(): void {
|
protected renderPorts(): React.ReactNode {
|
||||||
this.toDispose.dispose();
|
const filter = this.state.showAllPorts ? () => true : Port.isBoardPort;
|
||||||
}
|
const ports = this.state.knownPorts.filter(filter);
|
||||||
|
return !ports.length ? (
|
||||||
protected fireConfigChanged() {
|
<div className="loading noselect">No ports discovered</div>
|
||||||
const { selectedBoard, selectedPort } = this.state;
|
) : (
|
||||||
this.props.onConfigChange({ selectedBoard, selectedPort });
|
<div className="ports list">
|
||||||
}
|
{ports.map((port) => (
|
||||||
|
<Item<Port>
|
||||||
protected updateBoards = (eventOrQuery: React.ChangeEvent<HTMLInputElement> | string = '') => {
|
key={Port.toString(port)}
|
||||||
const query = typeof eventOrQuery === 'string'
|
item={port}
|
||||||
? eventOrQuery
|
label={Port.toString(port)}
|
||||||
: eventOrQuery.target.value.toLowerCase();
|
selected={Port.equals(this.state.selectedPort, port)}
|
||||||
this.setState({ query });
|
onClick={this.selectPort}
|
||||||
this.queryBoards({ query }).then(searchResults => this.setState({ searchResults }));
|
/>
|
||||||
}
|
))}
|
||||||
|
</div>
|
||||||
protected updatePorts = (ports: Port[] = [], removedPorts: Port[] = []) => {
|
);
|
||||||
this.queryPorts(Promise.resolve(ports)).then(({ knownPorts }) => {
|
}
|
||||||
let { selectedPort } = this.state;
|
|
||||||
// If the currently selected port is not available anymore, unset the selected port.
|
|
||||||
if (removedPorts.some(port => Port.equals(port, selectedPort))) {
|
|
||||||
selectedPort = undefined;
|
|
||||||
}
|
|
||||||
this.setState({ knownPorts, selectedPort }, () => this.fireConfigChanged());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected queryBoards = (options: { query?: string } = {}): Promise<Array<BoardWithPackage>> => {
|
|
||||||
return this.props.boardsServiceProvider.searchBoards(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected get availablePorts(): MaybePromise<Port[]> {
|
|
||||||
return this.props.boardsServiceProvider.availableBoards.map(({ port }) => port).filter(notEmpty);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected queryPorts = async (availablePorts: MaybePromise<Port[]> = this.availablePorts) => {
|
|
||||||
const ports = await availablePorts;
|
|
||||||
return { knownPorts: ports.sort(Port.compare) };
|
|
||||||
}
|
|
||||||
|
|
||||||
protected toggleFilterPorts = () => {
|
|
||||||
this.setState({ showAllPorts: !this.state.showAllPorts });
|
|
||||||
}
|
|
||||||
|
|
||||||
protected selectPort = (selectedPort: Port | undefined) => {
|
|
||||||
this.setState({ selectedPort }, () => this.fireConfigChanged());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected selectBoard = (selectedBoard: BoardWithPackage | undefined) => {
|
|
||||||
this.setState({ selectedBoard }, () => this.fireConfigChanged());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected focusNodeSet = (element: HTMLElement | null) => {
|
|
||||||
this.props.onFocusNodeSet(element || undefined);
|
|
||||||
}
|
|
||||||
|
|
||||||
render(): React.ReactNode {
|
|
||||||
return <div className='body'>
|
|
||||||
{this.renderContainer('boards', this.renderBoards.bind(this))}
|
|
||||||
{this.renderContainer('ports', this.renderPorts.bind(this), this.renderPortsFooter.bind(this))}
|
|
||||||
</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected renderContainer(title: string, contentRenderer: () => React.ReactNode, footerRenderer?: () => React.ReactNode): React.ReactNode {
|
|
||||||
return <div className='container'>
|
|
||||||
<div className='content'>
|
|
||||||
<div className='title'>
|
|
||||||
{title}
|
|
||||||
</div>
|
|
||||||
{contentRenderer()}
|
|
||||||
<div className='footer'>
|
|
||||||
{(footerRenderer ? footerRenderer() : '')}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected renderBoards(): React.ReactNode {
|
|
||||||
const { selectedBoard, searchResults, query } = this.state;
|
|
||||||
// Board names are not unique per core https://github.com/arduino/arduino-pro-ide/issues/262#issuecomment-661019560
|
|
||||||
// It is tricky when the core is not yet installed, no FQBNs are available.
|
|
||||||
const distinctBoards = new Map<string, Board.Detailed>();
|
|
||||||
const toKey = ({ name, packageName, fqbn }: Board.Detailed) => !!fqbn ? `${name}-${packageName}-${fqbn}` : `${name}-${packageName}`;
|
|
||||||
for (const board of Board.decorateBoards(selectedBoard, searchResults)) {
|
|
||||||
const key = toKey(board);
|
|
||||||
if (!distinctBoards.has(key)) {
|
|
||||||
distinctBoards.set(key, board);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return <React.Fragment>
|
|
||||||
<div className='search'>
|
|
||||||
<input
|
|
||||||
type='search'
|
|
||||||
value={query}
|
|
||||||
className='theia-input'
|
|
||||||
placeholder='SEARCH BOARD'
|
|
||||||
onChange={this.updateBoards}
|
|
||||||
ref={this.focusNodeSet}
|
|
||||||
/>
|
|
||||||
<i className='fa fa-search'></i>
|
|
||||||
</div>
|
|
||||||
<div className='boards list'>
|
|
||||||
{Array.from(distinctBoards.values()).map(board => <Item<BoardWithPackage>
|
|
||||||
key={`${board.name}-${board.packageName}`}
|
|
||||||
item={board}
|
|
||||||
label={board.name}
|
|
||||||
details={board.details}
|
|
||||||
selected={board.selected}
|
|
||||||
onClick={this.selectBoard}
|
|
||||||
missing={board.missing}
|
|
||||||
/>)}
|
|
||||||
</div>
|
|
||||||
</React.Fragment>;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected renderPorts(): React.ReactNode {
|
|
||||||
const filter = this.state.showAllPorts ? () => true : Port.isBoardPort;
|
|
||||||
const ports = this.state.knownPorts.filter(filter);
|
|
||||||
return !ports.length ?
|
|
||||||
(
|
|
||||||
<div className='loading noselect'>
|
|
||||||
No ports discovered
|
|
||||||
</div>
|
|
||||||
) :
|
|
||||||
(
|
|
||||||
<div className='ports list'>
|
|
||||||
{ports.map(port => <Item<Port>
|
|
||||||
key={Port.toString(port)}
|
|
||||||
item={port}
|
|
||||||
label={Port.toString(port)}
|
|
||||||
selected={Port.equals(this.state.selectedPort, port)}
|
|
||||||
onClick={this.selectPort}
|
|
||||||
/>)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected renderPortsFooter(): React.ReactNode {
|
|
||||||
return <div className='noselect'>
|
|
||||||
<label
|
|
||||||
title='Shows all available ports when enabled'>
|
|
||||||
<input
|
|
||||||
type='checkbox'
|
|
||||||
defaultChecked={this.state.showAllPorts}
|
|
||||||
onChange={this.toggleFilterPorts}
|
|
||||||
/>
|
|
||||||
<span>Show all ports</span>
|
|
||||||
</label>
|
|
||||||
</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
protected renderPortsFooter(): React.ReactNode {
|
||||||
|
return (
|
||||||
|
<div className="noselect">
|
||||||
|
<label title="Shows all available ports when enabled">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
defaultChecked={this.state.showAllPorts}
|
||||||
|
onChange={this.toggleFilterPorts}
|
||||||
|
/>
|
||||||
|
<span>Show all ports</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace BoardsConfig {
|
export namespace BoardsConfig {
|
||||||
|
export namespace Config {
|
||||||
export namespace Config {
|
export function sameAs(config: Config, other: Config | Board): boolean {
|
||||||
|
const { selectedBoard, selectedPort } = config;
|
||||||
export function sameAs(config: Config, other: Config | Board): boolean {
|
if (Board.is(other)) {
|
||||||
const { selectedBoard, selectedPort } = config;
|
return (
|
||||||
if (Board.is(other)) {
|
!!selectedBoard &&
|
||||||
return !!selectedBoard
|
Board.equals(other, selectedBoard) &&
|
||||||
&& Board.equals(other, selectedBoard)
|
Port.sameAs(selectedPort, other.port)
|
||||||
&& Port.sameAs(selectedPort, other.port);
|
);
|
||||||
}
|
}
|
||||||
return sameAs(config, other);
|
return sameAs(config, other);
|
||||||
}
|
|
||||||
|
|
||||||
export function equals(left: Config, right: Config): boolean {
|
|
||||||
return left.selectedBoard === right.selectedBoard
|
|
||||||
&& left.selectedPort === right.selectedPort;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function toString(config: Config, options: { default: string } = { default: '' }): string {
|
|
||||||
const { selectedBoard, selectedPort: port } = config;
|
|
||||||
if (!selectedBoard) {
|
|
||||||
return options.default;
|
|
||||||
}
|
|
||||||
const { name } = selectedBoard;
|
|
||||||
return `${name}${port ? ' at ' + Port.toString(port) : ''}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function equals(left: Config, right: Config): boolean {
|
||||||
|
return (
|
||||||
|
left.selectedBoard === right.selectedBoard &&
|
||||||
|
left.selectedPort === right.selectedPort
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function toString(
|
||||||
|
config: Config,
|
||||||
|
options: { default: string } = { default: '' }
|
||||||
|
): string {
|
||||||
|
const { selectedBoard, selectedPort: port } = config;
|
||||||
|
if (!selectedBoard) {
|
||||||
|
return options.default;
|
||||||
|
}
|
||||||
|
const { name } = selectedBoard;
|
||||||
|
return `${name}${port ? ' at ' + Port.toString(port) : ''}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setConfig(
|
||||||
|
config: Config | undefined,
|
||||||
|
urlToAttachTo: URL
|
||||||
|
): URL {
|
||||||
|
const copy = new URL(urlToAttachTo.toString());
|
||||||
|
if (!config) {
|
||||||
|
copy.searchParams.delete('boards-config');
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectedBoard = config.selectedBoard
|
||||||
|
? {
|
||||||
|
name: config.selectedBoard.name,
|
||||||
|
fqbn: config.selectedBoard.fqbn,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
const selectedPort = config.selectedPort
|
||||||
|
? {
|
||||||
|
protocol: config.selectedPort.protocol,
|
||||||
|
address: config.selectedPort.address,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
const jsonConfig = JSON.stringify({ selectedBoard, selectedPort });
|
||||||
|
copy.searchParams.set('boards-config', encodeURIComponent(jsonConfig));
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getConfig(url: URL): Config | undefined {
|
||||||
|
const encoded = url.searchParams.get('boards-config');
|
||||||
|
if (!encoded) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const raw = decodeURIComponent(encoded);
|
||||||
|
const candidate = JSON.parse(raw);
|
||||||
|
if (typeof candidate === 'object') {
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
|
console.warn(
|
||||||
|
`Expected candidate to be an object. It was ${typeof candidate}. URL was: ${url}`
|
||||||
|
);
|
||||||
|
return undefined;
|
||||||
|
} catch (e) {
|
||||||
|
console.log(`Could not get board config from URL: ${url}.`, e);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ import * as PQueue from 'p-queue';
|
|||||||
import { inject, injectable } from 'inversify';
|
import { inject, injectable } from 'inversify';
|
||||||
import { CommandRegistry } from '@theia/core/lib/common/command';
|
import { CommandRegistry } from '@theia/core/lib/common/command';
|
||||||
import { MenuModelRegistry } from '@theia/core/lib/common/menu';
|
import { MenuModelRegistry } from '@theia/core/lib/common/menu';
|
||||||
import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
|
import {
|
||||||
|
Disposable,
|
||||||
|
DisposableCollection,
|
||||||
|
} from '@theia/core/lib/common/disposable';
|
||||||
import { BoardsServiceProvider } from './boards-service-provider';
|
import { BoardsServiceProvider } from './boards-service-provider';
|
||||||
import { Board, ConfigOption, Programmer } from '../../common/protocol';
|
import { Board, ConfigOption, Programmer } from '../../common/protocol';
|
||||||
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
|
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
|
||||||
@@ -12,90 +15,145 @@ import { ArduinoMenus, unregisterSubmenu } from '../menu/arduino-menus';
|
|||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
|
export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
|
||||||
|
@inject(CommandRegistry)
|
||||||
|
protected readonly commandRegistry: CommandRegistry;
|
||||||
|
|
||||||
@inject(CommandRegistry)
|
@inject(MenuModelRegistry)
|
||||||
protected readonly commandRegistry: CommandRegistry;
|
protected readonly menuRegistry: MenuModelRegistry;
|
||||||
|
|
||||||
@inject(MenuModelRegistry)
|
@inject(MainMenuManager)
|
||||||
protected readonly menuRegistry: MenuModelRegistry;
|
protected readonly mainMenuManager: MainMenuManager;
|
||||||
|
|
||||||
@inject(MainMenuManager)
|
@inject(BoardsDataStore)
|
||||||
protected readonly mainMenuManager: MainMenuManager;
|
protected readonly boardsDataStore: BoardsDataStore;
|
||||||
|
|
||||||
@inject(BoardsDataStore)
|
@inject(BoardsServiceProvider)
|
||||||
protected readonly boardsDataStore: BoardsDataStore;
|
protected readonly boardsServiceClient: BoardsServiceProvider;
|
||||||
|
|
||||||
@inject(BoardsServiceProvider)
|
protected readonly queue = new PQueue({ autoStart: true, concurrency: 1 });
|
||||||
protected readonly boardsServiceClient: BoardsServiceProvider;
|
protected readonly toDisposeOnBoardChange = new DisposableCollection();
|
||||||
|
|
||||||
protected readonly queue = new PQueue({ autoStart: true, concurrency: 1 });
|
async onStart(): Promise<void> {
|
||||||
protected readonly toDisposeOnBoardChange = new DisposableCollection();
|
this.updateMenuActions(this.boardsServiceClient.boardsConfig.selectedBoard);
|
||||||
|
this.boardsDataStore.onChanged(() =>
|
||||||
|
this.updateMenuActions(
|
||||||
|
this.boardsServiceClient.boardsConfig.selectedBoard
|
||||||
|
)
|
||||||
|
);
|
||||||
|
this.boardsServiceClient.onBoardsConfigChanged(({ selectedBoard }) =>
|
||||||
|
this.updateMenuActions(selectedBoard)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async onStart(): Promise<void> {
|
protected async updateMenuActions(
|
||||||
this.updateMenuActions(this.boardsServiceClient.boardsConfig.selectedBoard);
|
selectedBoard: Board | undefined
|
||||||
this.boardsDataStore.onChanged(() => this.updateMenuActions(this.boardsServiceClient.boardsConfig.selectedBoard));
|
): Promise<void> {
|
||||||
this.boardsServiceClient.onBoardsConfigChanged(({ selectedBoard }) => this.updateMenuActions(selectedBoard));
|
return this.queue.add(async () => {
|
||||||
}
|
this.toDisposeOnBoardChange.dispose();
|
||||||
|
this.mainMenuManager.update();
|
||||||
protected async updateMenuActions(selectedBoard: Board | undefined): Promise<void> {
|
if (selectedBoard) {
|
||||||
return this.queue.add(async () => {
|
const { fqbn } = selectedBoard;
|
||||||
this.toDisposeOnBoardChange.dispose();
|
if (fqbn) {
|
||||||
this.mainMenuManager.update();
|
const { configOptions, programmers, selectedProgrammer } =
|
||||||
if (selectedBoard) {
|
await this.boardsDataStore.getData(fqbn);
|
||||||
const { fqbn } = selectedBoard;
|
if (configOptions.length) {
|
||||||
if (fqbn) {
|
const boardsConfigMenuPath = [
|
||||||
const { configOptions, programmers, selectedProgrammer } = await this.boardsDataStore.getData(fqbn);
|
...ArduinoMenus.TOOLS__BOARD_SETTINGS_GROUP,
|
||||||
if (configOptions.length) {
|
'z01_boardsConfig',
|
||||||
const boardsConfigMenuPath = [...ArduinoMenus.TOOLS__BOARD_SETTINGS_GROUP, 'z01_boardsConfig']; // `z_` is for ordering.
|
]; // `z_` is for ordering.
|
||||||
for (const { label, option, values } of configOptions.sort(ConfigOption.LABEL_COMPARATOR)) {
|
for (const { label, option, values } of configOptions.sort(
|
||||||
const menuPath = [...boardsConfigMenuPath, `${option}`];
|
ConfigOption.LABEL_COMPARATOR
|
||||||
const commands = new Map<string, Disposable & { label: string }>()
|
)) {
|
||||||
for (const value of values) {
|
const menuPath = [...boardsConfigMenuPath, `${option}`];
|
||||||
const id = `${fqbn}-${option}--${value.value}`;
|
const commands = new Map<
|
||||||
const command = { id };
|
string,
|
||||||
const selectedValue = value.value;
|
Disposable & { label: string }
|
||||||
const handler = {
|
>();
|
||||||
execute: () => this.boardsDataStore.selectConfigOption({ fqbn, option, selectedValue }),
|
for (const value of values) {
|
||||||
isToggled: () => value.selected
|
const id = `${fqbn}-${option}--${value.value}`;
|
||||||
};
|
const command = { id };
|
||||||
commands.set(id, Object.assign(this.commandRegistry.registerCommand(command, handler), { label: value.label }));
|
const selectedValue = value.value;
|
||||||
}
|
const handler = {
|
||||||
this.menuRegistry.registerSubmenu(menuPath, label);
|
execute: () =>
|
||||||
this.toDisposeOnBoardChange.pushAll([
|
this.boardsDataStore.selectConfigOption({
|
||||||
...commands.values(),
|
fqbn,
|
||||||
Disposable.create(() => unregisterSubmenu(menuPath, this.menuRegistry)),
|
option,
|
||||||
...Array.from(commands.keys()).map((commandId, i) => {
|
selectedValue,
|
||||||
const { label } = commands.get(commandId)!;
|
}),
|
||||||
this.menuRegistry.registerMenuAction(menuPath, { commandId, order: `${i}`, label });
|
isToggled: () => value.selected,
|
||||||
return Disposable.create(() => this.menuRegistry.unregisterMenuAction(commandId));
|
};
|
||||||
})
|
commands.set(
|
||||||
]);
|
id,
|
||||||
}
|
Object.assign(
|
||||||
}
|
this.commandRegistry.registerCommand(command, handler),
|
||||||
if (programmers.length) {
|
{ label: value.label }
|
||||||
const programmersMenuPath = [...ArduinoMenus.TOOLS__BOARD_SETTINGS_GROUP, 'z02_programmers'];
|
)
|
||||||
const label = selectedProgrammer ? `Programmer: "${selectedProgrammer.name}"` : 'Programmer'
|
);
|
||||||
this.menuRegistry.registerSubmenu(programmersMenuPath, label);
|
}
|
||||||
this.toDisposeOnBoardChange.push(Disposable.create(() => unregisterSubmenu(programmersMenuPath, this.menuRegistry)));
|
this.menuRegistry.registerSubmenu(menuPath, label);
|
||||||
for (const programmer of programmers) {
|
this.toDisposeOnBoardChange.pushAll([
|
||||||
const { id, name } = programmer;
|
...commands.values(),
|
||||||
const command = { id: `${fqbn}-programmer--${id}` };
|
Disposable.create(() =>
|
||||||
const handler = {
|
unregisterSubmenu(menuPath, this.menuRegistry)
|
||||||
execute: () => this.boardsDataStore.selectProgrammer({ fqbn, selectedProgrammer: programmer }),
|
),
|
||||||
isToggled: () => Programmer.equals(programmer, selectedProgrammer)
|
...Array.from(commands.keys()).map((commandId, i) => {
|
||||||
};
|
const { label } = commands.get(commandId)!;
|
||||||
this.menuRegistry.registerMenuAction(programmersMenuPath, { commandId: command.id, label: name });
|
this.menuRegistry.registerMenuAction(menuPath, {
|
||||||
this.commandRegistry.registerCommand(command, handler);
|
commandId,
|
||||||
this.toDisposeOnBoardChange.pushAll([
|
order: `${i}`,
|
||||||
Disposable.create(() => this.commandRegistry.unregisterCommand(command)),
|
label,
|
||||||
Disposable.create(() => this.menuRegistry.unregisterMenuAction(command.id))
|
});
|
||||||
]);
|
return Disposable.create(() =>
|
||||||
}
|
this.menuRegistry.unregisterMenuAction(commandId)
|
||||||
}
|
);
|
||||||
this.mainMenuManager.update();
|
}),
|
||||||
}
|
]);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
if (programmers.length) {
|
||||||
|
const programmersMenuPath = [
|
||||||
|
...ArduinoMenus.TOOLS__BOARD_SETTINGS_GROUP,
|
||||||
|
'z02_programmers',
|
||||||
|
];
|
||||||
|
const label = selectedProgrammer
|
||||||
|
? `Programmer: "${selectedProgrammer.name}"`
|
||||||
|
: 'Programmer';
|
||||||
|
this.menuRegistry.registerSubmenu(programmersMenuPath, label);
|
||||||
|
this.toDisposeOnBoardChange.push(
|
||||||
|
Disposable.create(() =>
|
||||||
|
unregisterSubmenu(programmersMenuPath, this.menuRegistry)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
for (const programmer of programmers) {
|
||||||
|
const { id, name } = programmer;
|
||||||
|
const command = { id: `${fqbn}-programmer--${id}` };
|
||||||
|
const handler = {
|
||||||
|
execute: () =>
|
||||||
|
this.boardsDataStore.selectProgrammer({
|
||||||
|
fqbn,
|
||||||
|
selectedProgrammer: programmer,
|
||||||
|
}),
|
||||||
|
isToggled: () =>
|
||||||
|
Programmer.equals(programmer, selectedProgrammer),
|
||||||
|
};
|
||||||
|
this.menuRegistry.registerMenuAction(programmersMenuPath, {
|
||||||
|
commandId: command.id,
|
||||||
|
label: name,
|
||||||
|
});
|
||||||
|
this.commandRegistry.registerCommand(command, handler);
|
||||||
|
this.toDisposeOnBoardChange.pushAll([
|
||||||
|
Disposable.create(() =>
|
||||||
|
this.commandRegistry.unregisterCommand(command)
|
||||||
|
),
|
||||||
|
Disposable.create(() =>
|
||||||
|
this.menuRegistry.unregisterMenuAction(command.id)
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.mainMenuManager.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,209 +3,270 @@ import { ILogger } from '@theia/core/lib/common/logger';
|
|||||||
import { deepClone } from '@theia/core/lib/common/objects';
|
import { deepClone } from '@theia/core/lib/common/objects';
|
||||||
import { MaybePromise } from '@theia/core/lib/common/types';
|
import { MaybePromise } from '@theia/core/lib/common/types';
|
||||||
import { Event, Emitter } from '@theia/core/lib/common/event';
|
import { Event, Emitter } from '@theia/core/lib/common/event';
|
||||||
import { FrontendApplicationContribution, LocalStorageService } from '@theia/core/lib/browser';
|
import {
|
||||||
|
FrontendApplicationContribution,
|
||||||
|
LocalStorageService,
|
||||||
|
} from '@theia/core/lib/browser';
|
||||||
import { notEmpty } from '../../common/utils';
|
import { notEmpty } from '../../common/utils';
|
||||||
import { BoardsService, ConfigOption, Installable, BoardDetails, Programmer } from '../../common/protocol';
|
import {
|
||||||
|
BoardsService,
|
||||||
|
ConfigOption,
|
||||||
|
Installable,
|
||||||
|
BoardDetails,
|
||||||
|
Programmer,
|
||||||
|
} from '../../common/protocol';
|
||||||
import { NotificationCenter } from '../notification-center';
|
import { NotificationCenter } from '../notification-center';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class BoardsDataStore implements FrontendApplicationContribution {
|
export class BoardsDataStore implements FrontendApplicationContribution {
|
||||||
|
@inject(ILogger)
|
||||||
|
@named('store')
|
||||||
|
protected readonly logger: ILogger;
|
||||||
|
|
||||||
@inject(ILogger)
|
@inject(BoardsService)
|
||||||
@named('store')
|
protected readonly boardsService: BoardsService;
|
||||||
protected readonly logger: ILogger;
|
|
||||||
|
|
||||||
@inject(BoardsService)
|
@inject(NotificationCenter)
|
||||||
protected readonly boardsService: BoardsService;
|
protected readonly notificationCenter: NotificationCenter;
|
||||||
|
|
||||||
@inject(NotificationCenter)
|
@inject(LocalStorageService)
|
||||||
protected readonly notificationCenter: NotificationCenter;
|
protected readonly storageService: LocalStorageService;
|
||||||
|
|
||||||
@inject(LocalStorageService)
|
protected readonly onChangedEmitter = new Emitter<void>();
|
||||||
protected readonly storageService: LocalStorageService;
|
|
||||||
|
|
||||||
protected readonly onChangedEmitter = new Emitter<void>();
|
onStart(): void {
|
||||||
|
this.notificationCenter.onPlatformInstalled(async ({ item }) => {
|
||||||
onStart(): void {
|
const { installedVersion: version } = item;
|
||||||
this.notificationCenter.onPlatformInstalled(async ({ item }) => {
|
if (!version) {
|
||||||
const { installedVersion: version } = item;
|
return;
|
||||||
if (!version) {
|
}
|
||||||
return;
|
let shouldFireChanged = false;
|
||||||
}
|
for (const fqbn of item.boards
|
||||||
let shouldFireChanged = false;
|
.map(({ fqbn }) => fqbn)
|
||||||
for (const fqbn of item.boards.map(({ fqbn }) => fqbn).filter(notEmpty).filter(fqbn => !!fqbn)) {
|
.filter(notEmpty)
|
||||||
const key = this.getStorageKey(fqbn, version);
|
.filter((fqbn) => !!fqbn)) {
|
||||||
let data = await this.storageService.getData<ConfigOption[] | undefined>(key);
|
|
||||||
if (!data || !data.length) {
|
|
||||||
const details = await this.getBoardDetailsSafe(fqbn);
|
|
||||||
if (details) {
|
|
||||||
data = details.configOptions;
|
|
||||||
if (data.length) {
|
|
||||||
await this.storageService.setData(key, data);
|
|
||||||
shouldFireChanged = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (shouldFireChanged) {
|
|
||||||
this.fireChanged();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
get onChanged(): Event<void> {
|
|
||||||
return this.onChangedEmitter.event;
|
|
||||||
}
|
|
||||||
|
|
||||||
async appendConfigToFqbn(
|
|
||||||
fqbn: string | undefined,
|
|
||||||
boardsPackageVersion: MaybePromise<Installable.Version | undefined> = this.getBoardsPackageVersion(fqbn)): Promise<string | undefined> {
|
|
||||||
|
|
||||||
if (!fqbn) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { configOptions } = await this.getData(fqbn, boardsPackageVersion);
|
|
||||||
return ConfigOption.decorate(fqbn, configOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
async getData(
|
|
||||||
fqbn: string | undefined,
|
|
||||||
boardsPackageVersion: MaybePromise<Installable.Version | undefined> = this.getBoardsPackageVersion(fqbn)): Promise<BoardsDataStore.Data> {
|
|
||||||
|
|
||||||
if (!fqbn) {
|
|
||||||
return BoardsDataStore.Data.EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
const version = await boardsPackageVersion;
|
|
||||||
if (!version) {
|
|
||||||
return BoardsDataStore.Data.EMPTY;
|
|
||||||
}
|
|
||||||
const key = this.getStorageKey(fqbn, version);
|
const key = this.getStorageKey(fqbn, version);
|
||||||
let data = await this.storageService.getData<BoardsDataStore.Data | undefined>(key, undefined);
|
let data = await this.storageService.getData<
|
||||||
if (BoardsDataStore.Data.is(data)) {
|
ConfigOption[] | undefined
|
||||||
return data;
|
>(key);
|
||||||
}
|
if (!data || !data.length) {
|
||||||
|
const details = await this.getBoardDetailsSafe(fqbn);
|
||||||
const boardDetails = await this.getBoardDetailsSafe(fqbn);
|
if (details) {
|
||||||
if (!boardDetails) {
|
data = details.configOptions;
|
||||||
return BoardsDataStore.Data.EMPTY;
|
if (data.length) {
|
||||||
}
|
await this.storageService.setData(key, data);
|
||||||
|
shouldFireChanged = true;
|
||||||
data = { configOptions: boardDetails.configOptions, programmers: boardDetails.programmers };
|
|
||||||
await this.storageService.setData(key, data);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async selectProgrammer(
|
|
||||||
{ fqbn, selectedProgrammer }: { fqbn: string, selectedProgrammer: Programmer },
|
|
||||||
boardsPackageVersion: MaybePromise<Installable.Version | undefined> = this.getBoardsPackageVersion(fqbn)): Promise<boolean> {
|
|
||||||
|
|
||||||
const data = deepClone(await this.getData(fqbn, boardsPackageVersion));
|
|
||||||
const { programmers } = data;
|
|
||||||
if (!programmers.find(p => Programmer.equals(selectedProgrammer, p))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const version = await boardsPackageVersion;
|
|
||||||
if (!version) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.setData({ fqbn, data: { ...data, selectedProgrammer }, version });
|
|
||||||
this.fireChanged();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
async selectConfigOption(
|
|
||||||
{ fqbn, option, selectedValue }: { fqbn: string, option: string, selectedValue: string },
|
|
||||||
boardsPackageVersion: MaybePromise<Installable.Version | undefined> = this.getBoardsPackageVersion(fqbn)): Promise<boolean> {
|
|
||||||
|
|
||||||
const data = deepClone(await this.getData(fqbn, boardsPackageVersion));
|
|
||||||
const { configOptions } = data;
|
|
||||||
const configOption = configOptions.find(c => c.option === option);
|
|
||||||
if (!configOption) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
let updated = false;
|
|
||||||
for (const value of configOption.values) {
|
|
||||||
if (value.value === selectedValue) {
|
|
||||||
(value as any).selected = true;
|
|
||||||
updated = true;
|
|
||||||
} else {
|
|
||||||
(value as any).selected = false;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!updated) {
|
}
|
||||||
return false;
|
if (shouldFireChanged) {
|
||||||
}
|
|
||||||
const version = await boardsPackageVersion;
|
|
||||||
if (!version) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.setData({ fqbn, data, version });
|
|
||||||
this.fireChanged();
|
this.fireChanged();
|
||||||
return true;
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get onChanged(): Event<void> {
|
||||||
|
return this.onChangedEmitter.event;
|
||||||
|
}
|
||||||
|
|
||||||
|
async appendConfigToFqbn(
|
||||||
|
fqbn: string | undefined,
|
||||||
|
boardsPackageVersion: MaybePromise<
|
||||||
|
Installable.Version | undefined
|
||||||
|
> = this.getBoardsPackageVersion(fqbn)
|
||||||
|
): Promise<string | undefined> {
|
||||||
|
if (!fqbn) {
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async setData(
|
const { configOptions } = await this.getData(fqbn, boardsPackageVersion);
|
||||||
{ fqbn, data, version }: { fqbn: string, data: BoardsDataStore.Data, version: Installable.Version }): Promise<void> {
|
return ConfigOption.decorate(fqbn, configOptions);
|
||||||
|
}
|
||||||
|
|
||||||
const key = this.getStorageKey(fqbn, version);
|
async getData(
|
||||||
return this.storageService.setData(key, data);
|
fqbn: string | undefined,
|
||||||
|
boardsPackageVersion: MaybePromise<
|
||||||
|
Installable.Version | undefined
|
||||||
|
> = this.getBoardsPackageVersion(fqbn)
|
||||||
|
): Promise<BoardsDataStore.Data> {
|
||||||
|
if (!fqbn) {
|
||||||
|
return BoardsDataStore.Data.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getStorageKey(fqbn: string, version: Installable.Version): string {
|
const version = await boardsPackageVersion;
|
||||||
return `.arduinoIDE-configOptions-${version}-${fqbn}`;
|
if (!version) {
|
||||||
|
return BoardsDataStore.Data.EMPTY;
|
||||||
|
}
|
||||||
|
const key = this.getStorageKey(fqbn, version);
|
||||||
|
let data = await this.storageService.getData<
|
||||||
|
BoardsDataStore.Data | undefined
|
||||||
|
>(key, undefined);
|
||||||
|
if (BoardsDataStore.Data.is(data)) {
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async getBoardDetailsSafe(fqbn: string): Promise<BoardDetails | undefined> {
|
const boardDetails = await this.getBoardDetailsSafe(fqbn);
|
||||||
try {
|
if (!boardDetails) {
|
||||||
const details = this.boardsService.getBoardDetails({ fqbn });
|
return BoardsDataStore.Data.EMPTY;
|
||||||
return details;
|
|
||||||
} catch (err) {
|
|
||||||
if (err instanceof Error && err.message.includes('loading board data') && err.message.includes('is not installed')) {
|
|
||||||
this.logger.warn(`The boards package is not installed for board with FQBN: ${fqbn}`);
|
|
||||||
} else {
|
|
||||||
this.logger.error(`An unexpected error occurred while retrieving the board details for ${fqbn}.`, err);
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fireChanged(): void {
|
data = {
|
||||||
this.onChangedEmitter.fire();
|
configOptions: boardDetails.configOptions,
|
||||||
|
programmers: boardDetails.programmers,
|
||||||
|
};
|
||||||
|
await this.storageService.setData(key, data);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async selectProgrammer(
|
||||||
|
{
|
||||||
|
fqbn,
|
||||||
|
selectedProgrammer,
|
||||||
|
}: { fqbn: string; selectedProgrammer: Programmer },
|
||||||
|
boardsPackageVersion: MaybePromise<
|
||||||
|
Installable.Version | undefined
|
||||||
|
> = this.getBoardsPackageVersion(fqbn)
|
||||||
|
): Promise<boolean> {
|
||||||
|
const data = deepClone(await this.getData(fqbn, boardsPackageVersion));
|
||||||
|
const { programmers } = data;
|
||||||
|
if (!programmers.find((p) => Programmer.equals(selectedProgrammer, p))) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async getBoardsPackageVersion(fqbn: string | undefined): Promise<Installable.Version | undefined> {
|
const version = await boardsPackageVersion;
|
||||||
if (!fqbn) {
|
if (!version) {
|
||||||
return undefined;
|
return false;
|
||||||
}
|
|
||||||
const boardsPackage = await this.boardsService.getContainerBoardPackage({ fqbn });
|
|
||||||
if (!boardsPackage) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
return boardsPackage.installedVersion;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await this.setData({
|
||||||
|
fqbn,
|
||||||
|
data: { ...data, selectedProgrammer },
|
||||||
|
version,
|
||||||
|
});
|
||||||
|
this.fireChanged();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
async selectConfigOption(
|
||||||
|
{
|
||||||
|
fqbn,
|
||||||
|
option,
|
||||||
|
selectedValue,
|
||||||
|
}: { fqbn: string; option: string; selectedValue: string },
|
||||||
|
boardsPackageVersion: MaybePromise<
|
||||||
|
Installable.Version | undefined
|
||||||
|
> = this.getBoardsPackageVersion(fqbn)
|
||||||
|
): Promise<boolean> {
|
||||||
|
const data = deepClone(await this.getData(fqbn, boardsPackageVersion));
|
||||||
|
const { configOptions } = data;
|
||||||
|
const configOption = configOptions.find((c) => c.option === option);
|
||||||
|
if (!configOption) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
let updated = false;
|
||||||
|
for (const value of configOption.values) {
|
||||||
|
if (value.value === selectedValue) {
|
||||||
|
(value as any).selected = true;
|
||||||
|
updated = true;
|
||||||
|
} else {
|
||||||
|
(value as any).selected = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!updated) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const version = await boardsPackageVersion;
|
||||||
|
if (!version) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.setData({ fqbn, data, version });
|
||||||
|
this.fireChanged();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async setData({
|
||||||
|
fqbn,
|
||||||
|
data,
|
||||||
|
version,
|
||||||
|
}: {
|
||||||
|
fqbn: string;
|
||||||
|
data: BoardsDataStore.Data;
|
||||||
|
version: Installable.Version;
|
||||||
|
}): Promise<void> {
|
||||||
|
const key = this.getStorageKey(fqbn, version);
|
||||||
|
return this.storageService.setData(key, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getStorageKey(fqbn: string, version: Installable.Version): string {
|
||||||
|
return `.arduinoIDE-configOptions-${version}-${fqbn}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async getBoardDetailsSafe(
|
||||||
|
fqbn: string
|
||||||
|
): Promise<BoardDetails | undefined> {
|
||||||
|
try {
|
||||||
|
const details = this.boardsService.getBoardDetails({ fqbn });
|
||||||
|
return details;
|
||||||
|
} catch (err) {
|
||||||
|
if (
|
||||||
|
err instanceof Error &&
|
||||||
|
err.message.includes('loading board data') &&
|
||||||
|
err.message.includes('is not installed')
|
||||||
|
) {
|
||||||
|
this.logger.warn(
|
||||||
|
`The boards package is not installed for board with FQBN: ${fqbn}`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
this.logger.error(
|
||||||
|
`An unexpected error occurred while retrieving the board details for ${fqbn}.`,
|
||||||
|
err
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fireChanged(): void {
|
||||||
|
this.onChangedEmitter.fire();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async getBoardsPackageVersion(
|
||||||
|
fqbn: string | undefined
|
||||||
|
): Promise<Installable.Version | undefined> {
|
||||||
|
if (!fqbn) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const boardsPackage = await this.boardsService.getContainerBoardPackage({
|
||||||
|
fqbn,
|
||||||
|
});
|
||||||
|
if (!boardsPackage) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return boardsPackage.installedVersion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace BoardsDataStore {
|
export namespace BoardsDataStore {
|
||||||
export interface Data {
|
export interface Data {
|
||||||
readonly configOptions: ConfigOption[];
|
readonly configOptions: ConfigOption[];
|
||||||
readonly programmers: Programmer[];
|
readonly programmers: Programmer[];
|
||||||
readonly selectedProgrammer?: Programmer;
|
readonly selectedProgrammer?: Programmer;
|
||||||
}
|
}
|
||||||
export namespace Data {
|
export namespace Data {
|
||||||
export const EMPTY: Data = {
|
export const EMPTY: Data = {
|
||||||
configOptions: [],
|
configOptions: [],
|
||||||
programmers: []
|
programmers: [],
|
||||||
};
|
};
|
||||||
export function is(arg: any): arg is Data {
|
export function is(arg: any): arg is Data {
|
||||||
return !!arg
|
return (
|
||||||
&& 'configOptions' in arg && Array.isArray(arg['configOptions'])
|
!!arg &&
|
||||||
&& 'programmers' in arg && Array.isArray(arg['programmers'])
|
'configOptions' in arg &&
|
||||||
}
|
Array.isArray(arg['configOptions']) &&
|
||||||
|
'programmers' in arg &&
|
||||||
|
Array.isArray(arg['programmers'])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,36 +1,73 @@
|
|||||||
import { inject, injectable, postConstruct } from 'inversify';
|
import { inject, injectable, postConstruct } from 'inversify';
|
||||||
import { BoardsPackage, BoardsService } from '../../common/protocol/boards-service';
|
import {
|
||||||
|
BoardsPackage,
|
||||||
|
BoardsService,
|
||||||
|
} from '../../common/protocol/boards-service';
|
||||||
import { ListWidget } from '../widgets/component-list/list-widget';
|
import { ListWidget } from '../widgets/component-list/list-widget';
|
||||||
import { ListItemRenderer } from '../widgets/component-list/list-item-renderer';
|
import { ListItemRenderer } from '../widgets/component-list/list-item-renderer';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class BoardsListWidget extends ListWidget<BoardsPackage> {
|
export class BoardsListWidget extends ListWidget<BoardsPackage> {
|
||||||
|
static WIDGET_ID = 'boards-list-widget';
|
||||||
|
static WIDGET_LABEL = 'Boards Manager';
|
||||||
|
|
||||||
static WIDGET_ID = 'boards-list-widget';
|
constructor(
|
||||||
static WIDGET_LABEL = 'Boards Manager';
|
@inject(BoardsService) protected service: BoardsService,
|
||||||
|
@inject(ListItemRenderer)
|
||||||
|
protected itemRenderer: ListItemRenderer<BoardsPackage>
|
||||||
|
) {
|
||||||
|
super({
|
||||||
|
id: BoardsListWidget.WIDGET_ID,
|
||||||
|
label: BoardsListWidget.WIDGET_LABEL,
|
||||||
|
iconClass: 'fa fa-microchip',
|
||||||
|
searchable: service,
|
||||||
|
installable: service,
|
||||||
|
itemLabel: (item: BoardsPackage) => item.name,
|
||||||
|
itemDeprecated: (item: BoardsPackage) => item.deprecated,
|
||||||
|
itemRenderer,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
constructor(
|
@postConstruct()
|
||||||
@inject(BoardsService) protected service: BoardsService,
|
protected init(): void {
|
||||||
@inject(ListItemRenderer) protected itemRenderer: ListItemRenderer<BoardsPackage>) {
|
super.init();
|
||||||
|
this.toDispose.pushAll([
|
||||||
|
this.notificationCenter.onPlatformInstalled(() =>
|
||||||
|
this.refresh(undefined)
|
||||||
|
),
|
||||||
|
this.notificationCenter.onPlatformUninstalled(() =>
|
||||||
|
this.refresh(undefined)
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
super({
|
protected async install({
|
||||||
id: BoardsListWidget.WIDGET_ID,
|
item,
|
||||||
label: BoardsListWidget.WIDGET_LABEL,
|
progressId,
|
||||||
iconClass: 'fa fa-microchip',
|
version,
|
||||||
searchable: service,
|
}: {
|
||||||
installable: service,
|
item: BoardsPackage;
|
||||||
itemLabel: (item: BoardsPackage) => item.name,
|
progressId: string;
|
||||||
itemRenderer
|
version: string;
|
||||||
});
|
}): Promise<void> {
|
||||||
}
|
await super.install({ item, progressId, version });
|
||||||
|
this.messageService.info(
|
||||||
@postConstruct()
|
`Successfully installed platform ${item.name}:${version}`,
|
||||||
protected init(): void {
|
{ timeout: 3000 }
|
||||||
super.init();
|
);
|
||||||
this.toDispose.pushAll([
|
}
|
||||||
this.notificationCenter.onPlatformInstalled(() => this.refresh(undefined)),
|
|
||||||
this.notificationCenter.onPlatformUninstalled(() => this.refresh(undefined)),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
protected async uninstall({
|
||||||
|
item,
|
||||||
|
progressId,
|
||||||
|
}: {
|
||||||
|
item: BoardsPackage;
|
||||||
|
progressId: string;
|
||||||
|
}): Promise<void> {
|
||||||
|
await super.uninstall({ item, progressId });
|
||||||
|
this.messageService.info(
|
||||||
|
`Successfully uninstalled platform ${item.name}:${item.installedVersion}`,
|
||||||
|
{ timeout: 3000 }
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -5,189 +5,218 @@ import { DisposableCollection } from '@theia/core/lib/common/disposable';
|
|||||||
import { Port } from '../../common/protocol';
|
import { Port } from '../../common/protocol';
|
||||||
import { BoardsConfig } from './boards-config';
|
import { BoardsConfig } from './boards-config';
|
||||||
import { ArduinoCommands } from '../arduino-commands';
|
import { ArduinoCommands } from '../arduino-commands';
|
||||||
import { BoardsServiceProvider, AvailableBoard } from './boards-service-provider';
|
import {
|
||||||
|
BoardsServiceProvider,
|
||||||
|
AvailableBoard,
|
||||||
|
} from './boards-service-provider';
|
||||||
|
|
||||||
export interface BoardsDropDownListCoords {
|
export interface BoardsDropDownListCoords {
|
||||||
readonly top: number;
|
readonly top: number;
|
||||||
readonly left: number;
|
readonly left: number;
|
||||||
readonly width: number;
|
readonly width: number;
|
||||||
readonly paddingTop: number;
|
readonly paddingTop: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace BoardsDropDown {
|
export namespace BoardsDropDown {
|
||||||
export interface Props {
|
export interface Props {
|
||||||
readonly coords: BoardsDropDownListCoords | 'hidden';
|
readonly coords: BoardsDropDownListCoords | 'hidden';
|
||||||
readonly items: Array<AvailableBoard & { onClick: () => void, port: Port }>;
|
readonly items: Array<AvailableBoard & { onClick: () => void; port: Port }>;
|
||||||
readonly openBoardsConfig: () => void;
|
readonly openBoardsConfig: () => void;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BoardsDropDown extends React.Component<BoardsDropDown.Props> {
|
export class BoardsDropDown extends React.Component<BoardsDropDown.Props> {
|
||||||
|
protected dropdownElement: HTMLElement;
|
||||||
|
|
||||||
protected dropdownElement: HTMLElement;
|
constructor(props: BoardsDropDown.Props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
constructor(props: BoardsDropDown.Props) {
|
let list = document.getElementById('boards-dropdown-container');
|
||||||
super(props);
|
if (!list) {
|
||||||
|
list = document.createElement('div');
|
||||||
let list = document.getElementById('boards-dropdown-container');
|
list.id = 'boards-dropdown-container';
|
||||||
if (!list) {
|
document.body.appendChild(list);
|
||||||
list = document.createElement('div');
|
this.dropdownElement = list;
|
||||||
list.id = 'boards-dropdown-container';
|
|
||||||
document.body.appendChild(list);
|
|
||||||
this.dropdownElement = list;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render(): React.ReactNode {
|
render(): React.ReactNode {
|
||||||
return ReactDOM.createPortal(this.renderNode(), this.dropdownElement);
|
return ReactDOM.createPortal(this.renderNode(), this.dropdownElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected renderNode(): React.ReactNode {
|
protected renderNode(): React.ReactNode {
|
||||||
const { coords, items } = this.props;
|
const { coords, items } = this.props;
|
||||||
if (coords === 'hidden') {
|
if (coords === 'hidden') {
|
||||||
return '';
|
return '';
|
||||||
}
|
|
||||||
return <div className='arduino-boards-dropdown-list'
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
...coords
|
|
||||||
}}>
|
|
||||||
{this.renderItem({
|
|
||||||
label: 'Select Other Board & Port',
|
|
||||||
onClick: () => this.props.openBoardsConfig()
|
|
||||||
})}
|
|
||||||
{items.map(({ name, port, selected, onClick }) => ({ label: `${name} at ${Port.toString(port)}`, selected, onClick })).map(this.renderItem)}
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
|
|
||||||
protected renderItem({ label, selected, onClick }: { label: string, selected?: boolean, onClick: () => void }): React.ReactNode {
|
|
||||||
return <div key={label} className={`arduino-boards-dropdown-item ${selected ? 'selected' : ''}`} onClick={onClick}>
|
|
||||||
<div>
|
|
||||||
{label}
|
|
||||||
</div>
|
|
||||||
{selected ? <span className='fa fa-check' /> : ''}
|
|
||||||
</div>
|
|
||||||
}
|
}
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="arduino-boards-dropdown-list"
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
...coords,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{this.renderItem({
|
||||||
|
label: 'Select Other Board & Port',
|
||||||
|
onClick: () => this.props.openBoardsConfig(),
|
||||||
|
})}
|
||||||
|
{items
|
||||||
|
.map(({ name, port, selected, onClick }) => ({
|
||||||
|
label: `${name} at ${Port.toString(port)}`,
|
||||||
|
selected,
|
||||||
|
onClick,
|
||||||
|
}))
|
||||||
|
.map(this.renderItem)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected renderItem({
|
||||||
|
label,
|
||||||
|
selected,
|
||||||
|
onClick,
|
||||||
|
}: {
|
||||||
|
label: string;
|
||||||
|
selected?: boolean;
|
||||||
|
onClick: () => void;
|
||||||
|
}): React.ReactNode {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={label}
|
||||||
|
className={`arduino-boards-dropdown-item ${selected ? 'selected' : ''}`}
|
||||||
|
onClick={onClick}
|
||||||
|
>
|
||||||
|
<div>{label}</div>
|
||||||
|
{selected ? <span className="fa fa-check" /> : ''}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BoardsToolBarItem extends React.Component<BoardsToolBarItem.Props, BoardsToolBarItem.State> {
|
export class BoardsToolBarItem extends React.Component<
|
||||||
|
BoardsToolBarItem.Props,
|
||||||
|
BoardsToolBarItem.State
|
||||||
|
> {
|
||||||
|
static TOOLBAR_ID: 'boards-toolbar';
|
||||||
|
|
||||||
static TOOLBAR_ID: 'boards-toolbar';
|
protected readonly toDispose: DisposableCollection =
|
||||||
|
new DisposableCollection();
|
||||||
|
|
||||||
protected readonly toDispose: DisposableCollection = new DisposableCollection();
|
constructor(props: BoardsToolBarItem.Props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
constructor(props: BoardsToolBarItem.Props) {
|
const { availableBoards } = props.boardsServiceClient;
|
||||||
super(props);
|
this.state = {
|
||||||
|
availableBoards,
|
||||||
|
coords: 'hidden',
|
||||||
|
};
|
||||||
|
|
||||||
const { availableBoards } = props.boardsServiceClient;
|
document.addEventListener('click', () => {
|
||||||
this.state = {
|
this.setState({ coords: 'hidden' });
|
||||||
availableBoards,
|
});
|
||||||
coords: 'hidden'
|
}
|
||||||
};
|
|
||||||
|
|
||||||
document.addEventListener('click', () => {
|
componentDidMount() {
|
||||||
this.setState({ coords: 'hidden' });
|
this.props.boardsServiceClient.onAvailableBoardsChanged((availableBoards) =>
|
||||||
|
this.setState({ availableBoards })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount(): void {
|
||||||
|
this.toDispose.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected readonly show = (event: React.MouseEvent<HTMLElement>) => {
|
||||||
|
const { currentTarget: element } = event;
|
||||||
|
if (element instanceof HTMLElement) {
|
||||||
|
if (this.state.coords === 'hidden') {
|
||||||
|
const rect = element.getBoundingClientRect();
|
||||||
|
this.setState({
|
||||||
|
coords: {
|
||||||
|
top: rect.top,
|
||||||
|
left: rect.left,
|
||||||
|
width: rect.width,
|
||||||
|
paddingTop: rect.height,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
this.props.boardsServiceClient.onAvailableBoardsChanged(availableBoards => this.setState({ availableBoards }));
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillUnmount(): void {
|
|
||||||
this.toDispose.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected readonly show = (event: React.MouseEvent<HTMLElement>) => {
|
|
||||||
const { currentTarget: element } = event;
|
|
||||||
if (element instanceof HTMLElement) {
|
|
||||||
if (this.state.coords === 'hidden') {
|
|
||||||
const rect = element.getBoundingClientRect();
|
|
||||||
this.setState({
|
|
||||||
coords: {
|
|
||||||
top: rect.top,
|
|
||||||
left: rect.left,
|
|
||||||
width: rect.width,
|
|
||||||
paddingTop: rect.height
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.setState({ coords: 'hidden' });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
event.stopPropagation();
|
|
||||||
event.nativeEvent.stopImmediatePropagation();
|
|
||||||
};
|
|
||||||
|
|
||||||
render(): React.ReactNode {
|
|
||||||
const { coords, availableBoards } = this.state;
|
|
||||||
const boardsConfig = this.props.boardsServiceClient.boardsConfig;
|
|
||||||
const title = BoardsConfig.Config.toString(boardsConfig, { default: 'no board selected' });
|
|
||||||
const decorator = (() => {
|
|
||||||
const selectedBoard = availableBoards.find(({ selected }) => selected);
|
|
||||||
if (!selectedBoard || !selectedBoard.port) {
|
|
||||||
return 'fa fa-times notAttached'
|
|
||||||
}
|
|
||||||
if (selectedBoard.state === AvailableBoard.State.guessed) {
|
|
||||||
return 'fa fa-exclamation-triangle guessed'
|
|
||||||
}
|
|
||||||
return ''
|
|
||||||
})();
|
|
||||||
|
|
||||||
return <React.Fragment>
|
|
||||||
<div className='arduino-boards-toolbar-item-container'>
|
|
||||||
<div className='arduino-boards-toolbar-item' title={title}>
|
|
||||||
<div className='inner-container' onClick={this.show}>
|
|
||||||
<span className={decorator} />
|
|
||||||
<div className='label noWrapInfo'>
|
|
||||||
<div className='noWrapInfo noselect'>
|
|
||||||
{title}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<span className='fa fa-caret-down caret' />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<BoardsDropDown
|
|
||||||
coords={coords}
|
|
||||||
items={availableBoards.filter(AvailableBoard.hasPort).map(board => ({
|
|
||||||
...board,
|
|
||||||
onClick: () => {
|
|
||||||
if (board.state === AvailableBoard.State.incomplete) {
|
|
||||||
this.props.boardsServiceClient.boardsConfig = {
|
|
||||||
selectedPort: board.port
|
|
||||||
};
|
|
||||||
this.openDialog();
|
|
||||||
} else {
|
|
||||||
this.props.boardsServiceClient.boardsConfig = {
|
|
||||||
selectedBoard: board,
|
|
||||||
selectedPort: board.port
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}))}
|
|
||||||
openBoardsConfig={this.openDialog}>
|
|
||||||
</BoardsDropDown>
|
|
||||||
</React.Fragment>;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected openDialog = () => {
|
|
||||||
this.props.commands.executeCommand(ArduinoCommands.OPEN_BOARDS_DIALOG.id);
|
|
||||||
this.setState({ coords: 'hidden' });
|
this.setState({ coords: 'hidden' });
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
event.stopPropagation();
|
||||||
|
event.nativeEvent.stopImmediatePropagation();
|
||||||
|
};
|
||||||
|
|
||||||
|
render(): React.ReactNode {
|
||||||
|
const { coords, availableBoards } = this.state;
|
||||||
|
const boardsConfig = this.props.boardsServiceClient.boardsConfig;
|
||||||
|
const title = BoardsConfig.Config.toString(boardsConfig, {
|
||||||
|
default: 'no board selected',
|
||||||
|
});
|
||||||
|
const decorator = (() => {
|
||||||
|
const selectedBoard = availableBoards.find(({ selected }) => selected);
|
||||||
|
if (!selectedBoard || !selectedBoard.port) {
|
||||||
|
return 'fa fa-times notAttached';
|
||||||
|
}
|
||||||
|
if (selectedBoard.state === AvailableBoard.State.guessed) {
|
||||||
|
return 'fa fa-exclamation-triangle guessed';
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
})();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<div className="arduino-boards-toolbar-item-container">
|
||||||
|
<div className="arduino-boards-toolbar-item" title={title}>
|
||||||
|
<div className="inner-container" onClick={this.show}>
|
||||||
|
<span className={decorator} />
|
||||||
|
<div className="label noWrapInfo">
|
||||||
|
<div className="noWrapInfo noselect">{title}</div>
|
||||||
|
</div>
|
||||||
|
<span className="fa fa-caret-down caret" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<BoardsDropDown
|
||||||
|
coords={coords}
|
||||||
|
items={availableBoards
|
||||||
|
.filter(AvailableBoard.hasPort)
|
||||||
|
.map((board) => ({
|
||||||
|
...board,
|
||||||
|
onClick: () => {
|
||||||
|
if (board.state === AvailableBoard.State.incomplete) {
|
||||||
|
this.props.boardsServiceClient.boardsConfig = {
|
||||||
|
selectedPort: board.port,
|
||||||
|
};
|
||||||
|
this.openDialog();
|
||||||
|
} else {
|
||||||
|
this.props.boardsServiceClient.boardsConfig = {
|
||||||
|
selectedBoard: board,
|
||||||
|
selectedPort: board.port,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}))}
|
||||||
|
openBoardsConfig={this.openDialog}
|
||||||
|
></BoardsDropDown>
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected openDialog = () => {
|
||||||
|
this.props.commands.executeCommand(ArduinoCommands.OPEN_BOARDS_DIALOG.id);
|
||||||
|
this.setState({ coords: 'hidden' });
|
||||||
|
};
|
||||||
}
|
}
|
||||||
export namespace BoardsToolBarItem {
|
export namespace BoardsToolBarItem {
|
||||||
|
export interface Props {
|
||||||
|
readonly boardsServiceClient: BoardsServiceProvider;
|
||||||
|
readonly commands: CommandRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Props {
|
export interface State {
|
||||||
readonly boardsServiceClient: BoardsServiceProvider;
|
availableBoards: AvailableBoard[];
|
||||||
readonly commands: CommandRegistry;
|
coords: BoardsDropDownListCoords | 'hidden';
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface State {
|
|
||||||
availableBoards: AvailableBoard[];
|
|
||||||
coords: BoardsDropDownListCoords | 'hidden';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,22 +5,20 @@ import { ListWidgetFrontendContribution } from '../widgets/component-list/list-w
|
|||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class BoardsListWidgetFrontendContribution extends ListWidgetFrontendContribution<BoardsPackage> {
|
export class BoardsListWidgetFrontendContribution extends ListWidgetFrontendContribution<BoardsPackage> {
|
||||||
|
constructor() {
|
||||||
|
super({
|
||||||
|
widgetId: BoardsListWidget.WIDGET_ID,
|
||||||
|
widgetName: BoardsListWidget.WIDGET_LABEL,
|
||||||
|
defaultWidgetOptions: {
|
||||||
|
area: 'left',
|
||||||
|
rank: 2,
|
||||||
|
},
|
||||||
|
toggleCommandId: `${BoardsListWidget.WIDGET_ID}:toggle`,
|
||||||
|
toggleKeybinding: 'CtrlCmd+Shift+B',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
constructor() {
|
async initializeLayout(): Promise<void> {
|
||||||
super({
|
this.openView();
|
||||||
widgetId: BoardsListWidget.WIDGET_ID,
|
}
|
||||||
widgetName: BoardsListWidget.WIDGET_LABEL,
|
|
||||||
defaultWidgetOptions: {
|
|
||||||
area: 'left',
|
|
||||||
rank: 600
|
|
||||||
},
|
|
||||||
toggleCommandId: `${BoardsListWidget.WIDGET_ID}:toggle`,
|
|
||||||
toggleKeybinding: 'CtrlCmd+Shift+B'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async initializeLayout(): Promise<void> {
|
|
||||||
this.openView();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
import { ContainerModule } from 'inversify';
|
|
||||||
import { ILogger } from '@theia/core/lib/common/logger';
|
|
||||||
import { CommandContribution } from '@theia/core/lib/common/command';
|
|
||||||
import { QuickOpenContribution } from '@theia/core/lib/browser/quick-open';
|
|
||||||
import { KeybindingContribution } from '@theia/core/lib/browser/keybinding';
|
|
||||||
import { BoardsQuickOpenService } from './boards-quick-open-service';
|
|
||||||
|
|
||||||
export default new ContainerModule(bind => {
|
|
||||||
bind(BoardsQuickOpenService).toSelf().inSingletonScope();
|
|
||||||
bind(CommandContribution).toService(BoardsQuickOpenService);
|
|
||||||
bind(KeybindingContribution).toService(BoardsQuickOpenService);
|
|
||||||
bind(QuickOpenContribution).toService(BoardsQuickOpenService);
|
|
||||||
bind(ILogger).toDynamicValue(({ container }) => container.get<ILogger>(ILogger).child('boards-quick-open'))
|
|
||||||
.inSingletonScope()
|
|
||||||
.whenTargetNamed('boards-quick-open');
|
|
||||||
});
|
|
||||||
@@ -1,309 +0,0 @@
|
|||||||
import * as fuzzy from 'fuzzy';
|
|
||||||
import { inject, injectable, postConstruct, named } from 'inversify';
|
|
||||||
import { ILogger } from '@theia/core/lib/common/logger';
|
|
||||||
import { CommandContribution, CommandRegistry, Command } from '@theia/core/lib/common/command';
|
|
||||||
import { KeybindingContribution, KeybindingRegistry } from '@theia/core/lib/browser/keybinding';
|
|
||||||
import { QuickOpenItem, QuickOpenModel, QuickOpenMode, QuickOpenGroupItem } from '@theia/core/lib/common/quick-open-model';
|
|
||||||
import {
|
|
||||||
QuickOpenService,
|
|
||||||
QuickOpenHandler,
|
|
||||||
QuickOpenOptions,
|
|
||||||
QuickOpenItemOptions,
|
|
||||||
QuickOpenContribution,
|
|
||||||
QuickOpenActionProvider,
|
|
||||||
QuickOpenHandlerRegistry,
|
|
||||||
QuickOpenGroupItemOptions
|
|
||||||
} from '@theia/core/lib/browser/quick-open';
|
|
||||||
import { naturalCompare } from '../../../common/utils';
|
|
||||||
import { BoardsService, Port, Board, ConfigOption, ConfigValue } from '../../../common/protocol';
|
|
||||||
import { BoardsDataStore } from '../boards-data-store';
|
|
||||||
import { BoardsServiceProvider, AvailableBoard } from '../boards-service-provider';
|
|
||||||
import { NotificationCenter } from '../../notification-center';
|
|
||||||
|
|
||||||
@injectable()
|
|
||||||
export class BoardsQuickOpenService implements QuickOpenContribution, QuickOpenModel, QuickOpenHandler, CommandContribution, KeybindingContribution, Command {
|
|
||||||
|
|
||||||
readonly id = 'arduino-boards-quick-open';
|
|
||||||
readonly prefix = '|';
|
|
||||||
readonly description = 'Configure Available Boards';
|
|
||||||
readonly label: 'Configure Available Boards';
|
|
||||||
|
|
||||||
@inject(ILogger)
|
|
||||||
@named('boards-quick-open')
|
|
||||||
protected readonly logger: ILogger;
|
|
||||||
|
|
||||||
@inject(QuickOpenService)
|
|
||||||
protected readonly quickOpenService: QuickOpenService;
|
|
||||||
|
|
||||||
@inject(BoardsService)
|
|
||||||
protected readonly boardsService: BoardsService;
|
|
||||||
|
|
||||||
@inject(BoardsServiceProvider)
|
|
||||||
protected readonly boardsServiceClient: BoardsServiceProvider;
|
|
||||||
|
|
||||||
@inject(BoardsDataStore)
|
|
||||||
protected readonly boardsDataStore: BoardsDataStore;
|
|
||||||
|
|
||||||
@inject(NotificationCenter)
|
|
||||||
protected notificationCenter: NotificationCenter;
|
|
||||||
|
|
||||||
protected isOpen: boolean = false;
|
|
||||||
protected currentQuery: string = '';
|
|
||||||
// Attached boards plus the user's config.
|
|
||||||
protected availableBoards: AvailableBoard[] = [];
|
|
||||||
// Only for the `selected` one from the `availableBoards`. Note: the `port` of the `selected` is optional.
|
|
||||||
protected data: BoardsDataStore.Data = BoardsDataStore.Data.EMPTY;
|
|
||||||
protected allBoards: Board.Detailed[] = []
|
|
||||||
protected selectedBoard?: (AvailableBoard & { port: Port });
|
|
||||||
|
|
||||||
// `init` name is used by the `QuickOpenHandler`.
|
|
||||||
@postConstruct()
|
|
||||||
protected postConstruct(): void {
|
|
||||||
this.notificationCenter.onIndexUpdated(() => this.update(this.availableBoards));
|
|
||||||
this.boardsServiceClient.onAvailableBoardsChanged(availableBoards => this.update(availableBoards));
|
|
||||||
this.update(this.boardsServiceClient.availableBoards);
|
|
||||||
}
|
|
||||||
|
|
||||||
registerCommands(registry: CommandRegistry): void {
|
|
||||||
registry.registerCommand(this, { execute: () => this.open() });
|
|
||||||
}
|
|
||||||
|
|
||||||
registerKeybindings(registry: KeybindingRegistry): void {
|
|
||||||
registry.registerKeybinding({ command: this.id, keybinding: 'ctrlCmd+k ctrlCmd+b' });
|
|
||||||
}
|
|
||||||
|
|
||||||
registerQuickOpenHandlers(registry: QuickOpenHandlerRegistry): void {
|
|
||||||
registry.registerHandler(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
getModel(): QuickOpenModel {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
getOptions(): QuickOpenOptions {
|
|
||||||
let placeholder = '';
|
|
||||||
if (!this.selectedBoard) {
|
|
||||||
placeholder += 'No board selected.';
|
|
||||||
}
|
|
||||||
placeholder += 'Type to filter boards';
|
|
||||||
if (this.data.configOptions.length) {
|
|
||||||
placeholder += ' or use the ↓↑ keys to adjust the board settings...';
|
|
||||||
} else {
|
|
||||||
placeholder += '...';
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
placeholder,
|
|
||||||
fuzzyMatchLabel: true,
|
|
||||||
onClose: () => this.isOpen = false
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
open(): void {
|
|
||||||
this.isOpen = true;
|
|
||||||
this.quickOpenService.open(this, this.getOptions());
|
|
||||||
}
|
|
||||||
|
|
||||||
onType(
|
|
||||||
lookFor: string,
|
|
||||||
acceptor: (items: QuickOpenItem<QuickOpenItemOptions>[], actionProvider?: QuickOpenActionProvider) => void): void {
|
|
||||||
|
|
||||||
this.currentQuery = lookFor;
|
|
||||||
const fuzzyFilter = this.fuzzyFilter(lookFor);
|
|
||||||
const availableBoards = this.availableBoards.filter(AvailableBoard.hasPort).filter(({ name }) => fuzzyFilter(name));
|
|
||||||
const toAccept: QuickOpenItem<QuickOpenItemOptions>[] = [];
|
|
||||||
|
|
||||||
// Show the selected attached in a different group.
|
|
||||||
if (this.selectedBoard && fuzzyFilter(this.selectedBoard.name)) {
|
|
||||||
toAccept.push(this.toQuickItem(this.selectedBoard, { groupLabel: 'Selected Board' }));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter the selected from the attached ones.
|
|
||||||
toAccept.push(...availableBoards.filter(board => board !== this.selectedBoard).map((board, i) => {
|
|
||||||
let group: QuickOpenGroupItemOptions | undefined = undefined;
|
|
||||||
if (i === 0) {
|
|
||||||
// If no `selectedBoard`, then this item is the top one, no borders required.
|
|
||||||
group = { groupLabel: 'Attached Boards', showBorder: !!this.selectedBoard };
|
|
||||||
}
|
|
||||||
return this.toQuickItem(board, group);
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Show the config only if the `input` is empty.
|
|
||||||
if (!lookFor.trim().length) {
|
|
||||||
toAccept.push(...this.data.configOptions.map((config, i) => {
|
|
||||||
let group: QuickOpenGroupItemOptions | undefined = undefined;
|
|
||||||
if (i === 0) {
|
|
||||||
group = { groupLabel: 'Board Settings', showBorder: true };
|
|
||||||
}
|
|
||||||
return this.toQuickItem(config, group);
|
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
toAccept.push(...this.allBoards.filter(({ name }) => fuzzyFilter(name)).map((board, i) => {
|
|
||||||
let group: QuickOpenGroupItemOptions | undefined = undefined;
|
|
||||||
if (i === 0) {
|
|
||||||
group = { groupLabel: 'Boards', showBorder: true };
|
|
||||||
}
|
|
||||||
return this.toQuickItem(board, group);
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
acceptor(toAccept);
|
|
||||||
}
|
|
||||||
|
|
||||||
private fuzzyFilter(lookFor: string): (inputString: string) => boolean {
|
|
||||||
const shouldFilter = !!lookFor.trim().length;
|
|
||||||
return (inputString: string) => shouldFilter ? fuzzy.test(lookFor.toLocaleLowerCase(), inputString.toLocaleLowerCase()) : true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async update(availableBoards: AvailableBoard[]): Promise<void> {
|
|
||||||
// `selectedBoard` is not an attached board, we need to show the board settings for it (TODO: clarify!)
|
|
||||||
const selectedBoard = availableBoards.filter(AvailableBoard.hasPort).find(({ selected }) => selected);
|
|
||||||
const [data, boards] = await Promise.all([
|
|
||||||
selectedBoard && selectedBoard.fqbn ? this.boardsDataStore.getData(selectedBoard.fqbn) : Promise.resolve(BoardsDataStore.Data.EMPTY),
|
|
||||||
this.boardsService.allBoards({})
|
|
||||||
]);
|
|
||||||
this.allBoards = Board.decorateBoards(selectedBoard, boards)
|
|
||||||
.filter(board => !availableBoards.some(availableBoard => Board.sameAs(availableBoard, board)));
|
|
||||||
this.availableBoards = availableBoards;
|
|
||||||
this.data = data;
|
|
||||||
this.selectedBoard = selectedBoard;
|
|
||||||
|
|
||||||
if (this.isOpen) {
|
|
||||||
// Hack, to update the state without closing and reopening the quick open widget.
|
|
||||||
(this.quickOpenService as any).onType(this.currentQuery);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected toQuickItem(item: BoardsQuickOpenService.Item, group?: QuickOpenGroupItemOptions): QuickOpenItem<QuickOpenItemOptions> {
|
|
||||||
let options: QuickOpenItemOptions;
|
|
||||||
if (AvailableBoard.is(item)) {
|
|
||||||
const description = `on ${Port.toString(item.port)}`
|
|
||||||
options = {
|
|
||||||
label: `${item.name}`,
|
|
||||||
description,
|
|
||||||
descriptionHighlights: [
|
|
||||||
{
|
|
||||||
start: 0,
|
|
||||||
end: description.length
|
|
||||||
}
|
|
||||||
],
|
|
||||||
run: this.toRun(() => this.boardsServiceClient.boardsConfig = ({ selectedBoard: item, selectedPort: item.port }))
|
|
||||||
};
|
|
||||||
} else if (ConfigOption.is(item)) {
|
|
||||||
const selected = item.values.find(({ selected }) => selected);
|
|
||||||
const value = selected ? selected.label : 'Not set';
|
|
||||||
const label = `${item.label}: ${value}`;
|
|
||||||
options = {
|
|
||||||
label,
|
|
||||||
// Intended to match the value part of a board setting.
|
|
||||||
// NOTE: this does not work, as `fuzzyMatchLabel: true` is set. Manual highlighting is ignored, apparently.
|
|
||||||
labelHighlights: [
|
|
||||||
{
|
|
||||||
start: label.length - value.length,
|
|
||||||
end: label.length
|
|
||||||
}
|
|
||||||
],
|
|
||||||
run: (mode) => {
|
|
||||||
if (mode === QuickOpenMode.OPEN) {
|
|
||||||
this.setConfig(item);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if (!selected) {
|
|
||||||
options.description = 'Not set';
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
options = {
|
|
||||||
label: `${item.name}`,
|
|
||||||
description: `${item.missing ? '' : `[installed with '${item.packageName}']`}`,
|
|
||||||
run: (mode) => {
|
|
||||||
if (mode === QuickOpenMode.OPEN) {
|
|
||||||
this.selectBoard(item);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (group) {
|
|
||||||
return new QuickOpenGroupItem<QuickOpenGroupItemOptions>({ ...options, ...group });
|
|
||||||
} else {
|
|
||||||
return new QuickOpenItem<QuickOpenItemOptions>(options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected toRun(run: (() => void)): ((mode: QuickOpenMode) => boolean) {
|
|
||||||
return (mode) => {
|
|
||||||
if (mode !== QuickOpenMode.OPEN) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
run();
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async selectBoard(board: Board): Promise<void> {
|
|
||||||
const allPorts = this.availableBoards.filter(AvailableBoard.hasPort).map(({ port }) => port).sort(Port.compare);
|
|
||||||
const toItem = (port: Port) => new QuickOpenItem<QuickOpenItemOptions>({
|
|
||||||
label: Port.toString(port, { useLabel: true }),
|
|
||||||
run: this.toRun(() => {
|
|
||||||
this.boardsServiceClient.boardsConfig = {
|
|
||||||
selectedBoard: board,
|
|
||||||
selectedPort: port
|
|
||||||
};
|
|
||||||
})
|
|
||||||
});
|
|
||||||
const options = {
|
|
||||||
placeholder: `Select a port for '${board.name}'. Press 'Enter' to confirm or 'Escape' to cancel.`,
|
|
||||||
fuzzyMatchLabel: true
|
|
||||||
}
|
|
||||||
this.quickOpenService.open({
|
|
||||||
onType: (lookFor, acceptor) => {
|
|
||||||
const fuzzyFilter = this.fuzzyFilter(lookFor);
|
|
||||||
acceptor(allPorts.filter(({ address }) => fuzzyFilter(address)).map(toItem));
|
|
||||||
}
|
|
||||||
}, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async setConfig(config: ConfigOption): Promise<void> {
|
|
||||||
const toItem = (value: ConfigValue) => new QuickOpenItem<QuickOpenItemOptions>({
|
|
||||||
label: value.label,
|
|
||||||
iconClass: value.selected ? 'fa fa-check' : '',
|
|
||||||
run: this.toRun(() => {
|
|
||||||
if (!this.selectedBoard) {
|
|
||||||
this.logger.warn(`Could not alter the boards settings. No board selected. ${JSON.stringify(config)}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!this.selectedBoard.fqbn) {
|
|
||||||
this.logger.warn(`Could not alter the boards settings. The selected board does not have a FQBN. ${JSON.stringify(this.selectedBoard)}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const { fqbn } = this.selectedBoard;
|
|
||||||
this.boardsDataStore.selectConfigOption({
|
|
||||||
fqbn,
|
|
||||||
option: config.option,
|
|
||||||
selectedValue: value.value
|
|
||||||
});
|
|
||||||
})
|
|
||||||
});
|
|
||||||
const options = {
|
|
||||||
placeholder: `Configure '${config.label}'. Press 'Enter' to confirm or 'Escape' to cancel.`,
|
|
||||||
fuzzyMatchLabel: true
|
|
||||||
}
|
|
||||||
this.quickOpenService.open({
|
|
||||||
onType: (lookFor, acceptor) => {
|
|
||||||
const fuzzyFilter = this.fuzzyFilter(lookFor);
|
|
||||||
acceptor(config.values
|
|
||||||
.filter(({ label }) => fuzzyFilter(label))
|
|
||||||
.sort((left, right) => naturalCompare(left.label, right.label))
|
|
||||||
.map(toItem));
|
|
||||||
}
|
|
||||||
}, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export namespace BoardsQuickOpenService {
|
|
||||||
export type Item = AvailableBoard & { port: Port } | Board.Detailed | ConfigOption;
|
|
||||||
}
|
|
||||||
@@ -4,102 +4,114 @@ import { remote } from 'electron';
|
|||||||
import { isOSX, isWindows } from '@theia/core/lib/common/os';
|
import { isOSX, isWindows } from '@theia/core/lib/common/os';
|
||||||
import { ClipboardService } from '@theia/core/lib/browser/clipboard-service';
|
import { ClipboardService } from '@theia/core/lib/browser/clipboard-service';
|
||||||
import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider';
|
import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider';
|
||||||
import { Contribution, Command, MenuModelRegistry, CommandRegistry } from './contribution';
|
import {
|
||||||
|
Contribution,
|
||||||
|
Command,
|
||||||
|
MenuModelRegistry,
|
||||||
|
CommandRegistry,
|
||||||
|
} from './contribution';
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
import { ConfigService } from '../../common/protocol';
|
import { ConfigService } from '../../common/protocol';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class About extends Contribution {
|
export class About extends Contribution {
|
||||||
|
@inject(ClipboardService)
|
||||||
|
protected readonly clipboardService: ClipboardService;
|
||||||
|
|
||||||
@inject(ClipboardService)
|
@inject(ConfigService)
|
||||||
protected readonly clipboardService: ClipboardService;
|
protected readonly configService: ConfigService;
|
||||||
|
|
||||||
@inject(ConfigService)
|
registerCommands(registry: CommandRegistry): void {
|
||||||
protected readonly configService: ConfigService;
|
registry.registerCommand(About.Commands.ABOUT_APP, {
|
||||||
|
execute: () => this.showAbout(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
registerCommands(registry: CommandRegistry): void {
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
registry.registerCommand(About.Commands.ABOUT_APP, {
|
registry.registerMenuAction(ArduinoMenus.HELP__ABOUT_GROUP, {
|
||||||
execute: () => this.showAbout()
|
commandId: About.Commands.ABOUT_APP.id,
|
||||||
});
|
label: `About ${this.applicationName}`,
|
||||||
|
order: '0',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async showAbout(): Promise<void> {
|
||||||
|
const {
|
||||||
|
version,
|
||||||
|
commit,
|
||||||
|
status: cliStatus,
|
||||||
|
} = await this.configService.getVersion();
|
||||||
|
const buildDate = this.buildDate;
|
||||||
|
const detail = (showAll: boolean) => `Version: ${remote.app.getVersion()}
|
||||||
|
Date: ${buildDate ? buildDate : 'dev build'}${
|
||||||
|
buildDate && showAll ? ` (${this.ago(buildDate)})` : ''
|
||||||
}
|
}
|
||||||
|
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
|
||||||
registry.registerMenuAction(ArduinoMenus.HELP__ABOUT_GROUP, {
|
|
||||||
commandId: About.Commands.ABOUT_APP.id,
|
|
||||||
label: `About ${this.applicationName}`,
|
|
||||||
order: '0'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async showAbout(): Promise<void> {
|
|
||||||
const { version, commit, status: cliStatus } = await this.configService.getVersion();
|
|
||||||
const buildDate = this.buildDate;
|
|
||||||
const detail = (showAll: boolean) => `Version: ${remote.app.getVersion()}
|
|
||||||
Date: ${buildDate ? buildDate : 'dev build'}${buildDate && showAll ? ` (${this.ago(buildDate)})` : ''}
|
|
||||||
CLI Version: ${version}${cliStatus ? ` ${cliStatus}` : ''} [${commit}]
|
CLI Version: ${version}${cliStatus ? ` ${cliStatus}` : ''} [${commit}]
|
||||||
|
|
||||||
${showAll ? `Copyright © ${new Date().getFullYear()} Arduino SA` : ''}
|
${showAll ? `Copyright © ${new Date().getFullYear()} Arduino SA` : ''}
|
||||||
`;
|
`;
|
||||||
const ok = 'OK';
|
const ok = 'OK';
|
||||||
const copy = 'Copy';
|
const copy = 'Copy';
|
||||||
const buttons = !isWindows && !isOSX ? [copy, ok] : [ok, copy];
|
const buttons = !isWindows && !isOSX ? [copy, ok] : [ok, copy];
|
||||||
const { response } = await remote.dialog.showMessageBox(remote.getCurrentWindow(), {
|
const { response } = await remote.dialog.showMessageBox(
|
||||||
message: `${this.applicationName}`,
|
remote.getCurrentWindow(),
|
||||||
title: `${this.applicationName}`,
|
{
|
||||||
type: 'info',
|
message: `${this.applicationName}`,
|
||||||
detail: detail(true),
|
title: `${this.applicationName}`,
|
||||||
buttons,
|
type: 'info',
|
||||||
noLink: true,
|
detail: detail(true),
|
||||||
defaultId: buttons.indexOf(ok),
|
buttons,
|
||||||
cancelId: buttons.indexOf(ok)
|
noLink: true,
|
||||||
});
|
defaultId: buttons.indexOf(ok),
|
||||||
|
cancelId: buttons.indexOf(ok),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
if (buttons[response] === copy) {
|
if (buttons[response] === copy) {
|
||||||
await this.clipboardService.writeText(detail(false).trim());
|
await this.clipboardService.writeText(detail(false).trim());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected get applicationName(): string {
|
protected get applicationName(): string {
|
||||||
return FrontendApplicationConfigProvider.get().applicationName;
|
return FrontendApplicationConfigProvider.get().applicationName;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected get buildDate(): string | undefined {
|
||||||
|
return FrontendApplicationConfigProvider.get().buildDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ago(isoTime: string): string {
|
||||||
|
const now = moment(Date.now());
|
||||||
|
const other = moment(isoTime);
|
||||||
|
let result = now.diff(other, 'minute');
|
||||||
|
if (result < 60) {
|
||||||
|
return result === 1 ? `${result} minute ago` : `${result} minute ago`;
|
||||||
}
|
}
|
||||||
|
result = now.diff(other, 'hour');
|
||||||
protected get buildDate(): string | undefined {
|
if (result < 25) {
|
||||||
return FrontendApplicationConfigProvider.get().buildDate;
|
return result === 1 ? `${result} hour ago` : `${result} hours ago`;
|
||||||
}
|
}
|
||||||
|
result = now.diff(other, 'day');
|
||||||
protected ago(isoTime: string): string {
|
if (result < 8) {
|
||||||
const now = moment(Date.now());
|
return result === 1 ? `${result} day ago` : `${result} days ago`;
|
||||||
const other = moment(isoTime);
|
|
||||||
let result = now.diff(other, 'minute');
|
|
||||||
if (result < 60) {
|
|
||||||
return result === 1 ? `${result} minute ago` : `${result} minute ago`;
|
|
||||||
}
|
|
||||||
result = now.diff(other, 'hour');
|
|
||||||
if (result < 25) {
|
|
||||||
return result === 1 ? `${result} hour ago` : `${result} hours ago`;
|
|
||||||
}
|
|
||||||
result = now.diff(other, 'day');
|
|
||||||
if (result < 8) {
|
|
||||||
return result === 1 ? `${result} day ago` : `${result} days ago`;
|
|
||||||
}
|
|
||||||
result = now.diff(other, 'week');
|
|
||||||
if (result < 5) {
|
|
||||||
return result === 1 ? `${result} week ago` : `${result} weeks ago`;
|
|
||||||
}
|
|
||||||
result = now.diff(other, 'month');
|
|
||||||
if (result < 13) {
|
|
||||||
return result === 1 ? `${result} month ago` : `${result} months ago`;
|
|
||||||
}
|
|
||||||
result = now.diff(other, 'year');
|
|
||||||
return result === 1 ? `${result} year ago` : `${result} years ago`;
|
|
||||||
}
|
}
|
||||||
|
result = now.diff(other, 'week');
|
||||||
|
if (result < 5) {
|
||||||
|
return result === 1 ? `${result} week ago` : `${result} weeks ago`;
|
||||||
|
}
|
||||||
|
result = now.diff(other, 'month');
|
||||||
|
if (result < 13) {
|
||||||
|
return result === 1 ? `${result} month ago` : `${result} months ago`;
|
||||||
|
}
|
||||||
|
result = now.diff(other, 'year');
|
||||||
|
return result === 1 ? `${result} year ago` : `${result} years ago`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace About {
|
export namespace About {
|
||||||
export namespace Commands {
|
export namespace Commands {
|
||||||
export const ABOUT_APP: Command = {
|
export const ABOUT_APP: Command = {
|
||||||
id: 'arduino-about'
|
id: 'arduino-about',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,68 +1,75 @@
|
|||||||
import { inject, injectable } from 'inversify';
|
import { inject, injectable } from 'inversify';
|
||||||
import { remote } from 'electron';
|
import { remote } from 'electron';
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, URI } from './contribution';
|
import {
|
||||||
|
SketchContribution,
|
||||||
|
Command,
|
||||||
|
CommandRegistry,
|
||||||
|
MenuModelRegistry,
|
||||||
|
URI,
|
||||||
|
} from './contribution';
|
||||||
import { FileDialogService } from '@theia/filesystem/lib/browser';
|
import { FileDialogService } from '@theia/filesystem/lib/browser';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class AddFile extends SketchContribution {
|
export class AddFile extends SketchContribution {
|
||||||
|
@inject(FileDialogService)
|
||||||
|
protected readonly fileDialogService: FileDialogService;
|
||||||
|
|
||||||
@inject(FileDialogService)
|
registerCommands(registry: CommandRegistry): void {
|
||||||
protected readonly fileDialogService: FileDialogService;
|
registry.registerCommand(AddFile.Commands.ADD_FILE, {
|
||||||
|
execute: () => this.addFile(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
registerCommands(registry: CommandRegistry): void {
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
registry.registerCommand(AddFile.Commands.ADD_FILE, {
|
registry.registerMenuAction(ArduinoMenus.SKETCH__UTILS_GROUP, {
|
||||||
execute: () => this.addFile()
|
commandId: AddFile.Commands.ADD_FILE.id,
|
||||||
});
|
label: 'Add File...',
|
||||||
|
order: '2',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async addFile(): Promise<void> {
|
||||||
|
const sketch = await this.sketchServiceClient.currentSketch();
|
||||||
|
if (!sketch) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
const toAddUri = await this.fileDialogService.showOpenDialog({
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
title: 'Add File',
|
||||||
registry.registerMenuAction(ArduinoMenus.SKETCH__UTILS_GROUP, {
|
canSelectFiles: true,
|
||||||
commandId: AddFile.Commands.ADD_FILE.id,
|
canSelectFolders: false,
|
||||||
label: 'Add File...',
|
canSelectMany: false,
|
||||||
order: '2'
|
});
|
||||||
});
|
if (!toAddUri) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
const sketchUri = new URI(sketch.uri);
|
||||||
protected async addFile(): Promise<void> {
|
const filename = toAddUri.path.base;
|
||||||
const sketch = await this.sketchServiceClient.currentSketch();
|
const targetUri = sketchUri.resolve('data').resolve(filename);
|
||||||
if (!sketch) {
|
const exists = await this.fileService.exists(targetUri);
|
||||||
return;
|
if (exists) {
|
||||||
}
|
const { response } = await remote.dialog.showMessageBox({
|
||||||
const toAddUri = await this.fileDialogService.showOpenDialog({
|
type: 'question',
|
||||||
title: 'Add File',
|
title: 'Replace',
|
||||||
canSelectFiles: true,
|
buttons: ['Cancel', 'OK'],
|
||||||
canSelectFolders: false,
|
message: `Replace the existing version of ${filename}?`,
|
||||||
canSelectMany: false
|
});
|
||||||
});
|
if (response === 0) {
|
||||||
if (!toAddUri) {
|
// Cancel
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const sketchUri = new URI(sketch.uri);
|
|
||||||
const filename = toAddUri.path.base;
|
|
||||||
const targetUri = sketchUri.resolve('data').resolve(filename);
|
|
||||||
const exists = await this.fileService.exists(targetUri);
|
|
||||||
if (exists) {
|
|
||||||
const { response } = await remote.dialog.showMessageBox({
|
|
||||||
type: 'question',
|
|
||||||
title: 'Replace',
|
|
||||||
buttons: ['Cancel', 'OK'],
|
|
||||||
message: `Replace the existing version of ${filename}?`
|
|
||||||
});
|
|
||||||
if (response === 0) { // Cancel
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await this.fileService.copy(toAddUri, targetUri, { overwrite: true });
|
|
||||||
this.messageService.info('One file added to the sketch.', { timeout: 2000 });
|
|
||||||
}
|
}
|
||||||
|
await this.fileService.copy(toAddUri, targetUri, { overwrite: true });
|
||||||
|
this.messageService.info('One file added to the sketch.', {
|
||||||
|
timeout: 2000,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace AddFile {
|
export namespace AddFile {
|
||||||
export namespace Commands {
|
export namespace Commands {
|
||||||
export const ADD_FILE: Command = {
|
export const ADD_FILE: Command = {
|
||||||
id: 'arduino-add-file'
|
id: 'arduino-add-file',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,133 @@
|
|||||||
|
import { inject, injectable } from 'inversify';
|
||||||
|
import { remote } from 'electron';
|
||||||
|
import URI from '@theia/core/lib/common/uri';
|
||||||
|
import { ConfirmDialog } from '@theia/core/lib/browser/dialogs';
|
||||||
|
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
|
||||||
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
|
import { ResponseServiceImpl } from '../response-service-impl';
|
||||||
|
import { Installable, LibraryService } from '../../common/protocol';
|
||||||
|
import {
|
||||||
|
SketchContribution,
|
||||||
|
Command,
|
||||||
|
CommandRegistry,
|
||||||
|
MenuModelRegistry,
|
||||||
|
} from './contribution';
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class AddZipLibrary extends SketchContribution {
|
||||||
|
@inject(EnvVariablesServer)
|
||||||
|
protected readonly envVariableServer: EnvVariablesServer;
|
||||||
|
|
||||||
|
@inject(ResponseServiceImpl)
|
||||||
|
protected readonly responseService: ResponseServiceImpl;
|
||||||
|
|
||||||
|
@inject(LibraryService)
|
||||||
|
protected readonly libraryService: LibraryService;
|
||||||
|
|
||||||
|
registerCommands(registry: CommandRegistry): void {
|
||||||
|
registry.registerCommand(AddZipLibrary.Commands.ADD_ZIP_LIBRARY, {
|
||||||
|
execute: () => this.addZipLibrary(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
|
const includeLibMenuPath = [
|
||||||
|
...ArduinoMenus.SKETCH__UTILS_GROUP,
|
||||||
|
'0_include',
|
||||||
|
];
|
||||||
|
// TODO: do we need it? calling `registerSubmenu` multiple times is noop, so it does not hurt.
|
||||||
|
registry.registerSubmenu(includeLibMenuPath, 'Include Library', {
|
||||||
|
order: '1',
|
||||||
|
});
|
||||||
|
registry.registerMenuAction([...includeLibMenuPath, '1_install'], {
|
||||||
|
commandId: AddZipLibrary.Commands.ADD_ZIP_LIBRARY.id,
|
||||||
|
label: 'Add .ZIP Library...',
|
||||||
|
order: '1',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async addZipLibrary(): Promise<void> {
|
||||||
|
const homeUri = await this.envVariableServer.getHomeDirUri();
|
||||||
|
const defaultPath = await this.fileService.fsPath(new URI(homeUri));
|
||||||
|
const { canceled, filePaths } = await remote.dialog.showOpenDialog({
|
||||||
|
title: "Select a zip file containing the library you'd like to add",
|
||||||
|
defaultPath,
|
||||||
|
properties: ['openFile'],
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
name: 'Library',
|
||||||
|
extensions: ['zip'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
if (!canceled && filePaths.length) {
|
||||||
|
const zipUri = await this.fileSystemExt.getUri(filePaths[0]);
|
||||||
|
try {
|
||||||
|
await this.doInstall(zipUri);
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof AlreadyInstalledError) {
|
||||||
|
const result = await new ConfirmDialog({
|
||||||
|
msg: error.message,
|
||||||
|
title: 'Do you want to overwrite the existing library?',
|
||||||
|
ok: 'Yes',
|
||||||
|
cancel: 'No',
|
||||||
|
}).open();
|
||||||
|
if (result) {
|
||||||
|
await this.doInstall(zipUri, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async doInstall(zipUri: string, overwrite?: boolean): Promise<void> {
|
||||||
|
try {
|
||||||
|
await Installable.doWithProgress({
|
||||||
|
messageService: this.messageService,
|
||||||
|
progressText: `Processing ${new URI(zipUri).path.base}`,
|
||||||
|
responseService: this.responseService,
|
||||||
|
run: () => this.libraryService.installZip({ zipUri, overwrite }),
|
||||||
|
});
|
||||||
|
this.messageService.info(
|
||||||
|
`Successfully installed library from ${
|
||||||
|
new URI(zipUri).path.base
|
||||||
|
} archive`,
|
||||||
|
{ timeout: 3000 }
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
const match = error.message.match(/library (.*?) already installed/);
|
||||||
|
if (match && match.length >= 2) {
|
||||||
|
const name = match[1].trim();
|
||||||
|
if (name) {
|
||||||
|
throw new AlreadyInstalledError(
|
||||||
|
`A library folder named ${name} already exists. Do you want to overwrite it?`,
|
||||||
|
name
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
throw new AlreadyInstalledError(
|
||||||
|
'A library already exists. Do you want to overwrite it?'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.messageService.error(error.toString());
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AlreadyInstalledError extends Error {
|
||||||
|
constructor(message: string, readonly libraryName?: string) {
|
||||||
|
super(message);
|
||||||
|
Object.setPrototypeOf(this, AlreadyInstalledError.prototype);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export namespace AddZipLibrary {
|
||||||
|
export namespace Commands {
|
||||||
|
export const ADD_ZIP_LIBRARY: Command = {
|
||||||
|
id: 'arduino-add-zip-library',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,53 +3,66 @@ import { remote } from 'electron';
|
|||||||
import * as dateFormat from 'dateformat';
|
import * as dateFormat from 'dateformat';
|
||||||
import URI from '@theia/core/lib/common/uri';
|
import URI from '@theia/core/lib/common/uri';
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry } from './contribution';
|
import {
|
||||||
|
SketchContribution,
|
||||||
|
Command,
|
||||||
|
CommandRegistry,
|
||||||
|
MenuModelRegistry,
|
||||||
|
} from './contribution';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class ArchiveSketch extends SketchContribution {
|
export class ArchiveSketch extends SketchContribution {
|
||||||
|
registerCommands(registry: CommandRegistry): void {
|
||||||
|
registry.registerCommand(ArchiveSketch.Commands.ARCHIVE_SKETCH, {
|
||||||
|
execute: () => this.archiveSketch(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
registerCommands(registry: CommandRegistry): void {
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
registry.registerCommand(ArchiveSketch.Commands.ARCHIVE_SKETCH, {
|
registry.registerMenuAction(ArduinoMenus.TOOLS__MAIN_GROUP, {
|
||||||
execute: () => this.archiveSketch()
|
commandId: ArchiveSketch.Commands.ARCHIVE_SKETCH.id,
|
||||||
});
|
label: 'Archive Sketch',
|
||||||
|
order: '1',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async archiveSketch(): Promise<void> {
|
||||||
|
const [sketch, config] = await Promise.all([
|
||||||
|
this.sketchServiceClient.currentSketch(),
|
||||||
|
this.configService.getConfiguration(),
|
||||||
|
]);
|
||||||
|
if (!sketch) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
const archiveBasename = `${sketch.name}-${dateFormat(
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
new Date(),
|
||||||
registry.registerMenuAction(ArduinoMenus.TOOLS__MAIN_GROUP, {
|
'yymmdd'
|
||||||
commandId: ArchiveSketch.Commands.ARCHIVE_SKETCH.id,
|
)}a.zip`;
|
||||||
label: 'Archive Sketch',
|
const defaultPath = await this.fileService.fsPath(
|
||||||
order: '1'
|
new URI(config.sketchDirUri).resolve(archiveBasename)
|
||||||
});
|
);
|
||||||
|
const { filePath, canceled } = await remote.dialog.showSaveDialog({
|
||||||
|
title: 'Save sketch folder as...',
|
||||||
|
defaultPath,
|
||||||
|
});
|
||||||
|
if (!filePath || canceled) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
const destinationUri = await this.fileSystemExt.getUri(filePath);
|
||||||
protected async archiveSketch(): Promise<void> {
|
if (!destinationUri) {
|
||||||
const [sketch, config] = await Promise.all([
|
return;
|
||||||
this.sketchServiceClient.currentSketch(),
|
|
||||||
this.configService.getConfiguration()
|
|
||||||
]);
|
|
||||||
if (!sketch) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const archiveBasename = `${sketch.name}-${dateFormat(new Date(), 'yymmdd')}a.zip`;
|
|
||||||
const defaultPath = await this.fileService.fsPath(new URI(config.sketchDirUri).resolve(archiveBasename));
|
|
||||||
const { filePath, canceled } = await remote.dialog.showSaveDialog({ title: 'Save sketch folder as...', defaultPath });
|
|
||||||
if (!filePath || canceled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const destinationUri = await this.fileSystemExt.getUri(filePath);
|
|
||||||
if (!destinationUri) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await this.sketchService.archive(sketch, destinationUri.toString());
|
|
||||||
this.messageService.info(`Created archive '${archiveBasename}'.`, { timeout: 2000 });
|
|
||||||
}
|
}
|
||||||
|
await this.sketchService.archive(sketch, destinationUri.toString());
|
||||||
|
this.messageService.info(`Created archive '${archiveBasename}'.`, {
|
||||||
|
timeout: 2000,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace ArchiveSketch {
|
export namespace ArchiveSketch {
|
||||||
export namespace Commands {
|
export namespace Commands {
|
||||||
export const ARCHIVE_SKETCH: Command = {
|
export const ARCHIVE_SKETCH: Command = {
|
||||||
id: 'arduino-archive-sketch'
|
id: 'arduino-archive-sketch',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,222 +1,315 @@
|
|||||||
import { inject, injectable } from 'inversify';
|
import { inject, injectable } from 'inversify';
|
||||||
import { remote } from 'electron';
|
import { remote } from 'electron';
|
||||||
import { MenuModelRegistry } from '@theia/core/lib/common/menu';
|
import { MenuModelRegistry } from '@theia/core/lib/common/menu';
|
||||||
import { DisposableCollection, Disposable } from '@theia/core/lib/common/disposable';
|
import {
|
||||||
|
DisposableCollection,
|
||||||
|
Disposable,
|
||||||
|
} from '@theia/core/lib/common/disposable';
|
||||||
import { firstToUpperCase } from '../../common/utils';
|
import { firstToUpperCase } from '../../common/utils';
|
||||||
import { BoardsConfig } from '../boards/boards-config';
|
import { BoardsConfig } from '../boards/boards-config';
|
||||||
import { MainMenuManager } from '../../common/main-menu-manager';
|
import { MainMenuManager } from '../../common/main-menu-manager';
|
||||||
import { BoardsListWidget } from '../boards/boards-list-widget';
|
import { BoardsListWidget } from '../boards/boards-list-widget';
|
||||||
import { NotificationCenter } from '../notification-center';
|
import { NotificationCenter } from '../notification-center';
|
||||||
import { BoardsServiceProvider } from '../boards/boards-service-provider';
|
import { BoardsServiceProvider } from '../boards/boards-service-provider';
|
||||||
import { ArduinoMenus, PlaceholderMenuNode, unregisterSubmenu } from '../menu/arduino-menus';
|
import {
|
||||||
import { BoardsService, InstalledBoardWithPackage, AvailablePorts, Port } from '../../common/protocol';
|
ArduinoMenus,
|
||||||
|
PlaceholderMenuNode,
|
||||||
|
unregisterSubmenu,
|
||||||
|
} from '../menu/arduino-menus';
|
||||||
|
import {
|
||||||
|
BoardsService,
|
||||||
|
InstalledBoardWithPackage,
|
||||||
|
AvailablePorts,
|
||||||
|
Port,
|
||||||
|
} from '../../common/protocol';
|
||||||
import { SketchContribution, Command, CommandRegistry } from './contribution';
|
import { SketchContribution, Command, CommandRegistry } from './contribution';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class BoardSelection extends SketchContribution {
|
export class BoardSelection extends SketchContribution {
|
||||||
|
@inject(CommandRegistry)
|
||||||
|
protected readonly commandRegistry: CommandRegistry;
|
||||||
|
|
||||||
@inject(CommandRegistry)
|
@inject(MainMenuManager)
|
||||||
protected readonly commandRegistry: CommandRegistry;
|
protected readonly mainMenuManager: MainMenuManager;
|
||||||
|
|
||||||
@inject(MainMenuManager)
|
@inject(MenuModelRegistry)
|
||||||
protected readonly mainMenuManager: MainMenuManager;
|
protected readonly menuModelRegistry: MenuModelRegistry;
|
||||||
|
|
||||||
@inject(MenuModelRegistry)
|
@inject(NotificationCenter)
|
||||||
protected readonly menuModelRegistry: MenuModelRegistry;
|
protected readonly notificationCenter: NotificationCenter;
|
||||||
|
|
||||||
@inject(NotificationCenter)
|
@inject(BoardsService)
|
||||||
protected readonly notificationCenter: NotificationCenter;
|
protected readonly boardsService: BoardsService;
|
||||||
|
|
||||||
@inject(BoardsService)
|
@inject(BoardsServiceProvider)
|
||||||
protected readonly boardsService: BoardsService;
|
protected readonly boardsServiceProvider: BoardsServiceProvider;
|
||||||
|
|
||||||
@inject(BoardsServiceProvider)
|
protected readonly toDisposeBeforeMenuRebuild = new DisposableCollection();
|
||||||
protected readonly boardsServiceProvider: BoardsServiceProvider;
|
|
||||||
|
|
||||||
protected readonly toDisposeBeforeMenuRebuild = new DisposableCollection();
|
registerCommands(registry: CommandRegistry): void {
|
||||||
|
registry.registerCommand(BoardSelection.Commands.GET_BOARD_INFO, {
|
||||||
registerCommands(registry: CommandRegistry): void {
|
execute: async () => {
|
||||||
registry.registerCommand(BoardSelection.Commands.GET_BOARD_INFO, {
|
const { selectedBoard, selectedPort } =
|
||||||
execute: async () => {
|
this.boardsServiceProvider.boardsConfig;
|
||||||
const { selectedBoard, selectedPort } = this.boardsServiceProvider.boardsConfig;
|
if (!selectedBoard) {
|
||||||
if (!selectedBoard) {
|
this.messageService.info(
|
||||||
this.messageService.info('Please select a board to obtain board info.');
|
'Please select a board to obtain board info.'
|
||||||
return;
|
);
|
||||||
}
|
return;
|
||||||
if (!selectedBoard.fqbn) {
|
}
|
||||||
this.messageService.info(`The platform for the selected '${selectedBoard.name}' board is not installed.`);
|
if (!selectedBoard.fqbn) {
|
||||||
return;
|
this.messageService.info(
|
||||||
}
|
`The platform for the selected '${selectedBoard.name}' board is not installed.`
|
||||||
if (!selectedPort) {
|
);
|
||||||
this.messageService.info('Please select a port to obtain board info.');
|
return;
|
||||||
return;
|
}
|
||||||
}
|
if (!selectedPort) {
|
||||||
const boardDetails = await this.boardsService.getBoardDetails({ fqbn: selectedBoard.fqbn });
|
this.messageService.info(
|
||||||
if (boardDetails) {
|
'Please select a port to obtain board info.'
|
||||||
const { VID, PID } = boardDetails;
|
);
|
||||||
const detail = `BN: ${selectedBoard.name}
|
return;
|
||||||
|
}
|
||||||
|
const boardDetails = await this.boardsService.getBoardDetails({
|
||||||
|
fqbn: selectedBoard.fqbn,
|
||||||
|
});
|
||||||
|
if (boardDetails) {
|
||||||
|
const { VID, PID } = boardDetails;
|
||||||
|
const detail = `BN: ${selectedBoard.name}
|
||||||
VID: ${VID}
|
VID: ${VID}
|
||||||
PID: ${PID}`;
|
PID: ${PID}`;
|
||||||
await remote.dialog.showMessageBox(remote.getCurrentWindow(), {
|
await remote.dialog.showMessageBox(remote.getCurrentWindow(), {
|
||||||
message: 'Board Info',
|
message: 'Board Info',
|
||||||
title: 'Board Info',
|
title: 'Board Info',
|
||||||
type: 'info',
|
type: 'info',
|
||||||
detail,
|
detail,
|
||||||
buttons: ['OK']
|
buttons: ['OK'],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onStart(): void {
|
||||||
|
this.updateMenus();
|
||||||
|
this.notificationCenter.onPlatformInstalled(this.updateMenus.bind(this));
|
||||||
|
this.notificationCenter.onPlatformUninstalled(this.updateMenus.bind(this));
|
||||||
|
this.boardsServiceProvider.onBoardsConfigChanged(
|
||||||
|
this.updateMenus.bind(this)
|
||||||
|
);
|
||||||
|
this.boardsServiceProvider.onAvailableBoardsChanged(
|
||||||
|
this.updateMenus.bind(this)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async updateMenus(): Promise<void> {
|
||||||
|
const [installedBoards, availablePorts, config] = await Promise.all([
|
||||||
|
this.installedBoards(),
|
||||||
|
this.boardsService.getState(),
|
||||||
|
this.boardsServiceProvider.boardsConfig,
|
||||||
|
]);
|
||||||
|
this.rebuildMenus(installedBoards, availablePorts, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected rebuildMenus(
|
||||||
|
installedBoards: InstalledBoardWithPackage[],
|
||||||
|
availablePorts: AvailablePorts,
|
||||||
|
config: BoardsConfig.Config
|
||||||
|
): void {
|
||||||
|
this.toDisposeBeforeMenuRebuild.dispose();
|
||||||
|
|
||||||
|
// Boards submenu
|
||||||
|
const boardsSubmenuPath = [
|
||||||
|
...ArduinoMenus.TOOLS__BOARD_SELECTION_GROUP,
|
||||||
|
'1_boards',
|
||||||
|
];
|
||||||
|
const boardsSubmenuLabel = config.selectedBoard?.name;
|
||||||
|
// Note: The submenu order starts from `100` because `Auto Format`, `Serial Monitor`, etc starts from `0` index.
|
||||||
|
// The board specific items, and the rest, have order with `z`. We needed something between `0` and `z` with natural-order.
|
||||||
|
this.menuModelRegistry.registerSubmenu(
|
||||||
|
boardsSubmenuPath,
|
||||||
|
`Board${!!boardsSubmenuLabel ? `: "${boardsSubmenuLabel}"` : ''}`,
|
||||||
|
{ order: '100' }
|
||||||
|
);
|
||||||
|
this.toDisposeBeforeMenuRebuild.push(
|
||||||
|
Disposable.create(() =>
|
||||||
|
unregisterSubmenu(boardsSubmenuPath, this.menuModelRegistry)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Ports submenu
|
||||||
|
const portsSubmenuPath = [
|
||||||
|
...ArduinoMenus.TOOLS__BOARD_SELECTION_GROUP,
|
||||||
|
'2_ports',
|
||||||
|
];
|
||||||
|
const portsSubmenuLabel = config.selectedPort?.address;
|
||||||
|
this.menuModelRegistry.registerSubmenu(
|
||||||
|
portsSubmenuPath,
|
||||||
|
`Port${!!portsSubmenuLabel ? `: "${portsSubmenuLabel}"` : ''}`,
|
||||||
|
{ order: '101' }
|
||||||
|
);
|
||||||
|
this.toDisposeBeforeMenuRebuild.push(
|
||||||
|
Disposable.create(() =>
|
||||||
|
unregisterSubmenu(portsSubmenuPath, this.menuModelRegistry)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
const getBoardInfo = {
|
||||||
|
commandId: BoardSelection.Commands.GET_BOARD_INFO.id,
|
||||||
|
label: 'Get Board Info',
|
||||||
|
order: '103',
|
||||||
|
};
|
||||||
|
this.menuModelRegistry.registerMenuAction(
|
||||||
|
ArduinoMenus.TOOLS__BOARD_SELECTION_GROUP,
|
||||||
|
getBoardInfo
|
||||||
|
);
|
||||||
|
this.toDisposeBeforeMenuRebuild.push(
|
||||||
|
Disposable.create(() =>
|
||||||
|
this.menuModelRegistry.unregisterMenuAction(getBoardInfo)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
const boardsManagerGroup = [...boardsSubmenuPath, '0_manager'];
|
||||||
|
const boardsPackagesGroup = [...boardsSubmenuPath, '1_packages'];
|
||||||
|
|
||||||
|
this.menuModelRegistry.registerMenuAction(boardsManagerGroup, {
|
||||||
|
commandId: `${BoardsListWidget.WIDGET_ID}:toggle`,
|
||||||
|
label: 'Boards Manager...',
|
||||||
|
});
|
||||||
|
|
||||||
|
// Installed boards
|
||||||
|
for (const board of installedBoards) {
|
||||||
|
const { packageId, packageName, fqbn, name, manuallyInstalled } = board;
|
||||||
|
|
||||||
|
const packageLabel =
|
||||||
|
packageName + `${manuallyInstalled ? ' (in Sketchbook)' : ''}`;
|
||||||
|
// Platform submenu
|
||||||
|
const platformMenuPath = [...boardsPackagesGroup, packageId];
|
||||||
|
// Note: Registering the same submenu twice is a noop. No need to group the boards per platform.
|
||||||
|
this.menuModelRegistry.registerSubmenu(platformMenuPath, packageLabel);
|
||||||
|
|
||||||
|
const id = `arduino-select-board--${fqbn}`;
|
||||||
|
const command = { id };
|
||||||
|
const handler = {
|
||||||
|
execute: () => {
|
||||||
|
if (
|
||||||
|
fqbn !== this.boardsServiceProvider.boardsConfig.selectedBoard?.fqbn
|
||||||
|
) {
|
||||||
|
this.boardsServiceProvider.boardsConfig = {
|
||||||
|
selectedBoard: {
|
||||||
|
name,
|
||||||
|
fqbn,
|
||||||
|
port: this.boardsServiceProvider.boardsConfig.selectedBoard
|
||||||
|
?.port, // TODO: verify!
|
||||||
|
},
|
||||||
|
selectedPort:
|
||||||
|
this.boardsServiceProvider.boardsConfig.selectedPort,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
isToggled: () =>
|
||||||
|
fqbn === this.boardsServiceProvider.boardsConfig.selectedBoard?.fqbn,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Board menu
|
||||||
|
const menuAction = { commandId: id, label: name };
|
||||||
|
this.commandRegistry.registerCommand(command, handler);
|
||||||
|
this.toDisposeBeforeMenuRebuild.push(
|
||||||
|
Disposable.create(() => this.commandRegistry.unregisterCommand(command))
|
||||||
|
);
|
||||||
|
this.menuModelRegistry.registerMenuAction(platformMenuPath, menuAction);
|
||||||
|
// Note: we do not dispose the menu actions individually. Calling `unregisterSubmenu` on the parent will wipe the children menu nodes recursively.
|
||||||
}
|
}
|
||||||
|
|
||||||
onStart(): void {
|
// Installed ports
|
||||||
this.updateMenus();
|
const registerPorts = (ports: AvailablePorts) => {
|
||||||
this.notificationCenter.onPlatformInstalled(this.updateMenus.bind(this));
|
const addresses = Object.keys(ports);
|
||||||
this.notificationCenter.onPlatformUninstalled(this.updateMenus.bind(this));
|
if (!addresses.length) {
|
||||||
this.boardsServiceProvider.onBoardsConfigChanged(this.updateMenus.bind(this));
|
return;
|
||||||
this.boardsServiceProvider.onAvailableBoardsChanged(this.updateMenus.bind(this));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected async updateMenus(): Promise<void> {
|
// Register placeholder for protocol
|
||||||
const [installedBoards, availablePorts, config] = await Promise.all([
|
const [port] = ports[addresses[0]];
|
||||||
this.installedBoards(),
|
const protocol = port.protocol;
|
||||||
this.boardsService.getState(),
|
const menuPath = [...portsSubmenuPath, protocol];
|
||||||
this.boardsServiceProvider.boardsConfig
|
const placeholder = new PlaceholderMenuNode(
|
||||||
]);
|
menuPath,
|
||||||
this.rebuildMenus(installedBoards, availablePorts, config);
|
`${firstToUpperCase(port.protocol)} ports`
|
||||||
}
|
);
|
||||||
|
this.menuModelRegistry.registerMenuNode(menuPath, placeholder);
|
||||||
|
this.toDisposeBeforeMenuRebuild.push(
|
||||||
|
Disposable.create(() =>
|
||||||
|
this.menuModelRegistry.unregisterMenuNode(placeholder.id)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
protected rebuildMenus(installedBoards: InstalledBoardWithPackage[], availablePorts: AvailablePorts, config: BoardsConfig.Config): void {
|
for (const address of addresses) {
|
||||||
this.toDisposeBeforeMenuRebuild.dispose();
|
if (!!ports[address]) {
|
||||||
|
const [port, boards] = ports[address];
|
||||||
// Boards submenu
|
if (!boards.length) {
|
||||||
const boardsSubmenuPath = [...ArduinoMenus.TOOLS__BOARD_SELECTION_GROUP, '1_boards'];
|
boards.push({
|
||||||
const boardsSubmenuLabel = config.selectedBoard?.name;
|
name: '',
|
||||||
// Note: The submenu order starts from `100` because `Auto Format`, `Serial Monitor`, etc starts from `0` index.
|
});
|
||||||
// The board specific items, and the rest, have order with `z`. We needed something between `0` and `z` with natural-order.
|
}
|
||||||
this.menuModelRegistry.registerSubmenu(boardsSubmenuPath, `Board${!!boardsSubmenuLabel ? `: "${boardsSubmenuLabel}"` : ''}`, { order: '100' });
|
for (const { name, fqbn } of boards) {
|
||||||
this.toDisposeBeforeMenuRebuild.push(Disposable.create(() => unregisterSubmenu(boardsSubmenuPath, this.menuModelRegistry)));
|
const id = `arduino-select-port--${address}${
|
||||||
|
fqbn ? `--${fqbn}` : ''
|
||||||
// Ports submenu
|
}`;
|
||||||
const portsSubmenuPath = [...ArduinoMenus.TOOLS__BOARD_SELECTION_GROUP, '2_ports'];
|
|
||||||
const portsSubmenuLabel = config.selectedPort?.address;
|
|
||||||
this.menuModelRegistry.registerSubmenu(portsSubmenuPath, `Port${!!portsSubmenuLabel ? `: "${portsSubmenuLabel}"` : ''}`, { order: '101' });
|
|
||||||
this.toDisposeBeforeMenuRebuild.push(Disposable.create(() => unregisterSubmenu(portsSubmenuPath, this.menuModelRegistry)));
|
|
||||||
|
|
||||||
const getBoardInfo = { commandId: BoardSelection.Commands.GET_BOARD_INFO.id, label: 'Get Board Info', order: '103' };
|
|
||||||
this.menuModelRegistry.registerMenuAction(ArduinoMenus.TOOLS__BOARD_SELECTION_GROUP, getBoardInfo);
|
|
||||||
this.toDisposeBeforeMenuRebuild.push(Disposable.create(() => this.menuModelRegistry.unregisterMenuAction(getBoardInfo)));
|
|
||||||
|
|
||||||
const boardsManagerGroup = [...boardsSubmenuPath, '0_manager'];
|
|
||||||
const boardsPackagesGroup = [...boardsSubmenuPath, '1_packages'];
|
|
||||||
|
|
||||||
this.menuModelRegistry.registerMenuAction(boardsManagerGroup, {
|
|
||||||
commandId: `${BoardsListWidget.WIDGET_ID}:toggle`,
|
|
||||||
label: 'Boards Manager...'
|
|
||||||
});
|
|
||||||
|
|
||||||
// Installed boards
|
|
||||||
for (const board of installedBoards) {
|
|
||||||
const { packageId, packageName, fqbn, name } = board;
|
|
||||||
|
|
||||||
// Platform submenu
|
|
||||||
const platformMenuPath = [...boardsPackagesGroup, packageId];
|
|
||||||
// Note: Registering the same submenu twice is a noop. No need to group the boards per platform.
|
|
||||||
this.menuModelRegistry.registerSubmenu(platformMenuPath, packageName);
|
|
||||||
|
|
||||||
const id = `arduino-select-board--${fqbn}`;
|
|
||||||
const command = { id };
|
const command = { id };
|
||||||
const handler = {
|
const handler = {
|
||||||
execute: () => {
|
execute: () => {
|
||||||
if (fqbn !== this.boardsServiceProvider.boardsConfig.selectedBoard?.fqbn) {
|
if (
|
||||||
this.boardsServiceProvider.boardsConfig = {
|
!Port.equals(
|
||||||
selectedBoard: {
|
port,
|
||||||
name,
|
this.boardsServiceProvider.boardsConfig.selectedPort
|
||||||
fqbn,
|
)
|
||||||
port: this.boardsServiceProvider.boardsConfig.selectedBoard?.port // TODO: verify!
|
) {
|
||||||
},
|
this.boardsServiceProvider.boardsConfig = {
|
||||||
selectedPort: this.boardsServiceProvider.boardsConfig.selectedPort
|
selectedBoard:
|
||||||
}
|
this.boardsServiceProvider.boardsConfig.selectedBoard,
|
||||||
}
|
selectedPort: port,
|
||||||
},
|
};
|
||||||
isToggled: () => fqbn === this.boardsServiceProvider.boardsConfig.selectedBoard?.fqbn
|
|
||||||
};
|
|
||||||
|
|
||||||
// Board menu
|
|
||||||
const menuAction = { commandId: id, label: name };
|
|
||||||
this.commandRegistry.registerCommand(command, handler);
|
|
||||||
this.toDisposeBeforeMenuRebuild.push(Disposable.create(() => this.commandRegistry.unregisterCommand(command)));
|
|
||||||
this.menuModelRegistry.registerMenuAction(platformMenuPath, menuAction);
|
|
||||||
// Note: we do not dispose the menu actions individually. Calling `unregisterSubmenu` on the parent will wipe the children menu nodes recursively.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Installed ports
|
|
||||||
const registerPorts = (ports: AvailablePorts) => {
|
|
||||||
const addresses = Object.keys(ports);
|
|
||||||
if (!addresses.length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register placeholder for protocol
|
|
||||||
const [port] = ports[addresses[0]];
|
|
||||||
const protocol = port.protocol;
|
|
||||||
const menuPath = [...portsSubmenuPath, protocol];
|
|
||||||
const placeholder = new PlaceholderMenuNode(menuPath, `${firstToUpperCase(port.protocol)} ports`);
|
|
||||||
this.menuModelRegistry.registerMenuNode(menuPath, placeholder);
|
|
||||||
this.toDisposeBeforeMenuRebuild.push(Disposable.create(() => this.menuModelRegistry.unregisterMenuNode(placeholder.id)));
|
|
||||||
|
|
||||||
for (const address of addresses) {
|
|
||||||
if (!!ports[address]) {
|
|
||||||
const [port, boards] = ports[address];
|
|
||||||
if (!boards.length) {
|
|
||||||
boards.push({
|
|
||||||
name: ''
|
|
||||||
});
|
|
||||||
}
|
|
||||||
for (const { name, fqbn } of boards) {
|
|
||||||
const id = `arduino-select-port--${address}${fqbn ? `--${fqbn}` : ''}`;
|
|
||||||
const command = { id };
|
|
||||||
const handler = {
|
|
||||||
execute: () => {
|
|
||||||
if (!Port.equals(port, this.boardsServiceProvider.boardsConfig.selectedPort)) {
|
|
||||||
this.boardsServiceProvider.boardsConfig = {
|
|
||||||
selectedBoard: this.boardsServiceProvider.boardsConfig.selectedBoard,
|
|
||||||
selectedPort: port
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
isToggled: () => Port.equals(port, this.boardsServiceProvider.boardsConfig.selectedPort)
|
|
||||||
};
|
|
||||||
const label = `${address}${name ? ` (${name})` : ''}`;
|
|
||||||
const menuAction = {
|
|
||||||
commandId: id,
|
|
||||||
label,
|
|
||||||
order: `1${label}` // `1` comes after the placeholder which has order `0`
|
|
||||||
};
|
|
||||||
this.commandRegistry.registerCommand(command, handler);
|
|
||||||
this.toDisposeBeforeMenuRebuild.push(Disposable.create(() => this.commandRegistry.unregisterCommand(command)));
|
|
||||||
this.menuModelRegistry.registerMenuAction(menuPath, menuAction);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
isToggled: () =>
|
||||||
|
Port.equals(
|
||||||
|
port,
|
||||||
|
this.boardsServiceProvider.boardsConfig.selectedPort
|
||||||
|
),
|
||||||
|
};
|
||||||
|
const label = `${address}${name ? ` (${name})` : ''}`;
|
||||||
|
const menuAction = {
|
||||||
|
commandId: id,
|
||||||
|
label,
|
||||||
|
order: `1${label}`, // `1` comes after the placeholder which has order `0`
|
||||||
|
};
|
||||||
|
this.commandRegistry.registerCommand(command, handler);
|
||||||
|
this.toDisposeBeforeMenuRebuild.push(
|
||||||
|
Disposable.create(() =>
|
||||||
|
this.commandRegistry.unregisterCommand(command)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
this.menuModelRegistry.registerMenuAction(menuPath, menuAction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const { serial, network, unknown } = AvailablePorts.groupByProtocol(availablePorts);
|
const { serial, network, unknown } =
|
||||||
registerPorts(serial);
|
AvailablePorts.groupByProtocol(availablePorts);
|
||||||
registerPorts(network);
|
registerPorts(serial);
|
||||||
registerPorts(unknown);
|
registerPorts(network);
|
||||||
|
registerPorts(unknown);
|
||||||
|
|
||||||
this.mainMenuManager.update();
|
this.mainMenuManager.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async installedBoards(): Promise<InstalledBoardWithPackage[]> {
|
|
||||||
const allBoards = await this.boardsService.allBoards({});
|
|
||||||
return allBoards.filter(InstalledBoardWithPackage.is);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
protected async installedBoards(): Promise<InstalledBoardWithPackage[]> {
|
||||||
|
const allBoards = await this.boardsService.searchBoards({});
|
||||||
|
return allBoards.filter(InstalledBoardWithPackage.is);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
export namespace BoardSelection {
|
export namespace BoardSelection {
|
||||||
export namespace Commands {
|
export namespace Commands {
|
||||||
export const GET_BOARD_INFO: Command = { id: 'arduino-get-board-info' };
|
export const GET_BOARD_INFO: Command = { id: 'arduino-get-board-info' };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,78 +5,86 @@ import { ArduinoMenus } from '../menu/arduino-menus';
|
|||||||
import { BoardsDataStore } from '../boards/boards-data-store';
|
import { BoardsDataStore } from '../boards/boards-data-store';
|
||||||
import { MonitorConnection } from '../monitor/monitor-connection';
|
import { MonitorConnection } from '../monitor/monitor-connection';
|
||||||
import { BoardsServiceProvider } from '../boards/boards-service-provider';
|
import { BoardsServiceProvider } from '../boards/boards-service-provider';
|
||||||
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry } from './contribution';
|
import {
|
||||||
|
SketchContribution,
|
||||||
|
Command,
|
||||||
|
CommandRegistry,
|
||||||
|
MenuModelRegistry,
|
||||||
|
} from './contribution';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class BurnBootloader extends SketchContribution {
|
export class BurnBootloader extends SketchContribution {
|
||||||
|
@inject(CoreService)
|
||||||
|
protected readonly coreService: CoreService;
|
||||||
|
|
||||||
@inject(CoreService)
|
@inject(MonitorConnection)
|
||||||
protected readonly coreService: CoreService;
|
protected readonly monitorConnection: MonitorConnection;
|
||||||
|
|
||||||
@inject(MonitorConnection)
|
@inject(BoardsDataStore)
|
||||||
protected readonly monitorConnection: MonitorConnection;
|
protected readonly boardsDataStore: BoardsDataStore;
|
||||||
|
|
||||||
@inject(BoardsDataStore)
|
@inject(BoardsServiceProvider)
|
||||||
protected readonly boardsDataStore: BoardsDataStore;
|
protected readonly boardsServiceClientImpl: BoardsServiceProvider;
|
||||||
|
|
||||||
@inject(BoardsServiceProvider)
|
@inject(OutputChannelManager)
|
||||||
protected readonly boardsServiceClientImpl: BoardsServiceProvider;
|
protected readonly outputChannelManager: OutputChannelManager;
|
||||||
|
|
||||||
@inject(OutputChannelManager)
|
registerCommands(registry: CommandRegistry): void {
|
||||||
protected readonly outputChannelManager: OutputChannelManager;
|
registry.registerCommand(BurnBootloader.Commands.BURN_BOOTLOADER, {
|
||||||
|
execute: () => this.burnBootloader(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
registerCommands(registry: CommandRegistry): void {
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
registry.registerCommand(BurnBootloader.Commands.BURN_BOOTLOADER, {
|
registry.registerMenuAction(ArduinoMenus.TOOLS__BOARD_SETTINGS_GROUP, {
|
||||||
execute: () => this.burnBootloader()
|
commandId: BurnBootloader.Commands.BURN_BOOTLOADER.id,
|
||||||
});
|
label: 'Burn Bootloader',
|
||||||
|
order: 'z99',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async burnBootloader(): Promise<void> {
|
||||||
|
const monitorConfig = this.monitorConnection.monitorConfig;
|
||||||
|
if (monitorConfig) {
|
||||||
|
await this.monitorConnection.disconnect();
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
const { boardsConfig } = this.boardsServiceClientImpl;
|
||||||
registry.registerMenuAction(ArduinoMenus.TOOLS__BOARD_SETTINGS_GROUP, {
|
const port = boardsConfig.selectedPort?.address;
|
||||||
commandId: BurnBootloader.Commands.BURN_BOOTLOADER.id,
|
const [fqbn, { selectedProgrammer: programmer }, verify, verbose] =
|
||||||
label: 'Burn Bootloader',
|
await Promise.all([
|
||||||
order: 'z99'
|
this.boardsDataStore.appendConfigToFqbn(
|
||||||
});
|
boardsConfig.selectedBoard?.fqbn
|
||||||
|
),
|
||||||
|
this.boardsDataStore.getData(boardsConfig.selectedBoard?.fqbn),
|
||||||
|
this.preferences.get('arduino.upload.verify'),
|
||||||
|
this.preferences.get('arduino.upload.verbose'),
|
||||||
|
]);
|
||||||
|
this.outputChannelManager.getChannel('Arduino').clear();
|
||||||
|
await this.coreService.burnBootloader({
|
||||||
|
fqbn,
|
||||||
|
programmer,
|
||||||
|
port,
|
||||||
|
verify,
|
||||||
|
verbose,
|
||||||
|
});
|
||||||
|
this.messageService.info('Done burning bootloader.', {
|
||||||
|
timeout: 3000,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
this.messageService.error(e.toString());
|
||||||
|
} finally {
|
||||||
|
if (monitorConfig) {
|
||||||
|
await this.monitorConnection.connect(monitorConfig);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
async burnBootloader(): Promise<void> {
|
|
||||||
const monitorConfig = this.monitorConnection.monitorConfig;
|
|
||||||
if (monitorConfig) {
|
|
||||||
await this.monitorConnection.disconnect();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const { boardsConfig } = this.boardsServiceClientImpl;
|
|
||||||
const port = boardsConfig.selectedPort?.address;
|
|
||||||
const [fqbn, { selectedProgrammer: programmer }, verify, verbose] = await Promise.all([
|
|
||||||
this.boardsDataStore.appendConfigToFqbn(boardsConfig.selectedBoard?.fqbn),
|
|
||||||
this.boardsDataStore.getData(boardsConfig.selectedBoard?.fqbn),
|
|
||||||
this.preferences.get('arduino.upload.verify'),
|
|
||||||
this.preferences.get('arduino.upload.verbose')
|
|
||||||
]);
|
|
||||||
this.outputChannelManager.getChannel('Arduino').clear();
|
|
||||||
await this.coreService.burnBootloader({
|
|
||||||
fqbn,
|
|
||||||
programmer,
|
|
||||||
port,
|
|
||||||
verify,
|
|
||||||
verbose
|
|
||||||
});
|
|
||||||
this.messageService.info('Done burning bootloader.', { timeout: 1000 });
|
|
||||||
} catch (e) {
|
|
||||||
this.messageService.error(e.toString());
|
|
||||||
} finally {
|
|
||||||
if (monitorConfig) {
|
|
||||||
await this.monitorConnection.connect(monitorConfig);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace BurnBootloader {
|
export namespace BurnBootloader {
|
||||||
export namespace Commands {
|
export namespace Commands {
|
||||||
export const BURN_BOOTLOADER: Command = {
|
export const BURN_BOOTLOADER: Command = {
|
||||||
id: 'arduino-burn-bootloader'
|
id: 'arduino-burn-bootloader',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,113 +7,126 @@ import { ApplicationShell } from '@theia/core/lib/browser/shell/application-shel
|
|||||||
import { FrontendApplication } from '@theia/core/lib/browser/frontend-application';
|
import { FrontendApplication } from '@theia/core/lib/browser/frontend-application';
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
import { SaveAsSketch } from './save-as-sketch';
|
import { SaveAsSketch } from './save-as-sketch';
|
||||||
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, URI } from './contribution';
|
import {
|
||||||
|
SketchContribution,
|
||||||
|
Command,
|
||||||
|
CommandRegistry,
|
||||||
|
MenuModelRegistry,
|
||||||
|
KeybindingRegistry,
|
||||||
|
URI,
|
||||||
|
} from './contribution';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the `current` closeable editor, or any closeable current widget from the main area, or the current sketch window.
|
* Closes the `current` closeable editor, or any closeable current widget from the main area, or the current sketch window.
|
||||||
*/
|
*/
|
||||||
@injectable()
|
@injectable()
|
||||||
export class Close extends SketchContribution {
|
export class Close extends SketchContribution {
|
||||||
|
@inject(EditorManager)
|
||||||
|
protected readonly editorManager: EditorManager;
|
||||||
|
|
||||||
@inject(EditorManager)
|
protected shell: ApplicationShell;
|
||||||
protected readonly editorManager: EditorManager;
|
|
||||||
|
|
||||||
protected shell: ApplicationShell;
|
onStart(app: FrontendApplication): void {
|
||||||
|
this.shell = app.shell;
|
||||||
|
}
|
||||||
|
|
||||||
onStart(app: FrontendApplication): void {
|
registerCommands(registry: CommandRegistry): void {
|
||||||
this.shell = app.shell;
|
registry.registerCommand(Close.Commands.CLOSE, {
|
||||||
}
|
execute: async () => {
|
||||||
|
// Close current editor if closeable.
|
||||||
registerCommands(registry: CommandRegistry): void {
|
const { currentEditor } = this.editorManager;
|
||||||
registry.registerCommand(Close.Commands.CLOSE, {
|
if (currentEditor && currentEditor.title.closable) {
|
||||||
execute: async () => {
|
currentEditor.close();
|
||||||
|
return;
|
||||||
// Close current editor if closeable.
|
|
||||||
const { currentEditor } = this.editorManager;
|
|
||||||
if (currentEditor && currentEditor.title.closable) {
|
|
||||||
currentEditor.close();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close current widget from the main area if possible.
|
|
||||||
const { currentWidget } = this.shell;
|
|
||||||
if (currentWidget) {
|
|
||||||
const currentWidgetInMain = toArray(this.shell.mainPanel.widgets()).find(widget => widget === currentWidget);
|
|
||||||
if (currentWidgetInMain && currentWidgetInMain.title.closable) {
|
|
||||||
return currentWidgetInMain.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close the sketch (window).
|
|
||||||
const sketch = await this.sketchServiceClient.currentSketch();
|
|
||||||
if (!sketch) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const isTemp = await this.sketchService.isTemp(sketch);
|
|
||||||
const uri = await this.sketchServiceClient.currentSketchFile();
|
|
||||||
if (!uri) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (isTemp && await this.wasTouched(uri)) {
|
|
||||||
const { response } = await remote.dialog.showMessageBox({
|
|
||||||
type: 'question',
|
|
||||||
buttons: ["Don't Save", 'Cancel', 'Save'],
|
|
||||||
message: 'Do you want to save changes to this sketch before closing?',
|
|
||||||
detail: "If you don't save, your changes will be lost."
|
|
||||||
});
|
|
||||||
if (response === 1) { // Cancel
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (response === 2) { // Save
|
|
||||||
const saved = await this.commandService.executeCommand(SaveAsSketch.Commands.SAVE_AS_SKETCH.id, { openAfterMove: false, execOnlyIfTemp: true });
|
|
||||||
if (!saved) { // If it was not saved, do bail the close.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
window.close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
|
||||||
registry.registerMenuAction(ArduinoMenus.FILE__SKETCH_GROUP, {
|
|
||||||
commandId: Close.Commands.CLOSE.id,
|
|
||||||
label: 'Close',
|
|
||||||
order: '5'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
registerKeybindings(registry: KeybindingRegistry): void {
|
|
||||||
registry.registerKeybinding({
|
|
||||||
command: Close.Commands.CLOSE.id,
|
|
||||||
keybinding: 'CtrlCmd+W'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If the file was ever touched/modified. We get this based on the `version` of the monaco model.
|
|
||||||
*/
|
|
||||||
protected async wasTouched(uri: string): Promise<boolean> {
|
|
||||||
const editorWidget = await this.editorManager.getByUri(new URI(uri));
|
|
||||||
if (editorWidget) {
|
|
||||||
const { editor } = editorWidget;
|
|
||||||
if (editor instanceof MonacoEditor) {
|
|
||||||
const versionId = editor.getControl().getModel()?.getVersionId();
|
|
||||||
if (Number.isInteger(versionId) && versionId! > 1) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Close current widget from the main area if possible.
|
||||||
|
const { currentWidget } = this.shell;
|
||||||
|
if (currentWidget) {
|
||||||
|
const currentWidgetInMain = toArray(
|
||||||
|
this.shell.mainPanel.widgets()
|
||||||
|
).find((widget) => widget === currentWidget);
|
||||||
|
if (currentWidgetInMain && currentWidgetInMain.title.closable) {
|
||||||
|
return currentWidgetInMain.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close the sketch (window).
|
||||||
|
const sketch = await this.sketchServiceClient.currentSketch();
|
||||||
|
if (!sketch) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const isTemp = await this.sketchService.isTemp(sketch);
|
||||||
|
const uri = await this.sketchServiceClient.currentSketchFile();
|
||||||
|
if (!uri) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isTemp && (await this.wasTouched(uri))) {
|
||||||
|
const { response } = await remote.dialog.showMessageBox({
|
||||||
|
type: 'question',
|
||||||
|
buttons: ["Don't Save", 'Cancel', 'Save'],
|
||||||
|
message:
|
||||||
|
'Do you want to save changes to this sketch before closing?',
|
||||||
|
detail: "If you don't save, your changes will be lost.",
|
||||||
|
});
|
||||||
|
if (response === 1) {
|
||||||
|
// Cancel
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (response === 2) {
|
||||||
|
// Save
|
||||||
|
const saved = await this.commandService.executeCommand(
|
||||||
|
SaveAsSketch.Commands.SAVE_AS_SKETCH.id,
|
||||||
|
{ openAfterMove: false, execOnlyIfTemp: true }
|
||||||
|
);
|
||||||
|
if (!saved) {
|
||||||
|
// If it was not saved, do bail the close.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.close();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
|
registry.registerMenuAction(ArduinoMenus.FILE__SKETCH_GROUP, {
|
||||||
|
commandId: Close.Commands.CLOSE.id,
|
||||||
|
label: 'Close',
|
||||||
|
order: '5',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerKeybindings(registry: KeybindingRegistry): void {
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: Close.Commands.CLOSE.id,
|
||||||
|
keybinding: 'CtrlCmd+W',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the file was ever touched/modified. We get this based on the `version` of the monaco model.
|
||||||
|
*/
|
||||||
|
protected async wasTouched(uri: string): Promise<boolean> {
|
||||||
|
const editorWidget = await this.editorManager.getByUri(new URI(uri));
|
||||||
|
if (editorWidget) {
|
||||||
|
const { editor } = editorWidget;
|
||||||
|
if (editor instanceof MonacoEditor) {
|
||||||
|
const versionId = editor.getControl().getModel()?.getVersionId();
|
||||||
|
if (Number.isInteger(versionId) && versionId! > 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace Close {
|
export namespace Close {
|
||||||
export namespace Commands {
|
export namespace Commands {
|
||||||
export const CLOSE: Command = {
|
export const CLOSE: Command = {
|
||||||
id: 'arduino-close'
|
id: 'arduino-close',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,110 +9,146 @@ import { EditorManager } from '@theia/editor/lib/browser/editor-manager';
|
|||||||
import { MessageService } from '@theia/core/lib/common/message-service';
|
import { MessageService } from '@theia/core/lib/common/message-service';
|
||||||
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
|
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
|
||||||
import { open, OpenerService } from '@theia/core/lib/browser/opener-service';
|
import { open, OpenerService } from '@theia/core/lib/browser/opener-service';
|
||||||
import { MenuModelRegistry, MenuContribution } from '@theia/core/lib/common/menu';
|
import { OutputChannelManager } from '@theia/output/lib/common/output-channel';
|
||||||
import { KeybindingRegistry, KeybindingContribution } from '@theia/core/lib/browser/keybinding';
|
import {
|
||||||
import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
|
MenuModelRegistry,
|
||||||
import { FrontendApplicationContribution, FrontendApplication } from '@theia/core/lib/browser/frontend-application';
|
MenuContribution,
|
||||||
import { Command, CommandRegistry, CommandContribution, CommandService } from '@theia/core/lib/common/command';
|
} from '@theia/core/lib/common/menu';
|
||||||
|
import {
|
||||||
|
KeybindingRegistry,
|
||||||
|
KeybindingContribution,
|
||||||
|
} from '@theia/core/lib/browser/keybinding';
|
||||||
|
import {
|
||||||
|
TabBarToolbarContribution,
|
||||||
|
TabBarToolbarRegistry,
|
||||||
|
} from '@theia/core/lib/browser/shell/tab-bar-toolbar';
|
||||||
|
import {
|
||||||
|
FrontendApplicationContribution,
|
||||||
|
FrontendApplication,
|
||||||
|
} from '@theia/core/lib/browser/frontend-application';
|
||||||
|
import {
|
||||||
|
Command,
|
||||||
|
CommandRegistry,
|
||||||
|
CommandContribution,
|
||||||
|
CommandService,
|
||||||
|
} from '@theia/core/lib/common/command';
|
||||||
import { EditorMode } from '../editor-mode';
|
import { EditorMode } from '../editor-mode';
|
||||||
import { SettingsService } from '../settings';
|
import { SettingsService } from '../settings';
|
||||||
import { SketchesServiceClientImpl } from '../../common/protocol/sketches-service-client-impl';
|
import { SketchesServiceClientImpl } from '../../common/protocol/sketches-service-client-impl';
|
||||||
import { SketchesService, ConfigService, FileSystemExt, Sketch } from '../../common/protocol';
|
import {
|
||||||
|
SketchesService,
|
||||||
|
ConfigService,
|
||||||
|
FileSystemExt,
|
||||||
|
Sketch,
|
||||||
|
} from '../../common/protocol';
|
||||||
import { ArduinoPreferences } from '../arduino-preferences';
|
import { ArduinoPreferences } from '../arduino-preferences';
|
||||||
|
|
||||||
export { Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, TabBarToolbarRegistry, URI, Sketch, open };
|
export {
|
||||||
|
Command,
|
||||||
|
CommandRegistry,
|
||||||
|
MenuModelRegistry,
|
||||||
|
KeybindingRegistry,
|
||||||
|
TabBarToolbarRegistry,
|
||||||
|
URI,
|
||||||
|
Sketch,
|
||||||
|
open,
|
||||||
|
};
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export abstract class Contribution implements CommandContribution, MenuContribution, KeybindingContribution, TabBarToolbarContribution, FrontendApplicationContribution {
|
export abstract class Contribution
|
||||||
|
implements
|
||||||
|
CommandContribution,
|
||||||
|
MenuContribution,
|
||||||
|
KeybindingContribution,
|
||||||
|
TabBarToolbarContribution,
|
||||||
|
FrontendApplicationContribution
|
||||||
|
{
|
||||||
|
@inject(ILogger)
|
||||||
|
protected readonly logger: ILogger;
|
||||||
|
|
||||||
@inject(ILogger)
|
@inject(MessageService)
|
||||||
protected readonly logger: ILogger;
|
protected readonly messageService: MessageService;
|
||||||
|
|
||||||
@inject(MessageService)
|
@inject(CommandService)
|
||||||
protected readonly messageService: MessageService;
|
protected readonly commandService: CommandService;
|
||||||
|
|
||||||
@inject(CommandService)
|
@inject(WorkspaceService)
|
||||||
protected readonly commandService: CommandService;
|
protected readonly workspaceService: WorkspaceService;
|
||||||
|
|
||||||
@inject(WorkspaceService)
|
@inject(EditorMode)
|
||||||
protected readonly workspaceService: WorkspaceService;
|
protected readonly editorMode: EditorMode;
|
||||||
|
|
||||||
@inject(EditorMode)
|
@inject(LabelProvider)
|
||||||
protected readonly editorMode: EditorMode;
|
protected readonly labelProvider: LabelProvider;
|
||||||
|
|
||||||
@inject(LabelProvider)
|
@inject(SettingsService)
|
||||||
protected readonly labelProvider: LabelProvider;
|
protected readonly settingsService: SettingsService;
|
||||||
|
|
||||||
@inject(SettingsService)
|
onStart(app: FrontendApplication): MaybePromise<void> {}
|
||||||
protected readonly settingsService: SettingsService;
|
|
||||||
|
|
||||||
onStart(app: FrontendApplication): MaybePromise<void> {
|
registerCommands(registry: CommandRegistry): void {}
|
||||||
}
|
|
||||||
|
|
||||||
registerCommands(registry: CommandRegistry): void {
|
registerMenus(registry: MenuModelRegistry): void {}
|
||||||
}
|
|
||||||
|
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
registerKeybindings(registry: KeybindingRegistry): void {}
|
||||||
}
|
|
||||||
|
|
||||||
registerKeybindings(registry: KeybindingRegistry): void {
|
|
||||||
}
|
|
||||||
|
|
||||||
registerToolbarItems(registry: TabBarToolbarRegistry): void {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
registerToolbarItems(registry: TabBarToolbarRegistry): void {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export abstract class SketchContribution extends Contribution {
|
export abstract class SketchContribution extends Contribution {
|
||||||
|
@inject(FileService)
|
||||||
|
protected readonly fileService: FileService;
|
||||||
|
|
||||||
@inject(FileService)
|
@inject(FileSystemExt)
|
||||||
protected readonly fileService: FileService;
|
protected readonly fileSystemExt: FileSystemExt;
|
||||||
|
|
||||||
@inject(FileSystemExt)
|
@inject(ConfigService)
|
||||||
protected readonly fileSystemExt: FileSystemExt;
|
protected readonly configService: ConfigService;
|
||||||
|
|
||||||
@inject(ConfigService)
|
@inject(SketchesService)
|
||||||
protected readonly configService: ConfigService;
|
protected readonly sketchService: SketchesService;
|
||||||
|
|
||||||
@inject(SketchesService)
|
@inject(OpenerService)
|
||||||
protected readonly sketchService: SketchesService;
|
protected readonly openerService: OpenerService;
|
||||||
|
|
||||||
@inject(OpenerService)
|
@inject(SketchesServiceClientImpl)
|
||||||
protected readonly openerService: OpenerService;
|
protected readonly sketchServiceClient: SketchesServiceClientImpl;
|
||||||
|
|
||||||
@inject(SketchesServiceClientImpl)
|
@inject(ArduinoPreferences)
|
||||||
protected readonly sketchServiceClient: SketchesServiceClientImpl;
|
protected readonly preferences: ArduinoPreferences;
|
||||||
|
|
||||||
@inject(ArduinoPreferences)
|
@inject(EditorManager)
|
||||||
protected readonly preferences: ArduinoPreferences;
|
protected readonly editorManager: EditorManager;
|
||||||
|
|
||||||
@inject(EditorManager)
|
@inject(OutputChannelManager)
|
||||||
protected readonly editorManager: EditorManager;
|
protected readonly outputChannelManager: OutputChannelManager;
|
||||||
|
|
||||||
protected async sourceOverride(): Promise<Record<string, string>> {
|
protected async sourceOverride(): Promise<Record<string, string>> {
|
||||||
const override: Record<string, string> = {};
|
const override: Record<string, string> = {};
|
||||||
const sketch = await this.sketchServiceClient.currentSketch();
|
const sketch = await this.sketchServiceClient.currentSketch();
|
||||||
if (sketch) {
|
if (sketch) {
|
||||||
for (const editor of this.editorManager.all) {
|
for (const editor of this.editorManager.all) {
|
||||||
const uri = editor.editor.uri;
|
const uri = editor.editor.uri;
|
||||||
if (Saveable.isDirty(editor) && Sketch.isInSketch(uri, sketch)) {
|
if (Saveable.isDirty(editor) && Sketch.isInSketch(uri, sketch)) {
|
||||||
override[uri.toString()] = editor.editor.document.getText();
|
override[uri.toString()] = editor.editor.document.getText();
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return override;
|
}
|
||||||
}
|
}
|
||||||
|
return override;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace Contribution {
|
export namespace Contribution {
|
||||||
export function configure<T>(bind: interfaces.Bind, serviceIdentifier: typeof Contribution): void {
|
export function configure<T>(
|
||||||
bind(serviceIdentifier).toSelf().inSingletonScope();
|
bind: interfaces.Bind,
|
||||||
bind(CommandContribution).toService(serviceIdentifier);
|
serviceIdentifier: typeof Contribution
|
||||||
bind(MenuContribution).toService(serviceIdentifier);
|
): void {
|
||||||
bind(KeybindingContribution).toService(serviceIdentifier);
|
bind(serviceIdentifier).toSelf().inSingletonScope();
|
||||||
bind(TabBarToolbarContribution).toService(serviceIdentifier);
|
bind(CommandContribution).toService(serviceIdentifier);
|
||||||
bind(FrontendApplicationContribution).toService(serviceIdentifier);
|
bind(MenuContribution).toService(serviceIdentifier);
|
||||||
}
|
bind(KeybindingContribution).toService(serviceIdentifier);
|
||||||
|
bind(TabBarToolbarContribution).toService(serviceIdentifier);
|
||||||
|
bind(FrontendApplicationContribution).toService(serviceIdentifier);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,130 +5,160 @@ import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
|
|||||||
import { NotificationCenter } from '../notification-center';
|
import { NotificationCenter } from '../notification-center';
|
||||||
import { Board, BoardsService, ExecutableService } from '../../common/protocol';
|
import { Board, BoardsService, ExecutableService } from '../../common/protocol';
|
||||||
import { BoardsServiceProvider } from '../boards/boards-service-provider';
|
import { BoardsServiceProvider } from '../boards/boards-service-provider';
|
||||||
import { URI, Command, CommandRegistry, SketchContribution, TabBarToolbarRegistry } from './contribution';
|
import {
|
||||||
|
URI,
|
||||||
|
Command,
|
||||||
|
CommandRegistry,
|
||||||
|
SketchContribution,
|
||||||
|
TabBarToolbarRegistry,
|
||||||
|
} from './contribution';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class Debug extends SketchContribution {
|
export class Debug extends SketchContribution {
|
||||||
|
@inject(HostedPluginSupport)
|
||||||
|
protected hostedPluginSupport: HostedPluginSupport;
|
||||||
|
|
||||||
@inject(HostedPluginSupport)
|
@inject(NotificationCenter)
|
||||||
protected hostedPluginSupport: HostedPluginSupport;
|
protected readonly notificationCenter: NotificationCenter;
|
||||||
|
|
||||||
@inject(NotificationCenter)
|
@inject(ExecutableService)
|
||||||
protected readonly notificationCenter: NotificationCenter;
|
protected readonly executableService: ExecutableService;
|
||||||
|
|
||||||
@inject(ExecutableService)
|
@inject(BoardsService)
|
||||||
protected readonly executableService: ExecutableService;
|
protected readonly boardService: BoardsService;
|
||||||
|
|
||||||
@inject(BoardsService)
|
@inject(BoardsServiceProvider)
|
||||||
protected readonly boardService: BoardsService;
|
protected readonly boardsServiceProvider: BoardsServiceProvider;
|
||||||
|
|
||||||
@inject(BoardsServiceProvider)
|
/**
|
||||||
protected readonly boardsServiceProvider: BoardsServiceProvider;
|
* If `undefined`, debugging is enabled. Otherwise, the reason why it's disabled.
|
||||||
|
*/
|
||||||
|
protected _disabledMessages?: string = 'No board selected'; // Initial pessimism.
|
||||||
|
protected disabledMessageDidChangeEmitter = new Emitter<string | undefined>();
|
||||||
|
protected onDisabledMessageDidChange =
|
||||||
|
this.disabledMessageDidChangeEmitter.event;
|
||||||
|
|
||||||
/**
|
protected get disabledMessage(): string | undefined {
|
||||||
* If `undefined`, debugging is enabled. Otherwise, the reason why it's disabled.
|
return this._disabledMessages;
|
||||||
*/
|
}
|
||||||
protected _disabledMessages?: string = 'No board selected'; // Initial pessimism.
|
protected set disabledMessage(message: string | undefined) {
|
||||||
protected disabledMessageDidChangeEmitter = new Emitter<string | undefined>();
|
this._disabledMessages = message;
|
||||||
protected onDisabledMessageDidChange = this.disabledMessageDidChangeEmitter.event;
|
this.disabledMessageDidChangeEmitter.fire(this._disabledMessages);
|
||||||
|
}
|
||||||
|
|
||||||
protected get disabledMessage(): string | undefined {
|
protected readonly debugToolbarItem = {
|
||||||
return this._disabledMessages;
|
id: Debug.Commands.START_DEBUGGING.id,
|
||||||
}
|
command: Debug.Commands.START_DEBUGGING.id,
|
||||||
protected set disabledMessage(message: string | undefined) {
|
tooltip: `${
|
||||||
this._disabledMessages = message;
|
this.disabledMessage
|
||||||
this.disabledMessageDidChangeEmitter.fire(this._disabledMessages);
|
? `Debug - ${this.disabledMessage}`
|
||||||
}
|
: 'Start Debugging'
|
||||||
|
}`,
|
||||||
|
priority: 3,
|
||||||
|
onDidChange: this.onDisabledMessageDidChange as Event<void>,
|
||||||
|
};
|
||||||
|
|
||||||
protected readonly debugToolbarItem = {
|
onStart(): void {
|
||||||
id: Debug.Commands.START_DEBUGGING.id,
|
this.onDisabledMessageDidChange(
|
||||||
command: Debug.Commands.START_DEBUGGING.id,
|
() =>
|
||||||
tooltip: `${this.disabledMessage ? `Debug - ${this.disabledMessage}` : 'Start Debugging'}`,
|
(this.debugToolbarItem.tooltip = `${
|
||||||
priority: 3,
|
this.disabledMessage
|
||||||
onDidChange: this.onDisabledMessageDidChange as Event<void>
|
? `Debug - ${this.disabledMessage}`
|
||||||
|
: 'Start Debugging'
|
||||||
|
}`)
|
||||||
|
);
|
||||||
|
const refreshState = async (
|
||||||
|
board: Board | undefined = this.boardsServiceProvider.boardsConfig
|
||||||
|
.selectedBoard
|
||||||
|
) => {
|
||||||
|
if (!board) {
|
||||||
|
this.disabledMessage = 'No board selected';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const fqbn = board.fqbn;
|
||||||
|
if (!fqbn) {
|
||||||
|
this.disabledMessage = `Platform is not installed for '${board.name}'`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const details = await this.boardService.getBoardDetails({ fqbn });
|
||||||
|
if (!details) {
|
||||||
|
this.disabledMessage = `Platform is not installed for '${board.name}'`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { debuggingSupported } = details;
|
||||||
|
if (!debuggingSupported) {
|
||||||
|
this.disabledMessage = `Debugging is not supported by '${board.name}'`;
|
||||||
|
} else {
|
||||||
|
this.disabledMessage = undefined;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
this.boardsServiceProvider.onBoardsConfigChanged(({ selectedBoard }) =>
|
||||||
|
refreshState(selectedBoard)
|
||||||
|
);
|
||||||
|
this.notificationCenter.onPlatformInstalled(() => refreshState());
|
||||||
|
this.notificationCenter.onPlatformUninstalled(() => refreshState());
|
||||||
|
refreshState();
|
||||||
|
}
|
||||||
|
|
||||||
onStart(): void {
|
registerCommands(registry: CommandRegistry): void {
|
||||||
this.onDisabledMessageDidChange(() => this.debugToolbarItem.tooltip = `${this.disabledMessage ? `Debug - ${this.disabledMessage}` : 'Start Debugging'}`);
|
registry.registerCommand(Debug.Commands.START_DEBUGGING, {
|
||||||
const refreshState = async (board: Board | undefined = this.boardsServiceProvider.boardsConfig.selectedBoard) => {
|
execute: () => this.startDebug(),
|
||||||
if (!board) {
|
isVisible: (widget) =>
|
||||||
this.disabledMessage = 'No board selected';
|
ArduinoToolbar.is(widget) && widget.side === 'left',
|
||||||
return;
|
isEnabled: () => !this.disabledMessage,
|
||||||
}
|
});
|
||||||
const fqbn = board.fqbn;
|
}
|
||||||
if (!fqbn) {
|
|
||||||
this.disabledMessage = `Platform is not installed for '${board.name}'`;
|
registerToolbarItems(registry: TabBarToolbarRegistry): void {
|
||||||
return;
|
registry.registerItem(this.debugToolbarItem);
|
||||||
}
|
}
|
||||||
const details = await this.boardService.getBoardDetails({ fqbn });
|
|
||||||
if (!details) {
|
protected async startDebug(
|
||||||
this.disabledMessage = `Platform is not installed for '${board.name}'`;
|
board: Board | undefined = this.boardsServiceProvider.boardsConfig
|
||||||
return;
|
.selectedBoard
|
||||||
}
|
): Promise<void> {
|
||||||
const { debuggingSupported } = details;
|
if (!board) {
|
||||||
if (!debuggingSupported) {
|
return;
|
||||||
this.disabledMessage = `Debugging is not supported by '${board.name}'`;
|
|
||||||
} else {
|
|
||||||
this.disabledMessage = undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.boardsServiceProvider.onBoardsConfigChanged(({ selectedBoard }) => refreshState(selectedBoard));
|
|
||||||
this.notificationCenter.onPlatformInstalled(() => refreshState());
|
|
||||||
this.notificationCenter.onPlatformUninstalled(() => refreshState());
|
|
||||||
refreshState();
|
|
||||||
}
|
}
|
||||||
|
const { name, fqbn } = board;
|
||||||
registerCommands(registry: CommandRegistry): void {
|
if (!fqbn) {
|
||||||
registry.registerCommand(Debug.Commands.START_DEBUGGING, {
|
return;
|
||||||
execute: () => this.startDebug(),
|
|
||||||
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
|
|
||||||
isEnabled: () => !this.disabledMessage
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
await this.hostedPluginSupport.didStart;
|
||||||
registerToolbarItems(registry: TabBarToolbarRegistry): void {
|
const [sketch, executables] = await Promise.all([
|
||||||
registry.registerItem(this.debugToolbarItem);
|
this.sketchServiceClient.currentSketch(),
|
||||||
|
this.executableService.list(),
|
||||||
|
]);
|
||||||
|
if (!sketch) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
const ideTempFolderUri = await this.sketchService.getIdeTempFolderUri(
|
||||||
protected async startDebug(board: Board | undefined = this.boardsServiceProvider.boardsConfig.selectedBoard): Promise<void> {
|
sketch
|
||||||
if (!board) {
|
);
|
||||||
return;
|
const [cliPath, sketchPath, configPath] = await Promise.all([
|
||||||
}
|
this.fileService.fsPath(new URI(executables.cliUri)),
|
||||||
const { name, fqbn } = board;
|
this.fileService.fsPath(new URI(sketch.uri)),
|
||||||
if (!fqbn) {
|
this.fileService.fsPath(new URI(ideTempFolderUri)),
|
||||||
return;
|
]);
|
||||||
}
|
const config = {
|
||||||
await this.hostedPluginSupport.didStart;
|
cliPath,
|
||||||
const [sketch, executables] = await Promise.all([
|
board: {
|
||||||
this.sketchServiceClient.currentSketch(),
|
fqbn,
|
||||||
this.executableService.list()
|
name,
|
||||||
]);
|
},
|
||||||
if (!sketch) {
|
sketchPath,
|
||||||
return;
|
configPath,
|
||||||
}
|
};
|
||||||
const [cliPath, sketchPath] = await Promise.all([
|
return this.commandService.executeCommand('arduino.debug.start', config);
|
||||||
this.fileService.fsPath(new URI(executables.cliUri)),
|
}
|
||||||
this.fileService.fsPath(new URI(sketch.uri))
|
|
||||||
])
|
|
||||||
const config = {
|
|
||||||
cliPath,
|
|
||||||
board: {
|
|
||||||
fqbn,
|
|
||||||
name
|
|
||||||
},
|
|
||||||
sketchPath
|
|
||||||
};
|
|
||||||
return this.commandService.executeCommand('arduino.debug.start', config);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace Debug {
|
export namespace Debug {
|
||||||
export namespace Commands {
|
export namespace Commands {
|
||||||
export const START_DEBUGGING: Command = {
|
export const START_DEBUGGING: Command = {
|
||||||
id: 'arduino-start-debug',
|
id: 'arduino-start-debug',
|
||||||
label: 'Start Debugging',
|
label: 'Start Debugging',
|
||||||
category: 'Arduino'
|
category: 'Arduino',
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,292 +3,318 @@ import { CommonCommands } from '@theia/core/lib/browser/common-frontend-contribu
|
|||||||
import { ClipboardService } from '@theia/core/lib/browser/clipboard-service';
|
import { ClipboardService } from '@theia/core/lib/browser/clipboard-service';
|
||||||
import { PreferenceService } from '@theia/core/lib/browser/preferences/preference-service';
|
import { PreferenceService } from '@theia/core/lib/browser/preferences/preference-service';
|
||||||
import { MonacoEditorService } from '@theia/monaco/lib/browser/monaco-editor-service';
|
import { MonacoEditorService } from '@theia/monaco/lib/browser/monaco-editor-service';
|
||||||
import { Contribution, Command, MenuModelRegistry, KeybindingRegistry, CommandRegistry } from './contribution';
|
import {
|
||||||
|
Contribution,
|
||||||
|
Command,
|
||||||
|
MenuModelRegistry,
|
||||||
|
KeybindingRegistry,
|
||||||
|
CommandRegistry,
|
||||||
|
} from './contribution';
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
|
|
||||||
// TODO: [macOS]: to remove `Start Dictation...` and `Emoji & Symbol` see this thread: https://github.com/electron/electron/issues/8283#issuecomment-269522072
|
// TODO: [macOS]: to remove `Start Dictation...` and `Emoji & Symbol` see this thread: https://github.com/electron/electron/issues/8283#issuecomment-269522072
|
||||||
// Depends on https://github.com/eclipse-theia/theia/pull/7964
|
// Depends on https://github.com/eclipse-theia/theia/pull/7964
|
||||||
@injectable()
|
@injectable()
|
||||||
export class EditContributions extends Contribution {
|
export class EditContributions extends Contribution {
|
||||||
|
@inject(MonacoEditorService)
|
||||||
|
protected readonly codeEditorService: MonacoEditorService;
|
||||||
|
|
||||||
@inject(MonacoEditorService)
|
@inject(ClipboardService)
|
||||||
protected readonly codeEditorService: MonacoEditorService;
|
protected readonly clipboardService: ClipboardService;
|
||||||
|
|
||||||
@inject(ClipboardService)
|
@inject(PreferenceService)
|
||||||
protected readonly clipboardService: ClipboardService;
|
protected readonly preferences: PreferenceService;
|
||||||
|
|
||||||
@inject(PreferenceService)
|
registerCommands(registry: CommandRegistry): void {
|
||||||
protected readonly preferences: PreferenceService;
|
registry.registerCommand(EditContributions.Commands.GO_TO_LINE, {
|
||||||
|
execute: () => this.run('editor.action.gotoLine'),
|
||||||
registerCommands(registry: CommandRegistry): void {
|
});
|
||||||
registry.registerCommand(EditContributions.Commands.GO_TO_LINE, { execute: () => this.run('editor.action.gotoLine') });
|
registry.registerCommand(EditContributions.Commands.TOGGLE_COMMENT, {
|
||||||
registry.registerCommand(EditContributions.Commands.TOGGLE_COMMENT, { execute: () => this.run('editor.action.commentLine') });
|
execute: () => this.run('editor.action.commentLine'),
|
||||||
registry.registerCommand(EditContributions.Commands.INDENT_LINES, { execute: () => this.run('editor.action.indentLines') });
|
});
|
||||||
registry.registerCommand(EditContributions.Commands.OUTDENT_LINES, { execute: () => this.run('editor.action.outdentLines') });
|
registry.registerCommand(EditContributions.Commands.INDENT_LINES, {
|
||||||
registry.registerCommand(EditContributions.Commands.FIND, { execute: () => this.run('actions.find') });
|
execute: () => this.run('editor.action.indentLines'),
|
||||||
registry.registerCommand(EditContributions.Commands.FIND_NEXT, { execute: () => this.run('actions.findWithSelection') });
|
});
|
||||||
registry.registerCommand(EditContributions.Commands.FIND_PREVIOUS, { execute: () => this.run('editor.action.nextMatchFindAction') });
|
registry.registerCommand(EditContributions.Commands.OUTDENT_LINES, {
|
||||||
registry.registerCommand(EditContributions.Commands.USE_FOR_FIND, { execute: () => this.run('editor.action.previousSelectionMatchFindAction') });
|
execute: () => this.run('editor.action.outdentLines'),
|
||||||
registry.registerCommand(EditContributions.Commands.INCREASE_FONT_SIZE, {
|
});
|
||||||
execute: async () => {
|
registry.registerCommand(EditContributions.Commands.FIND, {
|
||||||
const settings = await this.settingsService.settings();
|
execute: () => this.run('actions.find'),
|
||||||
if (settings.autoScaleInterface) {
|
});
|
||||||
settings.interfaceScale = settings.interfaceScale + 1;
|
registry.registerCommand(EditContributions.Commands.FIND_NEXT, {
|
||||||
} else {
|
execute: () => this.run('actions.findWithSelection'),
|
||||||
settings.editorFontSize = settings.editorFontSize + 1;
|
});
|
||||||
}
|
registry.registerCommand(EditContributions.Commands.FIND_PREVIOUS, {
|
||||||
await this.settingsService.update(settings);
|
execute: () => this.run('editor.action.nextMatchFindAction'),
|
||||||
await this.settingsService.save();
|
});
|
||||||
}
|
registry.registerCommand(EditContributions.Commands.USE_FOR_FIND, {
|
||||||
});
|
execute: () => this.run('editor.action.previousSelectionMatchFindAction'),
|
||||||
registry.registerCommand(EditContributions.Commands.DECREASE_FONT_SIZE, {
|
});
|
||||||
execute: async () => {
|
registry.registerCommand(EditContributions.Commands.INCREASE_FONT_SIZE, {
|
||||||
const settings = await this.settingsService.settings();
|
execute: async () => {
|
||||||
if (settings.autoScaleInterface) {
|
const settings = await this.settingsService.settings();
|
||||||
settings.interfaceScale = settings.interfaceScale - 1;
|
if (settings.autoScaleInterface) {
|
||||||
} else {
|
settings.interfaceScale = settings.interfaceScale + 1;
|
||||||
settings.editorFontSize = settings.editorFontSize - 1;
|
} else {
|
||||||
}
|
settings.editorFontSize = settings.editorFontSize + 1;
|
||||||
await this.settingsService.update(settings);
|
|
||||||
await this.settingsService.save();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
/* Tools */registry.registerCommand(EditContributions.Commands.AUTO_FORMAT, { execute: () => this.run('editor.action.formatDocument') });
|
|
||||||
registry.registerCommand(EditContributions.Commands.COPY_FOR_FORUM, {
|
|
||||||
execute: async () => {
|
|
||||||
const value = await this.currentValue();
|
|
||||||
if (value !== undefined) {
|
|
||||||
this.clipboardService.writeText(`[code]
|
|
||||||
${value}
|
|
||||||
[/code]`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
registry.registerCommand(EditContributions.Commands.COPY_FOR_GITHUB, {
|
|
||||||
execute: async () => {
|
|
||||||
const value = await this.currentValue();
|
|
||||||
if (value !== undefined) {
|
|
||||||
this.clipboardService.writeText(`\`\`\`cpp
|
|
||||||
${value}
|
|
||||||
\`\`\``)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
|
||||||
registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, {
|
|
||||||
commandId: CommonCommands.CUT.id,
|
|
||||||
order: '0'
|
|
||||||
});
|
|
||||||
registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, {
|
|
||||||
commandId: CommonCommands.COPY.id,
|
|
||||||
order: '1'
|
|
||||||
});
|
|
||||||
registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, {
|
|
||||||
commandId: EditContributions.Commands.COPY_FOR_FORUM.id,
|
|
||||||
label: 'Copy for Forum',
|
|
||||||
order: '2'
|
|
||||||
});
|
|
||||||
registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, {
|
|
||||||
commandId: EditContributions.Commands.COPY_FOR_GITHUB.id,
|
|
||||||
label: 'Copy for GitHub',
|
|
||||||
order: '3'
|
|
||||||
});
|
|
||||||
registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, {
|
|
||||||
commandId: CommonCommands.PASTE.id,
|
|
||||||
order: '4'
|
|
||||||
});
|
|
||||||
registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, {
|
|
||||||
commandId: CommonCommands.SELECT_ALL.id,
|
|
||||||
order: '5'
|
|
||||||
});
|
|
||||||
registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, {
|
|
||||||
commandId: EditContributions.Commands.GO_TO_LINE.id,
|
|
||||||
label: 'Go to Line...',
|
|
||||||
order: '6'
|
|
||||||
});
|
|
||||||
|
|
||||||
registry.registerMenuAction(ArduinoMenus.EDIT__CODE_CONTROL_GROUP, {
|
|
||||||
commandId: EditContributions.Commands.TOGGLE_COMMENT.id,
|
|
||||||
label: 'Comment/Uncomment',
|
|
||||||
order: '0'
|
|
||||||
});
|
|
||||||
registry.registerMenuAction(ArduinoMenus.EDIT__CODE_CONTROL_GROUP, {
|
|
||||||
commandId: EditContributions.Commands.INDENT_LINES.id,
|
|
||||||
label: 'Increase Indent',
|
|
||||||
order: '1'
|
|
||||||
});
|
|
||||||
registry.registerMenuAction(ArduinoMenus.EDIT__CODE_CONTROL_GROUP, {
|
|
||||||
commandId: EditContributions.Commands.OUTDENT_LINES.id,
|
|
||||||
label: 'Decrease Indent',
|
|
||||||
order: '2'
|
|
||||||
});
|
|
||||||
|
|
||||||
registry.registerMenuAction(ArduinoMenus.EDIT__FONT_CONTROL_GROUP, {
|
|
||||||
commandId: EditContributions.Commands.INCREASE_FONT_SIZE.id,
|
|
||||||
label: 'Increase Font Size',
|
|
||||||
order: '0'
|
|
||||||
});
|
|
||||||
registry.registerMenuAction(ArduinoMenus.EDIT__FONT_CONTROL_GROUP, {
|
|
||||||
commandId: EditContributions.Commands.DECREASE_FONT_SIZE.id,
|
|
||||||
label: 'Decrease Font Size',
|
|
||||||
order: '1'
|
|
||||||
});
|
|
||||||
|
|
||||||
registry.registerMenuAction(ArduinoMenus.EDIT__FIND_GROUP, {
|
|
||||||
commandId: EditContributions.Commands.FIND.id,
|
|
||||||
label: 'Find',
|
|
||||||
order: '0'
|
|
||||||
});
|
|
||||||
registry.registerMenuAction(ArduinoMenus.EDIT__FIND_GROUP, {
|
|
||||||
commandId: EditContributions.Commands.FIND_NEXT.id,
|
|
||||||
label: 'Find Next',
|
|
||||||
order: '1'
|
|
||||||
});
|
|
||||||
registry.registerMenuAction(ArduinoMenus.EDIT__FIND_GROUP, {
|
|
||||||
commandId: EditContributions.Commands.FIND_PREVIOUS.id,
|
|
||||||
label: 'Find Previous',
|
|
||||||
order: '2'
|
|
||||||
});
|
|
||||||
registry.registerMenuAction(ArduinoMenus.EDIT__FIND_GROUP, {
|
|
||||||
commandId: EditContributions.Commands.USE_FOR_FIND.id,
|
|
||||||
label: 'Use Selection for Find', // XXX: The Java IDE uses `Use Selection For Find`.
|
|
||||||
order: '3'
|
|
||||||
});
|
|
||||||
|
|
||||||
// `Tools`
|
|
||||||
registry.registerMenuAction(ArduinoMenus.TOOLS__MAIN_GROUP, {
|
|
||||||
commandId: EditContributions.Commands.AUTO_FORMAT.id,
|
|
||||||
label: 'Auto Format', // XXX: The Java IDE uses `Use Selection For Find`.
|
|
||||||
order: '0'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
registerKeybindings(registry: KeybindingRegistry): void {
|
|
||||||
registry.registerKeybinding({
|
|
||||||
command: EditContributions.Commands.COPY_FOR_FORUM.id,
|
|
||||||
keybinding: 'CtrlCmd+Shift+C',
|
|
||||||
when: 'editorFocus'
|
|
||||||
});
|
|
||||||
registry.registerKeybinding({
|
|
||||||
command: EditContributions.Commands.COPY_FOR_GITHUB.id,
|
|
||||||
keybinding: 'CtrlCmd+Alt+C',
|
|
||||||
when: 'editorFocus'
|
|
||||||
});
|
|
||||||
registry.registerKeybinding({
|
|
||||||
command: EditContributions.Commands.GO_TO_LINE.id,
|
|
||||||
keybinding: 'CtrlCmd+L',
|
|
||||||
when: 'editorFocus'
|
|
||||||
});
|
|
||||||
|
|
||||||
registry.registerKeybinding({
|
|
||||||
command: EditContributions.Commands.TOGGLE_COMMENT.id,
|
|
||||||
keybinding: 'CtrlCmd+/',
|
|
||||||
when: 'editorFocus'
|
|
||||||
});
|
|
||||||
|
|
||||||
registry.registerKeybinding({
|
|
||||||
command: EditContributions.Commands.INCREASE_FONT_SIZE.id,
|
|
||||||
keybinding: 'CtrlCmd+='
|
|
||||||
});
|
|
||||||
registry.registerKeybinding({
|
|
||||||
command: EditContributions.Commands.DECREASE_FONT_SIZE.id,
|
|
||||||
keybinding: 'CtrlCmd+-'
|
|
||||||
});
|
|
||||||
|
|
||||||
registry.registerKeybinding({
|
|
||||||
command: EditContributions.Commands.FIND.id,
|
|
||||||
keybinding: 'CtrlCmd+F'
|
|
||||||
});
|
|
||||||
registry.registerKeybinding({
|
|
||||||
command: EditContributions.Commands.FIND_NEXT.id,
|
|
||||||
keybinding: 'CtrlCmd+G'
|
|
||||||
});
|
|
||||||
registry.registerKeybinding({
|
|
||||||
command: EditContributions.Commands.FIND_PREVIOUS.id,
|
|
||||||
keybinding: 'CtrlCmd+Shift+G'
|
|
||||||
});
|
|
||||||
registry.registerKeybinding({
|
|
||||||
command: EditContributions.Commands.USE_FOR_FIND.id,
|
|
||||||
keybinding: 'CtrlCmd+E'
|
|
||||||
});
|
|
||||||
|
|
||||||
// `Tools`
|
|
||||||
registry.registerKeybinding({
|
|
||||||
command: EditContributions.Commands.AUTO_FORMAT.id,
|
|
||||||
keybinding: 'CtrlCmd+T'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async current(): Promise<monaco.editor.ICodeEditor | undefined> {
|
|
||||||
return this.codeEditorService.getFocusedCodeEditor() || this.codeEditorService.getActiveCodeEditor();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async currentValue(): Promise<string | undefined> {
|
|
||||||
const currentEditor = await this.current();
|
|
||||||
if (currentEditor) {
|
|
||||||
const selection = currentEditor.getSelection();
|
|
||||||
if (!selection || selection.isEmpty()) {
|
|
||||||
return currentEditor.getValue();
|
|
||||||
}
|
|
||||||
return currentEditor.getModel()?.getValueInRange(selection);
|
|
||||||
}
|
}
|
||||||
return undefined;
|
await this.settingsService.update(settings);
|
||||||
}
|
await this.settingsService.save();
|
||||||
|
},
|
||||||
protected async run(commandId: string): Promise<any> {
|
});
|
||||||
const editor = await this.current();
|
registry.registerCommand(EditContributions.Commands.DECREASE_FONT_SIZE, {
|
||||||
if (editor) {
|
execute: async () => {
|
||||||
const action = editor.getAction(commandId);
|
const settings = await this.settingsService.settings();
|
||||||
if (action) {
|
if (settings.autoScaleInterface) {
|
||||||
return action.run();
|
settings.interfaceScale = settings.interfaceScale - 1;
|
||||||
}
|
} else {
|
||||||
|
settings.editorFontSize = settings.editorFontSize - 1;
|
||||||
}
|
}
|
||||||
}
|
await this.settingsService.update(settings);
|
||||||
|
await this.settingsService.save();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
/* Tools */ registry.registerCommand(
|
||||||
|
EditContributions.Commands.AUTO_FORMAT,
|
||||||
|
{ execute: () => this.run('editor.action.formatDocument') }
|
||||||
|
);
|
||||||
|
registry.registerCommand(EditContributions.Commands.COPY_FOR_FORUM, {
|
||||||
|
execute: async () => {
|
||||||
|
const value = await this.currentValue();
|
||||||
|
if (value !== undefined) {
|
||||||
|
this.clipboardService.writeText(`[code]
|
||||||
|
${value}
|
||||||
|
[/code]`);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
registry.registerCommand(EditContributions.Commands.COPY_FOR_GITHUB, {
|
||||||
|
execute: async () => {
|
||||||
|
const value = await this.currentValue();
|
||||||
|
if (value !== undefined) {
|
||||||
|
this.clipboardService.writeText(`\`\`\`cpp
|
||||||
|
${value}
|
||||||
|
\`\`\``);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
|
registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, {
|
||||||
|
commandId: CommonCommands.CUT.id,
|
||||||
|
order: '0',
|
||||||
|
});
|
||||||
|
registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, {
|
||||||
|
commandId: CommonCommands.COPY.id,
|
||||||
|
order: '1',
|
||||||
|
});
|
||||||
|
registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, {
|
||||||
|
commandId: EditContributions.Commands.COPY_FOR_FORUM.id,
|
||||||
|
label: 'Copy for Forum',
|
||||||
|
order: '2',
|
||||||
|
});
|
||||||
|
registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, {
|
||||||
|
commandId: EditContributions.Commands.COPY_FOR_GITHUB.id,
|
||||||
|
label: 'Copy for GitHub',
|
||||||
|
order: '3',
|
||||||
|
});
|
||||||
|
registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, {
|
||||||
|
commandId: CommonCommands.PASTE.id,
|
||||||
|
order: '4',
|
||||||
|
});
|
||||||
|
registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, {
|
||||||
|
commandId: CommonCommands.SELECT_ALL.id,
|
||||||
|
order: '5',
|
||||||
|
});
|
||||||
|
registry.registerMenuAction(ArduinoMenus.EDIT__TEXT_CONTROL_GROUP, {
|
||||||
|
commandId: EditContributions.Commands.GO_TO_LINE.id,
|
||||||
|
label: 'Go to Line...',
|
||||||
|
order: '6',
|
||||||
|
});
|
||||||
|
|
||||||
|
registry.registerMenuAction(ArduinoMenus.EDIT__CODE_CONTROL_GROUP, {
|
||||||
|
commandId: EditContributions.Commands.TOGGLE_COMMENT.id,
|
||||||
|
label: 'Comment/Uncomment',
|
||||||
|
order: '0',
|
||||||
|
});
|
||||||
|
registry.registerMenuAction(ArduinoMenus.EDIT__CODE_CONTROL_GROUP, {
|
||||||
|
commandId: EditContributions.Commands.INDENT_LINES.id,
|
||||||
|
label: 'Increase Indent',
|
||||||
|
order: '1',
|
||||||
|
});
|
||||||
|
registry.registerMenuAction(ArduinoMenus.EDIT__CODE_CONTROL_GROUP, {
|
||||||
|
commandId: EditContributions.Commands.OUTDENT_LINES.id,
|
||||||
|
label: 'Decrease Indent',
|
||||||
|
order: '2',
|
||||||
|
});
|
||||||
|
|
||||||
|
registry.registerMenuAction(ArduinoMenus.EDIT__FONT_CONTROL_GROUP, {
|
||||||
|
commandId: EditContributions.Commands.INCREASE_FONT_SIZE.id,
|
||||||
|
label: 'Increase Font Size',
|
||||||
|
order: '0',
|
||||||
|
});
|
||||||
|
registry.registerMenuAction(ArduinoMenus.EDIT__FONT_CONTROL_GROUP, {
|
||||||
|
commandId: EditContributions.Commands.DECREASE_FONT_SIZE.id,
|
||||||
|
label: 'Decrease Font Size',
|
||||||
|
order: '1',
|
||||||
|
});
|
||||||
|
|
||||||
|
registry.registerMenuAction(ArduinoMenus.EDIT__FIND_GROUP, {
|
||||||
|
commandId: EditContributions.Commands.FIND.id,
|
||||||
|
label: 'Find',
|
||||||
|
order: '0',
|
||||||
|
});
|
||||||
|
registry.registerMenuAction(ArduinoMenus.EDIT__FIND_GROUP, {
|
||||||
|
commandId: EditContributions.Commands.FIND_NEXT.id,
|
||||||
|
label: 'Find Next',
|
||||||
|
order: '1',
|
||||||
|
});
|
||||||
|
registry.registerMenuAction(ArduinoMenus.EDIT__FIND_GROUP, {
|
||||||
|
commandId: EditContributions.Commands.FIND_PREVIOUS.id,
|
||||||
|
label: 'Find Previous',
|
||||||
|
order: '2',
|
||||||
|
});
|
||||||
|
registry.registerMenuAction(ArduinoMenus.EDIT__FIND_GROUP, {
|
||||||
|
commandId: EditContributions.Commands.USE_FOR_FIND.id,
|
||||||
|
label: 'Use Selection for Find', // XXX: The Java IDE uses `Use Selection For Find`.
|
||||||
|
order: '3',
|
||||||
|
});
|
||||||
|
|
||||||
|
// `Tools`
|
||||||
|
registry.registerMenuAction(ArduinoMenus.TOOLS__MAIN_GROUP, {
|
||||||
|
commandId: EditContributions.Commands.AUTO_FORMAT.id,
|
||||||
|
label: 'Auto Format', // XXX: The Java IDE uses `Use Selection For Find`.
|
||||||
|
order: '0',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerKeybindings(registry: KeybindingRegistry): void {
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: EditContributions.Commands.COPY_FOR_FORUM.id,
|
||||||
|
keybinding: 'CtrlCmd+Shift+C',
|
||||||
|
when: 'editorFocus',
|
||||||
|
});
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: EditContributions.Commands.COPY_FOR_GITHUB.id,
|
||||||
|
keybinding: 'CtrlCmd+Alt+C',
|
||||||
|
when: 'editorFocus',
|
||||||
|
});
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: EditContributions.Commands.GO_TO_LINE.id,
|
||||||
|
keybinding: 'CtrlCmd+L',
|
||||||
|
when: 'editorFocus',
|
||||||
|
});
|
||||||
|
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: EditContributions.Commands.TOGGLE_COMMENT.id,
|
||||||
|
keybinding: 'CtrlCmd+/',
|
||||||
|
when: 'editorFocus',
|
||||||
|
});
|
||||||
|
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: EditContributions.Commands.INCREASE_FONT_SIZE.id,
|
||||||
|
keybinding: 'CtrlCmd+=',
|
||||||
|
});
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: EditContributions.Commands.DECREASE_FONT_SIZE.id,
|
||||||
|
keybinding: 'CtrlCmd+-',
|
||||||
|
});
|
||||||
|
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: EditContributions.Commands.FIND.id,
|
||||||
|
keybinding: 'CtrlCmd+F',
|
||||||
|
});
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: EditContributions.Commands.FIND_NEXT.id,
|
||||||
|
keybinding: 'CtrlCmd+G',
|
||||||
|
});
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: EditContributions.Commands.FIND_PREVIOUS.id,
|
||||||
|
keybinding: 'CtrlCmd+Shift+G',
|
||||||
|
});
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: EditContributions.Commands.USE_FOR_FIND.id,
|
||||||
|
keybinding: 'CtrlCmd+E',
|
||||||
|
});
|
||||||
|
|
||||||
|
// `Tools`
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: EditContributions.Commands.AUTO_FORMAT.id,
|
||||||
|
keybinding: 'CtrlCmd+T',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async current(): Promise<monaco.editor.ICodeEditor | undefined> {
|
||||||
|
return (
|
||||||
|
this.codeEditorService.getFocusedCodeEditor() ||
|
||||||
|
this.codeEditorService.getActiveCodeEditor()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async currentValue(): Promise<string | undefined> {
|
||||||
|
const currentEditor = await this.current();
|
||||||
|
if (currentEditor) {
|
||||||
|
const selection = currentEditor.getSelection();
|
||||||
|
if (!selection || selection.isEmpty()) {
|
||||||
|
return currentEditor.getValue();
|
||||||
|
}
|
||||||
|
return currentEditor.getModel()?.getValueInRange(selection);
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async run(commandId: string): Promise<any> {
|
||||||
|
const editor = await this.current();
|
||||||
|
if (editor) {
|
||||||
|
const action = editor.getAction(commandId);
|
||||||
|
if (action) {
|
||||||
|
return action.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace EditContributions {
|
export namespace EditContributions {
|
||||||
export namespace Commands {
|
export namespace Commands {
|
||||||
export const COPY_FOR_FORUM: Command = {
|
export const COPY_FOR_FORUM: Command = {
|
||||||
id: 'arduino-copy-for-forum'
|
id: 'arduino-copy-for-forum',
|
||||||
};
|
};
|
||||||
export const COPY_FOR_GITHUB: Command = {
|
export const COPY_FOR_GITHUB: Command = {
|
||||||
id: 'arduino-copy-for-github'
|
id: 'arduino-copy-for-github',
|
||||||
};
|
};
|
||||||
export const GO_TO_LINE: Command = {
|
export const GO_TO_LINE: Command = {
|
||||||
id: 'arduino-go-to-line'
|
id: 'arduino-go-to-line',
|
||||||
};
|
};
|
||||||
export const TOGGLE_COMMENT: Command = {
|
export const TOGGLE_COMMENT: Command = {
|
||||||
id: 'arduino-toggle-comment'
|
id: 'arduino-toggle-comment',
|
||||||
};
|
};
|
||||||
export const INDENT_LINES: Command = {
|
export const INDENT_LINES: Command = {
|
||||||
id: 'arduino-indent-lines'
|
id: 'arduino-indent-lines',
|
||||||
};
|
};
|
||||||
export const OUTDENT_LINES: Command = {
|
export const OUTDENT_LINES: Command = {
|
||||||
id: 'arduino-outdent-lines'
|
id: 'arduino-outdent-lines',
|
||||||
};
|
};
|
||||||
export const FIND: Command = {
|
export const FIND: Command = {
|
||||||
id: 'arduino-find'
|
id: 'arduino-find',
|
||||||
};
|
};
|
||||||
export const FIND_NEXT: Command = {
|
export const FIND_NEXT: Command = {
|
||||||
id: 'arduino-find-next'
|
id: 'arduino-find-next',
|
||||||
};
|
};
|
||||||
export const FIND_PREVIOUS: Command = {
|
export const FIND_PREVIOUS: Command = {
|
||||||
id: 'arduino-find-previous'
|
id: 'arduino-find-previous',
|
||||||
};
|
};
|
||||||
export const USE_FOR_FIND: Command = {
|
export const USE_FOR_FIND: Command = {
|
||||||
id: 'arduino-for-find'
|
id: 'arduino-for-find',
|
||||||
};
|
};
|
||||||
export const INCREASE_FONT_SIZE: Command = {
|
export const INCREASE_FONT_SIZE: Command = {
|
||||||
id: 'arduino-increase-font-size'
|
id: 'arduino-increase-font-size',
|
||||||
};
|
};
|
||||||
export const DECREASE_FONT_SIZE: Command = {
|
export const DECREASE_FONT_SIZE: Command = {
|
||||||
id: 'arduino-decrease-font-size'
|
id: 'arduino-decrease-font-size',
|
||||||
};
|
};
|
||||||
export const AUTO_FORMAT: Command = {
|
export const AUTO_FORMAT: Command = {
|
||||||
id: 'arduino-auto-format' // `Auto Format` should belong to `Tool`.
|
id: 'arduino-auto-format', // `Auto Format` should belong to `Tool`.
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,169 +1,246 @@
|
|||||||
import * as PQueue from 'p-queue';
|
import * as PQueue from 'p-queue';
|
||||||
import { inject, injectable, postConstruct } from 'inversify';
|
import { inject, injectable, postConstruct } from 'inversify';
|
||||||
import { MenuPath, CompositeMenuNode } from '@theia/core/lib/common/menu';
|
import { CommandHandler } from '@theia/core/lib/common/command';
|
||||||
import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
|
import {
|
||||||
|
MenuPath,
|
||||||
|
CompositeMenuNode,
|
||||||
|
SubMenuOptions,
|
||||||
|
} from '@theia/core/lib/common/menu';
|
||||||
|
import {
|
||||||
|
Disposable,
|
||||||
|
DisposableCollection,
|
||||||
|
} from '@theia/core/lib/common/disposable';
|
||||||
import { OpenSketch } from './open-sketch';
|
import { OpenSketch } from './open-sketch';
|
||||||
import { ArduinoMenus, PlaceholderMenuNode } from '../menu/arduino-menus';
|
import { ArduinoMenus, PlaceholderMenuNode } from '../menu/arduino-menus';
|
||||||
import { MainMenuManager } from '../../common/main-menu-manager';
|
import { MainMenuManager } from '../../common/main-menu-manager';
|
||||||
import { BoardsServiceProvider } from '../boards/boards-service-provider';
|
import { BoardsServiceProvider } from '../boards/boards-service-provider';
|
||||||
import { ExamplesService, ExampleContainer } from '../../common/protocol/examples-service';
|
import { ExamplesService } from '../../common/protocol/examples-service';
|
||||||
import { SketchContribution, CommandRegistry, MenuModelRegistry } from './contribution';
|
import {
|
||||||
|
SketchContribution,
|
||||||
|
CommandRegistry,
|
||||||
|
MenuModelRegistry,
|
||||||
|
} from './contribution';
|
||||||
import { NotificationCenter } from '../notification-center';
|
import { NotificationCenter } from '../notification-center';
|
||||||
import { Board } from '../../common/protocol';
|
import { Board, Sketch, SketchContainer } from '../../common/protocol';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export abstract class Examples extends SketchContribution {
|
export abstract class Examples extends SketchContribution {
|
||||||
|
@inject(CommandRegistry)
|
||||||
|
protected readonly commandRegistry: CommandRegistry;
|
||||||
|
|
||||||
@inject(CommandRegistry)
|
@inject(MenuModelRegistry)
|
||||||
protected readonly commandRegistry: CommandRegistry;
|
protected readonly menuRegistry: MenuModelRegistry;
|
||||||
|
|
||||||
@inject(MenuModelRegistry)
|
@inject(MainMenuManager)
|
||||||
protected readonly menuRegistry: MenuModelRegistry;
|
protected readonly menuManager: MainMenuManager;
|
||||||
|
|
||||||
@inject(MainMenuManager)
|
@inject(ExamplesService)
|
||||||
protected readonly menuManager: MainMenuManager;
|
protected readonly examplesService: ExamplesService;
|
||||||
|
|
||||||
@inject(ExamplesService)
|
@inject(BoardsServiceProvider)
|
||||||
protected readonly examplesService: ExamplesService;
|
protected readonly boardsServiceClient: BoardsServiceProvider;
|
||||||
|
|
||||||
@inject(BoardsServiceProvider)
|
protected readonly toDispose = new DisposableCollection();
|
||||||
protected readonly boardsServiceClient: BoardsServiceProvider;
|
|
||||||
|
|
||||||
protected readonly toDispose = new DisposableCollection();
|
@postConstruct()
|
||||||
|
init(): void {
|
||||||
|
this.boardsServiceClient.onBoardsConfigChanged(({ selectedBoard }) =>
|
||||||
|
this.handleBoardChanged(selectedBoard)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@postConstruct()
|
protected handleBoardChanged(board: Board | undefined): void {
|
||||||
init(): void {
|
// NOOP
|
||||||
this.boardsServiceClient.onBoardsConfigChanged(({ selectedBoard }) => this.handleBoardChanged(selectedBoard));
|
}
|
||||||
|
|
||||||
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
|
try {
|
||||||
|
// This is a hack the ensures the desired menu ordering! We cannot use https://github.com/eclipse-theia/theia/pull/8377 due to ATL-222.
|
||||||
|
const index = ArduinoMenus.FILE__EXAMPLES_SUBMENU.length - 1;
|
||||||
|
const menuId = ArduinoMenus.FILE__EXAMPLES_SUBMENU[index];
|
||||||
|
const groupPath =
|
||||||
|
index === 0 ? [] : ArduinoMenus.FILE__EXAMPLES_SUBMENU.slice(0, index);
|
||||||
|
const parent: CompositeMenuNode = (registry as any).findGroup(groupPath);
|
||||||
|
const examples = new CompositeMenuNode(menuId, '', { order: '4' });
|
||||||
|
parent.addNode(examples);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
console.warn('Could not patch menu ordering.');
|
||||||
}
|
}
|
||||||
|
// Registering the same submenu multiple times has no side-effect.
|
||||||
|
// TODO: unregister submenu? https://github.com/eclipse-theia/theia/issues/7300
|
||||||
|
registry.registerSubmenu(ArduinoMenus.FILE__EXAMPLES_SUBMENU, 'Examples', {
|
||||||
|
order: '4',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
protected handleBoardChanged(board: Board | undefined): void {
|
registerRecursively(
|
||||||
// NOOP
|
sketchContainerOrPlaceholder:
|
||||||
}
|
| SketchContainer
|
||||||
|
| (Sketch | SketchContainer)[]
|
||||||
|
| string,
|
||||||
|
menuPath: MenuPath,
|
||||||
|
pushToDispose: DisposableCollection = new DisposableCollection(),
|
||||||
|
subMenuOptions?: SubMenuOptions | undefined
|
||||||
|
): void {
|
||||||
|
if (typeof sketchContainerOrPlaceholder === 'string') {
|
||||||
|
const placeholder = new PlaceholderMenuNode(
|
||||||
|
menuPath,
|
||||||
|
sketchContainerOrPlaceholder
|
||||||
|
);
|
||||||
|
this.menuRegistry.registerMenuNode(menuPath, placeholder);
|
||||||
|
pushToDispose.push(
|
||||||
|
Disposable.create(() =>
|
||||||
|
this.menuRegistry.unregisterMenuNode(placeholder.id)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
const sketches: Sketch[] = [];
|
||||||
|
const children: SketchContainer[] = [];
|
||||||
|
let submenuPath = menuPath;
|
||||||
|
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
if (SketchContainer.is(sketchContainerOrPlaceholder)) {
|
||||||
try {
|
const { label } = sketchContainerOrPlaceholder;
|
||||||
// This is a hack the ensures the desired menu ordering! We cannot use https://github.com/eclipse-theia/theia/pull/8377 due to ATL-222.
|
submenuPath = [...menuPath, label];
|
||||||
const index = ArduinoMenus.FILE__EXAMPLES_SUBMENU.length - 1;
|
this.menuRegistry.registerSubmenu(submenuPath, label, subMenuOptions);
|
||||||
const menuId = ArduinoMenus.FILE__EXAMPLES_SUBMENU[index];
|
sketches.push(...sketchContainerOrPlaceholder.sketches);
|
||||||
const groupPath = index === 0 ? [] : ArduinoMenus.FILE__EXAMPLES_SUBMENU.slice(0, index);
|
children.push(...sketchContainerOrPlaceholder.children);
|
||||||
const parent: CompositeMenuNode = (registry as any).findGroup(groupPath);
|
} else {
|
||||||
const examples = new CompositeMenuNode(menuId, '', { order: '4' });
|
for (const sketchOrContainer of sketchContainerOrPlaceholder) {
|
||||||
parent.addNode(examples);
|
if (SketchContainer.is(sketchOrContainer)) {
|
||||||
} catch (e) {
|
children.push(sketchOrContainer);
|
||||||
console.error(e);
|
} else {
|
||||||
console.warn('Could not patch menu ordering.');
|
sketches.push(sketchOrContainer);
|
||||||
}
|
}
|
||||||
// Registering the same submenu multiple times has no side-effect.
|
|
||||||
// TODO: unregister submenu? https://github.com/eclipse-theia/theia/issues/7300
|
|
||||||
registry.registerSubmenu(ArduinoMenus.FILE__EXAMPLES_SUBMENU, 'Examples', { order: '4' });
|
|
||||||
}
|
|
||||||
|
|
||||||
registerRecursively(
|
|
||||||
exampleContainerOrPlaceholder: ExampleContainer | string,
|
|
||||||
menuPath: MenuPath,
|
|
||||||
pushToDispose: DisposableCollection = new DisposableCollection()): void {
|
|
||||||
|
|
||||||
if (typeof exampleContainerOrPlaceholder === 'string') {
|
|
||||||
const placeholder = new PlaceholderMenuNode(menuPath, exampleContainerOrPlaceholder);
|
|
||||||
this.menuRegistry.registerMenuNode(menuPath, placeholder);
|
|
||||||
pushToDispose.push(Disposable.create(() => this.menuRegistry.unregisterMenuNode(placeholder.id)));
|
|
||||||
} else {
|
|
||||||
const { label, sketches, children } = exampleContainerOrPlaceholder;
|
|
||||||
const submenuPath = [...menuPath, label];
|
|
||||||
this.menuRegistry.registerSubmenu(submenuPath, label);
|
|
||||||
children.forEach(child => this.registerRecursively(child, submenuPath, pushToDispose));
|
|
||||||
for (const sketch of sketches) {
|
|
||||||
const { uri } = sketch;
|
|
||||||
const commandId = `arduino-open-example-${submenuPath.join(':')}--${uri}`;
|
|
||||||
const command = { id: commandId };
|
|
||||||
const handler = {
|
|
||||||
execute: async () => {
|
|
||||||
const sketch = await this.sketchService.cloneExample(uri);
|
|
||||||
this.commandService.executeCommand(OpenSketch.Commands.OPEN_SKETCH.id, sketch);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
pushToDispose.push(this.commandRegistry.registerCommand(command, handler));
|
|
||||||
this.menuRegistry.registerMenuAction(submenuPath, { commandId, label: sketch.name });
|
|
||||||
pushToDispose.push(Disposable.create(() => this.menuRegistry.unregisterMenuAction(command)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
children.forEach((child) =>
|
||||||
|
this.registerRecursively(child, submenuPath, pushToDispose)
|
||||||
|
);
|
||||||
|
for (const sketch of sketches) {
|
||||||
|
const { uri } = sketch;
|
||||||
|
const commandId = `arduino-open-example-${submenuPath.join(
|
||||||
|
':'
|
||||||
|
)}--${uri}`;
|
||||||
|
const command = { id: commandId };
|
||||||
|
const handler = this.createHandler(uri);
|
||||||
|
pushToDispose.push(
|
||||||
|
this.commandRegistry.registerCommand(command, handler)
|
||||||
|
);
|
||||||
|
this.menuRegistry.registerMenuAction(submenuPath, {
|
||||||
|
commandId,
|
||||||
|
label: sketch.name,
|
||||||
|
order: sketch.name.toLocaleLowerCase(),
|
||||||
|
});
|
||||||
|
pushToDispose.push(
|
||||||
|
Disposable.create(() =>
|
||||||
|
this.menuRegistry.unregisterMenuAction(command)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected createHandler(uri: string): CommandHandler {
|
||||||
|
return {
|
||||||
|
execute: async () => {
|
||||||
|
const sketch = await this.sketchService.cloneExample(uri);
|
||||||
|
return this.commandService.executeCommand(
|
||||||
|
OpenSketch.Commands.OPEN_SKETCH.id,
|
||||||
|
sketch
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class BuiltInExamples extends Examples {
|
export class BuiltInExamples extends Examples {
|
||||||
|
onStart(): void {
|
||||||
|
this.register(); // no `await`
|
||||||
|
}
|
||||||
|
|
||||||
onStart(): void {
|
protected async register(): Promise<void> {
|
||||||
this.register(); // no `await`
|
let sketchContainers: SketchContainer[] | undefined;
|
||||||
|
try {
|
||||||
|
sketchContainers = await this.examplesService.builtIns();
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Could not initialize built-in examples.', e);
|
||||||
|
this.messageService.error('Could not initialize built-in examples.');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
this.toDispose.dispose();
|
||||||
protected async register() {
|
for (const container of ['Built-in examples', ...sketchContainers]) {
|
||||||
let exampleContainers: ExampleContainer[] | undefined;
|
this.registerRecursively(
|
||||||
try {
|
container,
|
||||||
exampleContainers = await this.examplesService.builtIns();
|
ArduinoMenus.EXAMPLES__BUILT_IN_GROUP,
|
||||||
} catch (e) {
|
this.toDispose
|
||||||
console.error('Could not initialize built-in examples.', e);
|
);
|
||||||
this.messageService.error('Could not initialize built-in examples.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.toDispose.dispose();
|
|
||||||
for (const container of ['Built-in examples', ...exampleContainers]) {
|
|
||||||
this.registerRecursively(container, ArduinoMenus.EXAMPLES__BUILT_IN_GROUP, this.toDispose);
|
|
||||||
}
|
|
||||||
this.menuManager.update();
|
|
||||||
// TODO: remove
|
|
||||||
console.log(typeof this.menuRegistry);
|
|
||||||
}
|
}
|
||||||
|
this.menuManager.update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class LibraryExamples extends Examples {
|
export class LibraryExamples extends Examples {
|
||||||
|
@inject(NotificationCenter)
|
||||||
|
protected readonly notificationCenter: NotificationCenter;
|
||||||
|
|
||||||
@inject(NotificationCenter)
|
protected readonly queue = new PQueue({ autoStart: true, concurrency: 1 });
|
||||||
protected readonly notificationCenter: NotificationCenter;
|
|
||||||
|
|
||||||
protected readonly queue = new PQueue({ autoStart: true, concurrency: 1 });
|
onStart(): void {
|
||||||
|
this.register(); // no `await`
|
||||||
|
this.notificationCenter.onLibraryInstalled(() => this.register());
|
||||||
|
this.notificationCenter.onLibraryUninstalled(() => this.register());
|
||||||
|
}
|
||||||
|
|
||||||
onStart(): void {
|
protected handleBoardChanged(board: Board | undefined): void {
|
||||||
this.register(); // no `await`
|
this.register(board);
|
||||||
this.notificationCenter.onLibraryInstalled(() => this.register());
|
}
|
||||||
this.notificationCenter.onLibraryUninstalled(() => this.register());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected handleBoardChanged(board: Board | undefined): void {
|
|
||||||
this.register(board);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async register(board: Board | undefined = this.boardsServiceClient.boardsConfig.selectedBoard) {
|
|
||||||
return this.queue.add(async () => {
|
|
||||||
this.toDispose.dispose();
|
|
||||||
if (!board || !board.fqbn) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const { fqbn, name } = board;
|
|
||||||
const { user, current, any } = await this.examplesService.installed({ fqbn });
|
|
||||||
if (user.length) {
|
|
||||||
(user as any).unshift('Examples from Custom Libraries');
|
|
||||||
}
|
|
||||||
if (current.length) {
|
|
||||||
(current as any).unshift(`Examples for ${name}`);
|
|
||||||
}
|
|
||||||
if (any.length) {
|
|
||||||
(any as any).unshift('Examples for any board');
|
|
||||||
}
|
|
||||||
for (const container of user) {
|
|
||||||
this.registerRecursively(container, ArduinoMenus.EXAMPLES__USER_LIBS_GROUP, this.toDispose);
|
|
||||||
}
|
|
||||||
for (const container of current) {
|
|
||||||
this.registerRecursively(container, ArduinoMenus.EXAMPLES__CURRENT_BOARD_GROUP, this.toDispose);
|
|
||||||
}
|
|
||||||
for (const container of any) {
|
|
||||||
this.registerRecursively(container, ArduinoMenus.EXAMPLES__ANY_BOARD_GROUP, this.toDispose);
|
|
||||||
}
|
|
||||||
this.menuManager.update();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
protected async register(
|
||||||
|
board: Board | undefined = this.boardsServiceClient.boardsConfig
|
||||||
|
.selectedBoard
|
||||||
|
): Promise<void> {
|
||||||
|
return this.queue.add(async () => {
|
||||||
|
this.toDispose.dispose();
|
||||||
|
const fqbn = board?.fqbn;
|
||||||
|
const name = board?.name;
|
||||||
|
// Shows all examples when no board is selected, or the platform of the currently selected board is not installed.
|
||||||
|
const { user, current, any } = await this.examplesService.installed({
|
||||||
|
fqbn,
|
||||||
|
});
|
||||||
|
if (user.length) {
|
||||||
|
(user as any).unshift('Examples from Custom Libraries');
|
||||||
|
}
|
||||||
|
if (name && fqbn && current.length) {
|
||||||
|
(current as any).unshift(`Examples for ${name}`);
|
||||||
|
}
|
||||||
|
if (any.length) {
|
||||||
|
(any as any).unshift('Examples for any board');
|
||||||
|
}
|
||||||
|
for (const container of user) {
|
||||||
|
this.registerRecursively(
|
||||||
|
container,
|
||||||
|
ArduinoMenus.EXAMPLES__USER_LIBS_GROUP,
|
||||||
|
this.toDispose
|
||||||
|
);
|
||||||
|
}
|
||||||
|
for (const container of current) {
|
||||||
|
this.registerRecursively(
|
||||||
|
container,
|
||||||
|
ArduinoMenus.EXAMPLES__CURRENT_BOARD_GROUP,
|
||||||
|
this.toDispose
|
||||||
|
);
|
||||||
|
}
|
||||||
|
for (const container of any) {
|
||||||
|
this.registerRecursively(
|
||||||
|
container,
|
||||||
|
ArduinoMenus.EXAMPLES__ANY_BOARD_GROUP,
|
||||||
|
this.toDispose
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.menuManager.update();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,133 +5,161 @@ import { WindowService } from '@theia/core/lib/browser/window/window-service';
|
|||||||
import { CommandHandler } from '@theia/core/lib/common/command';
|
import { CommandHandler } from '@theia/core/lib/common/command';
|
||||||
import { QuickInputService } from '@theia/core/lib/browser/quick-open/quick-input-service';
|
import { QuickInputService } from '@theia/core/lib/browser/quick-open/quick-input-service';
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
import { Contribution, Command, MenuModelRegistry, CommandRegistry, KeybindingRegistry } from './contribution';
|
import {
|
||||||
|
Contribution,
|
||||||
|
Command,
|
||||||
|
MenuModelRegistry,
|
||||||
|
CommandRegistry,
|
||||||
|
KeybindingRegistry,
|
||||||
|
} from './contribution';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class Help extends Contribution {
|
export class Help extends Contribution {
|
||||||
|
@inject(EditorManager)
|
||||||
|
protected readonly editorManager: EditorManager;
|
||||||
|
|
||||||
@inject(EditorManager)
|
@inject(WindowService)
|
||||||
protected readonly editorManager: EditorManager;
|
protected readonly windowService: WindowService;
|
||||||
|
|
||||||
@inject(WindowService)
|
@inject(QuickInputService)
|
||||||
protected readonly windowService: WindowService;
|
protected readonly quickInputService: QuickInputService;
|
||||||
|
|
||||||
@inject(QuickInputService)
|
registerCommands(registry: CommandRegistry): void {
|
||||||
protected readonly quickInputService: QuickInputService;
|
const open = (url: string) =>
|
||||||
|
this.windowService.openNewWindow(url, { external: true });
|
||||||
|
const createOpenHandler = (url: string) =>
|
||||||
|
<CommandHandler>{
|
||||||
|
execute: () => open(url),
|
||||||
|
};
|
||||||
|
registry.registerCommand(
|
||||||
|
Help.Commands.GETTING_STARTED,
|
||||||
|
createOpenHandler('https://www.arduino.cc/en/Guide')
|
||||||
|
);
|
||||||
|
registry.registerCommand(
|
||||||
|
Help.Commands.ENVIRONMENT,
|
||||||
|
createOpenHandler('https://www.arduino.cc/en/Guide/Environment')
|
||||||
|
);
|
||||||
|
registry.registerCommand(
|
||||||
|
Help.Commands.TROUBLESHOOTING,
|
||||||
|
createOpenHandler('https://support.arduino.cc/hc/en-us')
|
||||||
|
);
|
||||||
|
registry.registerCommand(
|
||||||
|
Help.Commands.REFERENCE,
|
||||||
|
createOpenHandler('https://www.arduino.cc/reference/en/')
|
||||||
|
);
|
||||||
|
registry.registerCommand(Help.Commands.FIND_IN_REFERENCE, {
|
||||||
|
execute: async () => {
|
||||||
|
let searchFor: string | undefined = undefined;
|
||||||
|
const { currentEditor } = this.editorManager;
|
||||||
|
if (currentEditor && currentEditor.editor instanceof MonacoEditor) {
|
||||||
|
const codeEditor = currentEditor.editor.getControl();
|
||||||
|
const selection = codeEditor.getSelection();
|
||||||
|
const model = codeEditor.getModel();
|
||||||
|
if (model && selection && !monaco.Range.isEmpty(selection)) {
|
||||||
|
searchFor = model.getValueInRange(selection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!searchFor) {
|
||||||
|
searchFor = await this.quickInputService.open({
|
||||||
|
prompt: 'Search on Arduino.cc',
|
||||||
|
placeHolder: 'Type a keyword',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (searchFor) {
|
||||||
|
return open(
|
||||||
|
`https://www.arduino.cc/search?q=${encodeURIComponent(
|
||||||
|
searchFor
|
||||||
|
)}&tab=reference`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
registry.registerCommand(
|
||||||
|
Help.Commands.FAQ,
|
||||||
|
createOpenHandler('https://support.arduino.cc/hc/en-us')
|
||||||
|
);
|
||||||
|
registry.registerCommand(
|
||||||
|
Help.Commands.VISIT_ARDUINO,
|
||||||
|
createOpenHandler('https://www.arduino.cc/')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
registerCommands(registry: CommandRegistry): void {
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
const open = (url: string) => this.windowService.openNewWindow(url, { external: true });
|
registry.registerMenuAction(ArduinoMenus.HELP__MAIN_GROUP, {
|
||||||
const createOpenHandler = (url: string) => <CommandHandler>{
|
commandId: Help.Commands.GETTING_STARTED.id,
|
||||||
execute: () => open(url)
|
order: '0',
|
||||||
};
|
});
|
||||||
registry.registerCommand(Help.Commands.GETTING_STARTED, createOpenHandler('https://www.arduino.cc/en/Guide'));
|
registry.registerMenuAction(ArduinoMenus.HELP__MAIN_GROUP, {
|
||||||
registry.registerCommand(Help.Commands.ENVIRONMENT, createOpenHandler('https://www.arduino.cc/en/Guide/Environment'));
|
commandId: Help.Commands.ENVIRONMENT.id,
|
||||||
registry.registerCommand(Help.Commands.TROUBLESHOOTING, createOpenHandler('https://support.arduino.cc/hc/en-us'));
|
order: '1',
|
||||||
registry.registerCommand(Help.Commands.REFERENCE, createOpenHandler('https://www.arduino.cc/reference/en/'));
|
});
|
||||||
registry.registerCommand(Help.Commands.FIND_IN_REFERENCE, {
|
registry.registerMenuAction(ArduinoMenus.HELP__MAIN_GROUP, {
|
||||||
execute: async () => {
|
commandId: Help.Commands.TROUBLESHOOTING.id,
|
||||||
let searchFor: string | undefined = undefined;
|
order: '2',
|
||||||
const { currentEditor } = this.editorManager;
|
});
|
||||||
if (currentEditor && currentEditor.editor instanceof MonacoEditor) {
|
registry.registerMenuAction(ArduinoMenus.HELP__MAIN_GROUP, {
|
||||||
const codeEditor = currentEditor.editor.getControl();
|
commandId: Help.Commands.REFERENCE.id,
|
||||||
const selection = codeEditor.getSelection();
|
order: '3',
|
||||||
const model = codeEditor.getModel();
|
});
|
||||||
if (model && selection && !monaco.Range.isEmpty(selection)) {
|
|
||||||
searchFor = model.getValueInRange(selection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!searchFor) {
|
|
||||||
searchFor = await this.quickInputService.open({
|
|
||||||
prompt: 'Search on Arduino.cc',
|
|
||||||
placeHolder: 'Type a keyword'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (searchFor) {
|
|
||||||
return open(`https://www.arduino.cc/search?q=${encodeURIComponent(searchFor)}&tab=reference`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
registry.registerCommand(Help.Commands.FAQ, createOpenHandler('https://support.arduino.cc/hc/en-us'));
|
|
||||||
registry.registerCommand(Help.Commands.VISIT_ARDUINO, createOpenHandler('https://www.arduino.cc/'));
|
|
||||||
}
|
|
||||||
|
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
registry.registerMenuAction(ArduinoMenus.HELP__FIND_GROUP, {
|
||||||
registry.registerMenuAction(ArduinoMenus.HELP__MAIN_GROUP, {
|
commandId: Help.Commands.FIND_IN_REFERENCE.id,
|
||||||
commandId: Help.Commands.GETTING_STARTED.id,
|
order: '4',
|
||||||
order: '0'
|
});
|
||||||
});
|
registry.registerMenuAction(ArduinoMenus.HELP__FIND_GROUP, {
|
||||||
registry.registerMenuAction(ArduinoMenus.HELP__MAIN_GROUP, {
|
commandId: Help.Commands.FAQ.id,
|
||||||
commandId: Help.Commands.ENVIRONMENT.id,
|
order: '5',
|
||||||
order: '1'
|
});
|
||||||
});
|
registry.registerMenuAction(ArduinoMenus.HELP__FIND_GROUP, {
|
||||||
registry.registerMenuAction(ArduinoMenus.HELP__MAIN_GROUP, {
|
commandId: Help.Commands.VISIT_ARDUINO.id,
|
||||||
commandId: Help.Commands.TROUBLESHOOTING.id,
|
order: '6',
|
||||||
order: '2'
|
});
|
||||||
});
|
}
|
||||||
registry.registerMenuAction(ArduinoMenus.HELP__MAIN_GROUP, {
|
|
||||||
commandId: Help.Commands.REFERENCE.id,
|
|
||||||
order: '3'
|
|
||||||
});
|
|
||||||
|
|
||||||
registry.registerMenuAction(ArduinoMenus.HELP__FIND_GROUP, {
|
|
||||||
commandId: Help.Commands.FIND_IN_REFERENCE.id,
|
|
||||||
order: '4'
|
|
||||||
});
|
|
||||||
registry.registerMenuAction(ArduinoMenus.HELP__FIND_GROUP, {
|
|
||||||
commandId: Help.Commands.FAQ.id,
|
|
||||||
order: '5'
|
|
||||||
});
|
|
||||||
registry.registerMenuAction(ArduinoMenus.HELP__FIND_GROUP, {
|
|
||||||
commandId: Help.Commands.VISIT_ARDUINO.id,
|
|
||||||
order: '6'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
registerKeybindings(registry: KeybindingRegistry): void {
|
|
||||||
registry.registerKeybinding({
|
|
||||||
command: Help.Commands.FIND_IN_REFERENCE.id,
|
|
||||||
keybinding: 'CtrlCmd+Shift+F'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
registerKeybindings(registry: KeybindingRegistry): void {
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: Help.Commands.FIND_IN_REFERENCE.id,
|
||||||
|
keybinding: 'CtrlCmd+Shift+F',
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace Help {
|
export namespace Help {
|
||||||
export namespace Commands {
|
export namespace Commands {
|
||||||
export const GETTING_STARTED: Command = {
|
export const GETTING_STARTED: Command = {
|
||||||
id: 'arduino-getting-started',
|
id: 'arduino-getting-started',
|
||||||
label: 'Getting Started',
|
label: 'Getting Started',
|
||||||
category: 'Arduino'
|
category: 'Arduino',
|
||||||
};
|
};
|
||||||
export const ENVIRONMENT: Command = {
|
export const ENVIRONMENT: Command = {
|
||||||
id: 'arduino-environment',
|
id: 'arduino-environment',
|
||||||
label: 'Environment',
|
label: 'Environment',
|
||||||
category: 'Arduino'
|
category: 'Arduino',
|
||||||
};
|
};
|
||||||
export const TROUBLESHOOTING: Command = {
|
export const TROUBLESHOOTING: Command = {
|
||||||
id: 'arduino-troubleshooting',
|
id: 'arduino-troubleshooting',
|
||||||
label: 'Troubleshooting',
|
label: 'Troubleshooting',
|
||||||
category: 'Arduino'
|
category: 'Arduino',
|
||||||
};
|
};
|
||||||
export const REFERENCE: Command = {
|
export const REFERENCE: Command = {
|
||||||
id: 'arduino-reference',
|
id: 'arduino-reference',
|
||||||
label: 'Reference',
|
label: 'Reference',
|
||||||
category: 'Arduino'
|
category: 'Arduino',
|
||||||
};
|
};
|
||||||
export const FIND_IN_REFERENCE: Command = {
|
export const FIND_IN_REFERENCE: Command = {
|
||||||
id: 'arduino-find-in-reference',
|
id: 'arduino-find-in-reference',
|
||||||
label: 'Find in Reference',
|
label: 'Find in Reference',
|
||||||
category: 'Arduino'
|
category: 'Arduino',
|
||||||
};
|
};
|
||||||
export const FAQ: Command = {
|
export const FAQ: Command = {
|
||||||
id: 'arduino-faq',
|
id: 'arduino-faq',
|
||||||
label: 'Frequently Asked Questions',
|
label: 'Frequently Asked Questions',
|
||||||
category: 'Arduino'
|
category: 'Arduino',
|
||||||
};
|
};
|
||||||
export const VISIT_ARDUINO: Command = {
|
export const VISIT_ARDUINO: Command = {
|
||||||
id: 'arduino-visit-arduino',
|
id: 'arduino-visit-arduino',
|
||||||
label: 'Visit Arduino.cc',
|
label: 'Visit Arduino.cc',
|
||||||
category: 'Arduino'
|
category: 'Arduino',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import URI from '@theia/core/lib/common/uri';
|
|||||||
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
|
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
|
||||||
import { EditorManager } from '@theia/editor/lib/browser';
|
import { EditorManager } from '@theia/editor/lib/browser';
|
||||||
import { MenuModelRegistry, MenuPath } from '@theia/core/lib/common/menu';
|
import { MenuModelRegistry, MenuPath } from '@theia/core/lib/common/menu';
|
||||||
import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
|
import {
|
||||||
|
Disposable,
|
||||||
|
DisposableCollection,
|
||||||
|
} from '@theia/core/lib/common/disposable';
|
||||||
import { ArduinoMenus, PlaceholderMenuNode } from '../menu/arduino-menus';
|
import { ArduinoMenus, PlaceholderMenuNode } from '../menu/arduino-menus';
|
||||||
import { LibraryPackage, LibraryService } from '../../common/protocol';
|
import { LibraryPackage, LibraryService } from '../../common/protocol';
|
||||||
import { MainMenuManager } from '../../common/main-menu-manager';
|
import { MainMenuManager } from '../../common/main-menu-manager';
|
||||||
@@ -15,161 +18,198 @@ import { NotificationCenter } from '../notification-center';
|
|||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class IncludeLibrary extends SketchContribution {
|
export class IncludeLibrary extends SketchContribution {
|
||||||
|
@inject(CommandRegistry)
|
||||||
|
protected readonly commandRegistry: CommandRegistry;
|
||||||
|
|
||||||
@inject(CommandRegistry)
|
@inject(MenuModelRegistry)
|
||||||
protected readonly commandRegistry: CommandRegistry;
|
protected readonly menuRegistry: MenuModelRegistry;
|
||||||
|
|
||||||
@inject(MenuModelRegistry)
|
@inject(MainMenuManager)
|
||||||
protected readonly menuRegistry: MenuModelRegistry;
|
protected readonly mainMenuManager: MainMenuManager;
|
||||||
|
|
||||||
@inject(MainMenuManager)
|
@inject(EditorManager)
|
||||||
protected readonly mainMenuManager: MainMenuManager;
|
protected readonly editorManager: EditorManager;
|
||||||
|
|
||||||
@inject(EditorManager)
|
@inject(NotificationCenter)
|
||||||
protected readonly editorManager: EditorManager;
|
protected readonly notificationCenter: NotificationCenter;
|
||||||
|
|
||||||
@inject(NotificationCenter)
|
@inject(BoardsServiceProvider)
|
||||||
protected readonly notificationCenter: NotificationCenter;
|
protected readonly boardsServiceClient: BoardsServiceProvider;
|
||||||
|
|
||||||
@inject(BoardsServiceProvider)
|
@inject(LibraryService)
|
||||||
protected readonly boardsServiceClient: BoardsServiceProvider;
|
protected readonly libraryService: LibraryService;
|
||||||
|
|
||||||
@inject(LibraryService)
|
protected readonly queue = new PQueue({ autoStart: true, concurrency: 1 });
|
||||||
protected readonly libraryService: LibraryService;
|
protected readonly toDispose = new DisposableCollection();
|
||||||
|
|
||||||
protected readonly queue = new PQueue({ autoStart: true, concurrency: 1 });
|
onStart(): void {
|
||||||
protected readonly toDispose = new DisposableCollection();
|
this.updateMenuActions();
|
||||||
|
this.boardsServiceClient.onBoardsConfigChanged(() =>
|
||||||
|
this.updateMenuActions()
|
||||||
|
);
|
||||||
|
this.notificationCenter.onLibraryInstalled(() => this.updateMenuActions());
|
||||||
|
this.notificationCenter.onLibraryUninstalled(() =>
|
||||||
|
this.updateMenuActions()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
onStart(): void {
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
this.updateMenuActions();
|
// `Include Library` submenu
|
||||||
this.boardsServiceClient.onBoardsConfigChanged(() => this.updateMenuActions())
|
const includeLibMenuPath = [
|
||||||
this.notificationCenter.onLibraryInstalled(() => this.updateMenuActions());
|
...ArduinoMenus.SKETCH__UTILS_GROUP,
|
||||||
this.notificationCenter.onLibraryUninstalled(() => this.updateMenuActions());
|
'0_include',
|
||||||
|
];
|
||||||
|
registry.registerSubmenu(includeLibMenuPath, 'Include Library', {
|
||||||
|
order: '1',
|
||||||
|
});
|
||||||
|
// `Manage Libraries...` group.
|
||||||
|
registry.registerMenuAction([...includeLibMenuPath, '0_manage'], {
|
||||||
|
commandId: `${LibraryListWidget.WIDGET_ID}:toggle`,
|
||||||
|
label: 'Manage Libraries...',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerCommands(registry: CommandRegistry): void {
|
||||||
|
registry.registerCommand(IncludeLibrary.Commands.INCLUDE_LIBRARY, {
|
||||||
|
execute: async (arg) => {
|
||||||
|
if (LibraryPackage.is(arg)) {
|
||||||
|
this.includeLibrary(arg);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async updateMenuActions(): Promise<void> {
|
||||||
|
return this.queue.add(async () => {
|
||||||
|
this.toDispose.dispose();
|
||||||
|
this.mainMenuManager.update();
|
||||||
|
const libraries: LibraryPackage[] = [];
|
||||||
|
const fqbn = this.boardsServiceClient.boardsConfig.selectedBoard?.fqbn;
|
||||||
|
// Show all libraries, when no board is selected.
|
||||||
|
// Otherwise, show libraries only for the selected board.
|
||||||
|
libraries.push(...(await this.libraryService.list({ fqbn })));
|
||||||
|
|
||||||
|
const includeLibMenuPath = [
|
||||||
|
...ArduinoMenus.SKETCH__UTILS_GROUP,
|
||||||
|
'0_include',
|
||||||
|
];
|
||||||
|
// `Add .ZIP Library...`
|
||||||
|
// TODO: implement it
|
||||||
|
|
||||||
|
// `Arduino libraries`
|
||||||
|
const packageMenuPath = [...includeLibMenuPath, '2_arduino'];
|
||||||
|
const userMenuPath = [...includeLibMenuPath, '3_contributed'];
|
||||||
|
const { user, rest } = LibraryPackage.groupByLocation(libraries);
|
||||||
|
if (rest.length) {
|
||||||
|
(rest as any).unshift('Arduino libraries');
|
||||||
|
}
|
||||||
|
if (user.length) {
|
||||||
|
(user as any).unshift('Contributed libraries');
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const library of user) {
|
||||||
|
this.toDispose.push(this.registerLibrary(library, userMenuPath));
|
||||||
|
}
|
||||||
|
for (const library of rest) {
|
||||||
|
this.toDispose.push(this.registerLibrary(library, packageMenuPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.mainMenuManager.update();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected registerLibrary(
|
||||||
|
libraryOrPlaceholder: LibraryPackage | string,
|
||||||
|
menuPath: MenuPath
|
||||||
|
): Disposable {
|
||||||
|
if (typeof libraryOrPlaceholder === 'string') {
|
||||||
|
const placeholder = new PlaceholderMenuNode(
|
||||||
|
menuPath,
|
||||||
|
libraryOrPlaceholder
|
||||||
|
);
|
||||||
|
this.menuRegistry.registerMenuNode(menuPath, placeholder);
|
||||||
|
return Disposable.create(() =>
|
||||||
|
this.menuRegistry.unregisterMenuNode(placeholder.id)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const commandId = `arduino-include-library--${libraryOrPlaceholder.name}:${libraryOrPlaceholder.author}`;
|
||||||
|
const command = { id: commandId };
|
||||||
|
const handler = {
|
||||||
|
execute: () =>
|
||||||
|
this.commandRegistry.executeCommand(
|
||||||
|
IncludeLibrary.Commands.INCLUDE_LIBRARY.id,
|
||||||
|
libraryOrPlaceholder
|
||||||
|
),
|
||||||
|
};
|
||||||
|
const menuAction = { commandId, label: libraryOrPlaceholder.name };
|
||||||
|
this.menuRegistry.registerMenuAction(menuPath, menuAction);
|
||||||
|
return new DisposableCollection(
|
||||||
|
this.commandRegistry.registerCommand(command, handler),
|
||||||
|
Disposable.create(() =>
|
||||||
|
this.menuRegistry.unregisterMenuAction(menuAction)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async includeLibrary(library: LibraryPackage): Promise<void> {
|
||||||
|
const sketch = await this.sketchServiceClient.currentSketch();
|
||||||
|
if (!sketch) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// If the current editor is one of the additional files from the sketch, we use that.
|
||||||
|
// Otherwise, we pick the editor of the main sketch file.
|
||||||
|
let codeEditor: monaco.editor.IStandaloneCodeEditor | undefined;
|
||||||
|
const editor = this.editorManager.currentEditor?.editor;
|
||||||
|
if (editor instanceof MonacoEditor) {
|
||||||
|
if (
|
||||||
|
sketch.additionalFileUris.some((uri) => uri === editor.uri.toString())
|
||||||
|
) {
|
||||||
|
codeEditor = editor.getControl();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
registerCommands(registry: CommandRegistry): void {
|
if (!codeEditor) {
|
||||||
registry.registerCommand(IncludeLibrary.Commands.INCLUDE_LIBRARY, {
|
const widget = await this.editorManager.open(new URI(sketch.mainFileUri));
|
||||||
execute: async arg => {
|
if (widget.editor instanceof MonacoEditor) {
|
||||||
if (LibraryPackage.is(arg)) {
|
codeEditor = widget.editor.getControl();
|
||||||
this.includeLibrary(arg);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async updateMenuActions(): Promise<void> {
|
if (!codeEditor) {
|
||||||
return this.queue.add(async () => {
|
return;
|
||||||
this.toDispose.dispose();
|
|
||||||
this.mainMenuManager.update();
|
|
||||||
const libraries: LibraryPackage[] = []
|
|
||||||
const fqbn = this.boardsServiceClient.boardsConfig.selectedBoard?.fqbn;
|
|
||||||
// Do not show board specific examples, when no board is selected.
|
|
||||||
if (fqbn) {
|
|
||||||
libraries.push(...await this.libraryService.list({ fqbn }));
|
|
||||||
}
|
|
||||||
|
|
||||||
// `Include Library` submenu
|
|
||||||
const includeLibMenuPath = [...ArduinoMenus.SKETCH__UTILS_GROUP, '0_include'];
|
|
||||||
this.menuRegistry.registerSubmenu(includeLibMenuPath, 'Include Library', { order: '1' });
|
|
||||||
// `Manage Libraries...` group.
|
|
||||||
this.menuRegistry.registerMenuAction([...includeLibMenuPath, '0_manage'], {
|
|
||||||
commandId: `${LibraryListWidget.WIDGET_ID}:toggle`,
|
|
||||||
label: 'Manage Libraries...'
|
|
||||||
});
|
|
||||||
this.toDispose.push(Disposable.create(() => this.menuRegistry.unregisterMenuAction({ commandId: `${LibraryListWidget.WIDGET_ID}:toggle` })));
|
|
||||||
|
|
||||||
// `Add .ZIP Library...`
|
|
||||||
// TODO: implement it
|
|
||||||
|
|
||||||
// `Arduino libraries`
|
|
||||||
const packageMenuPath = [...includeLibMenuPath, '2_arduino'];
|
|
||||||
const userMenuPath = [...includeLibMenuPath, '3_contributed'];
|
|
||||||
const { user, rest } = LibraryPackage.groupByLocation(libraries);
|
|
||||||
if (rest.length) {
|
|
||||||
(rest as any).unshift('Arduino libraries');
|
|
||||||
}
|
|
||||||
if (user.length) {
|
|
||||||
(user as any).unshift('Contributed libraries');
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const library of user) {
|
|
||||||
this.toDispose.push(this.registerLibrary(library, userMenuPath));
|
|
||||||
}
|
|
||||||
for (const library of rest) {
|
|
||||||
this.toDispose.push(this.registerLibrary(library, packageMenuPath));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.mainMenuManager.update();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected registerLibrary(libraryOrPlaceholder: LibraryPackage | string, menuPath: MenuPath): Disposable {
|
const textModel = codeEditor.getModel();
|
||||||
if (typeof libraryOrPlaceholder === 'string') {
|
if (!textModel) {
|
||||||
const placeholder = new PlaceholderMenuNode(menuPath, libraryOrPlaceholder);
|
return;
|
||||||
this.menuRegistry.registerMenuNode(menuPath, placeholder);
|
|
||||||
return Disposable.create(() => this.menuRegistry.unregisterMenuNode(placeholder.id));
|
|
||||||
}
|
|
||||||
const commandId = `arduino-include-library--${libraryOrPlaceholder.name}:${libraryOrPlaceholder.author}`;
|
|
||||||
const command = { id: commandId };
|
|
||||||
const handler = { execute: () => this.commandRegistry.executeCommand(IncludeLibrary.Commands.INCLUDE_LIBRARY.id, libraryOrPlaceholder) };
|
|
||||||
const menuAction = { commandId, label: libraryOrPlaceholder.name };
|
|
||||||
this.menuRegistry.registerMenuAction(menuPath, menuAction);
|
|
||||||
return new DisposableCollection(
|
|
||||||
this.commandRegistry.registerCommand(command, handler),
|
|
||||||
Disposable.create(() => this.menuRegistry.unregisterMenuAction(menuAction)),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
const cursorState = codeEditor.getSelections() || [];
|
||||||
protected async includeLibrary(library: LibraryPackage): Promise<void> {
|
const eol = textModel.getEOL();
|
||||||
const sketch = await this.sketchServiceClient.currentSketch();
|
const includes = library.includes.slice();
|
||||||
if (!sketch) {
|
includes.push(''); // For the trailing new line.
|
||||||
return;
|
const text = includes
|
||||||
}
|
.map((include) => (include ? `#include <${include}>` : eol))
|
||||||
// If the current editor is one of the additional files from the sketch, we use that.
|
.join(eol);
|
||||||
// Otherwise, we pick the editor of the main sketch file.
|
textModel.pushStackElement(); // Start a fresh operation.
|
||||||
let codeEditor: monaco.editor.IStandaloneCodeEditor | undefined;
|
textModel.pushEditOperations(
|
||||||
const editor = this.editorManager.currentEditor?.editor;
|
cursorState,
|
||||||
if (editor instanceof MonacoEditor) {
|
[
|
||||||
if (sketch.additionalFileUris.some(uri => uri === editor.uri.toString())) {
|
{
|
||||||
codeEditor = editor.getControl();
|
range: new monaco.Range(1, 1, 1, 1),
|
||||||
}
|
text,
|
||||||
}
|
forceMoveMarkers: true,
|
||||||
|
},
|
||||||
if (!codeEditor) {
|
],
|
||||||
const widget = await this.editorManager.open(new URI(sketch.mainFileUri));
|
() => cursorState
|
||||||
if (widget.editor instanceof MonacoEditor) {
|
);
|
||||||
codeEditor = widget.editor.getControl();
|
textModel.pushStackElement(); // Make it undoable.
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!codeEditor) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const textModel = codeEditor.getModel();
|
|
||||||
if (!textModel) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const cursorState = codeEditor.getSelections() || [];
|
|
||||||
const eol = textModel.getEOL();
|
|
||||||
const includes = library.includes.slice();
|
|
||||||
includes.push(''); // For the trailing new line.
|
|
||||||
const text = includes.map(include => include ? `#include <${include}>` : eol).join(eol);
|
|
||||||
textModel.pushStackElement(); // Start a fresh operation.
|
|
||||||
textModel.pushEditOperations(cursorState, [{
|
|
||||||
range: new monaco.Range(1, 1, 1, 1),
|
|
||||||
text,
|
|
||||||
forceMoveMarkers: true
|
|
||||||
}], () => cursorState);
|
|
||||||
textModel.pushStackElement(); // Make it undoable.
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace IncludeLibrary {
|
export namespace IncludeLibrary {
|
||||||
export namespace Commands {
|
export namespace Commands {
|
||||||
export const INCLUDE_LIBRARY: Command = {
|
export const INCLUDE_LIBRARY: Command = {
|
||||||
id: 'arduino-include-library'
|
id: 'arduino-include-library',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,63 +1,70 @@
|
|||||||
import { injectable } from 'inversify';
|
import { injectable } from 'inversify';
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
|
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
|
||||||
import { SketchContribution, URI, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, TabBarToolbarRegistry } from './contribution';
|
import {
|
||||||
|
SketchContribution,
|
||||||
|
URI,
|
||||||
|
Command,
|
||||||
|
CommandRegistry,
|
||||||
|
MenuModelRegistry,
|
||||||
|
KeybindingRegistry,
|
||||||
|
TabBarToolbarRegistry,
|
||||||
|
} from './contribution';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class NewSketch extends SketchContribution {
|
export class NewSketch extends SketchContribution {
|
||||||
|
registerCommands(registry: CommandRegistry): void {
|
||||||
|
registry.registerCommand(NewSketch.Commands.NEW_SKETCH, {
|
||||||
|
execute: () => this.newSketch(),
|
||||||
|
});
|
||||||
|
registry.registerCommand(NewSketch.Commands.NEW_SKETCH__TOOLBAR, {
|
||||||
|
isVisible: (widget) =>
|
||||||
|
ArduinoToolbar.is(widget) && widget.side === 'left',
|
||||||
|
execute: () => registry.executeCommand(NewSketch.Commands.NEW_SKETCH.id),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
registerCommands(registry: CommandRegistry): void {
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
registry.registerCommand(NewSketch.Commands.NEW_SKETCH, {
|
registry.registerMenuAction(ArduinoMenus.FILE__SKETCH_GROUP, {
|
||||||
execute: () => this.newSketch()
|
commandId: NewSketch.Commands.NEW_SKETCH.id,
|
||||||
});
|
label: 'New',
|
||||||
registry.registerCommand(NewSketch.Commands.NEW_SKETCH__TOOLBAR, {
|
order: '0',
|
||||||
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
|
});
|
||||||
execute: () => registry.executeCommand(NewSketch.Commands.NEW_SKETCH.id)
|
}
|
||||||
});
|
|
||||||
|
registerKeybindings(registry: KeybindingRegistry): void {
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: NewSketch.Commands.NEW_SKETCH.id,
|
||||||
|
keybinding: 'CtrlCmd+N',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerToolbarItems(registry: TabBarToolbarRegistry): void {
|
||||||
|
registry.registerItem({
|
||||||
|
id: NewSketch.Commands.NEW_SKETCH__TOOLBAR.id,
|
||||||
|
command: NewSketch.Commands.NEW_SKETCH__TOOLBAR.id,
|
||||||
|
tooltip: 'New',
|
||||||
|
priority: 3,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async newSketch(): Promise<void> {
|
||||||
|
try {
|
||||||
|
const sketch = await this.sketchService.createNewSketch();
|
||||||
|
this.workspaceService.open(new URI(sketch.uri));
|
||||||
|
} catch (e) {
|
||||||
|
await this.messageService.error(e.toString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
|
||||||
registry.registerMenuAction(ArduinoMenus.FILE__SKETCH_GROUP, {
|
|
||||||
commandId: NewSketch.Commands.NEW_SKETCH.id,
|
|
||||||
label: 'New',
|
|
||||||
order: '0'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
registerKeybindings(registry: KeybindingRegistry): void {
|
|
||||||
registry.registerKeybinding({
|
|
||||||
command: NewSketch.Commands.NEW_SKETCH.id,
|
|
||||||
keybinding: 'CtrlCmd+N'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
registerToolbarItems(registry: TabBarToolbarRegistry): void {
|
|
||||||
registry.registerItem({
|
|
||||||
id: NewSketch.Commands.NEW_SKETCH__TOOLBAR.id,
|
|
||||||
command: NewSketch.Commands.NEW_SKETCH__TOOLBAR.id,
|
|
||||||
tooltip: 'New',
|
|
||||||
priority: 3
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async newSketch(): Promise<void> {
|
|
||||||
try {
|
|
||||||
const sketch = await this.sketchService.createNewSketch();
|
|
||||||
this.workspaceService.open(new URI(sketch.uri));
|
|
||||||
} catch (e) {
|
|
||||||
await this.messageService.error(e.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace NewSketch {
|
export namespace NewSketch {
|
||||||
export namespace Commands {
|
export namespace Commands {
|
||||||
export const NEW_SKETCH: Command = {
|
export const NEW_SKETCH: Command = {
|
||||||
id: 'arduino-new-sketch'
|
id: 'arduino-new-sketch',
|
||||||
};
|
};
|
||||||
export const NEW_SKETCH__TOOLBAR: Command = {
|
export const NEW_SKETCH__TOOLBAR: Command = {
|
||||||
id: 'arduino-new-sketch--toolbar'
|
id: 'arduino-new-sketch--toolbar',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,15 @@
|
|||||||
import { inject, injectable } from 'inversify';
|
import { inject, injectable } from 'inversify';
|
||||||
import { WorkspaceServer } from '@theia/workspace/lib/common/workspace-protocol';
|
import { WorkspaceServer } from '@theia/workspace/lib/common/workspace-protocol';
|
||||||
import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
|
import {
|
||||||
import { SketchContribution, CommandRegistry, MenuModelRegistry, Sketch } from './contribution';
|
Disposable,
|
||||||
|
DisposableCollection,
|
||||||
|
} from '@theia/core/lib/common/disposable';
|
||||||
|
import {
|
||||||
|
SketchContribution,
|
||||||
|
CommandRegistry,
|
||||||
|
MenuModelRegistry,
|
||||||
|
Sketch,
|
||||||
|
} from './contribution';
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
import { MainMenuManager } from '../../common/main-menu-manager';
|
import { MainMenuManager } from '../../common/main-menu-manager';
|
||||||
import { OpenSketch } from './open-sketch';
|
import { OpenSketch } from './open-sketch';
|
||||||
@@ -9,54 +17,78 @@ import { NotificationCenter } from '../notification-center';
|
|||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class OpenRecentSketch extends SketchContribution {
|
export class OpenRecentSketch extends SketchContribution {
|
||||||
|
@inject(CommandRegistry)
|
||||||
|
protected readonly commandRegistry: CommandRegistry;
|
||||||
|
|
||||||
@inject(CommandRegistry)
|
@inject(MenuModelRegistry)
|
||||||
protected readonly commandRegistry: CommandRegistry;
|
protected readonly menuRegistry: MenuModelRegistry;
|
||||||
|
|
||||||
@inject(MenuModelRegistry)
|
@inject(MainMenuManager)
|
||||||
protected readonly menuRegistry: MenuModelRegistry;
|
protected readonly mainMenuManager: MainMenuManager;
|
||||||
|
|
||||||
@inject(MainMenuManager)
|
@inject(WorkspaceServer)
|
||||||
protected readonly mainMenuManager: MainMenuManager;
|
protected readonly workspaceServer: WorkspaceServer;
|
||||||
|
|
||||||
@inject(WorkspaceServer)
|
@inject(NotificationCenter)
|
||||||
protected readonly workspaceServer: WorkspaceServer;
|
protected readonly notificationCenter: NotificationCenter;
|
||||||
|
|
||||||
@inject(NotificationCenter)
|
protected toDisposeBeforeRegister = new Map<string, DisposableCollection>();
|
||||||
protected readonly notificationCenter: NotificationCenter;
|
|
||||||
|
|
||||||
protected toDisposeBeforeRegister = new Map<string, DisposableCollection>();
|
onStart(): void {
|
||||||
|
const refreshMenu = (sketches: Sketch[]) => {
|
||||||
|
this.register(sketches);
|
||||||
|
this.mainMenuManager.update();
|
||||||
|
};
|
||||||
|
this.notificationCenter.onRecentSketchesChanged(({ sketches }) =>
|
||||||
|
refreshMenu(sketches)
|
||||||
|
);
|
||||||
|
this.sketchService.recentlyOpenedSketches().then(refreshMenu);
|
||||||
|
}
|
||||||
|
|
||||||
onStart(): void {
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
const refreshMenu = (sketches: Sketch[]) => {
|
registry.registerSubmenu(
|
||||||
this.register(sketches);
|
ArduinoMenus.FILE__OPEN_RECENT_SUBMENU,
|
||||||
this.mainMenuManager.update();
|
'Open Recent',
|
||||||
};
|
{ order: '2' }
|
||||||
this.notificationCenter.onRecentSketchesChanged(({ sketches }) => refreshMenu(sketches));
|
);
|
||||||
this.sketchService.recentlyOpenedSketches().then(refreshMenu);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
protected register(sketches: Sketch[]): void {
|
||||||
registry.registerSubmenu(ArduinoMenus.FILE__OPEN_RECENT_SUBMENU, 'Open Recent', { order: '2' });
|
const order = 0;
|
||||||
}
|
for (const sketch of sketches) {
|
||||||
|
const { uri } = sketch;
|
||||||
protected register(sketches: Sketch[]): void {
|
const toDispose = this.toDisposeBeforeRegister.get(uri);
|
||||||
let order = 0;
|
if (toDispose) {
|
||||||
for (const sketch of sketches) {
|
toDispose.dispose();
|
||||||
const { uri } = sketch;
|
}
|
||||||
const toDispose = this.toDisposeBeforeRegister.get(uri);
|
const command = { id: `arduino-open-recent--${uri}` };
|
||||||
if (toDispose) {
|
const handler = {
|
||||||
toDispose.dispose();
|
execute: () =>
|
||||||
}
|
this.commandRegistry.executeCommand(
|
||||||
const command = { id: `arduino-open-recent--${uri}` };
|
OpenSketch.Commands.OPEN_SKETCH.id,
|
||||||
const handler = { execute: () => this.commandRegistry.executeCommand(OpenSketch.Commands.OPEN_SKETCH.id, sketch) };
|
sketch
|
||||||
this.commandRegistry.registerCommand(command, handler);
|
),
|
||||||
this.menuRegistry.registerMenuAction(ArduinoMenus.FILE__OPEN_RECENT_SUBMENU, { commandId: command.id, label: sketch.name, order: String(order) });
|
};
|
||||||
this.toDisposeBeforeRegister.set(sketch.uri, new DisposableCollection(
|
this.commandRegistry.registerCommand(command, handler);
|
||||||
Disposable.create(() => this.commandRegistry.unregisterCommand(command)),
|
this.menuRegistry.registerMenuAction(
|
||||||
Disposable.create(() => this.menuRegistry.unregisterMenuAction(command))
|
ArduinoMenus.FILE__OPEN_RECENT_SUBMENU,
|
||||||
));
|
{
|
||||||
|
commandId: command.id,
|
||||||
|
label: sketch.name,
|
||||||
|
order: String(order),
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
this.toDisposeBeforeRegister.set(
|
||||||
|
sketch.uri,
|
||||||
|
new DisposableCollection(
|
||||||
|
Disposable.create(() =>
|
||||||
|
this.commandRegistry.unregisterCommand(command)
|
||||||
|
),
|
||||||
|
Disposable.create(() =>
|
||||||
|
this.menuRegistry.unregisterMenuAction(command)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,51 +2,55 @@ import { injectable } from 'inversify';
|
|||||||
import { remote } from 'electron';
|
import { remote } from 'electron';
|
||||||
import URI from '@theia/core/lib/common/uri';
|
import URI from '@theia/core/lib/common/uri';
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry } from './contribution';
|
import {
|
||||||
|
SketchContribution,
|
||||||
|
Command,
|
||||||
|
CommandRegistry,
|
||||||
|
MenuModelRegistry,
|
||||||
|
KeybindingRegistry,
|
||||||
|
} from './contribution';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class OpenSketchExternal extends SketchContribution {
|
export class OpenSketchExternal extends SketchContribution {
|
||||||
|
registerCommands(registry: CommandRegistry): void {
|
||||||
|
registry.registerCommand(OpenSketchExternal.Commands.OPEN_EXTERNAL, {
|
||||||
|
execute: () => this.openExternal(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
registerCommands(registry: CommandRegistry): void {
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
registry.registerCommand(OpenSketchExternal.Commands.OPEN_EXTERNAL, {
|
registry.registerMenuAction(ArduinoMenus.SKETCH__UTILS_GROUP, {
|
||||||
execute: () => this.openExternal()
|
commandId: OpenSketchExternal.Commands.OPEN_EXTERNAL.id,
|
||||||
});
|
label: 'Show Sketch Folder',
|
||||||
}
|
order: '0',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
registerKeybindings(registry: KeybindingRegistry): void {
|
||||||
registry.registerMenuAction(ArduinoMenus.SKETCH__UTILS_GROUP, {
|
registry.registerKeybinding({
|
||||||
commandId: OpenSketchExternal.Commands.OPEN_EXTERNAL.id,
|
command: OpenSketchExternal.Commands.OPEN_EXTERNAL.id,
|
||||||
label: 'Show Sketch Folder',
|
keybinding: 'CtrlCmd+Alt+K',
|
||||||
order: '0'
|
});
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
registerKeybindings(registry: KeybindingRegistry): void {
|
protected async openExternal(): Promise<void> {
|
||||||
registry.registerKeybinding({
|
const uri = await this.sketchServiceClient.currentSketchFile();
|
||||||
command: OpenSketchExternal.Commands.OPEN_EXTERNAL.id,
|
if (uri) {
|
||||||
keybinding: 'CtrlCmd+Alt+K'
|
const exists = this.fileService.exists(new URI(uri));
|
||||||
});
|
if (exists) {
|
||||||
}
|
const fsPath = await this.fileService.fsPath(new URI(uri));
|
||||||
|
if (fsPath) {
|
||||||
protected async openExternal(): Promise<void> {
|
remote.shell.showItemInFolder(fsPath);
|
||||||
const uri = await this.sketchServiceClient.currentSketchFile();
|
|
||||||
if (uri) {
|
|
||||||
const exists = this.fileService.exists(new URI(uri));
|
|
||||||
if (exists) {
|
|
||||||
const fsPath = await this.fileService.fsPath(new URI(uri));
|
|
||||||
if (fsPath) {
|
|
||||||
remote.shell.showItemInFolder(fsPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace OpenSketchExternal {
|
export namespace OpenSketchExternal {
|
||||||
export namespace Commands {
|
export namespace Commands {
|
||||||
export const OPEN_EXTERNAL: Command = {
|
export const OPEN_EXTERNAL: Command = {
|
||||||
id: 'arduino-open-sketch-external'
|
id: 'arduino-open-sketch-external',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,178 +2,217 @@ import { inject, injectable } from 'inversify';
|
|||||||
import { remote } from 'electron';
|
import { remote } from 'electron';
|
||||||
import { MaybePromise } from '@theia/core/lib/common/types';
|
import { MaybePromise } from '@theia/core/lib/common/types';
|
||||||
import { Widget, ContextMenuRenderer } from '@theia/core/lib/browser';
|
import { Widget, ContextMenuRenderer } from '@theia/core/lib/browser';
|
||||||
import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
|
import {
|
||||||
|
Disposable,
|
||||||
|
DisposableCollection,
|
||||||
|
} from '@theia/core/lib/common/disposable';
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
|
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
|
||||||
import { SketchContribution, Sketch, URI, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, TabBarToolbarRegistry } from './contribution';
|
import {
|
||||||
|
SketchContribution,
|
||||||
|
Sketch,
|
||||||
|
URI,
|
||||||
|
Command,
|
||||||
|
CommandRegistry,
|
||||||
|
MenuModelRegistry,
|
||||||
|
KeybindingRegistry,
|
||||||
|
TabBarToolbarRegistry,
|
||||||
|
} from './contribution';
|
||||||
import { ExamplesService } from '../../common/protocol/examples-service';
|
import { ExamplesService } from '../../common/protocol/examples-service';
|
||||||
import { BuiltInExamples } from './examples';
|
import { BuiltInExamples } from './examples';
|
||||||
|
import { Sketchbook } from './sketchbook';
|
||||||
|
import { SketchContainer } from '../../common/protocol';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class OpenSketch extends SketchContribution {
|
export class OpenSketch extends SketchContribution {
|
||||||
|
@inject(MenuModelRegistry)
|
||||||
|
protected readonly menuRegistry: MenuModelRegistry;
|
||||||
|
|
||||||
@inject(MenuModelRegistry)
|
@inject(ContextMenuRenderer)
|
||||||
protected readonly menuRegistry: MenuModelRegistry;
|
protected readonly contextMenuRenderer: ContextMenuRenderer;
|
||||||
|
|
||||||
@inject(ContextMenuRenderer)
|
@inject(BuiltInExamples)
|
||||||
protected readonly contextMenuRenderer: ContextMenuRenderer;
|
protected readonly builtInExamples: BuiltInExamples;
|
||||||
|
|
||||||
@inject(BuiltInExamples)
|
@inject(ExamplesService)
|
||||||
protected readonly builtInExamples: BuiltInExamples;
|
protected readonly examplesService: ExamplesService;
|
||||||
|
|
||||||
@inject(ExamplesService)
|
@inject(Sketchbook)
|
||||||
protected readonly examplesService: ExamplesService;
|
protected readonly sketchbook: Sketchbook;
|
||||||
|
|
||||||
protected readonly toDisposeBeforeCreateNewContextMenu = new DisposableCollection();
|
protected readonly toDispose = new DisposableCollection();
|
||||||
|
|
||||||
registerCommands(registry: CommandRegistry): void {
|
registerCommands(registry: CommandRegistry): void {
|
||||||
registry.registerCommand(OpenSketch.Commands.OPEN_SKETCH, {
|
registry.registerCommand(OpenSketch.Commands.OPEN_SKETCH, {
|
||||||
execute: arg => Sketch.is(arg) ? this.openSketch(arg) : this.openSketch()
|
execute: (arg) =>
|
||||||
|
Sketch.is(arg) ? this.openSketch(arg) : this.openSketch(),
|
||||||
|
});
|
||||||
|
registry.registerCommand(OpenSketch.Commands.OPEN_SKETCH__TOOLBAR, {
|
||||||
|
isVisible: (widget) =>
|
||||||
|
ArduinoToolbar.is(widget) && widget.side === 'left',
|
||||||
|
execute: async (_: Widget, target: EventTarget) => {
|
||||||
|
const container = await this.sketchService.getSketches({
|
||||||
|
exclude: ['**/hardware/**'],
|
||||||
});
|
});
|
||||||
registry.registerCommand(OpenSketch.Commands.OPEN_SKETCH__TOOLBAR, {
|
if (SketchContainer.isEmpty(container)) {
|
||||||
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
|
this.openSketch();
|
||||||
execute: async (_: Widget, target: EventTarget) => {
|
} else {
|
||||||
const sketches = await this.sketchService.getSketches();
|
this.toDispose.dispose();
|
||||||
if (!sketches.length) {
|
if (!(target instanceof HTMLElement)) {
|
||||||
this.openSketch();
|
return;
|
||||||
} else {
|
}
|
||||||
this.toDisposeBeforeCreateNewContextMenu.dispose();
|
const { parentElement } = target;
|
||||||
if (!(target instanceof HTMLElement)) {
|
if (!parentElement) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { parentElement } = target;
|
|
||||||
if (!parentElement) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.menuRegistry.registerMenuAction(ArduinoMenus.OPEN_SKETCH__CONTEXT__OPEN_GROUP, {
|
this.menuRegistry.registerMenuAction(
|
||||||
commandId: OpenSketch.Commands.OPEN_SKETCH.id,
|
ArduinoMenus.OPEN_SKETCH__CONTEXT__OPEN_GROUP,
|
||||||
label: 'Open...'
|
{
|
||||||
});
|
commandId: OpenSketch.Commands.OPEN_SKETCH.id,
|
||||||
this.toDisposeBeforeCreateNewContextMenu.push(Disposable.create(() => this.menuRegistry.unregisterMenuAction(OpenSketch.Commands.OPEN_SKETCH)));
|
label: 'Open...',
|
||||||
for (const sketch of sketches) {
|
|
||||||
const command = { id: `arduino-open-sketch--${sketch.uri}` };
|
|
||||||
const handler = { execute: () => this.openSketch(sketch) };
|
|
||||||
this.toDisposeBeforeCreateNewContextMenu.push(registry.registerCommand(command, handler));
|
|
||||||
this.menuRegistry.registerMenuAction(ArduinoMenus.OPEN_SKETCH__CONTEXT__RECENT_GROUP, {
|
|
||||||
commandId: command.id,
|
|
||||||
label: sketch.name
|
|
||||||
});
|
|
||||||
this.toDisposeBeforeCreateNewContextMenu.push(Disposable.create(() => this.menuRegistry.unregisterMenuAction(command)));
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const containers = await this.examplesService.builtIns();
|
|
||||||
for (const container of containers) {
|
|
||||||
this.builtInExamples.registerRecursively(container, ArduinoMenus.OPEN_SKETCH__CONTEXT__EXAMPLES_GROUP, this.toDisposeBeforeCreateNewContextMenu);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Error when collecting built-in examples.', e);
|
|
||||||
}
|
|
||||||
const options = {
|
|
||||||
menuPath: ArduinoMenus.OPEN_SKETCH__CONTEXT,
|
|
||||||
anchor: {
|
|
||||||
x: parentElement.getBoundingClientRect().left,
|
|
||||||
y: parentElement.getBoundingClientRect().top + parentElement.offsetHeight
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.contextMenuRenderer.render(options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
}
|
this.toDispose.push(
|
||||||
|
Disposable.create(() =>
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
this.menuRegistry.unregisterMenuAction(
|
||||||
registry.registerMenuAction(ArduinoMenus.FILE__SKETCH_GROUP, {
|
OpenSketch.Commands.OPEN_SKETCH
|
||||||
commandId: OpenSketch.Commands.OPEN_SKETCH.id,
|
)
|
||||||
label: 'Open...',
|
)
|
||||||
order: '1'
|
);
|
||||||
});
|
this.sketchbook.registerRecursively(
|
||||||
}
|
[...container.children, ...container.sketches],
|
||||||
|
ArduinoMenus.OPEN_SKETCH__CONTEXT__RECENT_GROUP,
|
||||||
registerKeybindings(registry: KeybindingRegistry): void {
|
this.toDispose
|
||||||
registry.registerKeybinding({
|
);
|
||||||
command: OpenSketch.Commands.OPEN_SKETCH.id,
|
try {
|
||||||
keybinding: 'CtrlCmd+O'
|
const containers = await this.examplesService.builtIns();
|
||||||
});
|
for (const container of containers) {
|
||||||
}
|
this.builtInExamples.registerRecursively(
|
||||||
|
container,
|
||||||
registerToolbarItems(registry: TabBarToolbarRegistry): void {
|
ArduinoMenus.OPEN_SKETCH__CONTEXT__EXAMPLES_GROUP,
|
||||||
registry.registerItem({
|
this.toDispose
|
||||||
id: OpenSketch.Commands.OPEN_SKETCH__TOOLBAR.id,
|
);
|
||||||
command: OpenSketch.Commands.OPEN_SKETCH__TOOLBAR.id,
|
|
||||||
tooltip: 'Open',
|
|
||||||
priority: 4
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async openSketch(toOpen: MaybePromise<Sketch | undefined> = this.selectSketch()): Promise<void> {
|
|
||||||
const sketch = await toOpen;
|
|
||||||
if (sketch) {
|
|
||||||
this.workspaceService.open(new URI(sketch.uri));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async selectSketch(): Promise<Sketch | undefined> {
|
|
||||||
const config = await this.configService.getConfiguration();
|
|
||||||
const defaultPath = await this.fileService.fsPath(new URI(config.sketchDirUri));
|
|
||||||
const { filePaths } = await remote.dialog.showOpenDialog({
|
|
||||||
defaultPath,
|
|
||||||
properties: ['createDirectory', 'openFile'],
|
|
||||||
filters: [
|
|
||||||
{
|
|
||||||
name: 'Sketch',
|
|
||||||
extensions: ['ino', 'pde']
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
if (!filePaths.length) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
if (filePaths.length > 1) {
|
|
||||||
this.logger.warn(`Multiple sketches were selected: ${filePaths}. Using the first one.`);
|
|
||||||
}
|
|
||||||
const sketchFilePath = filePaths[0];
|
|
||||||
const sketchFileUri = await this.fileSystemExt.getUri(sketchFilePath);
|
|
||||||
const sketch = await this.sketchService.getSketchFolder(sketchFileUri);
|
|
||||||
if (sketch) {
|
|
||||||
return sketch;
|
|
||||||
}
|
|
||||||
if (Sketch.isSketchFile(sketchFileUri)) {
|
|
||||||
const name = new URI(sketchFileUri).path.name;
|
|
||||||
const nameWithExt = this.labelProvider.getName(new URI(sketchFileUri));
|
|
||||||
const { response } = await remote.dialog.showMessageBox({
|
|
||||||
title: 'Moving',
|
|
||||||
type: 'question',
|
|
||||||
buttons: ['Cancel', 'OK'],
|
|
||||||
message: `The file "${nameWithExt}" needs to be inside a sketch folder named as "${name}".\nCreate this folder, move the file, and continue?`
|
|
||||||
});
|
|
||||||
if (response === 1) { // OK
|
|
||||||
const newSketchUri = new URI(sketchFileUri).parent.resolve(name);
|
|
||||||
const exists = await this.fileService.exists(newSketchUri);
|
|
||||||
if (exists) {
|
|
||||||
await remote.dialog.showMessageBox({
|
|
||||||
type: 'error',
|
|
||||||
title: 'Error',
|
|
||||||
message: `A folder named "${name}" already exists. Can't open sketch.`
|
|
||||||
});
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
await this.fileService.createFolder(newSketchUri);
|
|
||||||
await this.fileService.move(new URI(sketchFileUri), new URI(newSketchUri.resolve(nameWithExt).toString()));
|
|
||||||
return this.sketchService.getSketchFolder(newSketchUri.toString());
|
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error when collecting built-in examples.', e);
|
||||||
|
}
|
||||||
|
const options = {
|
||||||
|
menuPath: ArduinoMenus.OPEN_SKETCH__CONTEXT,
|
||||||
|
anchor: {
|
||||||
|
x: parentElement.getBoundingClientRect().left,
|
||||||
|
y:
|
||||||
|
parentElement.getBoundingClientRect().top +
|
||||||
|
parentElement.offsetHeight,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
this.contextMenuRenderer.render(options);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
|
registry.registerMenuAction(ArduinoMenus.FILE__SKETCH_GROUP, {
|
||||||
|
commandId: OpenSketch.Commands.OPEN_SKETCH.id,
|
||||||
|
label: 'Open...',
|
||||||
|
order: '1',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerKeybindings(registry: KeybindingRegistry): void {
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: OpenSketch.Commands.OPEN_SKETCH.id,
|
||||||
|
keybinding: 'CtrlCmd+O',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerToolbarItems(registry: TabBarToolbarRegistry): void {
|
||||||
|
registry.registerItem({
|
||||||
|
id: OpenSketch.Commands.OPEN_SKETCH__TOOLBAR.id,
|
||||||
|
command: OpenSketch.Commands.OPEN_SKETCH__TOOLBAR.id,
|
||||||
|
tooltip: 'Open',
|
||||||
|
priority: 4,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async openSketch(
|
||||||
|
toOpen: MaybePromise<Sketch | undefined> = this.selectSketch()
|
||||||
|
): Promise<void> {
|
||||||
|
const sketch = await toOpen;
|
||||||
|
if (sketch) {
|
||||||
|
this.workspaceService.open(new URI(sketch.uri));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async selectSketch(): Promise<Sketch | undefined> {
|
||||||
|
const config = await this.configService.getConfiguration();
|
||||||
|
const defaultPath = await this.fileService.fsPath(
|
||||||
|
new URI(config.sketchDirUri)
|
||||||
|
);
|
||||||
|
const { filePaths } = await remote.dialog.showOpenDialog({
|
||||||
|
defaultPath,
|
||||||
|
properties: ['createDirectory', 'openFile'],
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
name: 'Sketch',
|
||||||
|
extensions: ['ino', 'pde'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
if (!filePaths.length) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
if (filePaths.length > 1) {
|
||||||
|
this.logger.warn(
|
||||||
|
`Multiple sketches were selected: ${filePaths}. Using the first one.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const sketchFilePath = filePaths[0];
|
||||||
|
const sketchFileUri = await this.fileSystemExt.getUri(sketchFilePath);
|
||||||
|
const sketch = await this.sketchService.getSketchFolder(sketchFileUri);
|
||||||
|
if (sketch) {
|
||||||
|
return sketch;
|
||||||
|
}
|
||||||
|
if (Sketch.isSketchFile(sketchFileUri)) {
|
||||||
|
const name = new URI(sketchFileUri).path.name;
|
||||||
|
const nameWithExt = this.labelProvider.getName(new URI(sketchFileUri));
|
||||||
|
const { response } = await remote.dialog.showMessageBox({
|
||||||
|
title: 'Moving',
|
||||||
|
type: 'question',
|
||||||
|
buttons: ['Cancel', 'OK'],
|
||||||
|
message: `The file "${nameWithExt}" needs to be inside a sketch folder named as "${name}".\nCreate this folder, move the file, and continue?`,
|
||||||
|
});
|
||||||
|
if (response === 1) {
|
||||||
|
// OK
|
||||||
|
const newSketchUri = new URI(sketchFileUri).parent.resolve(name);
|
||||||
|
const exists = await this.fileService.exists(newSketchUri);
|
||||||
|
if (exists) {
|
||||||
|
await remote.dialog.showMessageBox({
|
||||||
|
type: 'error',
|
||||||
|
title: 'Error',
|
||||||
|
message: `A folder named "${name}" already exists. Can't open sketch.`,
|
||||||
|
});
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
await this.fileService.createFolder(newSketchUri);
|
||||||
|
await this.fileService.move(
|
||||||
|
new URI(sketchFileUri),
|
||||||
|
new URI(newSketchUri.resolve(nameWithExt).toString())
|
||||||
|
);
|
||||||
|
return this.sketchService.getSketchFolder(newSketchUri.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace OpenSketch {
|
export namespace OpenSketch {
|
||||||
export namespace Commands {
|
export namespace Commands {
|
||||||
export const OPEN_SKETCH: Command = {
|
export const OPEN_SKETCH: Command = {
|
||||||
id: 'arduino-open-sketch'
|
id: 'arduino-open-sketch',
|
||||||
};
|
};
|
||||||
export const OPEN_SKETCH__TOOLBAR: Command = {
|
export const OPEN_SKETCH__TOOLBAR: Command = {
|
||||||
id: 'arduino-open-sketch--toolbar'
|
id: 'arduino-open-sketch--toolbar',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,46 +1,50 @@
|
|||||||
import { injectable } from 'inversify';
|
import { injectable } from 'inversify';
|
||||||
import { remote } from 'electron';
|
import { remote } from 'electron';
|
||||||
import { isOSX } from '@theia/core/lib/common/os';
|
import { isOSX } from '@theia/core/lib/common/os';
|
||||||
import { Contribution, Command, MenuModelRegistry, KeybindingRegistry, CommandRegistry } from './contribution';
|
import {
|
||||||
|
Contribution,
|
||||||
|
Command,
|
||||||
|
MenuModelRegistry,
|
||||||
|
KeybindingRegistry,
|
||||||
|
CommandRegistry,
|
||||||
|
} from './contribution';
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class QuitApp extends Contribution {
|
export class QuitApp extends Contribution {
|
||||||
|
registerCommands(registry: CommandRegistry): void {
|
||||||
registerCommands(registry: CommandRegistry): void {
|
if (!isOSX) {
|
||||||
if (!isOSX) {
|
registry.registerCommand(QuitApp.Commands.QUIT_APP, {
|
||||||
registry.registerCommand(QuitApp.Commands.QUIT_APP, {
|
execute: () => remote.app.quit(),
|
||||||
execute: () => remote.app.quit()
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
// On macOS we will get the `Quit ${YOUR_APP_NAME}` menu item natively, no need to duplicate it.
|
// On macOS we will get the `Quit ${YOUR_APP_NAME}` menu item natively, no need to duplicate it.
|
||||||
if (!isOSX) {
|
if (!isOSX) {
|
||||||
registry.registerMenuAction(ArduinoMenus.FILE__QUIT_GROUP, {
|
registry.registerMenuAction(ArduinoMenus.FILE__QUIT_GROUP, {
|
||||||
commandId: QuitApp.Commands.QUIT_APP.id,
|
commandId: QuitApp.Commands.QUIT_APP.id,
|
||||||
label: 'Quit',
|
label: 'Quit',
|
||||||
order: '0'
|
order: '0',
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
registerKeybindings(registry: KeybindingRegistry): void {
|
registerKeybindings(registry: KeybindingRegistry): void {
|
||||||
if (!isOSX) {
|
if (!isOSX) {
|
||||||
registry.registerKeybinding({
|
registry.registerKeybinding({
|
||||||
command: QuitApp.Commands.QUIT_APP.id,
|
command: QuitApp.Commands.QUIT_APP.id,
|
||||||
keybinding: 'CtrlCmd+Q'
|
keybinding: 'CtrlCmd+Q',
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace QuitApp {
|
export namespace QuitApp {
|
||||||
export namespace Commands {
|
export namespace Commands {
|
||||||
export const QUIT_APP: Command = {
|
export const QUIT_APP: Command = {
|
||||||
id: 'arduino-quit-app'
|
id: 'arduino-quit-app',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,95 +2,127 @@ import { injectable } from 'inversify';
|
|||||||
import { remote } from 'electron';
|
import { remote } from 'electron';
|
||||||
import * as dateFormat from 'dateformat';
|
import * as dateFormat from 'dateformat';
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
import { SketchContribution, URI, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry } from './contribution';
|
import {
|
||||||
|
SketchContribution,
|
||||||
|
URI,
|
||||||
|
Command,
|
||||||
|
CommandRegistry,
|
||||||
|
MenuModelRegistry,
|
||||||
|
KeybindingRegistry,
|
||||||
|
} from './contribution';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class SaveAsSketch extends SketchContribution {
|
export class SaveAsSketch extends SketchContribution {
|
||||||
|
registerCommands(registry: CommandRegistry): void {
|
||||||
|
registry.registerCommand(SaveAsSketch.Commands.SAVE_AS_SKETCH, {
|
||||||
|
execute: (args) => this.saveAs(args),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
registerCommands(registry: CommandRegistry): void {
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
registry.registerCommand(SaveAsSketch.Commands.SAVE_AS_SKETCH, {
|
registry.registerMenuAction(ArduinoMenus.FILE__SKETCH_GROUP, {
|
||||||
execute: args => this.saveAs(args)
|
commandId: SaveAsSketch.Commands.SAVE_AS_SKETCH.id,
|
||||||
});
|
label: 'Save As...',
|
||||||
|
order: '7',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerKeybindings(registry: KeybindingRegistry): void {
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: SaveAsSketch.Commands.SAVE_AS_SKETCH.id,
|
||||||
|
keybinding: 'CtrlCmd+Shift+S',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves `true` if the sketch was successfully saved as something.
|
||||||
|
*/
|
||||||
|
async saveAs(
|
||||||
|
{
|
||||||
|
execOnlyIfTemp,
|
||||||
|
openAfterMove,
|
||||||
|
wipeOriginal,
|
||||||
|
}: SaveAsSketch.Options = SaveAsSketch.Options.DEFAULT
|
||||||
|
): Promise<boolean> {
|
||||||
|
const sketch = await this.sketchServiceClient.currentSketch();
|
||||||
|
if (!sketch) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
const isTemp = await this.sketchService.isTemp(sketch);
|
||||||
registry.registerMenuAction(ArduinoMenus.FILE__SKETCH_GROUP, {
|
if (!isTemp && !!execOnlyIfTemp) {
|
||||||
commandId: SaveAsSketch.Commands.SAVE_AS_SKETCH.id,
|
return false;
|
||||||
label: 'Save As...',
|
|
||||||
order: '7'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
registerKeybindings(registry: KeybindingRegistry): void {
|
// If target does not exist, propose a `directories.user`/${sketch.name} path
|
||||||
registry.registerKeybinding({
|
// If target exists, propose `directories.user`/${sketch.name}_copy_${yyyymmddHHMMss}
|
||||||
command: SaveAsSketch.Commands.SAVE_AS_SKETCH.id,
|
const sketchDirUri = new URI(
|
||||||
keybinding: 'CtrlCmd+Shift+S'
|
(await this.configService.getConfiguration()).sketchDirUri
|
||||||
});
|
);
|
||||||
|
const exists = await this.fileService.exists(
|
||||||
|
sketchDirUri.resolve(sketch.name)
|
||||||
|
);
|
||||||
|
const defaultUri = exists
|
||||||
|
? sketchDirUri.resolve(
|
||||||
|
sketchDirUri
|
||||||
|
.resolve(
|
||||||
|
`${sketch.name}_copy_${dateFormat(new Date(), 'yyyymmddHHMMss')}`
|
||||||
|
)
|
||||||
|
.toString()
|
||||||
|
)
|
||||||
|
: sketchDirUri.resolve(sketch.name);
|
||||||
|
const defaultPath = await this.fileService.fsPath(defaultUri);
|
||||||
|
const { filePath, canceled } = await remote.dialog.showSaveDialog({
|
||||||
|
title: 'Save sketch folder as...',
|
||||||
|
defaultPath,
|
||||||
|
});
|
||||||
|
if (!filePath || canceled) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
const destinationUri = await this.fileSystemExt.getUri(filePath);
|
||||||
/**
|
if (!destinationUri) {
|
||||||
* Resolves `true` if the sketch was successfully saved as something.
|
return false;
|
||||||
*/
|
|
||||||
async saveAs({ execOnlyIfTemp, openAfterMove, wipeOriginal }: SaveAsSketch.Options = SaveAsSketch.Options.DEFAULT): Promise<boolean> {
|
|
||||||
const sketch = await this.sketchServiceClient.currentSketch();
|
|
||||||
if (!sketch) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const isTemp = await this.sketchService.isTemp(sketch);
|
|
||||||
if (!isTemp && !!execOnlyIfTemp) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If target does not exist, propose a `directories.user`/${sketch.name} path
|
|
||||||
// If target exists, propose `directories.user`/${sketch.name}_copy_${yyyymmddHHMMss}
|
|
||||||
const sketchDirUri = new URI((await this.configService.getConfiguration()).sketchDirUri);
|
|
||||||
const exists = await this.fileService.exists(sketchDirUri.resolve(sketch.name));
|
|
||||||
const defaultUri = exists
|
|
||||||
? sketchDirUri.resolve(sketchDirUri.resolve(`${sketch.name}_copy_${dateFormat(new Date(), 'yyyymmddHHMMss')}`).toString())
|
|
||||||
: sketchDirUri.resolve(sketch.name);
|
|
||||||
const defaultPath = await this.fileService.fsPath(defaultUri);
|
|
||||||
const { filePath, canceled } = await remote.dialog.showSaveDialog({ title: 'Save sketch folder as...', defaultPath });
|
|
||||||
if (!filePath || canceled) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const destinationUri = await this.fileSystemExt.getUri(filePath);
|
|
||||||
if (!destinationUri) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const workspaceUri = await this.sketchService.copy(sketch, { destinationUri });
|
|
||||||
if (workspaceUri && openAfterMove) {
|
|
||||||
if (wipeOriginal || (openAfterMove && execOnlyIfTemp)) {
|
|
||||||
try {
|
|
||||||
await this.fileService.delete(new URI(sketch.uri), { recursive: true });
|
|
||||||
} catch { /* NOOP: from time to time, it's not possible to wipe the old resource from the temp dir on Windows */ }
|
|
||||||
}
|
|
||||||
this.workspaceService.open(new URI(workspaceUri), { preserveWindow: true });
|
|
||||||
}
|
|
||||||
return !!workspaceUri;
|
|
||||||
}
|
}
|
||||||
|
const workspaceUri = await this.sketchService.copy(sketch, {
|
||||||
|
destinationUri,
|
||||||
|
});
|
||||||
|
if (workspaceUri && openAfterMove) {
|
||||||
|
if (wipeOriginal || (openAfterMove && execOnlyIfTemp)) {
|
||||||
|
try {
|
||||||
|
await this.fileService.delete(new URI(sketch.uri), {
|
||||||
|
recursive: true,
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
/* NOOP: from time to time, it's not possible to wipe the old resource from the temp dir on Windows */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.workspaceService.open(new URI(workspaceUri), {
|
||||||
|
preserveWindow: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return !!workspaceUri;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace SaveAsSketch {
|
export namespace SaveAsSketch {
|
||||||
export namespace Commands {
|
export namespace Commands {
|
||||||
export const SAVE_AS_SKETCH: Command = {
|
export const SAVE_AS_SKETCH: Command = {
|
||||||
id: 'arduino-save-as-sketch'
|
id: 'arduino-save-as-sketch',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
export interface Options {
|
export interface Options {
|
||||||
readonly execOnlyIfTemp?: boolean;
|
readonly execOnlyIfTemp?: boolean;
|
||||||
readonly openAfterMove?: boolean;
|
readonly openAfterMove?: boolean;
|
||||||
/**
|
/**
|
||||||
* Ignored if `openAfterMove` is `false`.
|
* Ignored if `openAfterMove` is `false`.
|
||||||
*/
|
*/
|
||||||
readonly wipeOriginal?: boolean;
|
readonly wipeOriginal?: boolean;
|
||||||
}
|
}
|
||||||
export namespace Options {
|
export namespace Options {
|
||||||
export const DEFAULT: Options = {
|
export const DEFAULT: Options = {
|
||||||
execOnlyIfTemp: false,
|
execOnlyIfTemp: false,
|
||||||
openAfterMove: true,
|
openAfterMove: true,
|
||||||
wipeOriginal: false
|
wipeOriginal: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,58 +2,65 @@ import { injectable } from 'inversify';
|
|||||||
import { CommonCommands } from '@theia/core/lib/browser/common-frontend-contribution';
|
import { CommonCommands } from '@theia/core/lib/browser/common-frontend-contribution';
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
|
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
|
||||||
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, TabBarToolbarRegistry } from './contribution';
|
import {
|
||||||
|
SketchContribution,
|
||||||
|
Command,
|
||||||
|
CommandRegistry,
|
||||||
|
MenuModelRegistry,
|
||||||
|
KeybindingRegistry,
|
||||||
|
TabBarToolbarRegistry,
|
||||||
|
} from './contribution';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class SaveSketch extends SketchContribution {
|
export class SaveSketch extends SketchContribution {
|
||||||
|
registerCommands(registry: CommandRegistry): void {
|
||||||
|
registry.registerCommand(SaveSketch.Commands.SAVE_SKETCH, {
|
||||||
|
execute: () => this.saveSketch(),
|
||||||
|
});
|
||||||
|
registry.registerCommand(SaveSketch.Commands.SAVE_SKETCH__TOOLBAR, {
|
||||||
|
isVisible: (widget) =>
|
||||||
|
ArduinoToolbar.is(widget) && widget.side === 'left',
|
||||||
|
execute: () =>
|
||||||
|
registry.executeCommand(SaveSketch.Commands.SAVE_SKETCH.id),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
registerCommands(registry: CommandRegistry): void {
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
registry.registerCommand(SaveSketch.Commands.SAVE_SKETCH, {
|
registry.registerMenuAction(ArduinoMenus.FILE__SKETCH_GROUP, {
|
||||||
execute: () => this.saveSketch()
|
commandId: SaveSketch.Commands.SAVE_SKETCH.id,
|
||||||
});
|
label: 'Save',
|
||||||
registry.registerCommand(SaveSketch.Commands.SAVE_SKETCH__TOOLBAR, {
|
order: '6',
|
||||||
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
|
});
|
||||||
execute: () => registry.executeCommand(SaveSketch.Commands.SAVE_SKETCH.id)
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
registerKeybindings(registry: KeybindingRegistry): void {
|
||||||
registry.registerMenuAction(ArduinoMenus.FILE__SKETCH_GROUP, {
|
registry.registerKeybinding({
|
||||||
commandId: SaveSketch.Commands.SAVE_SKETCH.id,
|
command: SaveSketch.Commands.SAVE_SKETCH.id,
|
||||||
label: 'Save',
|
keybinding: 'CtrlCmd+S',
|
||||||
order: '6'
|
});
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
registerKeybindings(registry: KeybindingRegistry): void {
|
registerToolbarItems(registry: TabBarToolbarRegistry): void {
|
||||||
registry.registerKeybinding({
|
registry.registerItem({
|
||||||
command: SaveSketch.Commands.SAVE_SKETCH.id,
|
id: SaveSketch.Commands.SAVE_SKETCH__TOOLBAR.id,
|
||||||
keybinding: 'CtrlCmd+S'
|
command: SaveSketch.Commands.SAVE_SKETCH__TOOLBAR.id,
|
||||||
});
|
tooltip: 'Save',
|
||||||
}
|
priority: 5,
|
||||||
|
});
|
||||||
registerToolbarItems(registry: TabBarToolbarRegistry): void {
|
}
|
||||||
registry.registerItem({
|
|
||||||
id: SaveSketch.Commands.SAVE_SKETCH__TOOLBAR.id,
|
|
||||||
command: SaveSketch.Commands.SAVE_SKETCH__TOOLBAR.id,
|
|
||||||
tooltip: 'Save',
|
|
||||||
priority: 5
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async saveSketch(): Promise<void> {
|
|
||||||
return this.commandService.executeCommand(CommonCommands.SAVE_ALL.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
async saveSketch(): Promise<void> {
|
||||||
|
return this.commandService.executeCommand(CommonCommands.SAVE_ALL.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace SaveSketch {
|
export namespace SaveSketch {
|
||||||
export namespace Commands {
|
export namespace Commands {
|
||||||
export const SAVE_SKETCH: Command = {
|
export const SAVE_SKETCH: Command = {
|
||||||
id: 'arduino-save-sketch'
|
id: 'arduino-save-sketch',
|
||||||
};
|
};
|
||||||
export const SAVE_SKETCH__TOOLBAR: Command = {
|
export const SAVE_SKETCH__TOOLBAR: Command = {
|
||||||
id: 'arduino-save-sketch--toolbar'
|
id: 'arduino-save-sketch--toolbar',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,60 +1,65 @@
|
|||||||
import { inject, injectable } from 'inversify';
|
import { inject, injectable } from 'inversify';
|
||||||
import { Command, MenuModelRegistry, CommandRegistry, SketchContribution, KeybindingRegistry } from './contribution';
|
import {
|
||||||
|
Command,
|
||||||
|
MenuModelRegistry,
|
||||||
|
CommandRegistry,
|
||||||
|
SketchContribution,
|
||||||
|
KeybindingRegistry,
|
||||||
|
} from './contribution';
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
import { Settings as Preferences, SettingsDialog } from '../settings';
|
import { Settings as Preferences, SettingsDialog } from '../settings';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class Settings extends SketchContribution {
|
export class Settings extends SketchContribution {
|
||||||
|
@inject(SettingsDialog)
|
||||||
|
protected readonly settingsDialog: SettingsDialog;
|
||||||
|
|
||||||
@inject(SettingsDialog)
|
protected settingsOpened = false;
|
||||||
protected readonly settingsDialog: SettingsDialog;
|
|
||||||
|
|
||||||
protected settingsOpened = false;
|
registerCommands(registry: CommandRegistry): void {
|
||||||
|
registry.registerCommand(Settings.Commands.OPEN, {
|
||||||
|
execute: async () => {
|
||||||
|
let settings: Preferences | undefined = undefined;
|
||||||
|
try {
|
||||||
|
this.settingsOpened = true;
|
||||||
|
settings = await this.settingsDialog.open();
|
||||||
|
} finally {
|
||||||
|
this.settingsOpened = false;
|
||||||
|
}
|
||||||
|
if (settings) {
|
||||||
|
await this.settingsService.update(settings);
|
||||||
|
await this.settingsService.save();
|
||||||
|
} else {
|
||||||
|
await this.settingsService.reset();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
isEnabled: () => !this.settingsOpened,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
registerCommands(registry: CommandRegistry): void {
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
registry.registerCommand(Settings.Commands.OPEN, {
|
registry.registerMenuAction(ArduinoMenus.FILE__PREFERENCES_GROUP, {
|
||||||
execute: async () => {
|
commandId: Settings.Commands.OPEN.id,
|
||||||
let settings: Preferences | undefined = undefined;
|
label: 'Preferences...',
|
||||||
try {
|
order: '0',
|
||||||
this.settingsOpened = true;
|
});
|
||||||
settings = await this.settingsDialog.open();
|
registry.registerSubmenu(ArduinoMenus.FILE__ADVANCED_SUBMENU, 'Advanced');
|
||||||
} finally {
|
}
|
||||||
this.settingsOpened = false;
|
|
||||||
}
|
|
||||||
if (settings) {
|
|
||||||
await this.settingsService.update(settings);
|
|
||||||
await this.settingsService.save();
|
|
||||||
} else {
|
|
||||||
await this.settingsService.reset();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
isEnabled: () => !this.settingsOpened
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
|
||||||
registry.registerMenuAction(ArduinoMenus.FILE__SETTINGS_GROUP, {
|
|
||||||
commandId: Settings.Commands.OPEN.id,
|
|
||||||
label: 'Preferences...',
|
|
||||||
order: '0'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
registerKeybindings(registry: KeybindingRegistry): void {
|
|
||||||
registry.registerKeybinding({
|
|
||||||
command: Settings.Commands.OPEN.id,
|
|
||||||
keybinding: 'CtrlCmd+,',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
registerKeybindings(registry: KeybindingRegistry): void {
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: Settings.Commands.OPEN.id,
|
||||||
|
keybinding: 'CtrlCmd+,',
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace Settings {
|
export namespace Settings {
|
||||||
export namespace Commands {
|
export namespace Commands {
|
||||||
export const OPEN: Command = {
|
export const OPEN: Command = {
|
||||||
id: 'arduino-settings-open',
|
id: 'arduino-settings-open',
|
||||||
label: 'Open Preferences...',
|
label: 'Open Preferences...',
|
||||||
category: 'Arduino'
|
category: 'Arduino',
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,127 +3,275 @@ import { CommonCommands } from '@theia/core/lib/browser/common-frontend-contribu
|
|||||||
import { ApplicationShell } from '@theia/core/lib/browser/shell/application-shell';
|
import { ApplicationShell } from '@theia/core/lib/browser/shell/application-shell';
|
||||||
import { WorkspaceCommands } from '@theia/workspace/lib/browser';
|
import { WorkspaceCommands } from '@theia/workspace/lib/browser';
|
||||||
import { ContextMenuRenderer } from '@theia/core/lib/browser/context-menu-renderer';
|
import { ContextMenuRenderer } from '@theia/core/lib/browser/context-menu-renderer';
|
||||||
import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
|
import {
|
||||||
import { URI, SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, TabBarToolbarRegistry, open } from './contribution';
|
Disposable,
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
DisposableCollection,
|
||||||
|
} from '@theia/core/lib/common/disposable';
|
||||||
|
import {
|
||||||
|
URI,
|
||||||
|
SketchContribution,
|
||||||
|
Command,
|
||||||
|
CommandRegistry,
|
||||||
|
MenuModelRegistry,
|
||||||
|
KeybindingRegistry,
|
||||||
|
TabBarToolbarRegistry,
|
||||||
|
open,
|
||||||
|
} from './contribution';
|
||||||
|
import { ArduinoMenus, PlaceholderMenuNode } from '../menu/arduino-menus';
|
||||||
|
import { EditorManager } from '@theia/editor/lib/browser/editor-manager';
|
||||||
|
import { SketchesServiceClientImpl } from '../../common/protocol/sketches-service-client-impl';
|
||||||
|
import { LocalCacheFsProvider } from '../local-cache/local-cache-fs-provider';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class SketchControl extends SketchContribution {
|
export class SketchControl extends SketchContribution {
|
||||||
|
@inject(ApplicationShell)
|
||||||
|
protected readonly shell: ApplicationShell;
|
||||||
|
|
||||||
@inject(ApplicationShell)
|
@inject(MenuModelRegistry)
|
||||||
protected readonly shell: ApplicationShell;
|
protected readonly menuRegistry: MenuModelRegistry;
|
||||||
|
|
||||||
@inject(MenuModelRegistry)
|
@inject(ContextMenuRenderer)
|
||||||
protected readonly menuRegistry: MenuModelRegistry;
|
protected readonly contextMenuRenderer: ContextMenuRenderer;
|
||||||
|
|
||||||
@inject(ContextMenuRenderer)
|
@inject(EditorManager)
|
||||||
protected readonly contextMenuRenderer: ContextMenuRenderer;
|
protected readonly editorManager: EditorManager;
|
||||||
|
|
||||||
protected readonly toDisposeBeforeCreateNewContextMenu = new DisposableCollection();
|
@inject(SketchesServiceClientImpl)
|
||||||
|
protected readonly sketchesServiceClient: SketchesServiceClientImpl;
|
||||||
|
|
||||||
registerCommands(registry: CommandRegistry): void {
|
@inject(LocalCacheFsProvider)
|
||||||
registry.registerCommand(SketchControl.Commands.OPEN_SKETCH_CONTROL__TOOLBAR, {
|
protected readonly localCacheFsProvider: LocalCacheFsProvider;
|
||||||
isVisible: widget => this.shell.getWidgets('main').indexOf(widget) !== -1,
|
|
||||||
execute: async () => {
|
|
||||||
this.toDisposeBeforeCreateNewContextMenu.dispose();
|
|
||||||
const sketch = await this.sketchServiceClient.currentSketch();
|
|
||||||
if (!sketch) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const target = document.getElementById(SketchControl.Commands.OPEN_SKETCH_CONTROL__TOOLBAR.id);
|
protected readonly toDisposeBeforeCreateNewContextMenu =
|
||||||
if (!(target instanceof HTMLElement)) {
|
new DisposableCollection();
|
||||||
return;
|
|
||||||
}
|
|
||||||
const { parentElement } = target;
|
|
||||||
if (!parentElement) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { mainFileUri, rootFolderFileUris } = await this.sketchService.loadSketch(sketch.uri);
|
registerCommands(registry: CommandRegistry): void {
|
||||||
const uris = [mainFileUri, ...rootFolderFileUris];
|
registry.registerCommand(
|
||||||
for (let i = 0; i < uris.length; i++) {
|
SketchControl.Commands.OPEN_SKETCH_CONTROL__TOOLBAR,
|
||||||
const uri = new URI(uris[i]);
|
{
|
||||||
const command = { id: `arduino-focus-file--${uri.toString()}` };
|
isVisible: (widget) =>
|
||||||
const handler = { execute: () => open(this.openerService, uri) };
|
this.shell.getWidgets('main').indexOf(widget) !== -1,
|
||||||
this.toDisposeBeforeCreateNewContextMenu.push(registry.registerCommand(command, handler));
|
execute: async () => {
|
||||||
this.menuRegistry.registerMenuAction(ArduinoMenus.SKETCH_CONTROL__CONTEXT__RESOURCES_GROUP, {
|
this.toDisposeBeforeCreateNewContextMenu.dispose();
|
||||||
commandId: command.id,
|
const sketch = await this.sketchServiceClient.currentSketch();
|
||||||
label: this.labelProvider.getName(uri),
|
if (!sketch) {
|
||||||
order: `${i}`
|
return;
|
||||||
});
|
}
|
||||||
this.toDisposeBeforeCreateNewContextMenu.push(Disposable.create(() => this.menuRegistry.unregisterMenuAction(command)));
|
|
||||||
}
|
const target = document.getElementById(
|
||||||
const options = {
|
SketchControl.Commands.OPEN_SKETCH_CONTROL__TOOLBAR.id
|
||||||
menuPath: ArduinoMenus.SKETCH_CONTROL__CONTEXT,
|
);
|
||||||
anchor: {
|
if (!(target instanceof HTMLElement)) {
|
||||||
x: parentElement.getBoundingClientRect().left,
|
return;
|
||||||
y: parentElement.getBoundingClientRect().top + parentElement.offsetHeight
|
}
|
||||||
}
|
const { parentElement } = target;
|
||||||
}
|
if (!parentElement) {
|
||||||
this.contextMenuRenderer.render(options);
|
return;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
const { mainFileUri, rootFolderFileUris } =
|
||||||
|
await this.sketchService.loadSketch(sketch.uri);
|
||||||
|
const uris = [mainFileUri, ...rootFolderFileUris];
|
||||||
|
|
||||||
|
const currentSketch =
|
||||||
|
await this.sketchesServiceClient.currentSketch();
|
||||||
|
const parentsketchUri = this.editorManager.currentEditor
|
||||||
|
?.getResourceUri()
|
||||||
|
?.toString();
|
||||||
|
const parentsketch = await this.sketchService.getSketchFolder(
|
||||||
|
parentsketchUri || ''
|
||||||
|
);
|
||||||
|
|
||||||
|
// if the current file is in the current opened sketch, show extra menus
|
||||||
|
if (
|
||||||
|
currentSketch &&
|
||||||
|
parentsketch &&
|
||||||
|
parentsketch.uri === currentSketch.uri &&
|
||||||
|
(await this.allowRename(parentsketch.uri))
|
||||||
|
) {
|
||||||
|
this.menuRegistry.registerMenuAction(
|
||||||
|
ArduinoMenus.SKETCH_CONTROL__CONTEXT__MAIN_GROUP,
|
||||||
|
{
|
||||||
|
commandId: WorkspaceCommands.FILE_RENAME.id,
|
||||||
|
label: 'Rename',
|
||||||
|
order: '1',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
this.toDisposeBeforeCreateNewContextMenu.push(
|
||||||
|
Disposable.create(() =>
|
||||||
|
this.menuRegistry.unregisterMenuAction(
|
||||||
|
WorkspaceCommands.FILE_RENAME
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
const renamePlaceholder = new PlaceholderMenuNode(
|
||||||
|
ArduinoMenus.SKETCH_CONTROL__CONTEXT__MAIN_GROUP,
|
||||||
|
'Rename'
|
||||||
|
);
|
||||||
|
this.menuRegistry.registerMenuNode(
|
||||||
|
ArduinoMenus.SKETCH_CONTROL__CONTEXT__MAIN_GROUP,
|
||||||
|
renamePlaceholder
|
||||||
|
);
|
||||||
|
this.toDisposeBeforeCreateNewContextMenu.push(
|
||||||
|
Disposable.create(() =>
|
||||||
|
this.menuRegistry.unregisterMenuNode(renamePlaceholder.id)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
currentSketch &&
|
||||||
|
parentsketch &&
|
||||||
|
parentsketch.uri === currentSketch.uri &&
|
||||||
|
(await this.allowDelete(parentsketch.uri))
|
||||||
|
) {
|
||||||
|
this.menuRegistry.registerMenuAction(
|
||||||
|
ArduinoMenus.SKETCH_CONTROL__CONTEXT__MAIN_GROUP,
|
||||||
|
{
|
||||||
|
commandId: WorkspaceCommands.FILE_DELETE.id, // TODO: customize delete. Wipe sketch if deleting main file. Close window.
|
||||||
|
label: 'Delete',
|
||||||
|
order: '2',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
this.toDisposeBeforeCreateNewContextMenu.push(
|
||||||
|
Disposable.create(() =>
|
||||||
|
this.menuRegistry.unregisterMenuAction(
|
||||||
|
WorkspaceCommands.FILE_DELETE
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
const deletePlaceholder = new PlaceholderMenuNode(
|
||||||
|
ArduinoMenus.SKETCH_CONTROL__CONTEXT__MAIN_GROUP,
|
||||||
|
'Delete'
|
||||||
|
);
|
||||||
|
this.menuRegistry.registerMenuNode(
|
||||||
|
ArduinoMenus.SKETCH_CONTROL__CONTEXT__MAIN_GROUP,
|
||||||
|
deletePlaceholder
|
||||||
|
);
|
||||||
|
this.toDisposeBeforeCreateNewContextMenu.push(
|
||||||
|
Disposable.create(() =>
|
||||||
|
this.menuRegistry.unregisterMenuNode(deletePlaceholder.id)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < uris.length; i++) {
|
||||||
|
const uri = new URI(uris[i]);
|
||||||
|
|
||||||
|
// focus on the opened sketch
|
||||||
|
const command = {
|
||||||
|
id: `arduino-focus-file--${uri.toString()}`,
|
||||||
|
};
|
||||||
|
const handler = {
|
||||||
|
execute: () => open(this.openerService, uri),
|
||||||
|
};
|
||||||
|
this.toDisposeBeforeCreateNewContextMenu.push(
|
||||||
|
registry.registerCommand(command, handler)
|
||||||
|
);
|
||||||
|
this.menuRegistry.registerMenuAction(
|
||||||
|
ArduinoMenus.SKETCH_CONTROL__CONTEXT__RESOURCES_GROUP,
|
||||||
|
{
|
||||||
|
commandId: command.id,
|
||||||
|
label: this.labelProvider.getName(uri),
|
||||||
|
order: `${i}`,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
this.toDisposeBeforeCreateNewContextMenu.push(
|
||||||
|
Disposable.create(() =>
|
||||||
|
this.menuRegistry.unregisterMenuAction(command)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const options = {
|
||||||
|
menuPath: ArduinoMenus.SKETCH_CONTROL__CONTEXT,
|
||||||
|
anchor: {
|
||||||
|
x: parentElement.getBoundingClientRect().left,
|
||||||
|
y:
|
||||||
|
parentElement.getBoundingClientRect().top +
|
||||||
|
parentElement.offsetHeight,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
this.contextMenuRenderer.render(options);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
|
registry.registerMenuAction(
|
||||||
|
ArduinoMenus.SKETCH_CONTROL__CONTEXT__MAIN_GROUP,
|
||||||
|
{
|
||||||
|
commandId: WorkspaceCommands.NEW_FILE.id,
|
||||||
|
label: 'New Tab',
|
||||||
|
order: '0',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
registry.registerMenuAction(
|
||||||
|
ArduinoMenus.SKETCH_CONTROL__CONTEXT__NAVIGATION_GROUP,
|
||||||
|
{
|
||||||
|
commandId: CommonCommands.PREVIOUS_TAB.id,
|
||||||
|
label: 'Previous Tab',
|
||||||
|
order: '0',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
registry.registerMenuAction(
|
||||||
|
ArduinoMenus.SKETCH_CONTROL__CONTEXT__NAVIGATION_GROUP,
|
||||||
|
{
|
||||||
|
commandId: CommonCommands.NEXT_TAB.id,
|
||||||
|
label: 'Next Tab',
|
||||||
|
order: '0',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
registerKeybindings(registry: KeybindingRegistry): void {
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: WorkspaceCommands.NEW_FILE.id,
|
||||||
|
keybinding: 'CtrlCmd+Shift+N',
|
||||||
|
});
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: CommonCommands.PREVIOUS_TAB.id,
|
||||||
|
keybinding: 'CtrlCmd+Alt+Left', // TODO: check why electron does not show the keybindings in the UI.
|
||||||
|
});
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: CommonCommands.NEXT_TAB.id,
|
||||||
|
keybinding: 'CtrlCmd+Alt+Right',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerToolbarItems(registry: TabBarToolbarRegistry): void {
|
||||||
|
registry.registerItem({
|
||||||
|
id: SketchControl.Commands.OPEN_SKETCH_CONTROL__TOOLBAR.id,
|
||||||
|
command: SketchControl.Commands.OPEN_SKETCH_CONTROL__TOOLBAR.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async isCloudSketch(uri: string) {
|
||||||
|
const cloudCacheLocation = this.localCacheFsProvider.from(new URI(uri));
|
||||||
|
|
||||||
|
if (cloudCacheLocation) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
protected async allowRename(uri: string) {
|
||||||
registry.registerMenuAction(ArduinoMenus.SKETCH_CONTROL__CONTEXT__MAIN_GROUP, {
|
return !this.isCloudSketch(uri);
|
||||||
commandId: WorkspaceCommands.NEW_FILE.id,
|
}
|
||||||
label: 'New Tab',
|
|
||||||
order: '0'
|
|
||||||
});
|
|
||||||
registry.registerMenuAction(ArduinoMenus.SKETCH_CONTROL__CONTEXT__MAIN_GROUP, {
|
|
||||||
commandId: WorkspaceCommands.FILE_RENAME.id,
|
|
||||||
label: 'Rename',
|
|
||||||
order: '1'
|
|
||||||
});
|
|
||||||
registry.registerMenuAction(ArduinoMenus.SKETCH_CONTROL__CONTEXT__MAIN_GROUP, {
|
|
||||||
commandId: WorkspaceCommands.FILE_DELETE.id, // TODO: customize delete. Wipe sketch if deleting main file. Close window.
|
|
||||||
label: 'Delete',
|
|
||||||
order: '2'
|
|
||||||
});
|
|
||||||
|
|
||||||
registry.registerMenuAction(ArduinoMenus.SKETCH_CONTROL__CONTEXT__NAVIGATION_GROUP, {
|
|
||||||
commandId: CommonCommands.PREVIOUS_TAB.id,
|
|
||||||
label: 'Previous Tab',
|
|
||||||
order: '0'
|
|
||||||
});
|
|
||||||
registry.registerMenuAction(ArduinoMenus.SKETCH_CONTROL__CONTEXT__NAVIGATION_GROUP, {
|
|
||||||
commandId: CommonCommands.NEXT_TAB.id,
|
|
||||||
label: 'Next Tab',
|
|
||||||
order: '0'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
registerKeybindings(registry: KeybindingRegistry): void {
|
|
||||||
registry.registerKeybinding({
|
|
||||||
command: WorkspaceCommands.NEW_FILE.id,
|
|
||||||
keybinding: 'CtrlCmd+Shift+N'
|
|
||||||
});
|
|
||||||
registry.registerKeybinding({
|
|
||||||
command: CommonCommands.PREVIOUS_TAB.id,
|
|
||||||
keybinding: 'CtrlCmd+Alt+Left' // TODO: check why electron does not show the keybindings in the UI.
|
|
||||||
});
|
|
||||||
registry.registerKeybinding({
|
|
||||||
command: CommonCommands.NEXT_TAB.id,
|
|
||||||
keybinding: 'CtrlCmd+Alt+Right'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
registerToolbarItems(registry: TabBarToolbarRegistry): void {
|
|
||||||
registry.registerItem({
|
|
||||||
id: SketchControl.Commands.OPEN_SKETCH_CONTROL__TOOLBAR.id,
|
|
||||||
command: SketchControl.Commands.OPEN_SKETCH_CONTROL__TOOLBAR.id
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
protected async allowDelete(uri: string) {
|
||||||
|
return !this.isCloudSketch(uri);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace SketchControl {
|
export namespace SketchControl {
|
||||||
export namespace Commands {
|
export namespace Commands {
|
||||||
export const OPEN_SKETCH_CONTROL__TOOLBAR: Command = {
|
export const OPEN_SKETCH_CONTROL__TOOLBAR: Command = {
|
||||||
id: 'arduino-open-sketch-control--toolbar',
|
id: 'arduino-open-sketch-control--toolbar',
|
||||||
iconClass: 'fa fa-caret-down'
|
iconClass: 'fa fa-caret-down',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,69 +1,66 @@
|
|||||||
import { inject, injectable } from 'inversify';
|
import { inject, injectable } from 'inversify';
|
||||||
import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
|
import { CommandHandler } from '@theia/core/lib/common/command';
|
||||||
import { SketchContribution, CommandRegistry, MenuModelRegistry, Sketch } from './contribution';
|
import { CommandRegistry, MenuModelRegistry } from './contribution';
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
import { MainMenuManager } from '../../common/main-menu-manager';
|
import { MainMenuManager } from '../../common/main-menu-manager';
|
||||||
import { NotificationCenter } from '../notification-center';
|
import { NotificationCenter } from '../notification-center';
|
||||||
|
import { Examples } from './examples';
|
||||||
|
import { SketchContainer } from '../../common/protocol';
|
||||||
import { OpenSketch } from './open-sketch';
|
import { OpenSketch } from './open-sketch';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class Sketchbook extends SketchContribution {
|
export class Sketchbook extends Examples {
|
||||||
|
@inject(CommandRegistry)
|
||||||
|
protected readonly commandRegistry: CommandRegistry;
|
||||||
|
|
||||||
@inject(CommandRegistry)
|
@inject(MenuModelRegistry)
|
||||||
protected readonly commandRegistry: CommandRegistry;
|
protected readonly menuRegistry: MenuModelRegistry;
|
||||||
|
|
||||||
@inject(MenuModelRegistry)
|
@inject(MainMenuManager)
|
||||||
protected readonly menuRegistry: MenuModelRegistry;
|
protected readonly mainMenuManager: MainMenuManager;
|
||||||
|
|
||||||
@inject(MainMenuManager)
|
@inject(NotificationCenter)
|
||||||
protected readonly mainMenuManager: MainMenuManager;
|
protected readonly notificationCenter: NotificationCenter;
|
||||||
|
|
||||||
@inject(NotificationCenter)
|
onStart(): void {
|
||||||
protected readonly notificationCenter: NotificationCenter;
|
this.sketchService.getSketches({}).then((container) => {
|
||||||
|
this.register(container);
|
||||||
|
this.mainMenuManager.update();
|
||||||
|
});
|
||||||
|
this.sketchServiceClient.onSketchbookDidChange(() => {
|
||||||
|
this.sketchService.getSketches({}).then((container) => {
|
||||||
|
this.register(container);
|
||||||
|
this.mainMenuManager.update();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
protected toDisposePerSketch = new Map<string, DisposableCollection>();
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
|
registry.registerSubmenu(
|
||||||
|
ArduinoMenus.FILE__SKETCHBOOK_SUBMENU,
|
||||||
|
'Sketchbook',
|
||||||
|
{ order: '3' }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
onStart(): void {
|
protected register(container: SketchContainer): void {
|
||||||
this.sketchService.getSketches().then(sketches => {
|
this.toDispose.dispose();
|
||||||
this.register(sketches);
|
this.registerRecursively(
|
||||||
this.mainMenuManager.update();
|
[...container.children, ...container.sketches],
|
||||||
});
|
ArduinoMenus.FILE__SKETCHBOOK_SUBMENU,
|
||||||
this.sketchServiceClient.onSketchbookDidChange(({ created, removed }) => {
|
this.toDispose
|
||||||
this.unregister(removed);
|
);
|
||||||
this.register(created);
|
}
|
||||||
this.mainMenuManager.update();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
|
||||||
registry.registerSubmenu(ArduinoMenus.FILE__SKETCHBOOK_SUBMENU, 'Sketchbook', { order: '3' });
|
|
||||||
}
|
|
||||||
|
|
||||||
protected register(sketches: Sketch[]): void {
|
|
||||||
for (const sketch of sketches) {
|
|
||||||
const { uri } = sketch;
|
|
||||||
const toDispose = this.toDisposePerSketch.get(uri);
|
|
||||||
if (toDispose) {
|
|
||||||
toDispose.dispose();
|
|
||||||
}
|
|
||||||
const command = { id: `arduino-sketchbook-open--${uri}` };
|
|
||||||
const handler = { execute: () => this.commandRegistry.executeCommand(OpenSketch.Commands.OPEN_SKETCH.id, sketch) };
|
|
||||||
this.commandRegistry.registerCommand(command, handler);
|
|
||||||
this.menuRegistry.registerMenuAction(ArduinoMenus.FILE__SKETCHBOOK_SUBMENU, { commandId: command.id, label: sketch.name });
|
|
||||||
this.toDisposePerSketch.set(sketch.uri, new DisposableCollection(
|
|
||||||
Disposable.create(() => this.commandRegistry.unregisterCommand(command)),
|
|
||||||
Disposable.create(() => this.menuRegistry.unregisterMenuAction(command))
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected unregister(sketches: Sketch[]): void {
|
|
||||||
for (const { uri } of sketches) {
|
|
||||||
const toDispose = this.toDisposePerSketch.get(uri);
|
|
||||||
if (toDispose) {
|
|
||||||
toDispose.dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
protected createHandler(uri: string): CommandHandler {
|
||||||
|
return {
|
||||||
|
execute: async () => {
|
||||||
|
const sketch = await this.sketchService.loadSketch(uri);
|
||||||
|
return this.commandService.executeCommand(
|
||||||
|
OpenSketch.Commands.OPEN_SKETCH.id,
|
||||||
|
sketch
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,136 @@
|
|||||||
|
import { inject, injectable } from 'inversify';
|
||||||
|
import {
|
||||||
|
Command,
|
||||||
|
MenuModelRegistry,
|
||||||
|
CommandRegistry,
|
||||||
|
Contribution,
|
||||||
|
} from './contribution';
|
||||||
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
|
import { UploadCertificateDialog } from '../dialogs/certificate-uploader/certificate-uploader-dialog';
|
||||||
|
import { ContextMenuRenderer } from '@theia/core/lib/browser/context-menu-renderer';
|
||||||
|
import {
|
||||||
|
PreferenceScope,
|
||||||
|
PreferenceService,
|
||||||
|
} from '@theia/core/lib/browser/preferences/preference-service';
|
||||||
|
import { ArduinoPreferences } from '../arduino-preferences';
|
||||||
|
import {
|
||||||
|
arduinoCert,
|
||||||
|
certificateList,
|
||||||
|
} from '../dialogs/certificate-uploader/utils';
|
||||||
|
import { ArduinoFirmwareUploader } from '../../common/protocol/arduino-firmware-uploader';
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class UploadCertificate extends Contribution {
|
||||||
|
@inject(UploadCertificateDialog)
|
||||||
|
protected readonly dialog: UploadCertificateDialog;
|
||||||
|
|
||||||
|
@inject(ContextMenuRenderer)
|
||||||
|
protected readonly contextMenuRenderer: ContextMenuRenderer;
|
||||||
|
|
||||||
|
@inject(PreferenceService)
|
||||||
|
protected readonly preferenceService: PreferenceService;
|
||||||
|
|
||||||
|
@inject(ArduinoPreferences)
|
||||||
|
protected readonly arduinoPreferences: ArduinoPreferences;
|
||||||
|
|
||||||
|
@inject(ArduinoFirmwareUploader)
|
||||||
|
protected readonly arduinoFirmwareUploader: ArduinoFirmwareUploader;
|
||||||
|
|
||||||
|
protected dialogOpened = false;
|
||||||
|
|
||||||
|
registerCommands(registry: CommandRegistry): void {
|
||||||
|
registry.registerCommand(UploadCertificate.Commands.OPEN, {
|
||||||
|
execute: async () => {
|
||||||
|
try {
|
||||||
|
this.dialogOpened = true;
|
||||||
|
await this.dialog.open();
|
||||||
|
} finally {
|
||||||
|
this.dialogOpened = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
isEnabled: () => !this.dialogOpened,
|
||||||
|
});
|
||||||
|
|
||||||
|
registry.registerCommand(UploadCertificate.Commands.REMOVE_CERT, {
|
||||||
|
execute: async (certToRemove) => {
|
||||||
|
const certs = this.arduinoPreferences.get('arduino.board.certificates');
|
||||||
|
|
||||||
|
this.preferenceService.set(
|
||||||
|
'arduino.board.certificates',
|
||||||
|
certificateList(certs)
|
||||||
|
.filter((c) => c !== certToRemove)
|
||||||
|
.join(','),
|
||||||
|
PreferenceScope.User
|
||||||
|
);
|
||||||
|
},
|
||||||
|
isEnabled: (certToRemove) => certToRemove !== arduinoCert,
|
||||||
|
});
|
||||||
|
|
||||||
|
registry.registerCommand(UploadCertificate.Commands.UPLOAD_CERT, {
|
||||||
|
execute: async ({ fqbn, address, urls }) => {
|
||||||
|
return this.arduinoFirmwareUploader.uploadCertificates(
|
||||||
|
`-b ${fqbn} -a ${address} ${urls
|
||||||
|
.map((url: string) => `-u ${url}`)
|
||||||
|
.join(' ')}`
|
||||||
|
);
|
||||||
|
},
|
||||||
|
isEnabled: () => true,
|
||||||
|
});
|
||||||
|
|
||||||
|
registry.registerCommand(UploadCertificate.Commands.OPEN_CERT_CONTEXT, {
|
||||||
|
execute: async (args: any) => {
|
||||||
|
this.contextMenuRenderer.render({
|
||||||
|
menuPath: ArduinoMenus.ROOT_CERTIFICATES__CONTEXT,
|
||||||
|
anchor: {
|
||||||
|
x: args.x,
|
||||||
|
y: args.y,
|
||||||
|
},
|
||||||
|
args: [args.cert],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
isEnabled: () => true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
|
registry.registerMenuAction(ArduinoMenus.TOOLS__FIRMWARE_UPLOADER_GROUP, {
|
||||||
|
commandId: UploadCertificate.Commands.OPEN.id,
|
||||||
|
label: UploadCertificate.Commands.OPEN.label,
|
||||||
|
order: '1',
|
||||||
|
});
|
||||||
|
|
||||||
|
registry.registerMenuAction(ArduinoMenus.ROOT_CERTIFICATES__CONTEXT, {
|
||||||
|
commandId: UploadCertificate.Commands.REMOVE_CERT.id,
|
||||||
|
label: UploadCertificate.Commands.REMOVE_CERT.label,
|
||||||
|
order: '1',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export namespace UploadCertificate {
|
||||||
|
export namespace Commands {
|
||||||
|
export const OPEN: Command = {
|
||||||
|
id: 'arduino-upload-certificate-open',
|
||||||
|
label: 'Upload SSL Root Certificates',
|
||||||
|
category: 'Arduino',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const OPEN_CERT_CONTEXT: Command = {
|
||||||
|
id: 'arduino-certificate-open-context',
|
||||||
|
label: 'Open context',
|
||||||
|
category: 'Arduino',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const REMOVE_CERT: Command = {
|
||||||
|
id: 'arduino-certificate-remove',
|
||||||
|
label: 'Remove',
|
||||||
|
category: 'Arduino',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const UPLOAD_CERT: Command = {
|
||||||
|
id: 'arduino-certificate-upload',
|
||||||
|
label: 'Upload',
|
||||||
|
category: 'Arduino',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import { inject, injectable } from 'inversify';
|
||||||
|
import {
|
||||||
|
Command,
|
||||||
|
MenuModelRegistry,
|
||||||
|
CommandRegistry,
|
||||||
|
Contribution,
|
||||||
|
} from './contribution';
|
||||||
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
|
import { UploadFirmwareDialog } from '../dialogs/firmware-uploader/firmware-uploader-dialog';
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class UploadFirmware extends Contribution {
|
||||||
|
@inject(UploadFirmwareDialog)
|
||||||
|
protected readonly dialog: UploadFirmwareDialog;
|
||||||
|
|
||||||
|
protected dialogOpened = false;
|
||||||
|
|
||||||
|
registerCommands(registry: CommandRegistry): void {
|
||||||
|
registry.registerCommand(UploadFirmware.Commands.OPEN, {
|
||||||
|
execute: async () => {
|
||||||
|
try {
|
||||||
|
this.dialogOpened = true;
|
||||||
|
await this.dialog.open();
|
||||||
|
} finally {
|
||||||
|
this.dialogOpened = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
isEnabled: () => !this.dialogOpened,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
|
registry.registerMenuAction(ArduinoMenus.TOOLS__FIRMWARE_UPLOADER_GROUP, {
|
||||||
|
commandId: UploadFirmware.Commands.OPEN.id,
|
||||||
|
label: UploadFirmware.Commands.OPEN.label,
|
||||||
|
order: '0',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export namespace UploadFirmware {
|
||||||
|
export namespace Commands {
|
||||||
|
export const OPEN: Command = {
|
||||||
|
id: 'arduino-upload-firmware-open',
|
||||||
|
label: 'WiFi101 / WiFiNINA Firmware Updater',
|
||||||
|
category: 'Arduino',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,169 +1,206 @@
|
|||||||
import { inject, injectable } from 'inversify';
|
import { inject, injectable } from 'inversify';
|
||||||
import { OutputChannelManager } from '@theia/output/lib/common/output-channel';
|
import { Emitter } from '@theia/core/lib/common/event';
|
||||||
import { CoreService } from '../../common/protocol';
|
import { CoreService } from '../../common/protocol';
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
|
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
|
||||||
import { BoardsDataStore } from '../boards/boards-data-store';
|
import { BoardsDataStore } from '../boards/boards-data-store';
|
||||||
import { MonitorConnection } from '../monitor/monitor-connection';
|
import { MonitorConnection } from '../monitor/monitor-connection';
|
||||||
import { BoardsServiceProvider } from '../boards/boards-service-provider';
|
import { BoardsServiceProvider } from '../boards/boards-service-provider';
|
||||||
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, TabBarToolbarRegistry } from './contribution';
|
import {
|
||||||
|
SketchContribution,
|
||||||
|
Command,
|
||||||
|
CommandRegistry,
|
||||||
|
MenuModelRegistry,
|
||||||
|
KeybindingRegistry,
|
||||||
|
TabBarToolbarRegistry,
|
||||||
|
} from './contribution';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class UploadSketch extends SketchContribution {
|
export class UploadSketch extends SketchContribution {
|
||||||
|
@inject(CoreService)
|
||||||
|
protected readonly coreService: CoreService;
|
||||||
|
|
||||||
@inject(CoreService)
|
@inject(MonitorConnection)
|
||||||
protected readonly coreService: CoreService;
|
protected readonly monitorConnection: MonitorConnection;
|
||||||
|
|
||||||
@inject(MonitorConnection)
|
@inject(BoardsDataStore)
|
||||||
protected readonly monitorConnection: MonitorConnection;
|
protected readonly boardsDataStore: BoardsDataStore;
|
||||||
|
|
||||||
@inject(BoardsDataStore)
|
@inject(BoardsServiceProvider)
|
||||||
protected readonly boardsDataStore: BoardsDataStore;
|
protected readonly boardsServiceClientImpl: BoardsServiceProvider;
|
||||||
|
|
||||||
@inject(BoardsServiceProvider)
|
protected readonly onDidChangeEmitter = new Emitter<Readonly<void>>();
|
||||||
protected readonly boardsServiceClientImpl: BoardsServiceProvider;
|
readonly onDidChange = this.onDidChangeEmitter.event;
|
||||||
|
|
||||||
@inject(OutputChannelManager)
|
protected uploadInProgress = false;
|
||||||
protected readonly outputChannelManager: OutputChannelManager;
|
|
||||||
|
|
||||||
registerCommands(registry: CommandRegistry): void {
|
registerCommands(registry: CommandRegistry): void {
|
||||||
registry.registerCommand(UploadSketch.Commands.UPLOAD_SKETCH, {
|
registry.registerCommand(UploadSketch.Commands.UPLOAD_SKETCH, {
|
||||||
execute: () => this.uploadSketch()
|
execute: () => this.uploadSketch(),
|
||||||
});
|
isEnabled: () => !this.uploadInProgress,
|
||||||
registry.registerCommand(UploadSketch.Commands.UPLOAD_SKETCH_USING_PROGRAMMER, {
|
});
|
||||||
execute: () => this.uploadSketch(true)
|
registry.registerCommand(
|
||||||
});
|
UploadSketch.Commands.UPLOAD_SKETCH_USING_PROGRAMMER,
|
||||||
registry.registerCommand(UploadSketch.Commands.UPLOAD_SKETCH_TOOLBAR, {
|
{
|
||||||
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
|
execute: () => this.uploadSketch(true),
|
||||||
execute: () => registry.executeCommand(UploadSketch.Commands.UPLOAD_SKETCH.id)
|
isEnabled: () => !this.uploadInProgress,
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
registry.registerCommand(UploadSketch.Commands.UPLOAD_SKETCH_TOOLBAR, {
|
||||||
|
isVisible: (widget) =>
|
||||||
|
ArduinoToolbar.is(widget) && widget.side === 'left',
|
||||||
|
isEnabled: () => !this.uploadInProgress,
|
||||||
|
isToggled: () => this.uploadInProgress,
|
||||||
|
execute: () =>
|
||||||
|
registry.executeCommand(UploadSketch.Commands.UPLOAD_SKETCH.id),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
|
registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, {
|
||||||
|
commandId: UploadSketch.Commands.UPLOAD_SKETCH.id,
|
||||||
|
label: 'Upload',
|
||||||
|
order: '1',
|
||||||
|
});
|
||||||
|
registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, {
|
||||||
|
commandId: UploadSketch.Commands.UPLOAD_SKETCH_USING_PROGRAMMER.id,
|
||||||
|
label: 'Upload Using Programmer',
|
||||||
|
order: '2',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerKeybindings(registry: KeybindingRegistry): void {
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: UploadSketch.Commands.UPLOAD_SKETCH.id,
|
||||||
|
keybinding: 'CtrlCmd+U',
|
||||||
|
});
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: UploadSketch.Commands.UPLOAD_SKETCH_USING_PROGRAMMER.id,
|
||||||
|
keybinding: 'CtrlCmd+Shift+U',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerToolbarItems(registry: TabBarToolbarRegistry): void {
|
||||||
|
registry.registerItem({
|
||||||
|
id: UploadSketch.Commands.UPLOAD_SKETCH_TOOLBAR.id,
|
||||||
|
command: UploadSketch.Commands.UPLOAD_SKETCH_TOOLBAR.id,
|
||||||
|
tooltip: 'Upload',
|
||||||
|
priority: 1,
|
||||||
|
onDidChange: this.onDidChange,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async uploadSketch(usingProgrammer = false): Promise<void> {
|
||||||
|
// even with buttons disabled, better to double check if an upload is already in progress
|
||||||
|
if (this.uploadInProgress) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
// toggle the toolbar button and menu item state.
|
||||||
registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, {
|
// uploadInProgress will be set to false whether the upload fails or not
|
||||||
commandId: UploadSketch.Commands.UPLOAD_SKETCH.id,
|
this.uploadInProgress = true;
|
||||||
label: 'Upload',
|
this.onDidChangeEmitter.fire();
|
||||||
order: '1'
|
const sketch = await this.sketchServiceClient.currentSketch();
|
||||||
});
|
if (!sketch) {
|
||||||
registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, {
|
return;
|
||||||
commandId: UploadSketch.Commands.UPLOAD_SKETCH_USING_PROGRAMMER.id,
|
|
||||||
label: 'Upload Using Programmer',
|
|
||||||
order: '2'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
let shouldAutoConnect = false;
|
||||||
registerKeybindings(registry: KeybindingRegistry): void {
|
const monitorConfig = this.monitorConnection.monitorConfig;
|
||||||
registry.registerKeybinding({
|
if (monitorConfig) {
|
||||||
command: UploadSketch.Commands.UPLOAD_SKETCH.id,
|
await this.monitorConnection.disconnect();
|
||||||
keybinding: 'CtrlCmd+U'
|
if (this.monitorConnection.autoConnect) {
|
||||||
});
|
shouldAutoConnect = true;
|
||||||
registry.registerKeybinding({
|
}
|
||||||
command: UploadSketch.Commands.UPLOAD_SKETCH_USING_PROGRAMMER.id,
|
this.monitorConnection.autoConnect = false;
|
||||||
keybinding: 'CtrlCmd+Shift+U'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
const { boardsConfig } = this.boardsServiceClientImpl;
|
||||||
|
const [fqbn, { selectedProgrammer }, verify, verbose, sourceOverride] =
|
||||||
|
await Promise.all([
|
||||||
|
this.boardsDataStore.appendConfigToFqbn(
|
||||||
|
boardsConfig.selectedBoard?.fqbn
|
||||||
|
),
|
||||||
|
this.boardsDataStore.getData(boardsConfig.selectedBoard?.fqbn),
|
||||||
|
this.preferences.get('arduino.upload.verify'),
|
||||||
|
this.preferences.get('arduino.upload.verbose'),
|
||||||
|
this.sourceOverride(),
|
||||||
|
]);
|
||||||
|
|
||||||
registerToolbarItems(registry: TabBarToolbarRegistry): void {
|
let options: CoreService.Upload.Options | undefined = undefined;
|
||||||
registry.registerItem({
|
const sketchUri = sketch.uri;
|
||||||
id: UploadSketch.Commands.UPLOAD_SKETCH_TOOLBAR.id,
|
const optimizeForDebug = this.editorMode.compileForDebug;
|
||||||
command: UploadSketch.Commands.UPLOAD_SKETCH_TOOLBAR.id,
|
const { selectedPort } = boardsConfig;
|
||||||
tooltip: 'Upload',
|
const port = selectedPort?.address;
|
||||||
priority: 1
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async uploadSketch(usingProgrammer: boolean = false): Promise<void> {
|
if (usingProgrammer) {
|
||||||
const sketch = await this.sketchServiceClient.currentSketch();
|
const programmer = selectedProgrammer;
|
||||||
if (!sketch) {
|
options = {
|
||||||
return;
|
sketchUri,
|
||||||
}
|
fqbn,
|
||||||
let shouldAutoConnect = false;
|
optimizeForDebug,
|
||||||
const monitorConfig = this.monitorConnection.monitorConfig;
|
programmer,
|
||||||
if (monitorConfig) {
|
port,
|
||||||
await this.monitorConnection.disconnect();
|
verbose,
|
||||||
if (this.monitorConnection.autoConnect) {
|
verify,
|
||||||
shouldAutoConnect = true;
|
sourceOverride,
|
||||||
}
|
};
|
||||||
this.monitorConnection.autoConnect = false;
|
} else {
|
||||||
}
|
options = {
|
||||||
|
sketchUri,
|
||||||
|
fqbn,
|
||||||
|
optimizeForDebug,
|
||||||
|
port,
|
||||||
|
verbose,
|
||||||
|
verify,
|
||||||
|
sourceOverride,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
this.outputChannelManager.getChannel('Arduino').clear();
|
||||||
|
if (usingProgrammer) {
|
||||||
|
await this.coreService.uploadUsingProgrammer(options);
|
||||||
|
} else {
|
||||||
|
await this.coreService.upload(options);
|
||||||
|
}
|
||||||
|
this.messageService.info('Done uploading.', { timeout: 3000 });
|
||||||
|
} catch (e) {
|
||||||
|
this.messageService.error(e.toString());
|
||||||
|
} finally {
|
||||||
|
this.uploadInProgress = false;
|
||||||
|
this.onDidChangeEmitter.fire();
|
||||||
|
|
||||||
|
if (monitorConfig) {
|
||||||
|
const { board, port } = monitorConfig;
|
||||||
try {
|
try {
|
||||||
const { boardsConfig } = this.boardsServiceClientImpl;
|
await this.boardsServiceClientImpl.waitUntilAvailable(
|
||||||
const [fqbn, { selectedProgrammer }, verify, verbose, sourceOverride] = await Promise.all([
|
Object.assign(board, { port }),
|
||||||
this.boardsDataStore.appendConfigToFqbn(boardsConfig.selectedBoard?.fqbn),
|
10_000
|
||||||
this.boardsDataStore.getData(boardsConfig.selectedBoard?.fqbn),
|
);
|
||||||
this.preferences.get('arduino.upload.verify'),
|
if (shouldAutoConnect) {
|
||||||
this.preferences.get('arduino.upload.verbose'),
|
// Enabling auto-connect will trigger a connect.
|
||||||
this.sourceOverride()
|
this.monitorConnection.autoConnect = true;
|
||||||
]);
|
} else {
|
||||||
|
await this.monitorConnection.connect(monitorConfig);
|
||||||
let options: CoreService.Upload.Options | undefined = undefined;
|
}
|
||||||
const sketchUri = sketch.uri;
|
} catch (waitError) {
|
||||||
const optimizeForDebug = this.editorMode.compileForDebug;
|
this.messageService.error(
|
||||||
const { selectedPort } = boardsConfig;
|
`Could not reconnect to serial monitor. ${waitError.toString()}`
|
||||||
const port = selectedPort?.address;
|
);
|
||||||
|
|
||||||
if (usingProgrammer) {
|
|
||||||
const programmer = selectedProgrammer;
|
|
||||||
options = {
|
|
||||||
sketchUri,
|
|
||||||
fqbn,
|
|
||||||
optimizeForDebug,
|
|
||||||
programmer,
|
|
||||||
port,
|
|
||||||
verbose,
|
|
||||||
verify,
|
|
||||||
sourceOverride
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
options = {
|
|
||||||
sketchUri,
|
|
||||||
fqbn,
|
|
||||||
optimizeForDebug,
|
|
||||||
port,
|
|
||||||
verbose,
|
|
||||||
verify,
|
|
||||||
sourceOverride
|
|
||||||
};
|
|
||||||
}
|
|
||||||
this.outputChannelManager.getChannel('Arduino').clear();
|
|
||||||
if (usingProgrammer) {
|
|
||||||
await this.coreService.uploadUsingProgrammer(options);
|
|
||||||
} else {
|
|
||||||
await this.coreService.upload(options);
|
|
||||||
}
|
|
||||||
this.messageService.info('Done uploading.', { timeout: 1000 });
|
|
||||||
} catch (e) {
|
|
||||||
this.messageService.error(e.toString());
|
|
||||||
} finally {
|
|
||||||
if (monitorConfig) {
|
|
||||||
const { board, port } = monitorConfig;
|
|
||||||
try {
|
|
||||||
await this.boardsServiceClientImpl.waitUntilAvailable(Object.assign(board, { port }), 10_000);
|
|
||||||
if (shouldAutoConnect) {
|
|
||||||
// Enabling auto-connect will trigger a connect.
|
|
||||||
this.monitorConnection.autoConnect = true;
|
|
||||||
} else {
|
|
||||||
await this.monitorConnection.connect(monitorConfig);
|
|
||||||
}
|
|
||||||
} catch (waitError) {
|
|
||||||
this.messageService.error(`Could not reconnect to serial monitor. ${waitError.toString()}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace UploadSketch {
|
export namespace UploadSketch {
|
||||||
export namespace Commands {
|
export namespace Commands {
|
||||||
export const UPLOAD_SKETCH: Command = {
|
export const UPLOAD_SKETCH: Command = {
|
||||||
id: 'arduino-upload-sketch'
|
id: 'arduino-upload-sketch',
|
||||||
};
|
};
|
||||||
export const UPLOAD_SKETCH_USING_PROGRAMMER: Command = {
|
export const UPLOAD_SKETCH_USING_PROGRAMMER: Command = {
|
||||||
id: 'arduino-upload-sketch-using-programmer'
|
id: 'arduino-upload-sketch-using-programmer',
|
||||||
};
|
};
|
||||||
export const UPLOAD_SKETCH_TOOLBAR: Command = {
|
export const UPLOAD_SKETCH_TOOLBAR: Command = {
|
||||||
id: 'arduino-upload-sketch--toolbar'
|
id: 'arduino-upload-sketch--toolbar',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,112 +1,143 @@
|
|||||||
import { inject, injectable } from 'inversify';
|
import { inject, injectable } from 'inversify';
|
||||||
import { OutputChannelManager } from '@theia/output/lib/common/output-channel';
|
import { Emitter } from '@theia/core/lib/common/event';
|
||||||
import { CoreService } from '../../common/protocol';
|
import { CoreService } from '../../common/protocol';
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
|
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
|
||||||
import { BoardsDataStore } from '../boards/boards-data-store';
|
import { BoardsDataStore } from '../boards/boards-data-store';
|
||||||
import { BoardsServiceProvider } from '../boards/boards-service-provider';
|
import { BoardsServiceProvider } from '../boards/boards-service-provider';
|
||||||
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, TabBarToolbarRegistry } from './contribution';
|
import {
|
||||||
|
SketchContribution,
|
||||||
|
Command,
|
||||||
|
CommandRegistry,
|
||||||
|
MenuModelRegistry,
|
||||||
|
KeybindingRegistry,
|
||||||
|
TabBarToolbarRegistry,
|
||||||
|
} from './contribution';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class VerifySketch extends SketchContribution {
|
export class VerifySketch extends SketchContribution {
|
||||||
|
@inject(CoreService)
|
||||||
|
protected readonly coreService: CoreService;
|
||||||
|
|
||||||
@inject(CoreService)
|
@inject(BoardsDataStore)
|
||||||
protected readonly coreService: CoreService;
|
protected readonly boardsDataStore: BoardsDataStore;
|
||||||
|
|
||||||
@inject(BoardsDataStore)
|
@inject(BoardsServiceProvider)
|
||||||
protected readonly boardsDataStore: BoardsDataStore;
|
protected readonly boardsServiceClientImpl: BoardsServiceProvider;
|
||||||
|
|
||||||
@inject(BoardsServiceProvider)
|
protected readonly onDidChangeEmitter = new Emitter<Readonly<void>>();
|
||||||
protected readonly boardsServiceClientImpl: BoardsServiceProvider;
|
readonly onDidChange = this.onDidChangeEmitter.event;
|
||||||
|
|
||||||
@inject(OutputChannelManager)
|
protected verifyInProgress = false;
|
||||||
protected readonly outputChannelManager: OutputChannelManager;
|
|
||||||
|
|
||||||
registerCommands(registry: CommandRegistry): void {
|
registerCommands(registry: CommandRegistry): void {
|
||||||
registry.registerCommand(VerifySketch.Commands.VERIFY_SKETCH, {
|
registry.registerCommand(VerifySketch.Commands.VERIFY_SKETCH, {
|
||||||
execute: () => this.verifySketch()
|
execute: () => this.verifySketch(),
|
||||||
});
|
isEnabled: () => !this.verifyInProgress,
|
||||||
registry.registerCommand(VerifySketch.Commands.EXPORT_BINARIES, {
|
});
|
||||||
execute: () => this.verifySketch(true)
|
registry.registerCommand(VerifySketch.Commands.EXPORT_BINARIES, {
|
||||||
});
|
execute: () => this.verifySketch(true),
|
||||||
registry.registerCommand(VerifySketch.Commands.VERIFY_SKETCH_TOOLBAR, {
|
isEnabled: () => !this.verifyInProgress,
|
||||||
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
|
});
|
||||||
execute: () => registry.executeCommand(VerifySketch.Commands.VERIFY_SKETCH.id)
|
registry.registerCommand(VerifySketch.Commands.VERIFY_SKETCH_TOOLBAR, {
|
||||||
});
|
isVisible: (widget) =>
|
||||||
|
ArduinoToolbar.is(widget) && widget.side === 'left',
|
||||||
|
isEnabled: () => !this.verifyInProgress,
|
||||||
|
isToggled: () => this.verifyInProgress,
|
||||||
|
execute: () =>
|
||||||
|
registry.executeCommand(VerifySketch.Commands.VERIFY_SKETCH.id),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
|
registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, {
|
||||||
|
commandId: VerifySketch.Commands.VERIFY_SKETCH.id,
|
||||||
|
label: 'Verify/Compile',
|
||||||
|
order: '0',
|
||||||
|
});
|
||||||
|
registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, {
|
||||||
|
commandId: VerifySketch.Commands.EXPORT_BINARIES.id,
|
||||||
|
label: 'Export compiled Binary',
|
||||||
|
order: '3',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerKeybindings(registry: KeybindingRegistry): void {
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: VerifySketch.Commands.VERIFY_SKETCH.id,
|
||||||
|
keybinding: 'CtrlCmd+R',
|
||||||
|
});
|
||||||
|
registry.registerKeybinding({
|
||||||
|
command: VerifySketch.Commands.EXPORT_BINARIES.id,
|
||||||
|
keybinding: 'CtrlCmd+Alt+S',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerToolbarItems(registry: TabBarToolbarRegistry): void {
|
||||||
|
registry.registerItem({
|
||||||
|
id: VerifySketch.Commands.VERIFY_SKETCH_TOOLBAR.id,
|
||||||
|
command: VerifySketch.Commands.VERIFY_SKETCH_TOOLBAR.id,
|
||||||
|
tooltip: 'Verify',
|
||||||
|
priority: 0,
|
||||||
|
onDidChange: this.onDidChange,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async verifySketch(exportBinaries?: boolean): Promise<void> {
|
||||||
|
// even with buttons disabled, better to double check if a verify is already in progress
|
||||||
|
if (this.verifyInProgress) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
// toggle the toolbar button and menu item state.
|
||||||
registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, {
|
// verifyInProgress will be set to false whether the compilation fails or not
|
||||||
commandId: VerifySketch.Commands.VERIFY_SKETCH.id,
|
this.verifyInProgress = true;
|
||||||
label: 'Verify/Compile',
|
this.onDidChangeEmitter.fire();
|
||||||
order: '0'
|
const sketch = await this.sketchServiceClient.currentSketch();
|
||||||
});
|
|
||||||
registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, {
|
|
||||||
commandId: VerifySketch.Commands.EXPORT_BINARIES.id,
|
|
||||||
label: 'Export compiled Binary',
|
|
||||||
order: '3'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
registerKeybindings(registry: KeybindingRegistry): void {
|
if (!sketch) {
|
||||||
registry.registerKeybinding({
|
return;
|
||||||
command: VerifySketch.Commands.VERIFY_SKETCH.id,
|
|
||||||
keybinding: 'CtrlCmd+R'
|
|
||||||
});
|
|
||||||
registry.registerKeybinding({
|
|
||||||
command: VerifySketch.Commands.EXPORT_BINARIES.id,
|
|
||||||
keybinding: 'CtrlCmd+Alt+S'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
registerToolbarItems(registry: TabBarToolbarRegistry): void {
|
const { boardsConfig } = this.boardsServiceClientImpl;
|
||||||
registry.registerItem({
|
const [fqbn, sourceOverride] = await Promise.all([
|
||||||
id: VerifySketch.Commands.VERIFY_SKETCH_TOOLBAR.id,
|
this.boardsDataStore.appendConfigToFqbn(
|
||||||
command: VerifySketch.Commands.VERIFY_SKETCH_TOOLBAR.id,
|
boardsConfig.selectedBoard?.fqbn
|
||||||
tooltip: 'Verify',
|
),
|
||||||
priority: 0
|
this.sourceOverride(),
|
||||||
});
|
]);
|
||||||
|
const verbose = this.preferences.get('arduino.compile.verbose');
|
||||||
|
const compilerWarnings = this.preferences.get('arduino.compile.warnings');
|
||||||
|
this.outputChannelManager.getChannel('Arduino').clear();
|
||||||
|
await this.coreService.compile({
|
||||||
|
sketchUri: sketch.uri,
|
||||||
|
fqbn,
|
||||||
|
optimizeForDebug: this.editorMode.compileForDebug,
|
||||||
|
verbose,
|
||||||
|
exportBinaries,
|
||||||
|
sourceOverride,
|
||||||
|
compilerWarnings,
|
||||||
|
});
|
||||||
|
this.messageService.info('Done compiling.', { timeout: 3000 });
|
||||||
|
} catch (e) {
|
||||||
|
this.messageService.error(e.toString());
|
||||||
|
} finally {
|
||||||
|
this.verifyInProgress = false;
|
||||||
|
this.onDidChangeEmitter.fire();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
async verifySketch(exportBinaries?: boolean): Promise<void> {
|
|
||||||
const sketch = await this.sketchServiceClient.currentSketch();
|
|
||||||
if (!sketch) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const { boardsConfig } = this.boardsServiceClientImpl;
|
|
||||||
const [fqbn, sourceOverride] = await Promise.all([
|
|
||||||
this.boardsDataStore.appendConfigToFqbn(boardsConfig.selectedBoard?.fqbn),
|
|
||||||
this.sourceOverride()
|
|
||||||
]);
|
|
||||||
const verbose = this.preferences.get('arduino.compile.verbose');
|
|
||||||
this.outputChannelManager.getChannel('Arduino').clear();
|
|
||||||
await this.coreService.compile({
|
|
||||||
sketchUri: sketch.uri,
|
|
||||||
fqbn,
|
|
||||||
optimizeForDebug: this.editorMode.compileForDebug,
|
|
||||||
verbose,
|
|
||||||
exportBinaries,
|
|
||||||
sourceOverride
|
|
||||||
});
|
|
||||||
this.messageService.info('Done compiling.', { timeout: 1000 });
|
|
||||||
} catch (e) {
|
|
||||||
this.messageService.error(e.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace VerifySketch {
|
export namespace VerifySketch {
|
||||||
export namespace Commands {
|
export namespace Commands {
|
||||||
export const VERIFY_SKETCH: Command = {
|
export const VERIFY_SKETCH: Command = {
|
||||||
id: 'arduino-verify-sketch'
|
id: 'arduino-verify-sketch',
|
||||||
};
|
};
|
||||||
export const EXPORT_BINARIES: Command = {
|
export const EXPORT_BINARIES: Command = {
|
||||||
id: 'arduino-export-binaries'
|
id: 'arduino-export-binaries',
|
||||||
};
|
};
|
||||||
export const VERIFY_SKETCH_TOOLBAR: Command = {
|
export const VERIFY_SKETCH_TOOLBAR: Command = {
|
||||||
id: 'arduino-verify-sketch--toolbar'
|
id: 'arduino-verify-sketch--toolbar',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
479
arduino-ide-extension/src/browser/create/create-api.ts
Normal file
479
arduino-ide-extension/src/browser/create/create-api.ts
Normal file
@@ -0,0 +1,479 @@
|
|||||||
|
import { injectable, inject } from 'inversify';
|
||||||
|
import * as createPaths from './create-paths';
|
||||||
|
import { posix } from './create-paths';
|
||||||
|
import { AuthenticationClientService } from '../auth/authentication-client-service';
|
||||||
|
import { ArduinoPreferences } from '../arduino-preferences';
|
||||||
|
import { SketchCache } from '../widgets/cloud-sketchbook/cloud-sketch-cache';
|
||||||
|
import { Create, CreateError } from './typings';
|
||||||
|
|
||||||
|
export interface ResponseResultProvider {
|
||||||
|
(response: Response): Promise<any>;
|
||||||
|
}
|
||||||
|
export namespace ResponseResultProvider {
|
||||||
|
export const NOOP: ResponseResultProvider = async () => undefined;
|
||||||
|
export const TEXT: ResponseResultProvider = (response) => response.text();
|
||||||
|
export const JSON: ResponseResultProvider = (response) => response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
type ResourceType = 'f' | 'd';
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class CreateApi {
|
||||||
|
@inject(SketchCache)
|
||||||
|
protected sketchCache: SketchCache;
|
||||||
|
|
||||||
|
protected authenticationService: AuthenticationClientService;
|
||||||
|
protected arduinoPreferences: ArduinoPreferences;
|
||||||
|
|
||||||
|
public init(
|
||||||
|
authenticationService: AuthenticationClientService,
|
||||||
|
arduinoPreferences: ArduinoPreferences
|
||||||
|
): CreateApi {
|
||||||
|
this.authenticationService = authenticationService;
|
||||||
|
this.arduinoPreferences = arduinoPreferences;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
getSketchSecretStat(sketch: Create.Sketch): Create.Resource {
|
||||||
|
return {
|
||||||
|
href: `${sketch.href}${posix.sep}${Create.arduino_secrets_file}`,
|
||||||
|
modified_at: sketch.modified_at,
|
||||||
|
created_at: sketch.created_at,
|
||||||
|
name: `${Create.arduino_secrets_file}`,
|
||||||
|
path: `${sketch.path}${posix.sep}${Create.arduino_secrets_file}`,
|
||||||
|
mimetype: 'text/x-c++src; charset=utf-8',
|
||||||
|
type: 'file',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async sketch(id: string): Promise<Create.Sketch> {
|
||||||
|
const url = new URL(`${this.domain()}/sketches/byID/${id}`);
|
||||||
|
|
||||||
|
url.searchParams.set('user_id', 'me');
|
||||||
|
const headers = await this.headers();
|
||||||
|
const result = await this.run<Create.Sketch>(url, {
|
||||||
|
method: 'GET',
|
||||||
|
headers,
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
async sketches(): Promise<Create.Sketch[]> {
|
||||||
|
const url = new URL(`${this.domain()}/sketches`);
|
||||||
|
url.searchParams.set('user_id', 'me');
|
||||||
|
const headers = await this.headers();
|
||||||
|
const result = await this.run<{ sketches: Create.Sketch[] }>(url, {
|
||||||
|
method: 'GET',
|
||||||
|
headers,
|
||||||
|
});
|
||||||
|
result.sketches.forEach((sketch) => this.sketchCache.addSketch(sketch));
|
||||||
|
return result.sketches;
|
||||||
|
}
|
||||||
|
|
||||||
|
async createSketch(
|
||||||
|
posixPath: string,
|
||||||
|
content: string = CreateApi.defaultInoContent
|
||||||
|
): Promise<Create.Sketch> {
|
||||||
|
const url = new URL(`${this.domain()}/sketches`);
|
||||||
|
const headers = await this.headers();
|
||||||
|
const payload = {
|
||||||
|
ino: btoa(content),
|
||||||
|
path: posixPath,
|
||||||
|
user_id: 'me',
|
||||||
|
};
|
||||||
|
const init = {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
headers,
|
||||||
|
};
|
||||||
|
const result = await this.run<Create.Sketch>(url, init);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
async readDirectory(
|
||||||
|
posixPath: string,
|
||||||
|
options: {
|
||||||
|
recursive?: boolean;
|
||||||
|
match?: string;
|
||||||
|
skipSketchCache?: boolean;
|
||||||
|
} = {}
|
||||||
|
): Promise<Create.Resource[]> {
|
||||||
|
const url = new URL(
|
||||||
|
`${this.domain()}/files/d/$HOME/sketches_v2${posixPath}`
|
||||||
|
);
|
||||||
|
if (options.recursive) {
|
||||||
|
url.searchParams.set('deep', 'true');
|
||||||
|
}
|
||||||
|
if (options.match) {
|
||||||
|
url.searchParams.set('name_like', options.match);
|
||||||
|
}
|
||||||
|
const headers = await this.headers();
|
||||||
|
|
||||||
|
const cachedSketch = this.sketchCache.getSketch(posixPath);
|
||||||
|
|
||||||
|
const sketchPromise = options.skipSketchCache
|
||||||
|
? (cachedSketch && this.sketch(cachedSketch.id)) || Promise.resolve(null)
|
||||||
|
: Promise.resolve(this.sketchCache.getSketch(posixPath));
|
||||||
|
|
||||||
|
return Promise.all([
|
||||||
|
sketchPromise,
|
||||||
|
this.run<Create.RawResource[]>(url, {
|
||||||
|
method: 'GET',
|
||||||
|
headers,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
.then(async ([sketch, result]) => {
|
||||||
|
if (posixPath.length && posixPath !== posix.sep) {
|
||||||
|
if (sketch && sketch.secrets && sketch.secrets.length > 0) {
|
||||||
|
result.push(this.getSketchSecretStat(sketch));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.filter(
|
||||||
|
(res) => !Create.do_not_sync_files.includes(res.name)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.catch((reason) => {
|
||||||
|
if (reason?.status === 404) return [] as Create.Resource[];
|
||||||
|
else throw reason;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async createDirectory(posixPath: string): Promise<void> {
|
||||||
|
const url = new URL(
|
||||||
|
`${this.domain()}/files/d/$HOME/sketches_v2${posixPath}`
|
||||||
|
);
|
||||||
|
const headers = await this.headers();
|
||||||
|
await this.run(url, {
|
||||||
|
method: 'POST',
|
||||||
|
headers,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async stat(posixPath: string): Promise<Create.Resource> {
|
||||||
|
// The root is a directory read.
|
||||||
|
if (posixPath === '/') {
|
||||||
|
throw new Error('Stating the root is not supported');
|
||||||
|
}
|
||||||
|
// The RESTful API has different endpoints for files and directories.
|
||||||
|
// The RESTful API does not provide specific error codes, only HTP 500.
|
||||||
|
// We query the parent directory and look for the file with the last segment.
|
||||||
|
const parentPosixPath = createPaths.parentPosix(posixPath);
|
||||||
|
const basename = createPaths.basename(posixPath);
|
||||||
|
|
||||||
|
let resources;
|
||||||
|
if (basename === Create.arduino_secrets_file) {
|
||||||
|
const sketch = this.sketchCache.getSketch(parentPosixPath);
|
||||||
|
resources = sketch ? [this.getSketchSecretStat(sketch)] : [];
|
||||||
|
} else {
|
||||||
|
resources = await this.readDirectory(parentPosixPath, {
|
||||||
|
match: basename,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const resource = resources.find(
|
||||||
|
({ path }) => createPaths.splitSketchPath(path)[1] === posixPath
|
||||||
|
);
|
||||||
|
if (!resource) {
|
||||||
|
throw new CreateError(`Not found: ${posixPath}.`, 404);
|
||||||
|
}
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async toggleSecretsInclude(
|
||||||
|
path: string,
|
||||||
|
data: string,
|
||||||
|
mode: 'add' | 'remove'
|
||||||
|
) {
|
||||||
|
const includeString = `#include "${Create.arduino_secrets_file}"`;
|
||||||
|
const includeRegexp = new RegExp(includeString + '\\s*', 'g');
|
||||||
|
|
||||||
|
const basename = createPaths.basename(path);
|
||||||
|
if (mode === 'add') {
|
||||||
|
const doesIncludeSecrets = includeRegexp.test(data);
|
||||||
|
|
||||||
|
if (doesIncludeSecrets) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
const sketch = this.sketchCache.getSketch(createPaths.parentPosix(path));
|
||||||
|
|
||||||
|
if (
|
||||||
|
sketch &&
|
||||||
|
(sketch.name + '.ino' === basename ||
|
||||||
|
sketch.name + '.pde' === basename) &&
|
||||||
|
sketch.secrets &&
|
||||||
|
sketch.secrets.length > 0
|
||||||
|
) {
|
||||||
|
return includeString + '\n' + data;
|
||||||
|
}
|
||||||
|
} else if (mode === 'remove') {
|
||||||
|
return data.replace(includeRegexp, '');
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async readFile(posixPath: string): Promise<string> {
|
||||||
|
const basename = createPaths.basename(posixPath);
|
||||||
|
|
||||||
|
if (basename === Create.arduino_secrets_file) {
|
||||||
|
const parentPosixPath = createPaths.parentPosix(posixPath);
|
||||||
|
|
||||||
|
//retrieve the sketch id from the cache
|
||||||
|
const cacheSketch = this.sketchCache.getSketch(parentPosixPath);
|
||||||
|
if (!cacheSketch) {
|
||||||
|
throw new Error(`Unable to find sketch ${parentPosixPath} in cache`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get a fresh copy of the sketch in order to guarantee fresh secrets
|
||||||
|
const sketch = await this.sketch(cacheSketch.id);
|
||||||
|
if (!sketch) {
|
||||||
|
throw new Error(
|
||||||
|
`Unable to get a fresh copy of the sketch ${cacheSketch.id}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.sketchCache.addSketch(sketch);
|
||||||
|
|
||||||
|
let file = '';
|
||||||
|
if (sketch && sketch.secrets) {
|
||||||
|
for (const item of sketch.secrets) {
|
||||||
|
file += `#define ${item.name} "${item.value}"\r\n`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = new URL(
|
||||||
|
`${this.domain()}/files/f/$HOME/sketches_v2${posixPath}`
|
||||||
|
);
|
||||||
|
const headers = await this.headers();
|
||||||
|
const result = await this.run<{ data: string; path: string }>(url, {
|
||||||
|
method: 'GET',
|
||||||
|
headers,
|
||||||
|
});
|
||||||
|
let { data } = result;
|
||||||
|
|
||||||
|
// add includes to main arduino file
|
||||||
|
data = await this.toggleSecretsInclude(posixPath, atob(data), 'add');
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async writeFile(
|
||||||
|
posixPath: string,
|
||||||
|
content: string | Uint8Array
|
||||||
|
): Promise<void> {
|
||||||
|
const basename = createPaths.basename(posixPath);
|
||||||
|
|
||||||
|
if (basename === Create.arduino_secrets_file) {
|
||||||
|
const parentPosixPath = createPaths.parentPosix(posixPath);
|
||||||
|
|
||||||
|
const sketch = this.sketchCache.getSketch(parentPosixPath);
|
||||||
|
|
||||||
|
if (sketch) {
|
||||||
|
const url = new URL(`${this.domain()}/sketches/${sketch.id}`);
|
||||||
|
const headers = await this.headers();
|
||||||
|
|
||||||
|
// parse the secret file
|
||||||
|
const secrets = (
|
||||||
|
typeof content === 'string'
|
||||||
|
? content
|
||||||
|
: new TextDecoder().decode(content)
|
||||||
|
)
|
||||||
|
.split(/\r?\n/)
|
||||||
|
.reduce((prev, curr) => {
|
||||||
|
// check if the line contains a secret
|
||||||
|
const secret = curr.split('SECRET_')[1] || null;
|
||||||
|
if (!secret) {
|
||||||
|
return prev;
|
||||||
|
}
|
||||||
|
const regexp = /(\S*)\s+([\S\s]*)/g;
|
||||||
|
const tokens = regexp.exec(secret) || [];
|
||||||
|
const name = tokens[1].length > 0 ? `SECRET_${tokens[1]}` : '';
|
||||||
|
|
||||||
|
let value = '';
|
||||||
|
if (tokens[2].length > 0) {
|
||||||
|
value = JSON.parse(
|
||||||
|
JSON.stringify(
|
||||||
|
tokens[2].replace(/^['"]?/g, '').replace(/['"]?$/g, '')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name.length === 0) {
|
||||||
|
return prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [...prev, { name, value }];
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
id: sketch.id,
|
||||||
|
libraries: sketch.libraries,
|
||||||
|
secrets: { data: secrets },
|
||||||
|
};
|
||||||
|
|
||||||
|
// replace the sketch in the cache with the one we are pushing
|
||||||
|
// TODO: we should do a get after the POST, in order to be sure the cache
|
||||||
|
// is updated the most recent metadata
|
||||||
|
this.sketchCache.addSketch(sketch);
|
||||||
|
|
||||||
|
const init = {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
headers,
|
||||||
|
};
|
||||||
|
await this.run(url, init);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// do not upload "do_not_sync" files/directoris and their descendants
|
||||||
|
const segments = posixPath.split(posix.sep) || [];
|
||||||
|
if (
|
||||||
|
segments.some((segment) => Create.do_not_sync_files.includes(segment))
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = new URL(
|
||||||
|
`${this.domain()}/files/f/$HOME/sketches_v2${posixPath}`
|
||||||
|
);
|
||||||
|
const headers = await this.headers();
|
||||||
|
|
||||||
|
let data: string =
|
||||||
|
typeof content === 'string' ? content : new TextDecoder().decode(content);
|
||||||
|
data = await this.toggleSecretsInclude(posixPath, data, 'remove');
|
||||||
|
|
||||||
|
const payload = { data: btoa(data) };
|
||||||
|
const init = {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
headers,
|
||||||
|
};
|
||||||
|
await this.run(url, init);
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteFile(posixPath: string): Promise<void> {
|
||||||
|
await this.delete(posixPath, 'f');
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteDirectory(posixPath: string): Promise<void> {
|
||||||
|
await this.delete(posixPath, 'd');
|
||||||
|
}
|
||||||
|
|
||||||
|
private async delete(posixPath: string, type: ResourceType): Promise<void> {
|
||||||
|
const url = new URL(
|
||||||
|
`${this.domain()}/files/${type}/$HOME/sketches_v2${posixPath}`
|
||||||
|
);
|
||||||
|
const headers = await this.headers();
|
||||||
|
await this.run(url, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async rename(fromPosixPath: string, toPosixPath: string): Promise<void> {
|
||||||
|
const url = new URL(`${this.domain('v3')}/files/mv`);
|
||||||
|
const headers = await this.headers();
|
||||||
|
const payload = {
|
||||||
|
from: `$HOME/sketches_v2${fromPosixPath}`,
|
||||||
|
to: `$HOME/sketches_v2${toPosixPath}`,
|
||||||
|
};
|
||||||
|
const init = {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
headers,
|
||||||
|
};
|
||||||
|
await this.run(url, init, ResponseResultProvider.NOOP);
|
||||||
|
}
|
||||||
|
|
||||||
|
async editSketch({
|
||||||
|
id,
|
||||||
|
params,
|
||||||
|
}: {
|
||||||
|
id: string;
|
||||||
|
params: Record<string, unknown>;
|
||||||
|
}): Promise<Create.Sketch> {
|
||||||
|
const url = new URL(`${this.domain()}/sketches/${id}`);
|
||||||
|
|
||||||
|
const headers = await this.headers();
|
||||||
|
const result = await this.run<Create.Sketch>(url, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ id, ...params }),
|
||||||
|
headers,
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
async copy(fromPosixPath: string, toPosixPath: string): Promise<void> {
|
||||||
|
const payload = {
|
||||||
|
from: `$HOME/sketches_v2${fromPosixPath}`,
|
||||||
|
to: `$HOME/sketches_v2${toPosixPath}`,
|
||||||
|
};
|
||||||
|
const url = new URL(`${this.domain('v3')}/files/cp`);
|
||||||
|
const headers = await this.headers();
|
||||||
|
const init = {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
headers,
|
||||||
|
};
|
||||||
|
await this.run(url, init, ResponseResultProvider.NOOP);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async run<T>(
|
||||||
|
requestInfo: RequestInfo | URL,
|
||||||
|
init: RequestInit | undefined,
|
||||||
|
resultProvider: ResponseResultProvider = ResponseResultProvider.JSON
|
||||||
|
): Promise<T> {
|
||||||
|
const response = await fetch(
|
||||||
|
requestInfo instanceof URL ? requestInfo.toString() : requestInfo,
|
||||||
|
init
|
||||||
|
);
|
||||||
|
if (!response.ok) {
|
||||||
|
let details: string | undefined = undefined;
|
||||||
|
try {
|
||||||
|
details = await response.json();
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Cloud not get the error details.', e);
|
||||||
|
}
|
||||||
|
const { statusText, status } = response;
|
||||||
|
throw new CreateError(statusText, status, details);
|
||||||
|
}
|
||||||
|
const result = await resultProvider(response);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async headers(): Promise<Record<string, string>> {
|
||||||
|
const token = await this.token();
|
||||||
|
return {
|
||||||
|
'content-type': 'application/json',
|
||||||
|
accept: 'application/json',
|
||||||
|
authorization: `Bearer ${token}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private domain(apiVersion = 'v2'): string {
|
||||||
|
const endpoint = this.arduinoPreferences['arduino.cloud.sketchSyncEnpoint'];
|
||||||
|
return `${endpoint}/${apiVersion}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async token(): Promise<string> {
|
||||||
|
return this.authenticationService.session?.accessToken || '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export namespace CreateApi {
|
||||||
|
export const defaultInoContent = `/*
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
`;
|
||||||
|
}
|
||||||
198
arduino-ide-extension/src/browser/create/create-fs-provider.ts
Normal file
198
arduino-ide-extension/src/browser/create/create-fs-provider.ts
Normal file
@@ -0,0 +1,198 @@
|
|||||||
|
import { inject, injectable } from 'inversify';
|
||||||
|
import URI from '@theia/core/lib/common/uri';
|
||||||
|
import { Event } from '@theia/core/lib/common/event';
|
||||||
|
import {
|
||||||
|
Disposable,
|
||||||
|
DisposableCollection,
|
||||||
|
} from '@theia/core/lib/common/disposable';
|
||||||
|
import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application';
|
||||||
|
import {
|
||||||
|
Stat,
|
||||||
|
FileType,
|
||||||
|
FileChange,
|
||||||
|
FileWriteOptions,
|
||||||
|
FileDeleteOptions,
|
||||||
|
FileOverwriteOptions,
|
||||||
|
FileSystemProvider,
|
||||||
|
FileSystemProviderError,
|
||||||
|
FileSystemProviderErrorCode,
|
||||||
|
FileSystemProviderCapabilities,
|
||||||
|
WatchOptions,
|
||||||
|
} from '@theia/filesystem/lib/common/files';
|
||||||
|
import {
|
||||||
|
FileService,
|
||||||
|
FileServiceContribution,
|
||||||
|
} from '@theia/filesystem/lib/browser/file-service';
|
||||||
|
import { AuthenticationClientService } from '../auth/authentication-client-service';
|
||||||
|
import { CreateApi } from './create-api';
|
||||||
|
import { CreateUri } from './create-uri';
|
||||||
|
import { SketchesService } from '../../common/protocol';
|
||||||
|
import { ArduinoPreferences } from '../arduino-preferences';
|
||||||
|
import { Create } from './typings';
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class CreateFsProvider
|
||||||
|
implements
|
||||||
|
FileSystemProvider,
|
||||||
|
FrontendApplicationContribution,
|
||||||
|
FileServiceContribution
|
||||||
|
{
|
||||||
|
@inject(AuthenticationClientService)
|
||||||
|
protected readonly authenticationService: AuthenticationClientService;
|
||||||
|
|
||||||
|
@inject(CreateApi)
|
||||||
|
protected readonly createApi: CreateApi;
|
||||||
|
|
||||||
|
@inject(SketchesService)
|
||||||
|
protected readonly sketchesService: SketchesService;
|
||||||
|
|
||||||
|
@inject(ArduinoPreferences)
|
||||||
|
protected readonly arduinoPreferences: ArduinoPreferences;
|
||||||
|
|
||||||
|
protected readonly toDispose = new DisposableCollection();
|
||||||
|
|
||||||
|
readonly onFileWatchError: Event<void> = Event.None;
|
||||||
|
readonly onDidChangeFile: Event<readonly FileChange[]> = Event.None;
|
||||||
|
readonly onDidChangeCapabilities: Event<void> = Event.None;
|
||||||
|
readonly capabilities: FileSystemProviderCapabilities =
|
||||||
|
FileSystemProviderCapabilities.FileReadWrite |
|
||||||
|
FileSystemProviderCapabilities.PathCaseSensitive |
|
||||||
|
FileSystemProviderCapabilities.Access;
|
||||||
|
|
||||||
|
onStop(): void {
|
||||||
|
this.toDispose.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
registerFileSystemProviders(service: FileService): void {
|
||||||
|
service.onWillActivateFileSystemProvider((event) => {
|
||||||
|
if (event.scheme === CreateUri.scheme) {
|
||||||
|
event.waitUntil(
|
||||||
|
(async () => {
|
||||||
|
service.registerProvider(CreateUri.scheme, this);
|
||||||
|
})()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(uri: URI, opts: WatchOptions): Disposable {
|
||||||
|
return Disposable.NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
async stat(uri: URI): Promise<Stat> {
|
||||||
|
if (CreateUri.equals(CreateUri.root, uri)) {
|
||||||
|
this.getCreateApi; // This will throw when not logged in.
|
||||||
|
return {
|
||||||
|
type: FileType.Directory,
|
||||||
|
ctime: 0,
|
||||||
|
mtime: 0,
|
||||||
|
size: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const resource = await this.getCreateApi.stat(uri.path.toString());
|
||||||
|
const mtime = Date.parse(resource.modified_at);
|
||||||
|
return {
|
||||||
|
type: this.toFileType(resource.type),
|
||||||
|
ctime: mtime,
|
||||||
|
mtime,
|
||||||
|
size: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async mkdir(uri: URI): Promise<void> {
|
||||||
|
await this.getCreateApi.createDirectory(uri.path.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
async readdir(uri: URI): Promise<[string, FileType][]> {
|
||||||
|
const resources = await this.getCreateApi.readDirectory(
|
||||||
|
uri.path.toString()
|
||||||
|
);
|
||||||
|
return resources.map(({ name, type }) => [name, this.toFileType(type)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
async delete(uri: URI, opts: FileDeleteOptions): Promise<void> {
|
||||||
|
if (!opts.recursive) {
|
||||||
|
throw new Error(
|
||||||
|
'Arduino Create file-system provider does not support non-recursive deletion.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const stat = await this.stat(uri);
|
||||||
|
if (!stat) {
|
||||||
|
throw new FileSystemProviderError(
|
||||||
|
'File not found.',
|
||||||
|
FileSystemProviderErrorCode.FileNotFound
|
||||||
|
);
|
||||||
|
}
|
||||||
|
switch (stat.type) {
|
||||||
|
case FileType.Directory: {
|
||||||
|
await this.getCreateApi.deleteDirectory(uri.path.toString());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case FileType.File: {
|
||||||
|
await this.getCreateApi.deleteFile(uri.path.toString());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
throw new FileSystemProviderError(
|
||||||
|
`Unexpected file type '${stat.type}' for resource: ${uri.toString()}`,
|
||||||
|
FileSystemProviderErrorCode.Unknown
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async rename(
|
||||||
|
oldUri: URI,
|
||||||
|
newUri: URI,
|
||||||
|
options: FileOverwriteOptions
|
||||||
|
): Promise<void> {
|
||||||
|
await this.getCreateApi.rename(
|
||||||
|
oldUri.path.toString(),
|
||||||
|
newUri.path.toString()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async readFile(uri: URI): Promise<Uint8Array> {
|
||||||
|
const content = await this.getCreateApi.readFile(uri.path.toString());
|
||||||
|
return new TextEncoder().encode(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
async writeFile(
|
||||||
|
uri: URI,
|
||||||
|
content: Uint8Array,
|
||||||
|
options: FileWriteOptions
|
||||||
|
): Promise<void> {
|
||||||
|
await this.getCreateApi.writeFile(uri.path.toString(), content);
|
||||||
|
}
|
||||||
|
|
||||||
|
async access(uri: URI, mode?: number): Promise<void> {
|
||||||
|
this.getCreateApi; // Will throw if not logged in.
|
||||||
|
}
|
||||||
|
|
||||||
|
public toFileType(type: Create.ResourceType): FileType {
|
||||||
|
switch (type) {
|
||||||
|
case 'file':
|
||||||
|
return FileType.File;
|
||||||
|
case 'sketch':
|
||||||
|
case 'folder':
|
||||||
|
return FileType.Directory;
|
||||||
|
default:
|
||||||
|
return FileType.Unknown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private get getCreateApi(): CreateApi {
|
||||||
|
const { session } = this.authenticationService;
|
||||||
|
if (!session) {
|
||||||
|
throw new FileSystemProviderError(
|
||||||
|
'Not logged in.',
|
||||||
|
FileSystemProviderErrorCode.NoPermissions
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.createApi.init(
|
||||||
|
this.authenticationService,
|
||||||
|
this.arduinoPreferences
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
59
arduino-ide-extension/src/browser/create/create-paths.ts
Normal file
59
arduino-ide-extension/src/browser/create/create-paths.ts
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
export const posix = { sep: '/' };
|
||||||
|
|
||||||
|
// TODO: poor man's `path.join(path, '..')` in the browser.
|
||||||
|
export function parentPosix(path: string): string {
|
||||||
|
const segments = path.split(posix.sep) || [];
|
||||||
|
segments.pop();
|
||||||
|
let modified = segments.join(posix.sep);
|
||||||
|
if (path.charAt(path.length - 1) === posix.sep) {
|
||||||
|
modified += posix.sep;
|
||||||
|
}
|
||||||
|
return modified;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function basename(path: string): string {
|
||||||
|
const segments = path.split(posix.sep) || [];
|
||||||
|
return segments.pop()!;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function posixSegments(posixPath: string): string[] {
|
||||||
|
return posixPath.split(posix.sep).filter((segment) => !!segment);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits the `raw` path into two segments, a root that contains user information and the relevant POSIX path. \
|
||||||
|
* For examples:
|
||||||
|
* ```
|
||||||
|
* `29ad0829759028dde9b877343fa3b0e1:testrest/sketches_v2/xxx_folder/xxx_sub_folder/sketch_in_folder/sketch_in_folder.ino`
|
||||||
|
* ```
|
||||||
|
* will be:
|
||||||
|
* ```
|
||||||
|
* ['29ad0829759028dde9b877343fa3b0e1:testrest/sketches_v2', '/xxx_folder/xxx_sub_folder/sketch_in_folder/sketch_in_folder.ino']
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export function splitSketchPath(
|
||||||
|
raw: string,
|
||||||
|
sep = '/sketches_v2/'
|
||||||
|
): [string, string] {
|
||||||
|
if (!sep) {
|
||||||
|
throw new Error('Invalid separator. Cannot be zero length.');
|
||||||
|
}
|
||||||
|
const index = raw.indexOf(sep);
|
||||||
|
if (index === -1) {
|
||||||
|
throw new Error(`Invalid path pattern. Raw path was '${raw}'.`);
|
||||||
|
}
|
||||||
|
const createRoot = raw.substring(0, index + sep.length - 1); // TODO: validate the `createRoot` format.
|
||||||
|
const posixPath = raw.substr(index + sep.length - 1);
|
||||||
|
if (!posixPath) {
|
||||||
|
throw new Error(`Could not extract POSIX path from '${raw}'.`);
|
||||||
|
}
|
||||||
|
return [createRoot, posixPath];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function toPosixPath(raw: string): string {
|
||||||
|
if (raw === posix.sep) {
|
||||||
|
return posix.sep; // Handles the root resource case.
|
||||||
|
}
|
||||||
|
const [, posixPath] = splitSketchPath(raw);
|
||||||
|
return posixPath;
|
||||||
|
}
|
||||||
37
arduino-ide-extension/src/browser/create/create-uri.ts
Normal file
37
arduino-ide-extension/src/browser/create/create-uri.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import { URI as Uri } from 'vscode-uri';
|
||||||
|
import URI from '@theia/core/lib/common/uri';
|
||||||
|
import { toPosixPath, parentPosix, posix } from './create-paths';
|
||||||
|
import { Create } from './typings';
|
||||||
|
|
||||||
|
export namespace CreateUri {
|
||||||
|
export const scheme = 'arduino-create';
|
||||||
|
export const root = toUri(posix.sep);
|
||||||
|
|
||||||
|
export function toUri(posixPathOrResource: string | Create.Resource): URI {
|
||||||
|
const posixPath =
|
||||||
|
typeof posixPathOrResource === 'string'
|
||||||
|
? posixPathOrResource
|
||||||
|
: toPosixPath(posixPathOrResource.path);
|
||||||
|
return new URI(Uri.parse(posixPath).with({ scheme, authority: 'create' }));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function is(uri: URI): boolean {
|
||||||
|
return uri.scheme === scheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function equals(left: URI, right: URI): boolean {
|
||||||
|
return is(left) && is(right) && left.toString() === right.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parent(uri: URI): URI {
|
||||||
|
if (!is(uri)) {
|
||||||
|
throw new Error(
|
||||||
|
`Invalid URI scheme. Expected '${scheme}' got '${uri.scheme}' instead.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (equals(uri, root)) {
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
return toUri(parentPosix(uri.path.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
73
arduino-ide-extension/src/browser/create/typings.ts
Normal file
73
arduino-ide-extension/src/browser/create/typings.ts
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
export namespace Create {
|
||||||
|
export interface Sketch {
|
||||||
|
readonly name: string;
|
||||||
|
readonly path: string;
|
||||||
|
readonly modified_at: string;
|
||||||
|
readonly created_at: string;
|
||||||
|
|
||||||
|
readonly secrets?: { name: string; value: string }[];
|
||||||
|
|
||||||
|
readonly id: string;
|
||||||
|
readonly is_public: boolean;
|
||||||
|
readonly board_fqbn: '';
|
||||||
|
readonly board_name: '';
|
||||||
|
readonly board_type: 'serial' | 'network' | 'cloud' | '';
|
||||||
|
readonly href?: string;
|
||||||
|
readonly libraries: string[];
|
||||||
|
readonly tutorials: string[] | null;
|
||||||
|
readonly types: string[] | null;
|
||||||
|
readonly user_id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ResourceType = 'sketch' | 'folder' | 'file';
|
||||||
|
export const arduino_secrets_file = 'arduino_secrets.h';
|
||||||
|
export const do_not_sync_files = ['.theia', 'sketch.json'];
|
||||||
|
export interface Resource {
|
||||||
|
readonly name: string;
|
||||||
|
/**
|
||||||
|
* Note: this path is **not** the POSIX path we use. It has the leading segments with the `user_id`.
|
||||||
|
*/
|
||||||
|
readonly path: string;
|
||||||
|
readonly type: ResourceType;
|
||||||
|
readonly sketchId?: string;
|
||||||
|
readonly modified_at: string; // As an ISO-8601 formatted string: `YYYY-MM-DDTHH:mm:ss.sssZ`
|
||||||
|
readonly created_at: string; // As an ISO-8601 formatted string: `YYYY-MM-DDTHH:mm:ss.sssZ`
|
||||||
|
readonly children?: number; // For 'sketch' and 'folder' types.
|
||||||
|
readonly size?: number; // For 'sketch' type only.
|
||||||
|
readonly isPublic?: boolean; // For 'sketch' type only.
|
||||||
|
|
||||||
|
readonly mimetype?: string; // For 'file' type.
|
||||||
|
readonly href?: string;
|
||||||
|
}
|
||||||
|
export namespace Resource {
|
||||||
|
export function is(arg: any): arg is Resource {
|
||||||
|
return (
|
||||||
|
!!arg &&
|
||||||
|
'name' in arg &&
|
||||||
|
typeof arg['name'] === 'string' &&
|
||||||
|
'path' in arg &&
|
||||||
|
typeof arg['path'] === 'string' &&
|
||||||
|
'type' in arg &&
|
||||||
|
typeof arg['type'] === 'string' &&
|
||||||
|
'modified_at' in arg &&
|
||||||
|
typeof arg['modified_at'] === 'string' &&
|
||||||
|
(arg['type'] === 'sketch' ||
|
||||||
|
arg['type'] === 'folder' ||
|
||||||
|
arg['type'] === 'file')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export type RawResource = Omit<Resource, 'sketchId' | 'isPublic'>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CreateError extends Error {
|
||||||
|
constructor(
|
||||||
|
message: string,
|
||||||
|
readonly status: number,
|
||||||
|
readonly details?: string
|
||||||
|
) {
|
||||||
|
super(message);
|
||||||
|
Object.setPrototypeOf(this, CreateError.prototype);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,7 +28,8 @@
|
|||||||
"scope": [
|
"scope": [
|
||||||
"meta.function.c",
|
"meta.function.c",
|
||||||
"entity.name.function",
|
"entity.name.function",
|
||||||
"meta.function-call.c"
|
"meta.function-call.c",
|
||||||
|
"variable.other"
|
||||||
],
|
],
|
||||||
"settings": {
|
"settings": {
|
||||||
"foreground": "#D35400"
|
"foreground": "#D35400"
|
||||||
@@ -42,16 +43,19 @@
|
|||||||
"meta.block.c",
|
"meta.block.c",
|
||||||
"meta.function.c",
|
"meta.function.c",
|
||||||
"entity.name.function.preprocessor.c",
|
"entity.name.function.preprocessor.c",
|
||||||
"meta.preprocessor.macro.c"
|
"meta.preprocessor.macro.c",
|
||||||
|
"variable",
|
||||||
|
"variable.name"
|
||||||
],
|
],
|
||||||
"settings": {
|
"settings": {
|
||||||
"foreground": "#434f54"
|
"foreground": "#434f54"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "strings",
|
"name": "constants",
|
||||||
"scope": [
|
"scope": [
|
||||||
"string.quoted.double"
|
"string.quoted.double",
|
||||||
|
"constant"
|
||||||
],
|
],
|
||||||
"settings": {
|
"settings": {
|
||||||
"foreground": "#005C5F"
|
"foreground": "#005C5F"
|
||||||
@@ -80,22 +84,28 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"colors": {
|
"colors": {
|
||||||
"list.highlightForeground": "#006468",
|
"list.highlightForeground": "#005c5f",
|
||||||
"list.activeSelectionBackground": "#006468",
|
"list.activeSelectionForeground": "#424242",
|
||||||
|
"list.activeSelectionBackground": "#DAE3E3",
|
||||||
|
"list.inactiveSelectionForeground": "#424242",
|
||||||
|
"list.inactiveSelectionBackground": "#DAE3E3",
|
||||||
|
"list.hoverBackground": "#ECF1F1",
|
||||||
|
"progressBar.background": "#005c5f",
|
||||||
"editor.background": "#ffffff",
|
"editor.background": "#ffffff",
|
||||||
"editorCursor.foreground": "#434f54",
|
"editorCursor.foreground": "#434f54",
|
||||||
"editor.foreground": "#434f54",
|
"editor.foreground": "#434f54",
|
||||||
"editorWhitespace.foreground": "#bfbfbf",
|
"editorWhitespace.foreground": "#bfbfbf",
|
||||||
"editor.lineHighlightBackground": "#434f5410",
|
"editor.lineHighlightBackground": "#434f5410",
|
||||||
"editor.selectionBackground": "#ffcb00",
|
"editor.selectionBackground": "#ffcb00",
|
||||||
"focusBorder": "#4db7bb99",
|
"editorWidget.background": "#F7F9F9",
|
||||||
|
"focusBorder": "#7fcbcd99",
|
||||||
"menubar.selectionBackground": "#ffffff",
|
"menubar.selectionBackground": "#ffffff",
|
||||||
"menubar.selectionForeground": "#212121",
|
"menubar.selectionForeground": "#212121",
|
||||||
"menu.selectionBackground": "#dae3e3",
|
"menu.selectionBackground": "#dae3e3",
|
||||||
"menu.selectionForeground": "#212121",
|
"menu.selectionForeground": "#212121",
|
||||||
"editorGroupHeader.tabsBackground": "#f7f9f9",
|
"editorGroupHeader.tabsBackground": "#f7f9f9",
|
||||||
"button.background": "#4db7bb",
|
"button.background": "#7fcbcd",
|
||||||
"titleBar.activeBackground": "#006468",
|
"titleBar.activeBackground": "#005c5f",
|
||||||
"titleBar.activeForeground": "#ffffff",
|
"titleBar.activeForeground": "#ffffff",
|
||||||
"terminal.background": "#000000",
|
"terminal.background": "#000000",
|
||||||
"terminal.foreground": "#e0e0e0",
|
"terminal.foreground": "#e0e0e0",
|
||||||
@@ -103,8 +113,9 @@
|
|||||||
"dropdown.background": "#ececec",
|
"dropdown.background": "#ececec",
|
||||||
"activityBar.background": "#ececec",
|
"activityBar.background": "#ececec",
|
||||||
"activityBar.foreground": "#616161",
|
"activityBar.foreground": "#616161",
|
||||||
"statusBar.background": "#006468",
|
"statusBar.background": "#005c5f",
|
||||||
"secondaryButton.background": "#b5c8c9",
|
"secondaryButton.background": "#b5c8c9",
|
||||||
|
"secondaryButton.foreground": "#ececec",
|
||||||
"secondaryButton.hoverBackground": "#dae3e3",
|
"secondaryButton.hoverBackground": "#dae3e3",
|
||||||
"arduino.branding.primary": "#00979d",
|
"arduino.branding.primary": "#00979d",
|
||||||
"arduino.branding.secondary": "#b5c8c9",
|
"arduino.branding.secondary": "#b5c8c9",
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
export const CertificateAddComponent = ({
|
||||||
|
addCertificate,
|
||||||
|
}: {
|
||||||
|
addCertificate: (cert: string) => void;
|
||||||
|
}): React.ReactElement => {
|
||||||
|
const [value, setValue] = React.useState('');
|
||||||
|
|
||||||
|
const handleChange = React.useCallback((event) => {
|
||||||
|
setValue(event.target.value);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form
|
||||||
|
className="certificate-add"
|
||||||
|
onSubmit={(event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
addCertificate(value);
|
||||||
|
setValue('');
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<label>
|
||||||
|
<div>Add URL to fetch SSL certificate</div>
|
||||||
|
<input
|
||||||
|
className="theia-input"
|
||||||
|
placeholder="Enter URL"
|
||||||
|
type="text"
|
||||||
|
name="add"
|
||||||
|
onChange={handleChange}
|
||||||
|
value={value}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
export const CertificateListComponent = ({
|
||||||
|
certificates,
|
||||||
|
selectedCerts,
|
||||||
|
setSelectedCerts,
|
||||||
|
openContextMenu,
|
||||||
|
}: {
|
||||||
|
certificates: string[];
|
||||||
|
selectedCerts: string[];
|
||||||
|
setSelectedCerts: React.Dispatch<React.SetStateAction<string[]>>;
|
||||||
|
openContextMenu: (x: number, y: number, cert: string) => void;
|
||||||
|
}): React.ReactElement => {
|
||||||
|
const handleOnChange = (event: any) => {
|
||||||
|
const target = event.target;
|
||||||
|
|
||||||
|
const newSelectedCerts = selectedCerts.filter(
|
||||||
|
(cert) => cert !== target.name
|
||||||
|
);
|
||||||
|
|
||||||
|
if (target.checked) {
|
||||||
|
newSelectedCerts.push(target.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
setSelectedCerts(newSelectedCerts);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleContextMenu = (event: React.MouseEvent, cert: string) => {
|
||||||
|
openContextMenu(event.clientX, event.clientY, cert);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="certificate-list">
|
||||||
|
{certificates.map((certificate, i) => (
|
||||||
|
<label
|
||||||
|
key={i}
|
||||||
|
className="certificate-row"
|
||||||
|
onContextMenu={(e) => handleContextMenu(e, certificate)}
|
||||||
|
>
|
||||||
|
<span className="fl1">{certificate}</span>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
name={certificate}
|
||||||
|
checked={selectedCerts.includes(certificate)}
|
||||||
|
onChange={handleOnChange}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import Tippy from '@tippyjs/react';
|
||||||
|
import { AvailableBoard } from '../../boards/boards-service-provider';
|
||||||
|
import { CertificateListComponent } from './certificate-list';
|
||||||
|
import { SelectBoardComponent } from './select-board-components';
|
||||||
|
import { CertificateAddComponent } from './certificate-add-new';
|
||||||
|
|
||||||
|
export const CertificateUploaderComponent = ({
|
||||||
|
availableBoards,
|
||||||
|
certificates,
|
||||||
|
addCertificate,
|
||||||
|
updatableFqbns,
|
||||||
|
uploadCertificates,
|
||||||
|
openContextMenu,
|
||||||
|
}: {
|
||||||
|
availableBoards: AvailableBoard[];
|
||||||
|
certificates: string[];
|
||||||
|
addCertificate: (cert: string) => void;
|
||||||
|
updatableFqbns: string[];
|
||||||
|
uploadCertificates: (
|
||||||
|
fqbn: string,
|
||||||
|
address: string,
|
||||||
|
urls: string[]
|
||||||
|
) => Promise<any>;
|
||||||
|
openContextMenu: (x: number, y: number, cert: string) => void;
|
||||||
|
}): React.ReactElement => {
|
||||||
|
const [installFeedback, setInstallFeedback] = React.useState<
|
||||||
|
'ok' | 'fail' | 'installing' | null
|
||||||
|
>(null);
|
||||||
|
|
||||||
|
const [showAdd, setShowAdd] = React.useState(false);
|
||||||
|
|
||||||
|
const [selectedCerts, setSelectedCerts] = React.useState<string[]>([]);
|
||||||
|
|
||||||
|
const [selectedBoard, setSelectedBoard] =
|
||||||
|
React.useState<AvailableBoard | null>(null);
|
||||||
|
|
||||||
|
const installCertificates = async () => {
|
||||||
|
if (!selectedBoard || !selectedBoard.fqbn || !selectedBoard.port) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setInstallFeedback('installing');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await uploadCertificates(
|
||||||
|
selectedBoard.fqbn,
|
||||||
|
selectedBoard.port.address,
|
||||||
|
selectedCerts
|
||||||
|
);
|
||||||
|
setInstallFeedback('ok');
|
||||||
|
} catch {
|
||||||
|
setInstallFeedback('fail');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onBoardSelect = React.useCallback(
|
||||||
|
(board: AvailableBoard) => {
|
||||||
|
const newFqbn = (board && board.fqbn) || null;
|
||||||
|
const prevFqbn = (selectedBoard && selectedBoard.fqbn) || null;
|
||||||
|
|
||||||
|
if (newFqbn !== prevFqbn) {
|
||||||
|
setInstallFeedback(null);
|
||||||
|
setSelectedBoard(board);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[selectedBoard]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="dialogSection">
|
||||||
|
<div className="dialogRow">
|
||||||
|
<strong className="fl1">1. Select certificate to upload</strong>
|
||||||
|
<Tippy
|
||||||
|
content={
|
||||||
|
<CertificateAddComponent
|
||||||
|
addCertificate={(cert) => {
|
||||||
|
addCertificate(cert);
|
||||||
|
setShowAdd(false);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
placement="bottom-end"
|
||||||
|
onClickOutside={() => setShowAdd(false)}
|
||||||
|
visible={showAdd}
|
||||||
|
interactive={true}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="theia-button primary add-cert-btn"
|
||||||
|
onClick={() => {
|
||||||
|
showAdd ? setShowAdd(false) : setShowAdd(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Add New <span className="fa fa-caret-down caret"></span>
|
||||||
|
</button>
|
||||||
|
</Tippy>
|
||||||
|
</div>
|
||||||
|
<div className="dialogRow">
|
||||||
|
<CertificateListComponent
|
||||||
|
certificates={certificates}
|
||||||
|
selectedCerts={selectedCerts}
|
||||||
|
setSelectedCerts={setSelectedCerts}
|
||||||
|
openContextMenu={openContextMenu}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="dialogSection">
|
||||||
|
<div className="dialogRow">
|
||||||
|
<strong>2. Select destination board and upload certificate</strong>
|
||||||
|
</div>
|
||||||
|
<div className="dialogRow">
|
||||||
|
<div className="fl1">
|
||||||
|
<SelectBoardComponent
|
||||||
|
availableBoards={availableBoards}
|
||||||
|
updatableFqbns={updatableFqbns}
|
||||||
|
onBoardSelect={onBoardSelect}
|
||||||
|
selectedBoard={selectedBoard}
|
||||||
|
busy={installFeedback === 'installing'}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="dialogRow">
|
||||||
|
<div className="upload-status">
|
||||||
|
{installFeedback === 'installing' && (
|
||||||
|
<div className="success">
|
||||||
|
<div className="spinner" />
|
||||||
|
Uploading certificates.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{installFeedback === 'ok' && (
|
||||||
|
<div className="success">
|
||||||
|
<i className="fa fa-info status-icon" />
|
||||||
|
Cetificates uploaded.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{installFeedback === 'fail' && (
|
||||||
|
<div className="warn">
|
||||||
|
<i className="fa fa-exclamation status-icon" />
|
||||||
|
Upload failed. Please try again.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="theia-button primary install-cert-btn"
|
||||||
|
onClick={installCertificates}
|
||||||
|
disabled={selectedCerts.length === 0 || !selectedBoard}
|
||||||
|
>
|
||||||
|
Upload
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,190 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { inject, injectable, postConstruct } from 'inversify';
|
||||||
|
import { AbstractDialog, DialogProps } from '@theia/core/lib/browser/dialogs';
|
||||||
|
import { Widget } from '@phosphor/widgets';
|
||||||
|
import { Message } from '@phosphor/messaging';
|
||||||
|
import { ReactWidget } from '@theia/core/lib/browser/widgets/react-widget';
|
||||||
|
import {
|
||||||
|
AvailableBoard,
|
||||||
|
BoardsServiceProvider,
|
||||||
|
} from '../../boards/boards-service-provider';
|
||||||
|
import { CertificateUploaderComponent } from './certificate-uploader-component';
|
||||||
|
import { ArduinoPreferences } from '../../arduino-preferences';
|
||||||
|
import {
|
||||||
|
PreferenceScope,
|
||||||
|
PreferenceService,
|
||||||
|
} from '@theia/core/lib/browser/preferences/preference-service';
|
||||||
|
import { CommandRegistry } from '@theia/core/lib/common/command';
|
||||||
|
import { certificateList, sanifyCertString } from './utils';
|
||||||
|
import { ArduinoFirmwareUploader } from '../../../common/protocol/arduino-firmware-uploader';
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class UploadCertificateDialogWidget extends ReactWidget {
|
||||||
|
@inject(BoardsServiceProvider)
|
||||||
|
protected readonly boardsServiceClient: BoardsServiceProvider;
|
||||||
|
|
||||||
|
@inject(ArduinoPreferences)
|
||||||
|
protected readonly arduinoPreferences: ArduinoPreferences;
|
||||||
|
|
||||||
|
@inject(PreferenceService)
|
||||||
|
protected readonly preferenceService: PreferenceService;
|
||||||
|
|
||||||
|
@inject(CommandRegistry)
|
||||||
|
protected readonly commandRegistry: CommandRegistry;
|
||||||
|
|
||||||
|
@inject(ArduinoFirmwareUploader)
|
||||||
|
protected readonly arduinoFirmwareUploader: ArduinoFirmwareUploader;
|
||||||
|
|
||||||
|
protected certificates: string[] = [];
|
||||||
|
protected updatableFqbns: string[] = [];
|
||||||
|
protected availableBoards: AvailableBoard[] = [];
|
||||||
|
|
||||||
|
public busyCallback = (busy: boolean) => {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@postConstruct()
|
||||||
|
protected init(): void {
|
||||||
|
this.arduinoPreferences.ready.then(() => {
|
||||||
|
this.certificates = certificateList(
|
||||||
|
this.arduinoPreferences.get('arduino.board.certificates')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
this.arduinoPreferences.onPreferenceChanged((event) => {
|
||||||
|
if (
|
||||||
|
event.preferenceName === 'arduino.board.certificates' &&
|
||||||
|
event.newValue !== event.oldValue
|
||||||
|
) {
|
||||||
|
this.certificates = certificateList(event.newValue);
|
||||||
|
this.update();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.arduinoFirmwareUploader.updatableBoards().then((fqbns) => {
|
||||||
|
this.updatableFqbns = fqbns;
|
||||||
|
this.update();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.boardsServiceClient.onAvailableBoardsChanged((availableBoards) => {
|
||||||
|
this.availableBoards = availableBoards;
|
||||||
|
this.update();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private addCertificate(certificate: string) {
|
||||||
|
const certString = sanifyCertString(certificate);
|
||||||
|
|
||||||
|
if (certString.length > 0) {
|
||||||
|
this.certificates.push(sanifyCertString(certificate));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.preferenceService.set(
|
||||||
|
'arduino.board.certificates',
|
||||||
|
this.certificates.join(','),
|
||||||
|
PreferenceScope.User
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected openContextMenu(x: number, y: number, cert: string): void {
|
||||||
|
this.commandRegistry.executeCommand(
|
||||||
|
'arduino-certificate-open-context',
|
||||||
|
Object.assign({}, { x, y, cert })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected uploadCertificates(
|
||||||
|
fqbn: string,
|
||||||
|
address: string,
|
||||||
|
urls: string[]
|
||||||
|
): Promise<any> {
|
||||||
|
this.busyCallback(true);
|
||||||
|
return this.commandRegistry
|
||||||
|
.executeCommand('arduino-certificate-upload', {
|
||||||
|
fqbn,
|
||||||
|
address,
|
||||||
|
urls,
|
||||||
|
})
|
||||||
|
.finally(() => this.busyCallback(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render(): React.ReactNode {
|
||||||
|
return (
|
||||||
|
<CertificateUploaderComponent
|
||||||
|
availableBoards={this.availableBoards}
|
||||||
|
certificates={this.certificates}
|
||||||
|
updatableFqbns={this.updatableFqbns}
|
||||||
|
addCertificate={this.addCertificate.bind(this)}
|
||||||
|
uploadCertificates={this.uploadCertificates.bind(this)}
|
||||||
|
openContextMenu={this.openContextMenu.bind(this)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class UploadCertificateDialogProps extends DialogProps {}
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class UploadCertificateDialog extends AbstractDialog<void> {
|
||||||
|
@inject(UploadCertificateDialogWidget)
|
||||||
|
protected readonly widget: UploadCertificateDialogWidget;
|
||||||
|
|
||||||
|
private busy = false;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
@inject(UploadCertificateDialogProps)
|
||||||
|
protected readonly props: UploadCertificateDialogProps
|
||||||
|
) {
|
||||||
|
super({ title: 'Upload SSL Root Certificates' });
|
||||||
|
this.contentNode.classList.add('certificate-uploader-dialog');
|
||||||
|
this.acceptButton = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
get value(): void {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected onAfterAttach(msg: Message): void {
|
||||||
|
if (this.widget.isAttached) {
|
||||||
|
Widget.detach(this.widget);
|
||||||
|
}
|
||||||
|
Widget.attach(this.widget, this.contentNode);
|
||||||
|
this.widget.busyCallback = this.busyCallback.bind(this);
|
||||||
|
super.onAfterAttach(msg);
|
||||||
|
this.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected onUpdateRequest(msg: Message): void {
|
||||||
|
super.onUpdateRequest(msg);
|
||||||
|
this.widget.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected onActivateRequest(msg: Message): void {
|
||||||
|
super.onActivateRequest(msg);
|
||||||
|
this.widget.activate();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected handleEnter(event: KeyboardEvent): boolean | void {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(): void {
|
||||||
|
if (this.busy) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
super.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
busyCallback(busy: boolean): void {
|
||||||
|
this.busy = busy;
|
||||||
|
if (busy) {
|
||||||
|
this.closeCrossNode.classList.add('disabled');
|
||||||
|
} else {
|
||||||
|
this.closeCrossNode.classList.remove('disabled');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { AvailableBoard } from '../../boards/boards-service-provider';
|
||||||
|
import { ArduinoSelect } from '../../widgets/arduino-select';
|
||||||
|
|
||||||
|
type BoardOption = { value: string; label: string };
|
||||||
|
|
||||||
|
export const SelectBoardComponent = ({
|
||||||
|
availableBoards,
|
||||||
|
updatableFqbns,
|
||||||
|
onBoardSelect,
|
||||||
|
selectedBoard,
|
||||||
|
busy,
|
||||||
|
}: {
|
||||||
|
availableBoards: AvailableBoard[];
|
||||||
|
updatableFqbns: string[];
|
||||||
|
onBoardSelect: (board: AvailableBoard | null) => void;
|
||||||
|
selectedBoard: AvailableBoard | null;
|
||||||
|
busy: boolean;
|
||||||
|
}): React.ReactElement => {
|
||||||
|
const [selectOptions, setSelectOptions] = React.useState<BoardOption[]>([]);
|
||||||
|
|
||||||
|
const [selectBoardPlaceholder, setSelectBoardPlaceholder] =
|
||||||
|
React.useState('');
|
||||||
|
|
||||||
|
const selectOption = React.useCallback(
|
||||||
|
(boardOpt: BoardOption) => {
|
||||||
|
onBoardSelect(
|
||||||
|
(boardOpt &&
|
||||||
|
availableBoards.find((board) => board.fqbn === boardOpt.value)) ||
|
||||||
|
null
|
||||||
|
);
|
||||||
|
},
|
||||||
|
[availableBoards, onBoardSelect]
|
||||||
|
);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
// if there is activity going on, skip updating the boards (avoid flickering)
|
||||||
|
if (busy) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let placeholderTxt = 'Select a board...';
|
||||||
|
let selBoard = -1;
|
||||||
|
const updatableBoards = availableBoards.filter(
|
||||||
|
(board) => board.port && board.fqbn && updatableFqbns.includes(board.fqbn)
|
||||||
|
);
|
||||||
|
const boardsList: BoardOption[] = updatableBoards.map((board, i) => {
|
||||||
|
if (board.selected) {
|
||||||
|
selBoard = i;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
label: `${board.name} at ${board.port?.address}`,
|
||||||
|
value: board.fqbn || '',
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
if (boardsList.length === 0) {
|
||||||
|
placeholderTxt = 'No supported board connected';
|
||||||
|
}
|
||||||
|
|
||||||
|
setSelectBoardPlaceholder(placeholderTxt);
|
||||||
|
setSelectOptions(boardsList);
|
||||||
|
|
||||||
|
if (selectedBoard) {
|
||||||
|
selBoard = boardsList
|
||||||
|
.map((boardOpt) => boardOpt.value)
|
||||||
|
.indexOf(selectedBoard.fqbn || '');
|
||||||
|
}
|
||||||
|
|
||||||
|
selectOption(boardsList[selBoard] || null);
|
||||||
|
}, [busy, availableBoards, selectOption, updatableFqbns, selectedBoard]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ArduinoSelect
|
||||||
|
id="board-select"
|
||||||
|
menuPosition="fixed"
|
||||||
|
isDisabled={selectOptions.length === 0 || busy}
|
||||||
|
placeholder={selectBoardPlaceholder}
|
||||||
|
options={selectOptions}
|
||||||
|
value={
|
||||||
|
(selectedBoard && {
|
||||||
|
value: selectedBoard.fqbn,
|
||||||
|
label: `${selectedBoard.name} at ${selectedBoard.port?.address}`,
|
||||||
|
}) ||
|
||||||
|
null
|
||||||
|
}
|
||||||
|
tabSelectsValue={false}
|
||||||
|
onChange={selectOption}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
export const arduinoCert = 'arduino.cc:443';
|
||||||
|
|
||||||
|
export function sanifyCertString(cert: string): string {
|
||||||
|
const regex = /^(?:.*:\/\/)*(\S+\.+[^:]*):*(\d*)*$/gm;
|
||||||
|
|
||||||
|
const m = regex.exec(cert);
|
||||||
|
|
||||||
|
if (!m) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const domain = m[1] || '';
|
||||||
|
const port = m[2] || '443';
|
||||||
|
|
||||||
|
if (domain.length === 0 || port.length === 0) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${domain}:${port}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function certificateList(certificates: string): string[] {
|
||||||
|
let certs = certificates
|
||||||
|
.split(',')
|
||||||
|
.map((cert) => sanifyCertString(cert.trim()))
|
||||||
|
.filter((cert) => {
|
||||||
|
// remove empty certificates
|
||||||
|
if (!cert || cert.length === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// add arduino certificate at the top of the list
|
||||||
|
certs = certs.filter((cert) => cert !== arduinoCert);
|
||||||
|
certs.unshift(arduinoCert);
|
||||||
|
return certs;
|
||||||
|
}
|
||||||
@@ -0,0 +1,171 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { inject, injectable } from 'inversify';
|
||||||
|
import { Widget } from '@phosphor/widgets';
|
||||||
|
import { Message } from '@phosphor/messaging';
|
||||||
|
import { clipboard } from 'electron';
|
||||||
|
import {
|
||||||
|
AbstractDialog,
|
||||||
|
ReactWidget,
|
||||||
|
DialogProps,
|
||||||
|
} from '@theia/core/lib/browser';
|
||||||
|
import { CreateApi } from '../create/create-api';
|
||||||
|
|
||||||
|
const RadioButton = (props: {
|
||||||
|
id: string;
|
||||||
|
changed: (evt: React.BaseSyntheticEvent) => void;
|
||||||
|
value: string;
|
||||||
|
isSelected: boolean;
|
||||||
|
isDisabled: boolean;
|
||||||
|
label: string;
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<p className="RadioButton">
|
||||||
|
<input
|
||||||
|
id={props.id}
|
||||||
|
onChange={props.changed}
|
||||||
|
value={props.value}
|
||||||
|
type="radio"
|
||||||
|
checked={props.isSelected}
|
||||||
|
disabled={props.isDisabled}
|
||||||
|
/>
|
||||||
|
<label htmlFor={props.id}>{props.label}</label>
|
||||||
|
</p>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ShareSketchComponent = ({
|
||||||
|
treeNode,
|
||||||
|
createApi,
|
||||||
|
domain = 'https://create.arduino.cc',
|
||||||
|
}: {
|
||||||
|
treeNode: any;
|
||||||
|
createApi: CreateApi;
|
||||||
|
domain?: string;
|
||||||
|
}): React.ReactElement => {
|
||||||
|
const [loading, setloading] = React.useState<boolean>(false);
|
||||||
|
|
||||||
|
const radioChangeHandler = async (event: React.BaseSyntheticEvent) => {
|
||||||
|
setloading(true);
|
||||||
|
const sketch = await createApi.editSketch({
|
||||||
|
id: treeNode.sketchId,
|
||||||
|
params: {
|
||||||
|
is_public: event.target.value === 'private' ? false : true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// setPublicVisibility(sketch.is_public);
|
||||||
|
treeNode.isPublic = sketch.is_public;
|
||||||
|
setloading(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const sketchLink = `${domain}/editor/_/${treeNode.sketchId}/preview`;
|
||||||
|
const embedLink = `<iframe src="${sketchLink}?embed" style="height:510px;width:100%;margin:10px 0" frameborder=0></iframe>`;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div id="widget-container arduino-sharesketch-dialog">
|
||||||
|
<p>Choose visibility of your Sketch:</p>
|
||||||
|
<RadioButton
|
||||||
|
changed={radioChangeHandler}
|
||||||
|
id="1"
|
||||||
|
isSelected={treeNode.isPublic === false}
|
||||||
|
label="Private. Only you can view the Sketch."
|
||||||
|
value="private"
|
||||||
|
isDisabled={loading}
|
||||||
|
/>
|
||||||
|
<RadioButton
|
||||||
|
changed={radioChangeHandler}
|
||||||
|
id="2"
|
||||||
|
isSelected={treeNode.isPublic === true}
|
||||||
|
label="Public. Anyone with the link can view the Sketch."
|
||||||
|
value="public"
|
||||||
|
isDisabled={loading}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{treeNode.isPublic && (
|
||||||
|
<div>
|
||||||
|
<p>Link:</p>
|
||||||
|
<div className="sketch-link">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
readOnly
|
||||||
|
value={sketchLink}
|
||||||
|
className="theia-input"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
onClick={() => clipboard.writeText(sketchLink)}
|
||||||
|
value="copy"
|
||||||
|
className="theia-button secondary"
|
||||||
|
>
|
||||||
|
Copy
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p>Embed:</p>
|
||||||
|
<div className="sketch-link-embed">
|
||||||
|
<textarea
|
||||||
|
readOnly
|
||||||
|
value={embedLink}
|
||||||
|
className="theia-input stretch"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class ShareSketchWidget extends ReactWidget {
|
||||||
|
constructor(private treeNode: any, private createApi: CreateApi) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render(): React.ReactNode {
|
||||||
|
return (
|
||||||
|
<ShareSketchComponent
|
||||||
|
treeNode={this.treeNode}
|
||||||
|
createApi={this.createApi}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class ShareSketchDialogProps extends DialogProps {
|
||||||
|
readonly node: any;
|
||||||
|
readonly createApi: CreateApi;
|
||||||
|
}
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class ShareSketchDialog extends AbstractDialog<void> {
|
||||||
|
protected widget: ShareSketchWidget;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
@inject(ShareSketchDialogProps)
|
||||||
|
protected readonly props: ShareSketchDialogProps
|
||||||
|
) {
|
||||||
|
super({ title: props.title });
|
||||||
|
this.contentNode.classList.add('arduino-share-sketch-dialog');
|
||||||
|
this.widget = new ShareSketchWidget(props.node, props.createApi);
|
||||||
|
}
|
||||||
|
|
||||||
|
get value(): void {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
protected onAfterAttach(msg: Message): void {
|
||||||
|
if (this.widget.isAttached) {
|
||||||
|
Widget.detach(this.widget);
|
||||||
|
}
|
||||||
|
Widget.attach(this.widget, this.contentNode);
|
||||||
|
super.onAfterAttach(msg);
|
||||||
|
this.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected onUpdateRequest(msg: Message): void {
|
||||||
|
super.onUpdateRequest(msg);
|
||||||
|
this.widget.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected onActivateRequest(msg: Message): void {
|
||||||
|
super.onActivateRequest(msg);
|
||||||
|
this.widget.activate();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
import { inject, injectable } from 'inversify';
|
||||||
|
import { Widget } from '@phosphor/widgets';
|
||||||
|
import { CancellationTokenSource } from '@theia/core/lib/common/cancellation';
|
||||||
|
import {
|
||||||
|
ConfirmDialog,
|
||||||
|
ConfirmDialogProps,
|
||||||
|
DialogError,
|
||||||
|
} from '@theia/core/lib/browser/dialogs';
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class DoNotAskAgainDialogProps extends ConfirmDialogProps {
|
||||||
|
readonly onAccept: () => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class DoNotAskAgainConfirmDialog extends ConfirmDialog {
|
||||||
|
protected readonly doNotAskAgainCheckbox: HTMLInputElement;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
@inject(DoNotAskAgainDialogProps)
|
||||||
|
protected readonly props: DoNotAskAgainDialogProps
|
||||||
|
) {
|
||||||
|
super(props);
|
||||||
|
this.controlPanel.removeChild(this.errorMessageNode);
|
||||||
|
const doNotAskAgainNode = document.createElement('div');
|
||||||
|
doNotAskAgainNode.setAttribute('style', 'flex: 2');
|
||||||
|
this.controlPanel.insertBefore(
|
||||||
|
doNotAskAgainNode,
|
||||||
|
this.controlPanel.firstChild
|
||||||
|
);
|
||||||
|
const doNotAskAgainLabel = document.createElement('label');
|
||||||
|
doNotAskAgainLabel.classList.add('flex-line');
|
||||||
|
doNotAskAgainNode.appendChild(doNotAskAgainLabel);
|
||||||
|
doNotAskAgainLabel.textContent = "Don't ask again";
|
||||||
|
this.doNotAskAgainCheckbox = document.createElement('input');
|
||||||
|
this.doNotAskAgainCheckbox.setAttribute('align-self', 'center');
|
||||||
|
doNotAskAgainLabel.appendChild(this.doNotAskAgainCheckbox);
|
||||||
|
this.doNotAskAgainCheckbox.type = 'checkbox';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async accept(): Promise<void> {
|
||||||
|
if (!this.resolve) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.acceptCancellationSource.cancel();
|
||||||
|
this.acceptCancellationSource = new CancellationTokenSource();
|
||||||
|
const token = this.acceptCancellationSource.token;
|
||||||
|
const value = this.value;
|
||||||
|
const error = await this.isValid(value, 'open');
|
||||||
|
if (token.isCancellationRequested) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!DialogError.getResult(error)) {
|
||||||
|
this.setErrorMessage(error);
|
||||||
|
} else {
|
||||||
|
if (this.doNotAskAgainCheckbox.checked) {
|
||||||
|
await this.props.onAccept();
|
||||||
|
}
|
||||||
|
this.resolve(value);
|
||||||
|
Widget.detach(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected setErrorMessage(error: DialogError): void {
|
||||||
|
if (this.acceptButton) {
|
||||||
|
this.acceptButton.disabled = !DialogError.getResult(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,204 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import {
|
||||||
|
ArduinoFirmwareUploader,
|
||||||
|
FirmwareInfo,
|
||||||
|
} from '../../../common/protocol/arduino-firmware-uploader';
|
||||||
|
import { AvailableBoard } from '../../boards/boards-service-provider';
|
||||||
|
import { ArduinoSelect } from '../../widgets/arduino-select';
|
||||||
|
import { SelectBoardComponent } from '../certificate-uploader/select-board-components';
|
||||||
|
|
||||||
|
type FirmwareOption = { value: string; label: string };
|
||||||
|
|
||||||
|
export const FirmwareUploaderComponent = ({
|
||||||
|
availableBoards,
|
||||||
|
firmwareUploader,
|
||||||
|
updatableFqbns,
|
||||||
|
flashFirmware,
|
||||||
|
isOpen,
|
||||||
|
}: {
|
||||||
|
availableBoards: AvailableBoard[];
|
||||||
|
firmwareUploader: ArduinoFirmwareUploader;
|
||||||
|
updatableFqbns: string[];
|
||||||
|
flashFirmware: (firmware: FirmwareInfo, port: string) => Promise<any>;
|
||||||
|
isOpen: any;
|
||||||
|
}): React.ReactElement => {
|
||||||
|
// boolean states for buttons
|
||||||
|
const [firmwaresFetching, setFirmwaresFetching] = React.useState(false);
|
||||||
|
|
||||||
|
const [installFeedback, setInstallFeedback] = React.useState<
|
||||||
|
'ok' | 'fail' | 'installing' | null
|
||||||
|
>(null);
|
||||||
|
|
||||||
|
const [selectedBoard, setSelectedBoard] =
|
||||||
|
React.useState<AvailableBoard | null>(null);
|
||||||
|
|
||||||
|
const [availableFirmwares, setAvailableFirmwares] = React.useState<
|
||||||
|
FirmwareInfo[]
|
||||||
|
>([]);
|
||||||
|
React.useEffect(() => {
|
||||||
|
setAvailableFirmwares([]);
|
||||||
|
}, [isOpen]);
|
||||||
|
const [selectedFirmware, setSelectedFirmware] =
|
||||||
|
React.useState<FirmwareOption | null>(null);
|
||||||
|
|
||||||
|
const [firmwareOptions, setFirmwareOptions] = React.useState<
|
||||||
|
FirmwareOption[]
|
||||||
|
>([]);
|
||||||
|
|
||||||
|
const fetchFirmwares = React.useCallback(async () => {
|
||||||
|
setInstallFeedback(null);
|
||||||
|
setFirmwaresFetching(true);
|
||||||
|
if (!selectedBoard) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// fetch the firmwares for the selected board
|
||||||
|
const firmwaresForFqbn = await firmwareUploader.availableFirmwares(
|
||||||
|
selectedBoard.fqbn || ''
|
||||||
|
);
|
||||||
|
setAvailableFirmwares(firmwaresForFqbn);
|
||||||
|
|
||||||
|
const firmwaresOpts = firmwaresForFqbn.map((f) => ({
|
||||||
|
label: f.firmware_version,
|
||||||
|
value: f.firmware_version,
|
||||||
|
}));
|
||||||
|
|
||||||
|
setFirmwareOptions(firmwaresOpts);
|
||||||
|
|
||||||
|
if (firmwaresForFqbn.length > 0) setSelectedFirmware(firmwaresOpts[0]);
|
||||||
|
setFirmwaresFetching(false);
|
||||||
|
}, [firmwareUploader, selectedBoard]);
|
||||||
|
|
||||||
|
const installFirmware = React.useCallback(async () => {
|
||||||
|
setInstallFeedback('installing');
|
||||||
|
|
||||||
|
const firmwareToFlash = availableFirmwares.find(
|
||||||
|
(firmware) => firmware.firmware_version === selectedFirmware?.value
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const installStatus =
|
||||||
|
!!firmwareToFlash &&
|
||||||
|
!!selectedBoard?.port &&
|
||||||
|
(await flashFirmware(firmwareToFlash, selectedBoard?.port.address));
|
||||||
|
|
||||||
|
setInstallFeedback((installStatus && 'ok') || 'fail');
|
||||||
|
} catch {
|
||||||
|
setInstallFeedback('fail');
|
||||||
|
}
|
||||||
|
}, [firmwareUploader, selectedBoard, selectedFirmware, availableFirmwares]);
|
||||||
|
|
||||||
|
const onBoardSelect = React.useCallback(
|
||||||
|
(board: AvailableBoard) => {
|
||||||
|
const newFqbn = (board && board.fqbn) || null;
|
||||||
|
const prevFqbn = (selectedBoard && selectedBoard.fqbn) || null;
|
||||||
|
|
||||||
|
if (newFqbn !== prevFqbn) {
|
||||||
|
setInstallFeedback(null);
|
||||||
|
setAvailableFirmwares([]);
|
||||||
|
setSelectedBoard(board);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[selectedBoard]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="dialogSection">
|
||||||
|
<div className="dialogRow">
|
||||||
|
<label htmlFor="board-select">Select board</label>
|
||||||
|
</div>
|
||||||
|
<div className="dialogRow">
|
||||||
|
<div className="fl1">
|
||||||
|
<SelectBoardComponent
|
||||||
|
availableBoards={availableBoards}
|
||||||
|
updatableFqbns={updatableFqbns}
|
||||||
|
onBoardSelect={onBoardSelect}
|
||||||
|
selectedBoard={selectedBoard}
|
||||||
|
busy={installFeedback === 'installing'}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="theia-button secondary"
|
||||||
|
disabled={
|
||||||
|
selectedBoard === null ||
|
||||||
|
firmwaresFetching ||
|
||||||
|
installFeedback === 'installing'
|
||||||
|
}
|
||||||
|
onClick={fetchFirmwares}
|
||||||
|
>
|
||||||
|
Check Updates
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{availableFirmwares.length > 0 && (
|
||||||
|
<>
|
||||||
|
<div className="dialogSection">
|
||||||
|
<div className="dialogRow">
|
||||||
|
<label htmlFor="firmware-select" className="fl1">
|
||||||
|
Select firmware version
|
||||||
|
</label>
|
||||||
|
<ArduinoSelect
|
||||||
|
id="firmware-select"
|
||||||
|
menuPosition="fixed"
|
||||||
|
isDisabled={
|
||||||
|
!selectedBoard ||
|
||||||
|
firmwaresFetching ||
|
||||||
|
installFeedback === 'installing'
|
||||||
|
}
|
||||||
|
options={firmwareOptions}
|
||||||
|
value={selectedFirmware}
|
||||||
|
tabSelectsValue={false}
|
||||||
|
onChange={(value) => {
|
||||||
|
if (value) {
|
||||||
|
setInstallFeedback(null);
|
||||||
|
setSelectedFirmware(value);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="theia-button primary"
|
||||||
|
disabled={
|
||||||
|
selectedFirmware === null ||
|
||||||
|
firmwaresFetching ||
|
||||||
|
installFeedback === 'installing'
|
||||||
|
}
|
||||||
|
onClick={installFirmware}
|
||||||
|
>
|
||||||
|
Install
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="dialogSection">
|
||||||
|
{installFeedback === null && (
|
||||||
|
<div className="dialogRow warn">
|
||||||
|
<i className="fa fa-exclamation status-icon" />
|
||||||
|
Installation will overwrite the Sketch on the board.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{installFeedback === 'installing' && (
|
||||||
|
<div className="dialogRow success">
|
||||||
|
<div className="spinner" />
|
||||||
|
Installing firmware.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{installFeedback === 'ok' && (
|
||||||
|
<div className="dialogRow success">
|
||||||
|
<i className="fa fa-info status-icon" />
|
||||||
|
Firmware succesfully installed.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{installFeedback === 'fail' && (
|
||||||
|
<div className="dialogRow warn">
|
||||||
|
<i className="fa fa-exclamation status-icon" />
|
||||||
|
Installation failed. Please try again.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,141 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { inject, injectable, postConstruct } from 'inversify';
|
||||||
|
import { AbstractDialog, DialogProps } from '@theia/core/lib/browser/dialogs';
|
||||||
|
import { Widget } from '@phosphor/widgets';
|
||||||
|
import { Message } from '@phosphor/messaging';
|
||||||
|
import { ReactWidget } from '@theia/core/lib/browser/widgets/react-widget';
|
||||||
|
import {
|
||||||
|
AvailableBoard,
|
||||||
|
BoardsServiceProvider,
|
||||||
|
} from '../../boards/boards-service-provider';
|
||||||
|
import {
|
||||||
|
ArduinoFirmwareUploader,
|
||||||
|
FirmwareInfo,
|
||||||
|
} from '../../../common/protocol/arduino-firmware-uploader';
|
||||||
|
import { FirmwareUploaderComponent } from './firmware-uploader-component';
|
||||||
|
import { UploadFirmware } from '../../contributions/upload-firmware';
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class UploadFirmwareDialogWidget extends ReactWidget {
|
||||||
|
@inject(BoardsServiceProvider)
|
||||||
|
protected readonly boardsServiceClient: BoardsServiceProvider;
|
||||||
|
|
||||||
|
@inject(ArduinoFirmwareUploader)
|
||||||
|
protected readonly arduinoFirmwareUploader: ArduinoFirmwareUploader;
|
||||||
|
|
||||||
|
protected updatableFqbns: string[] = [];
|
||||||
|
protected availableBoards: AvailableBoard[] = [];
|
||||||
|
protected isOpen = new Object();
|
||||||
|
|
||||||
|
public busyCallback = (busy: boolean) => {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@postConstruct()
|
||||||
|
protected init(): void {
|
||||||
|
this.arduinoFirmwareUploader.updatableBoards().then((fqbns) => {
|
||||||
|
this.updatableFqbns = fqbns;
|
||||||
|
this.update();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.boardsServiceClient.onAvailableBoardsChanged((availableBoards) => {
|
||||||
|
this.availableBoards = availableBoards;
|
||||||
|
this.update();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected flashFirmware(firmware: FirmwareInfo, port: string): Promise<any> {
|
||||||
|
this.busyCallback(true);
|
||||||
|
return this.arduinoFirmwareUploader
|
||||||
|
.flash(firmware, port)
|
||||||
|
.finally(() => this.busyCallback(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
onCloseRequest(msg: Message): void {
|
||||||
|
super.onCloseRequest(msg);
|
||||||
|
this.isOpen = new Object();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render(): React.ReactNode {
|
||||||
|
return (
|
||||||
|
<form>
|
||||||
|
<FirmwareUploaderComponent
|
||||||
|
availableBoards={this.availableBoards}
|
||||||
|
firmwareUploader={this.arduinoFirmwareUploader}
|
||||||
|
flashFirmware={this.flashFirmware.bind(this)}
|
||||||
|
updatableFqbns={this.updatableFqbns}
|
||||||
|
isOpen={this.isOpen}
|
||||||
|
/>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class UploadFirmwareDialogProps extends DialogProps {}
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class UploadFirmwareDialog extends AbstractDialog<void> {
|
||||||
|
@inject(UploadFirmwareDialogWidget)
|
||||||
|
protected readonly widget: UploadFirmwareDialogWidget;
|
||||||
|
|
||||||
|
private busy = false;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
@inject(UploadFirmwareDialogProps)
|
||||||
|
protected readonly props: UploadFirmwareDialogProps
|
||||||
|
) {
|
||||||
|
super({ title: UploadFirmware.Commands.OPEN.label || '' });
|
||||||
|
this.contentNode.classList.add('firmware-uploader-dialog');
|
||||||
|
this.acceptButton = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
get value(): void {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected onAfterAttach(msg: Message): void {
|
||||||
|
if (this.widget.isAttached) {
|
||||||
|
Widget.detach(this.widget);
|
||||||
|
}
|
||||||
|
Widget.attach(this.widget, this.contentNode);
|
||||||
|
this.widget.busyCallback = this.busyCallback.bind(this);
|
||||||
|
super.onAfterAttach(msg);
|
||||||
|
this.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected onUpdateRequest(msg: Message): void {
|
||||||
|
super.onUpdateRequest(msg);
|
||||||
|
this.widget.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected onActivateRequest(msg: Message): void {
|
||||||
|
super.onActivateRequest(msg);
|
||||||
|
this.widget.activate();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected handleEnter(event: KeyboardEvent): boolean | void {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(): void {
|
||||||
|
if (this.busy) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.widget.close();
|
||||||
|
super.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
busyCallback(busy: boolean): void {
|
||||||
|
this.busy = busy;
|
||||||
|
if (busy) {
|
||||||
|
this.closeCrossNode.classList.add('disabled');
|
||||||
|
} else {
|
||||||
|
this.closeCrossNode.classList.remove('disabled');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,33 +1,37 @@
|
|||||||
import { injectable, inject } from 'inversify';
|
import { injectable, inject } from 'inversify';
|
||||||
import { FrontendApplicationContribution, FrontendApplication } from '@theia/core/lib/browser';
|
import {
|
||||||
|
FrontendApplicationContribution,
|
||||||
|
FrontendApplication,
|
||||||
|
} from '@theia/core/lib/browser';
|
||||||
import { MainMenuManager } from '../common/main-menu-manager';
|
import { MainMenuManager } from '../common/main-menu-manager';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class EditorMode implements FrontendApplicationContribution {
|
export class EditorMode implements FrontendApplicationContribution {
|
||||||
|
@inject(MainMenuManager)
|
||||||
|
protected readonly mainMenuManager: MainMenuManager;
|
||||||
|
|
||||||
@inject(MainMenuManager)
|
protected app: FrontendApplication;
|
||||||
protected readonly mainMenuManager: MainMenuManager;
|
|
||||||
|
|
||||||
protected app: FrontendApplication;
|
onStart(app: FrontendApplication): void {
|
||||||
|
this.app = app;
|
||||||
|
}
|
||||||
|
|
||||||
onStart(app: FrontendApplication): void {
|
get compileForDebug(): boolean {
|
||||||
this.app = app;
|
const value = window.localStorage.getItem(EditorMode.COMPILE_FOR_DEBUG_KEY);
|
||||||
}
|
return value === 'true';
|
||||||
|
}
|
||||||
get compileForDebug(): boolean {
|
|
||||||
const value = window.localStorage.getItem(EditorMode.COMPILE_FOR_DEBUG_KEY);
|
|
||||||
return value === 'true';
|
|
||||||
}
|
|
||||||
|
|
||||||
async toggleCompileForDebug(): Promise<void> {
|
|
||||||
const oldState = this.compileForDebug;
|
|
||||||
const newState = !oldState;
|
|
||||||
window.localStorage.setItem(EditorMode.COMPILE_FOR_DEBUG_KEY, String(newState));
|
|
||||||
this.mainMenuManager.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
async toggleCompileForDebug(): Promise<void> {
|
||||||
|
const oldState = this.compileForDebug;
|
||||||
|
const newState = !oldState;
|
||||||
|
window.localStorage.setItem(
|
||||||
|
EditorMode.COMPILE_FOR_DEBUG_KEY,
|
||||||
|
String(newState)
|
||||||
|
);
|
||||||
|
this.mainMenuManager.update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace EditorMode {
|
export namespace EditorMode {
|
||||||
export const COMPILE_FOR_DEBUG_KEY = 'arduino-compile-for-debug';
|
export const COMPILE_FOR_DEBUG_KEY = 'arduino-compile-for-debug';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,36 +1,195 @@
|
|||||||
import { injectable, postConstruct, inject } from 'inversify';
|
import { injectable, postConstruct, inject } from 'inversify';
|
||||||
import { LibraryPackage, LibraryService } from '../../common/protocol/library-service';
|
import { Message } from '@phosphor/messaging';
|
||||||
|
import { addEventListener } from '@theia/core/lib/browser/widgets/widget';
|
||||||
|
import { AbstractDialog, DialogProps } from '@theia/core/lib/browser/dialogs';
|
||||||
|
import {
|
||||||
|
LibraryPackage,
|
||||||
|
LibraryService,
|
||||||
|
} from '../../common/protocol/library-service';
|
||||||
import { ListWidget } from '../widgets/component-list/list-widget';
|
import { ListWidget } from '../widgets/component-list/list-widget';
|
||||||
|
import { Installable } from '../../common/protocol';
|
||||||
import { ListItemRenderer } from '../widgets/component-list/list-item-renderer';
|
import { ListItemRenderer } from '../widgets/component-list/list-item-renderer';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class LibraryListWidget extends ListWidget<LibraryPackage> {
|
export class LibraryListWidget extends ListWidget<LibraryPackage> {
|
||||||
|
static WIDGET_ID = 'library-list-widget';
|
||||||
|
static WIDGET_LABEL = 'Library Manager';
|
||||||
|
|
||||||
static WIDGET_ID = 'library-list-widget';
|
constructor(
|
||||||
static WIDGET_LABEL = 'Library Manager';
|
@inject(LibraryService) protected service: LibraryService,
|
||||||
|
@inject(ListItemRenderer)
|
||||||
|
protected itemRenderer: ListItemRenderer<LibraryPackage>
|
||||||
|
) {
|
||||||
|
super({
|
||||||
|
id: LibraryListWidget.WIDGET_ID,
|
||||||
|
label: LibraryListWidget.WIDGET_LABEL,
|
||||||
|
iconClass: 'library-tab-icon',
|
||||||
|
searchable: service,
|
||||||
|
installable: service,
|
||||||
|
itemLabel: (item: LibraryPackage) => item.name,
|
||||||
|
itemDeprecated: (item: LibraryPackage) => item.deprecated,
|
||||||
|
itemRenderer,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
constructor(
|
@postConstruct()
|
||||||
@inject(LibraryService) protected service: LibraryService,
|
protected init(): void {
|
||||||
@inject(ListItemRenderer) protected itemRenderer: ListItemRenderer<LibraryPackage>) {
|
super.init();
|
||||||
|
this.toDispose.pushAll([
|
||||||
|
this.notificationCenter.onLibraryInstalled(() => this.refresh(undefined)),
|
||||||
|
this.notificationCenter.onLibraryUninstalled(() =>
|
||||||
|
this.refresh(undefined)
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
super({
|
protected async install({
|
||||||
id: LibraryListWidget.WIDGET_ID,
|
item,
|
||||||
label: LibraryListWidget.WIDGET_LABEL,
|
progressId,
|
||||||
iconClass: 'library-tab-icon',
|
version,
|
||||||
searchable: service,
|
}: {
|
||||||
installable: service,
|
item: LibraryPackage;
|
||||||
itemLabel: (item: LibraryPackage) => item.name,
|
progressId: string;
|
||||||
itemRenderer
|
version: Installable.Version;
|
||||||
});
|
}): Promise<void> {
|
||||||
|
const dependencies = await this.service.listDependencies({
|
||||||
|
item,
|
||||||
|
version,
|
||||||
|
filterSelf: true,
|
||||||
|
});
|
||||||
|
let installDependencies: boolean | undefined = undefined;
|
||||||
|
if (dependencies.length) {
|
||||||
|
const message = document.createElement('div');
|
||||||
|
message.innerHTML = `The library <b>${item.name}:${version}</b> needs ${
|
||||||
|
dependencies.length === 1
|
||||||
|
? 'another dependency'
|
||||||
|
: 'some other dependencies'
|
||||||
|
} currently not installed:`;
|
||||||
|
const listContainer = document.createElement('div');
|
||||||
|
listContainer.style.maxHeight = '300px';
|
||||||
|
listContainer.style.overflowY = 'auto';
|
||||||
|
const list = document.createElement('ul');
|
||||||
|
list.style.listStyleType = 'none';
|
||||||
|
for (const { name } of dependencies) {
|
||||||
|
const listItem = document.createElement('li');
|
||||||
|
listItem.textContent = ` - ${name}`;
|
||||||
|
listItem.style.fontWeight = 'bold';
|
||||||
|
list.appendChild(listItem);
|
||||||
|
}
|
||||||
|
listContainer.appendChild(list);
|
||||||
|
message.appendChild(listContainer);
|
||||||
|
const question = document.createElement('div');
|
||||||
|
question.textContent = `Would you like to install ${
|
||||||
|
dependencies.length === 1
|
||||||
|
? 'the missing dependency'
|
||||||
|
: 'all the missing dependencies'
|
||||||
|
}?`;
|
||||||
|
message.appendChild(question);
|
||||||
|
const result = await new MessageBoxDialog({
|
||||||
|
title: `Dependencies for library ${item.name}:${version}`,
|
||||||
|
message,
|
||||||
|
buttons: ['Install all', `Install ${item.name} only`, 'Cancel'],
|
||||||
|
maxWidth: 740, // Aligned with `settings-dialog.css`.
|
||||||
|
}).open();
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
const { response } = result;
|
||||||
|
if (response === 0) {
|
||||||
|
// All
|
||||||
|
installDependencies = true;
|
||||||
|
} else if (response === 1) {
|
||||||
|
// Current only
|
||||||
|
installDependencies = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// The lib does not have any dependencies.
|
||||||
|
installDependencies = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@postConstruct()
|
if (typeof installDependencies === 'boolean') {
|
||||||
protected init(): void {
|
await this.service.install({
|
||||||
super.init();
|
item,
|
||||||
this.toDispose.pushAll([
|
version,
|
||||||
this.notificationCenter.onLibraryInstalled(() => this.refresh(undefined)),
|
progressId,
|
||||||
this.notificationCenter.onLibraryUninstalled(() => this.refresh(undefined)),
|
installDependencies,
|
||||||
]);
|
});
|
||||||
|
this.messageService.info(
|
||||||
|
`Successfully installed library ${item.name}:${version}`,
|
||||||
|
{ timeout: 3000 }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async uninstall({
|
||||||
|
item,
|
||||||
|
progressId,
|
||||||
|
}: {
|
||||||
|
item: LibraryPackage;
|
||||||
|
progressId: string;
|
||||||
|
}): Promise<void> {
|
||||||
|
await super.uninstall({ item, progressId });
|
||||||
|
this.messageService.info(
|
||||||
|
`Successfully uninstalled library ${item.name}:${item.installedVersion}`,
|
||||||
|
{ timeout: 3000 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MessageBoxDialog extends AbstractDialog<MessageBoxDialog.Result> {
|
||||||
|
protected response: number;
|
||||||
|
|
||||||
|
constructor(protected readonly options: MessageBoxDialog.Options) {
|
||||||
|
super(options);
|
||||||
|
this.contentNode.appendChild(this.createMessageNode(this.options.message));
|
||||||
|
(options.buttons || ['OK']).forEach((text, index) => {
|
||||||
|
const button = this.createButton(text);
|
||||||
|
button.classList.add(index === 0 ? 'main' : 'secondary');
|
||||||
|
this.controlPanel.appendChild(button);
|
||||||
|
this.toDisposeOnDetach.push(
|
||||||
|
addEventListener(button, 'click', () => {
|
||||||
|
this.response = index;
|
||||||
|
this.accept();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected onCloseRequest(message: Message): void {
|
||||||
|
super.onCloseRequest(message);
|
||||||
|
this.accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
get value(): MessageBoxDialog.Result {
|
||||||
|
return { response: this.response };
|
||||||
|
}
|
||||||
|
|
||||||
|
protected createMessageNode(message: string | HTMLElement): HTMLElement {
|
||||||
|
if (typeof message === 'string') {
|
||||||
|
const messageNode = document.createElement('div');
|
||||||
|
messageNode.textContent = message;
|
||||||
|
return messageNode;
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected handleEnter(event: KeyboardEvent): boolean | void {
|
||||||
|
this.response = 0;
|
||||||
|
super.handleEnter(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export namespace MessageBoxDialog {
|
||||||
|
export interface Options extends DialogProps {
|
||||||
|
/**
|
||||||
|
* When empty, `['OK']` will be inferred.
|
||||||
|
*/
|
||||||
|
buttons?: string[];
|
||||||
|
message: string | HTMLElement;
|
||||||
|
}
|
||||||
|
export interface Result {
|
||||||
|
/**
|
||||||
|
* The index of `buttons` that was clicked.
|
||||||
|
*/
|
||||||
|
readonly response: number;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,33 +6,34 @@ import { LibraryListWidget } from './library-list-widget';
|
|||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class LibraryListWidgetFrontendContribution extends AbstractViewContribution<LibraryListWidget> implements FrontendApplicationContribution {
|
export class LibraryListWidgetFrontendContribution
|
||||||
|
extends AbstractViewContribution<LibraryListWidget>
|
||||||
|
implements FrontendApplicationContribution
|
||||||
|
{
|
||||||
|
constructor() {
|
||||||
|
super({
|
||||||
|
widgetId: LibraryListWidget.WIDGET_ID,
|
||||||
|
widgetName: LibraryListWidget.WIDGET_LABEL,
|
||||||
|
defaultWidgetOptions: {
|
||||||
|
area: 'left',
|
||||||
|
rank: 3,
|
||||||
|
},
|
||||||
|
toggleCommandId: `${LibraryListWidget.WIDGET_ID}:toggle`,
|
||||||
|
toggleKeybinding: 'CtrlCmd+Shift+I',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
constructor() {
|
async initializeLayout(): Promise<void> {
|
||||||
super({
|
this.openView();
|
||||||
widgetId: LibraryListWidget.WIDGET_ID,
|
}
|
||||||
widgetName: LibraryListWidget.WIDGET_LABEL,
|
|
||||||
defaultWidgetOptions: {
|
registerMenus(menus: MenuModelRegistry): void {
|
||||||
area: 'left',
|
if (this.toggleCommand) {
|
||||||
rank: 700
|
menus.registerMenuAction(ArduinoMenus.TOOLS__MAIN_GROUP, {
|
||||||
},
|
commandId: this.toggleCommand.id,
|
||||||
toggleCommandId: `${LibraryListWidget.WIDGET_ID}:toggle`,
|
label: 'Manage Libraries...',
|
||||||
toggleKeybinding: 'CtrlCmd+Shift+I'
|
order: '3',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
async initializeLayout(): Promise<void> {
|
|
||||||
this.openView();
|
|
||||||
}
|
|
||||||
|
|
||||||
registerMenus(menus: MenuModelRegistry): void {
|
|
||||||
if (this.toggleCommand) {
|
|
||||||
menus.registerMenuAction(ArduinoMenus.TOOLS__MAIN_GROUP, {
|
|
||||||
commandId: this.toggleCommand.id,
|
|
||||||
label: 'Manage Libraries...',
|
|
||||||
order: '3'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,160 @@
|
|||||||
|
import { inject, injectable } from 'inversify';
|
||||||
|
import { URI as Uri } from 'vscode-uri';
|
||||||
|
import URI from '@theia/core/lib/common/uri';
|
||||||
|
import { Deferred } from '@theia/core/lib/common/promise-util';
|
||||||
|
import {
|
||||||
|
FileSystemProvider,
|
||||||
|
FileSystemProviderError,
|
||||||
|
FileSystemProviderErrorCode,
|
||||||
|
} from '@theia/filesystem/lib/common/files';
|
||||||
|
import { DisposableCollection } from '@theia/core/lib/common/disposable';
|
||||||
|
import { DelegatingFileSystemProvider } from '@theia/filesystem/lib/common/delegating-file-system-provider';
|
||||||
|
import {
|
||||||
|
FileService,
|
||||||
|
FileServiceContribution,
|
||||||
|
} from '@theia/filesystem/lib/browser/file-service';
|
||||||
|
import { AuthenticationClientService } from '../auth/authentication-client-service';
|
||||||
|
import { AuthenticationSession } from '../../common/protocol/authentication-service';
|
||||||
|
import { ConfigService } from '../../common/protocol';
|
||||||
|
|
||||||
|
export namespace LocalCacheUri {
|
||||||
|
export const scheme = 'arduino-local-cache';
|
||||||
|
export const root = new URI(
|
||||||
|
Uri.parse('/').with({ scheme, authority: 'create' })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class LocalCacheFsProvider
|
||||||
|
implements FileServiceContribution, DelegatingFileSystemProvider.URIConverter
|
||||||
|
{
|
||||||
|
@inject(ConfigService)
|
||||||
|
protected readonly configService: ConfigService;
|
||||||
|
|
||||||
|
@inject(AuthenticationClientService)
|
||||||
|
protected readonly authenticationService: AuthenticationClientService;
|
||||||
|
|
||||||
|
// TODO: do we need this? Cannot we `await` on the `init` call from `registerFileSystemProviders`?
|
||||||
|
readonly ready = new Deferred<void>();
|
||||||
|
|
||||||
|
private _localCacheRoot: URI;
|
||||||
|
|
||||||
|
registerFileSystemProviders(fileService: FileService): void {
|
||||||
|
fileService.onWillActivateFileSystemProvider(async (event) => {
|
||||||
|
if (event.scheme === LocalCacheUri.scheme) {
|
||||||
|
event.waitUntil(
|
||||||
|
(async () => {
|
||||||
|
this.init(fileService);
|
||||||
|
const provider = await this.createProvider(fileService);
|
||||||
|
fileService.registerProvider(LocalCacheUri.scheme, provider);
|
||||||
|
})()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
to(resource: URI): URI | undefined {
|
||||||
|
const relativePath = LocalCacheUri.root.relative(resource);
|
||||||
|
if (relativePath) {
|
||||||
|
return this.currentUserUri.resolve(relativePath).normalizePath();
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
from(resource: URI): URI | undefined {
|
||||||
|
const relativePath = this.currentUserUri.relative(resource);
|
||||||
|
if (relativePath) {
|
||||||
|
return LocalCacheUri.root.resolve(relativePath);
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async createProvider(
|
||||||
|
fileService: FileService
|
||||||
|
): Promise<FileSystemProvider> {
|
||||||
|
const delegate = await fileService.activateProvider('file');
|
||||||
|
await this.ready.promise;
|
||||||
|
return new DelegatingFileSystemProvider(
|
||||||
|
delegate,
|
||||||
|
{
|
||||||
|
uriConverter: this,
|
||||||
|
},
|
||||||
|
new DisposableCollection(
|
||||||
|
delegate.watch(this.localCacheRoot, {
|
||||||
|
excludes: [],
|
||||||
|
recursive: true,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async init(fileService: FileService): Promise<void> {
|
||||||
|
const config = await this.configService.getConfiguration();
|
||||||
|
this._localCacheRoot = new URI(config.dataDirUri);
|
||||||
|
for (const segment of ['RemoteSketchbook', 'ArduinoCloud']) {
|
||||||
|
this._localCacheRoot = this._localCacheRoot.resolve(segment);
|
||||||
|
await fileService.createFolder(this._localCacheRoot);
|
||||||
|
}
|
||||||
|
this.session(fileService).then(() => this.ready.resolve());
|
||||||
|
this.authenticationService.onSessionDidChange(async (session) => {
|
||||||
|
if (session) {
|
||||||
|
await this.ensureExists(session, fileService);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public get currentUserUri(): URI {
|
||||||
|
const { session } = this.authenticationService;
|
||||||
|
if (!session) {
|
||||||
|
throw new FileSystemProviderError(
|
||||||
|
'Not logged in.',
|
||||||
|
FileSystemProviderErrorCode.NoPermissions
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return this.toUri(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
private get localCacheRoot(): URI {
|
||||||
|
return this._localCacheRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async session(
|
||||||
|
fileService: FileService
|
||||||
|
): Promise<AuthenticationSession> {
|
||||||
|
return new Promise<AuthenticationSession>(async (resolve) => {
|
||||||
|
const { session } = this.authenticationService;
|
||||||
|
if (session) {
|
||||||
|
await this.ensureExists(session, fileService);
|
||||||
|
resolve(session);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const toDispose = new DisposableCollection();
|
||||||
|
toDispose.push(
|
||||||
|
this.authenticationService.onSessionDidChange(async (session) => {
|
||||||
|
if (session) {
|
||||||
|
await this.ensureExists(session, fileService);
|
||||||
|
toDispose.dispose();
|
||||||
|
resolve(session);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private async ensureExists(
|
||||||
|
session: AuthenticationSession,
|
||||||
|
fileService: FileService
|
||||||
|
): Promise<URI> {
|
||||||
|
const uri = this.toUri(session);
|
||||||
|
const exists = await fileService.exists(uri);
|
||||||
|
if (!exists) {
|
||||||
|
await fileService.createFolder(uri);
|
||||||
|
}
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
private toUri(session: AuthenticationSession): URI {
|
||||||
|
// Hack: instead of getting the UUID only, we get `auth0|UUID` after the authentication. `|` cannot be part of filesystem path or filename.
|
||||||
|
return this._localCacheRoot.resolve(session.id.split('|')[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,122 +1,208 @@
|
|||||||
import { isOSX } from '@theia/core/lib/common/os';
|
import { isOSX } from '@theia/core/lib/common/os';
|
||||||
import { CommonMenus } from '@theia/core/lib/browser/common-frontend-contribution';
|
import { CommonMenus } from '@theia/core/lib/browser/common-frontend-contribution';
|
||||||
import { MAIN_MENU_BAR, MenuModelRegistry, MenuNode, MenuPath, SubMenuOptions } from '@theia/core/lib/common/menu';
|
import {
|
||||||
|
MAIN_MENU_BAR,
|
||||||
|
MenuModelRegistry,
|
||||||
|
MenuNode,
|
||||||
|
MenuPath,
|
||||||
|
SubMenuOptions,
|
||||||
|
} from '@theia/core/lib/common/menu';
|
||||||
|
|
||||||
export namespace ArduinoMenus {
|
export namespace ArduinoMenus {
|
||||||
|
// Main menu
|
||||||
|
// -- File
|
||||||
|
export const FILE__SKETCH_GROUP = [...CommonMenus.FILE, '0_sketch'];
|
||||||
|
export const FILE__PRINT_GROUP = [...CommonMenus.FILE, '1_print'];
|
||||||
|
// XXX: on macOS, the "Preferences" and "Advanced" group is not under `File`
|
||||||
|
// The empty path ensures no top level menu is created for the preferences, even if they contains sub menus
|
||||||
|
export const FILE__PREFERENCES_GROUP = [
|
||||||
|
...(isOSX ? [''] : CommonMenus.FILE),
|
||||||
|
'2_preferences',
|
||||||
|
];
|
||||||
|
export const FILE__ADVANCED_GROUP = [
|
||||||
|
...(isOSX ? [''] : CommonMenus.FILE),
|
||||||
|
'3_advanced',
|
||||||
|
];
|
||||||
|
export const FILE__ADVANCED_SUBMENU = [
|
||||||
|
...FILE__ADVANCED_GROUP,
|
||||||
|
'0_advanced_sub',
|
||||||
|
];
|
||||||
|
|
||||||
// Main menu
|
export const FILE__QUIT_GROUP = [...CommonMenus.FILE, '3_quit'];
|
||||||
// -- File
|
|
||||||
export const FILE__SKETCH_GROUP = [...CommonMenus.FILE, '0_sketch'];
|
|
||||||
export const FILE__PRINT_GROUP = [...CommonMenus.FILE, '1_print'];
|
|
||||||
// XXX: on macOS, the settings group is not under `File`
|
|
||||||
export const FILE__SETTINGS_GROUP = [...(isOSX ? MAIN_MENU_BAR : CommonMenus.FILE), '2_settings'];
|
|
||||||
export const FILE__QUIT_GROUP = [...CommonMenus.FILE, '3_quit'];
|
|
||||||
|
|
||||||
// -- File / Open Recent
|
// -- File / Open Recent
|
||||||
export const FILE__OPEN_RECENT_SUBMENU = [...FILE__SKETCH_GROUP, '0_open_recent'];
|
export const FILE__OPEN_RECENT_SUBMENU = [
|
||||||
|
...FILE__SKETCH_GROUP,
|
||||||
|
'0_open_recent',
|
||||||
|
];
|
||||||
|
|
||||||
// -- File / Sketchbook
|
// -- File / Sketchbook
|
||||||
export const FILE__SKETCHBOOK_SUBMENU = [...FILE__SKETCH_GROUP, '1_sketchbook'];
|
export const FILE__SKETCHBOOK_SUBMENU = [
|
||||||
|
...FILE__SKETCH_GROUP,
|
||||||
|
'1_sketchbook',
|
||||||
|
];
|
||||||
|
|
||||||
// -- File / Examples
|
// -- File / Examples
|
||||||
export const FILE__EXAMPLES_SUBMENU = [...FILE__SKETCH_GROUP, '2_examples'];
|
export const FILE__EXAMPLES_SUBMENU = [...FILE__SKETCH_GROUP, '2_examples'];
|
||||||
export const EXAMPLES__BUILT_IN_GROUP = [...FILE__EXAMPLES_SUBMENU, '0_built_ins'];
|
export const EXAMPLES__BUILT_IN_GROUP = [
|
||||||
export const EXAMPLES__ANY_BOARD_GROUP = [...FILE__EXAMPLES_SUBMENU, '1_any_board'];
|
...FILE__EXAMPLES_SUBMENU,
|
||||||
export const EXAMPLES__CURRENT_BOARD_GROUP = [...FILE__EXAMPLES_SUBMENU, '2_current_board'];
|
'0_built_ins',
|
||||||
export const EXAMPLES__USER_LIBS_GROUP = [...FILE__EXAMPLES_SUBMENU, '3_user_libs'];
|
];
|
||||||
|
export const EXAMPLES__ANY_BOARD_GROUP = [
|
||||||
|
...FILE__EXAMPLES_SUBMENU,
|
||||||
|
'1_any_board',
|
||||||
|
];
|
||||||
|
export const EXAMPLES__CURRENT_BOARD_GROUP = [
|
||||||
|
...FILE__EXAMPLES_SUBMENU,
|
||||||
|
'2_current_board',
|
||||||
|
];
|
||||||
|
export const EXAMPLES__USER_LIBS_GROUP = [
|
||||||
|
...FILE__EXAMPLES_SUBMENU,
|
||||||
|
'3_user_libs',
|
||||||
|
];
|
||||||
|
|
||||||
// -- Edit
|
// -- Edit
|
||||||
// `Copy`, `Copy to Forum`, `Paste`, etc.
|
// `Copy`, `Copy to Forum`, `Paste`, etc.
|
||||||
// Note: `1_undo` is the first group from Theia, we start with `2`
|
// Note: `1_undo` is the first group from Theia, we start with `2`
|
||||||
export const EDIT__TEXT_CONTROL_GROUP = [...CommonMenus.EDIT, '2_text_control'];
|
export const EDIT__TEXT_CONTROL_GROUP = [
|
||||||
// `Comment/Uncomment`, etc.
|
...CommonMenus.EDIT,
|
||||||
export const EDIT__CODE_CONTROL_GROUP = [...CommonMenus.EDIT, '3_code_control'];
|
'2_text_control',
|
||||||
export const EDIT__FONT_CONTROL_GROUP = [...CommonMenus.EDIT, '4_font_control'];
|
];
|
||||||
export const EDIT__FIND_GROUP = [...CommonMenus.EDIT, '5_find'];
|
// `Comment/Uncomment`, etc.
|
||||||
|
export const EDIT__CODE_CONTROL_GROUP = [
|
||||||
|
...CommonMenus.EDIT,
|
||||||
|
'3_code_control',
|
||||||
|
];
|
||||||
|
export const EDIT__FONT_CONTROL_GROUP = [
|
||||||
|
...CommonMenus.EDIT,
|
||||||
|
'4_font_control',
|
||||||
|
];
|
||||||
|
export const EDIT__FIND_GROUP = [...CommonMenus.EDIT, '5_find'];
|
||||||
|
|
||||||
// -- Sketch
|
// -- Sketch
|
||||||
export const SKETCH = [...MAIN_MENU_BAR, '3_sketch'];
|
export const SKETCH = [...MAIN_MENU_BAR, '3_sketch'];
|
||||||
export const SKETCH__MAIN_GROUP = [...SKETCH, '0_main'];
|
export const SKETCH__MAIN_GROUP = [...SKETCH, '0_main'];
|
||||||
export const SKETCH__UTILS_GROUP = [...SKETCH, '1_utils'];
|
export const SKETCH__UTILS_GROUP = [...SKETCH, '1_utils'];
|
||||||
|
|
||||||
// -- Tools
|
// -- Tools
|
||||||
export const TOOLS = [...MAIN_MENU_BAR, '4_tools'];
|
export const TOOLS = [...MAIN_MENU_BAR, '4_tools'];
|
||||||
// `Auto Format`, `Library Manager...`, `Boards Manager...`
|
// `Auto Format`, `Archive Sketch`, `Manage Libraries...`, `Serial Monitor`
|
||||||
export const TOOLS__MAIN_GROUP = [...TOOLS, '0_main'];
|
export const TOOLS__MAIN_GROUP = [...TOOLS, '0_main'];
|
||||||
// `Board`, `Port`, and `Get Board Info`.
|
// `WiFi101 / WiFiNINA Firmware Updater`
|
||||||
export const TOOLS__BOARD_SELECTION_GROUP = [...TOOLS, '2_board_selection'];
|
export const TOOLS__FIRMWARE_UPLOADER_GROUP = [
|
||||||
// Core settings, such as `Processor` and `Programmers` for the board and `Burn Bootloader`
|
...TOOLS,
|
||||||
export const TOOLS__BOARD_SETTINGS_GROUP = [...TOOLS, '3_board_settings'];
|
'1_firmware_uploader',
|
||||||
|
];
|
||||||
|
// `Board`, `Port`, and `Get Board Info`.
|
||||||
|
export const TOOLS__BOARD_SELECTION_GROUP = [...TOOLS, '2_board_selection'];
|
||||||
|
// Core settings, such as `Processor` and `Programmers` for the board and `Burn Bootloader`
|
||||||
|
export const TOOLS__BOARD_SETTINGS_GROUP = [...TOOLS, '3_board_settings'];
|
||||||
|
|
||||||
// -- Help
|
// -- Help
|
||||||
// `Getting Started`, `Environment`, `Troubleshooting`, etc.
|
// `Getting Started`, `Environment`, `Troubleshooting`, etc.
|
||||||
export const HELP__MAIN_GROUP = [...CommonMenus.HELP, '0_main'];
|
export const HELP__MAIN_GROUP = [...CommonMenus.HELP, '0_main'];
|
||||||
// `Find in reference`, `FAQ`, etc.
|
// `Find in reference`, `FAQ`, etc.
|
||||||
export const HELP__FIND_GROUP = [...CommonMenus.HELP, '1_find'];
|
export const HELP__FIND_GROUP = [...CommonMenus.HELP, '1_find'];
|
||||||
// `Advanced Mode`.
|
// `Advanced Mode`.
|
||||||
// XXX: this will be removed.
|
// XXX: this will be removed.
|
||||||
export const HELP__CONTROL_GROUP = [...CommonMenus.HELP, '2_control'];
|
export const HELP__CONTROL_GROUP = [...CommonMenus.HELP, '2_control'];
|
||||||
// `About` group
|
// `About` group
|
||||||
// XXX: on macOS, the about group is not under `Help`
|
// XXX: on macOS, the about group is not under `Help`
|
||||||
export const HELP__ABOUT_GROUP = [...(isOSX ? MAIN_MENU_BAR : CommonMenus.HELP), '999_about'];
|
export const HELP__ABOUT_GROUP = [
|
||||||
|
...(isOSX ? MAIN_MENU_BAR : CommonMenus.HELP),
|
||||||
|
'999_about',
|
||||||
|
];
|
||||||
|
|
||||||
// ------------
|
// ------------
|
||||||
|
|
||||||
// Context menus
|
// Context menus
|
||||||
// -- Open
|
// -- Open
|
||||||
export const OPEN_SKETCH__CONTEXT = ['arduino-open-sketch--context'];
|
export const OPEN_SKETCH__CONTEXT = ['arduino-open-sketch--context'];
|
||||||
export const OPEN_SKETCH__CONTEXT__OPEN_GROUP = [...OPEN_SKETCH__CONTEXT, '0_open'];
|
export const OPEN_SKETCH__CONTEXT__OPEN_GROUP = [
|
||||||
export const OPEN_SKETCH__CONTEXT__RECENT_GROUP = [...OPEN_SKETCH__CONTEXT, '1_recent'];
|
...OPEN_SKETCH__CONTEXT,
|
||||||
export const OPEN_SKETCH__CONTEXT__EXAMPLES_GROUP = [...OPEN_SKETCH__CONTEXT, '2_examples'];
|
'0_open',
|
||||||
|
];
|
||||||
|
export const OPEN_SKETCH__CONTEXT__RECENT_GROUP = [
|
||||||
|
...OPEN_SKETCH__CONTEXT,
|
||||||
|
'1_recent',
|
||||||
|
];
|
||||||
|
export const OPEN_SKETCH__CONTEXT__EXAMPLES_GROUP = [
|
||||||
|
...OPEN_SKETCH__CONTEXT,
|
||||||
|
'2_examples',
|
||||||
|
];
|
||||||
|
|
||||||
// -- Sketch control
|
// -- Sketch control
|
||||||
export const SKETCH_CONTROL__CONTEXT = ['arduino-sketch-control--context'];
|
export const SKETCH_CONTROL__CONTEXT = ['arduino-sketch-control--context'];
|
||||||
// `New Tab`, `Rename`, `Delete`
|
// `New Tab`, `Rename`, `Delete`
|
||||||
export const SKETCH_CONTROL__CONTEXT__MAIN_GROUP = [...SKETCH_CONTROL__CONTEXT, '0_main'];
|
export const SKETCH_CONTROL__CONTEXT__MAIN_GROUP = [
|
||||||
// `Previous Tab`, `Next Tab`
|
...SKETCH_CONTROL__CONTEXT,
|
||||||
export const SKETCH_CONTROL__CONTEXT__NAVIGATION_GROUP = [...SKETCH_CONTROL__CONTEXT, '1_navigation'];
|
'0_main',
|
||||||
// Sketch files opened in editors
|
];
|
||||||
export const SKETCH_CONTROL__CONTEXT__RESOURCES_GROUP = [...SKETCH_CONTROL__CONTEXT, '2_resources'];
|
// `Previous Tab`, `Next Tab`
|
||||||
|
export const SKETCH_CONTROL__CONTEXT__NAVIGATION_GROUP = [
|
||||||
|
...SKETCH_CONTROL__CONTEXT,
|
||||||
|
'1_navigation',
|
||||||
|
];
|
||||||
|
// Sketch files opened in editors
|
||||||
|
export const SKETCH_CONTROL__CONTEXT__RESOURCES_GROUP = [
|
||||||
|
...SKETCH_CONTROL__CONTEXT,
|
||||||
|
'2_resources',
|
||||||
|
];
|
||||||
|
|
||||||
|
// -- ROOT SSL CERTIFICATES
|
||||||
|
export const ROOT_CERTIFICATES__CONTEXT = [
|
||||||
|
'arduino-root-certificates--context',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a hack. It removes a submenu with all its children if any.
|
* This is a hack. It removes a submenu with all its children if any.
|
||||||
* Theia cannot dispose submenu entries with a proper API: https://github.com/eclipse-theia/theia/issues/7299
|
* Theia cannot dispose submenu entries with a proper API: https://github.com/eclipse-theia/theia/issues/7299
|
||||||
*/
|
*/
|
||||||
export function unregisterSubmenu(menuPath: string[], menuRegistry: MenuModelRegistry): void {
|
export function unregisterSubmenu(
|
||||||
if (menuPath.length < 2) {
|
menuPath: string[],
|
||||||
throw new Error(`Expected at least two item as a menu-path. Got ${JSON.stringify(menuPath)} instead.`);
|
menuRegistry: MenuModelRegistry
|
||||||
}
|
): void {
|
||||||
const toRemove = menuPath[menuPath.length - 1];
|
if (menuPath.length < 2) {
|
||||||
const parentMenuPath = menuPath.slice(0, menuPath.length - 1);
|
throw new Error(
|
||||||
// This is unsafe. Calling `getMenu` with a non-existing menu-path will result in a new menu creation.
|
`Expected at least two item as a menu-path. Got ${JSON.stringify(
|
||||||
// https://github.com/eclipse-theia/theia/issues/7300
|
menuPath
|
||||||
const parent = menuRegistry.getMenu(parentMenuPath);
|
)} instead.`
|
||||||
const index = parent.children.findIndex(({ id }) => id === toRemove);
|
);
|
||||||
if (index === -1) {
|
}
|
||||||
throw new Error(`Could not find menu with menu-path: ${JSON.stringify(menuPath)}.`);
|
const toRemove = menuPath[menuPath.length - 1];
|
||||||
}
|
const parentMenuPath = menuPath.slice(0, menuPath.length - 1);
|
||||||
(parent.children as Array<MenuNode>).splice(index, 1);
|
// This is unsafe. Calling `getMenu` with a non-existing menu-path will result in a new menu creation.
|
||||||
|
// https://github.com/eclipse-theia/theia/issues/7300
|
||||||
|
const parent = menuRegistry.getMenu(parentMenuPath);
|
||||||
|
const index = parent.children.findIndex(({ id }) => id === toRemove);
|
||||||
|
if (index === -1) {
|
||||||
|
throw new Error(
|
||||||
|
`Could not find menu with menu-path: ${JSON.stringify(menuPath)}.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
(parent.children as Array<MenuNode>).splice(index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Special menu node that is not backed by any commands and is always disabled.
|
* Special menu node that is not backed by any commands and is always disabled.
|
||||||
*/
|
*/
|
||||||
export class PlaceholderMenuNode implements MenuNode {
|
export class PlaceholderMenuNode implements MenuNode {
|
||||||
|
constructor(
|
||||||
|
protected readonly menuPath: MenuPath,
|
||||||
|
readonly label: string,
|
||||||
|
protected options: SubMenuOptions = { order: '0' }
|
||||||
|
) {}
|
||||||
|
|
||||||
constructor(protected readonly menuPath: MenuPath, readonly label: string, protected options: SubMenuOptions = { order: '0' }) { }
|
get icon(): string | undefined {
|
||||||
|
return this.options?.iconClass;
|
||||||
|
}
|
||||||
|
|
||||||
get icon(): string | undefined {
|
get sortString(): string {
|
||||||
return this.options?.iconClass;
|
return this.options?.order || this.label;
|
||||||
}
|
}
|
||||||
|
|
||||||
get sortString(): string {
|
|
||||||
return this.options?.order || this.label;
|
|
||||||
}
|
|
||||||
|
|
||||||
get id(): string {
|
|
||||||
return [...this.menuPath, 'placeholder'].join('-');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
get id(): string {
|
||||||
|
return [...this.menuPath, 'placeholder'].join('-');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,19 @@ import { deepClone } from '@theia/core/lib/common/objects';
|
|||||||
import { Emitter, Event } from '@theia/core/lib/common/event';
|
import { Emitter, Event } from '@theia/core/lib/common/event';
|
||||||
import { MessageService } from '@theia/core/lib/common/message-service';
|
import { MessageService } from '@theia/core/lib/common/message-service';
|
||||||
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
|
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
|
||||||
import { MonitorService, MonitorConfig, MonitorError, Status, MonitorReadEvent } from '../../common/protocol/monitor-service';
|
import {
|
||||||
|
MonitorService,
|
||||||
|
MonitorConfig,
|
||||||
|
MonitorError,
|
||||||
|
Status,
|
||||||
|
} from '../../common/protocol/monitor-service';
|
||||||
import { BoardsServiceProvider } from '../boards/boards-service-provider';
|
import { BoardsServiceProvider } from '../boards/boards-service-provider';
|
||||||
import { Port, Board, BoardsService, AttachedBoardsChangeEvent } from '../../common/protocol/boards-service';
|
import {
|
||||||
|
Port,
|
||||||
|
Board,
|
||||||
|
BoardsService,
|
||||||
|
AttachedBoardsChangeEvent,
|
||||||
|
} from '../../common/protocol/boards-service';
|
||||||
import { MonitorServiceClientImpl } from './monitor-service-client-impl';
|
import { MonitorServiceClientImpl } from './monitor-service-client-impl';
|
||||||
import { BoardsConfig } from '../boards/boards-config';
|
import { BoardsConfig } from '../boards/boards-config';
|
||||||
import { MonitorModel } from './monitor-model';
|
import { MonitorModel } from './monitor-model';
|
||||||
@@ -13,262 +23,332 @@ import { NotificationCenter } from '../notification-center';
|
|||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class MonitorConnection {
|
export class MonitorConnection {
|
||||||
|
@inject(MonitorModel)
|
||||||
|
protected readonly monitorModel: MonitorModel;
|
||||||
|
|
||||||
@inject(MonitorModel)
|
@inject(MonitorService)
|
||||||
protected readonly monitorModel: MonitorModel;
|
protected readonly monitorService: MonitorService;
|
||||||
|
|
||||||
@inject(MonitorService)
|
@inject(MonitorServiceClientImpl)
|
||||||
protected readonly monitorService: MonitorService;
|
protected readonly monitorServiceClient: MonitorServiceClientImpl;
|
||||||
|
|
||||||
@inject(MonitorServiceClientImpl)
|
@inject(BoardsService)
|
||||||
protected readonly monitorServiceClient: MonitorServiceClientImpl;
|
protected readonly boardsService: BoardsService;
|
||||||
|
|
||||||
@inject(BoardsService)
|
@inject(BoardsServiceProvider)
|
||||||
protected readonly boardsService: BoardsService;
|
protected readonly boardsServiceProvider: BoardsServiceProvider;
|
||||||
|
|
||||||
@inject(BoardsServiceProvider)
|
@inject(NotificationCenter)
|
||||||
protected readonly boardsServiceProvider: BoardsServiceProvider;
|
protected readonly notificationCenter: NotificationCenter;
|
||||||
|
|
||||||
@inject(NotificationCenter)
|
@inject(MessageService)
|
||||||
protected readonly notificationCenter: NotificationCenter;
|
protected messageService: MessageService;
|
||||||
|
|
||||||
@inject(MessageService)
|
@inject(FrontendApplicationStateService)
|
||||||
protected messageService: MessageService;
|
protected readonly applicationState: FrontendApplicationStateService;
|
||||||
|
|
||||||
@inject(FrontendApplicationStateService)
|
protected state: MonitorConnection.State | undefined;
|
||||||
protected readonly applicationState: FrontendApplicationStateService;
|
/**
|
||||||
|
* Note: The idea is to toggle this property from the UI (`Monitor` view)
|
||||||
|
* and the boards config and the boards attachment/detachment logic can be at on place, here.
|
||||||
|
*/
|
||||||
|
protected _autoConnect = false;
|
||||||
|
protected readonly onConnectionChangedEmitter = new Emitter<
|
||||||
|
MonitorConnection.State | undefined
|
||||||
|
>();
|
||||||
|
/**
|
||||||
|
* This emitter forwards all read events **iff** the connection is established.
|
||||||
|
*/
|
||||||
|
protected readonly onReadEmitter = new Emitter<{ message: string }>();
|
||||||
|
|
||||||
protected state: MonitorConnection.State | undefined;
|
/**
|
||||||
/**
|
* Array for storing previous monitor errors received from the server, and based on the number of elements in this array,
|
||||||
* Note: The idea is to toggle this property from the UI (`Monitor` view)
|
* we adjust the reconnection delay.
|
||||||
* and the boards config and the boards attachment/detachment logic can be at on place, here.
|
* Super naive way: we wait `array.length * 1000` ms. Once we hit 10 errors, we do not try to reconnect and clean the array.
|
||||||
*/
|
*/
|
||||||
protected _autoConnect: boolean = false;
|
protected monitorErrors: MonitorError[] = [];
|
||||||
protected readonly onConnectionChangedEmitter = new Emitter<MonitorConnection.State | undefined>();
|
protected reconnectTimeout?: number;
|
||||||
/**
|
|
||||||
* This emitter forwards all read events **iff** the connection is established.
|
|
||||||
*/
|
|
||||||
protected readonly onReadEmitter = new Emitter<MonitorReadEvent>();
|
|
||||||
|
|
||||||
/**
|
@postConstruct()
|
||||||
* Array for storing previous monitor errors received from the server, and based on the number of elements in this array,
|
protected init(): void {
|
||||||
* we adjust the reconnection delay.
|
this.monitorServiceClient.onError(async (error) => {
|
||||||
* Super naive way: we wait `array.length * 1000` ms. Once we hit 10 errors, we do not try to reconnect and clean the array.
|
let shouldReconnect = false;
|
||||||
*/
|
if (this.state) {
|
||||||
protected monitorErrors: MonitorError[] = [];
|
const { code, config } = error;
|
||||||
protected reconnectTimeout?: number;
|
const { board, port } = config;
|
||||||
|
const options = { timeout: 3000 };
|
||||||
@postConstruct()
|
switch (code) {
|
||||||
protected init(): void {
|
case MonitorError.ErrorCodes.CLIENT_CANCEL: {
|
||||||
// Forward the messages from the board **iff** connected.
|
console.debug(
|
||||||
this.monitorServiceClient.onRead(event => {
|
`Connection was canceled by client: ${MonitorConnection.State.toString(
|
||||||
if (this.connected) {
|
this.state
|
||||||
this.onReadEmitter.fire(event);
|
)}.`
|
||||||
}
|
);
|
||||||
});
|
break;
|
||||||
this.monitorServiceClient.onError(async error => {
|
}
|
||||||
let shouldReconnect = false;
|
case MonitorError.ErrorCodes.DEVICE_BUSY: {
|
||||||
if (this.state) {
|
this.messageService.warn(
|
||||||
const { code, config } = error;
|
`Connection failed. Serial port is busy: ${Port.toString(port)}.`,
|
||||||
const { board, port } = config;
|
options
|
||||||
const options = { timeout: 3000 };
|
);
|
||||||
switch (code) {
|
shouldReconnect = this.autoConnect;
|
||||||
case MonitorError.ErrorCodes.CLIENT_CANCEL: {
|
this.monitorErrors.push(error);
|
||||||
console.debug(`Connection was canceled by client: ${MonitorConnection.State.toString(this.state)}.`);
|
break;
|
||||||
break;
|
}
|
||||||
}
|
case MonitorError.ErrorCodes.DEVICE_NOT_CONFIGURED: {
|
||||||
case MonitorError.ErrorCodes.DEVICE_BUSY: {
|
this.messageService.info(
|
||||||
this.messageService.warn(`Connection failed. Serial port is busy: ${Port.toString(port)}.`, options);
|
`Disconnected ${Board.toString(board, {
|
||||||
shouldReconnect = this.autoConnect;
|
useFqbn: false,
|
||||||
this.monitorErrors.push(error);
|
})} from ${Port.toString(port)}.`,
|
||||||
break;
|
options
|
||||||
}
|
);
|
||||||
case MonitorError.ErrorCodes.DEVICE_NOT_CONFIGURED: {
|
break;
|
||||||
this.messageService.info(`Disconnected ${Board.toString(board, { useFqbn: false })} from ${Port.toString(port)}.`, options);
|
}
|
||||||
break;
|
case undefined: {
|
||||||
}
|
this.messageService.error(
|
||||||
case undefined: {
|
`Unexpected error. Reconnecting ${Board.toString(
|
||||||
this.messageService.error(`Unexpected error. Reconnecting ${Board.toString(board)} on port ${Port.toString(port)}.`, options);
|
board
|
||||||
console.error(JSON.stringify(error));
|
)} on port ${Port.toString(port)}.`,
|
||||||
shouldReconnect = this.connected && this.autoConnect;
|
options
|
||||||
break;
|
);
|
||||||
}
|
console.error(JSON.stringify(error));
|
||||||
}
|
shouldReconnect = this.connected && this.autoConnect;
|
||||||
const oldState = this.state;
|
break;
|
||||||
this.state = undefined;
|
}
|
||||||
this.onConnectionChangedEmitter.fire(this.state);
|
|
||||||
if (shouldReconnect) {
|
|
||||||
if (this.monitorErrors.length >= 10) {
|
|
||||||
this.messageService.warn(`Failed to reconnect ${Board.toString(board, { useFqbn: false })} to the the serial-monitor after 10 consecutive attempts. The ${Port.toString(port)} serial port is busy. after 10 consecutive attempts.`);
|
|
||||||
this.monitorErrors.length = 0;
|
|
||||||
} else {
|
|
||||||
const attempts = (this.monitorErrors.length || 1);
|
|
||||||
if (this.reconnectTimeout !== undefined) {
|
|
||||||
// Clear the previous timer.
|
|
||||||
window.clearTimeout(this.reconnectTimeout);
|
|
||||||
}
|
|
||||||
const timeout = attempts * 1000;
|
|
||||||
this.messageService.warn(`Reconnecting ${Board.toString(board, { useFqbn: false })} to ${Port.toString(port)} in ${attempts} seconds...`, { timeout });
|
|
||||||
this.reconnectTimeout = window.setTimeout(() => this.connect(oldState.config), timeout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.boardsServiceProvider.onBoardsConfigChanged(this.handleBoardConfigChange.bind(this));
|
|
||||||
this.notificationCenter.onAttachedBoardsChanged(event => {
|
|
||||||
if (this.autoConnect && this.connected) {
|
|
||||||
const { boardsConfig } = this.boardsServiceProvider;
|
|
||||||
if (this.boardsServiceProvider.canUploadTo(boardsConfig, { silent: false })) {
|
|
||||||
const { attached } = AttachedBoardsChangeEvent.diff(event);
|
|
||||||
if (attached.boards.some(board => !!board.port && BoardsConfig.Config.sameAs(boardsConfig, board))) {
|
|
||||||
const { selectedBoard: board, selectedPort: port } = boardsConfig;
|
|
||||||
const { baudRate } = this.monitorModel;
|
|
||||||
this.disconnect()
|
|
||||||
.then(() => this.connect({ board, port, baudRate }));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// Handles the `baudRate` changes by reconnecting if required.
|
|
||||||
this.monitorModel.onChange(({ property }) => {
|
|
||||||
if (property === 'baudRate' && this.autoConnect && this.connected) {
|
|
||||||
const { boardsConfig } = this.boardsServiceProvider;
|
|
||||||
this.handleBoardConfigChange(boardsConfig);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
get connected(): boolean {
|
|
||||||
return !!this.state;
|
|
||||||
}
|
|
||||||
|
|
||||||
get monitorConfig(): MonitorConfig | undefined {
|
|
||||||
return this.state ? this.state.config : undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
get autoConnect(): boolean {
|
|
||||||
return this._autoConnect;
|
|
||||||
}
|
|
||||||
|
|
||||||
set autoConnect(value: boolean) {
|
|
||||||
const oldValue = this._autoConnect;
|
|
||||||
this._autoConnect = value;
|
|
||||||
// When we enable the auto-connect, we have to connect
|
|
||||||
if (!oldValue && value) {
|
|
||||||
// We have to make sure the previous boards config has been restored.
|
|
||||||
// Otherwise, we might start the auto-connection without configured boards.
|
|
||||||
this.applicationState.reachedState('started_contributions').then(() => {
|
|
||||||
const { boardsConfig } = this.boardsServiceProvider;
|
|
||||||
this.handleBoardConfigChange(boardsConfig);
|
|
||||||
});
|
|
||||||
} else if (oldValue && !value) {
|
|
||||||
if (this.reconnectTimeout !== undefined) {
|
|
||||||
window.clearTimeout(this.reconnectTimeout);
|
|
||||||
this.monitorErrors.length = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async connect(config: MonitorConfig): Promise<Status> {
|
|
||||||
if (this.connected) {
|
|
||||||
const disconnectStatus = await this.disconnect();
|
|
||||||
if (!Status.isOK(disconnectStatus)) {
|
|
||||||
return disconnectStatus;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
console.info(`>>> Creating serial monitor connection for ${Board.toString(config.board)} on port ${Port.toString(config.port)}...`);
|
|
||||||
const connectStatus = await this.monitorService.connect(config);
|
|
||||||
if (Status.isOK(connectStatus)) {
|
|
||||||
this.state = { config };
|
|
||||||
console.info(`<<< Serial monitor connection created for ${Board.toString(config.board, { useFqbn: false })} on port ${Port.toString(config.port)}.`);
|
|
||||||
}
|
|
||||||
this.onConnectionChangedEmitter.fire(this.state);
|
|
||||||
return Status.isOK(connectStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
async disconnect(): Promise<Status> {
|
|
||||||
if (!this.connected) {
|
|
||||||
return Status.OK;
|
|
||||||
}
|
|
||||||
const stateCopy = deepClone(this.state);
|
|
||||||
if (!stateCopy) {
|
|
||||||
return Status.OK;
|
|
||||||
}
|
|
||||||
console.log('>>> Disposing existing monitor connection...');
|
|
||||||
const status = await this.monitorService.disconnect();
|
|
||||||
if (Status.isOK(status)) {
|
|
||||||
console.log(`<<< Disposed connection. Was: ${MonitorConnection.State.toString(stateCopy)}`);
|
|
||||||
} else {
|
|
||||||
console.warn(`<<< Could not dispose connection. Activate connection: ${MonitorConnection.State.toString(stateCopy)}`);
|
|
||||||
}
|
}
|
||||||
|
const oldState = this.state;
|
||||||
this.state = undefined;
|
this.state = undefined;
|
||||||
this.onConnectionChangedEmitter.fire(this.state);
|
this.onConnectionChangedEmitter.fire(this.state);
|
||||||
return status;
|
if (shouldReconnect) {
|
||||||
}
|
if (this.monitorErrors.length >= 10) {
|
||||||
|
this.messageService.warn(
|
||||||
/**
|
`Failed to reconnect ${Board.toString(board, {
|
||||||
* Sends the data to the connected serial monitor.
|
useFqbn: false,
|
||||||
* The desired EOL is appended to `data`, you do not have to add it.
|
})} to the the serial-monitor after 10 consecutive attempts. The ${Port.toString(
|
||||||
* It is a NOOP if connected.
|
port
|
||||||
*/
|
)} serial port is busy. after 10 consecutive attempts.`
|
||||||
async send(data: string): Promise<Status> {
|
);
|
||||||
if (!this.connected) {
|
this.monitorErrors.length = 0;
|
||||||
return Status.NOT_CONNECTED;
|
} else {
|
||||||
}
|
const attempts = this.monitorErrors.length || 1;
|
||||||
return new Promise<Status>(resolve => {
|
if (this.reconnectTimeout !== undefined) {
|
||||||
this.monitorService.send(data + this.monitorModel.lineEnding)
|
// Clear the previous timer.
|
||||||
.then(() => resolve(Status.OK));
|
window.clearTimeout(this.reconnectTimeout);
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
get onConnectionChanged(): Event<MonitorConnection.State | undefined> {
|
|
||||||
return this.onConnectionChangedEmitter.event;
|
|
||||||
}
|
|
||||||
|
|
||||||
get onRead(): Event<MonitorReadEvent> {
|
|
||||||
return this.onReadEmitter.event;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async handleBoardConfigChange(boardsConfig: BoardsConfig.Config): Promise<void> {
|
|
||||||
if (this.autoConnect) {
|
|
||||||
if (this.boardsServiceProvider.canUploadTo(boardsConfig, { silent: false })) {
|
|
||||||
// Instead of calling `getAttachedBoards` and filtering for `AttachedSerialBoard` we have to check the available ports.
|
|
||||||
// The connected board might be unknown. See: https://github.com/arduino/arduino-pro-ide/issues/127#issuecomment-563251881
|
|
||||||
this.boardsService.getAvailablePorts().then(ports => {
|
|
||||||
if (ports.some(port => Port.equals(port, boardsConfig.selectedPort))) {
|
|
||||||
new Promise<void>(resolve => {
|
|
||||||
// First, disconnect if connected.
|
|
||||||
if (this.connected) {
|
|
||||||
this.disconnect().then(() => resolve());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
resolve();
|
|
||||||
}).then(() => {
|
|
||||||
// Then (re-)connect.
|
|
||||||
const { selectedBoard: board, selectedPort: port } = boardsConfig;
|
|
||||||
const { baudRate } = this.monitorModel;
|
|
||||||
this.connect({ board, port, baudRate });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
const timeout = attempts * 1000;
|
||||||
|
this.messageService.warn(
|
||||||
|
`Reconnecting ${Board.toString(board, {
|
||||||
|
useFqbn: false,
|
||||||
|
})} to ${Port.toString(port)} in ${attempts} seconds...`,
|
||||||
|
{ timeout }
|
||||||
|
);
|
||||||
|
this.reconnectTimeout = window.setTimeout(
|
||||||
|
() => this.connect(oldState.config),
|
||||||
|
timeout
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
this.boardsServiceProvider.onBoardsConfigChanged(
|
||||||
|
this.handleBoardConfigChange.bind(this)
|
||||||
|
);
|
||||||
|
this.notificationCenter.onAttachedBoardsChanged((event) => {
|
||||||
|
if (this.autoConnect && this.connected) {
|
||||||
|
const { boardsConfig } = this.boardsServiceProvider;
|
||||||
|
if (
|
||||||
|
this.boardsServiceProvider.canUploadTo(boardsConfig, {
|
||||||
|
silent: false,
|
||||||
|
})
|
||||||
|
) {
|
||||||
|
const { attached } = AttachedBoardsChangeEvent.diff(event);
|
||||||
|
if (
|
||||||
|
attached.boards.some(
|
||||||
|
(board) =>
|
||||||
|
!!board.port && BoardsConfig.Config.sameAs(boardsConfig, board)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
const { selectedBoard: board, selectedPort: port } = boardsConfig;
|
||||||
|
const { baudRate } = this.monitorModel;
|
||||||
|
this.disconnect().then(() =>
|
||||||
|
this.connect({ board, port, baudRate })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Handles the `baudRate` changes by reconnecting if required.
|
||||||
|
this.monitorModel.onChange(({ property }) => {
|
||||||
|
if (property === 'baudRate' && this.autoConnect && this.connected) {
|
||||||
|
const { boardsConfig } = this.boardsServiceProvider;
|
||||||
|
this.handleBoardConfigChange(boardsConfig);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get connected(): boolean {
|
||||||
|
return !!this.state;
|
||||||
|
}
|
||||||
|
|
||||||
|
get monitorConfig(): MonitorConfig | undefined {
|
||||||
|
return this.state ? this.state.config : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
get autoConnect(): boolean {
|
||||||
|
return this._autoConnect;
|
||||||
|
}
|
||||||
|
|
||||||
|
set autoConnect(value: boolean) {
|
||||||
|
const oldValue = this._autoConnect;
|
||||||
|
this._autoConnect = value;
|
||||||
|
// When we enable the auto-connect, we have to connect
|
||||||
|
if (!oldValue && value) {
|
||||||
|
// We have to make sure the previous boards config has been restored.
|
||||||
|
// Otherwise, we might start the auto-connection without configured boards.
|
||||||
|
this.applicationState.reachedState('started_contributions').then(() => {
|
||||||
|
const { boardsConfig } = this.boardsServiceProvider;
|
||||||
|
this.handleBoardConfigChange(boardsConfig);
|
||||||
|
});
|
||||||
|
} else if (oldValue && !value) {
|
||||||
|
if (this.reconnectTimeout !== undefined) {
|
||||||
|
window.clearTimeout(this.reconnectTimeout);
|
||||||
|
this.monitorErrors.length = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async connect(config: MonitorConfig): Promise<Status> {
|
||||||
|
if (this.connected) {
|
||||||
|
const disconnectStatus = await this.disconnect();
|
||||||
|
if (!Status.isOK(disconnectStatus)) {
|
||||||
|
return disconnectStatus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.info(
|
||||||
|
`>>> Creating serial monitor connection for ${Board.toString(
|
||||||
|
config.board
|
||||||
|
)} on port ${Port.toString(config.port)}...`
|
||||||
|
);
|
||||||
|
const connectStatus = await this.monitorService.connect(config);
|
||||||
|
if (Status.isOK(connectStatus)) {
|
||||||
|
const requestMessage = () => {
|
||||||
|
this.monitorService.request().then(({ message }) => {
|
||||||
|
if (this.connected) {
|
||||||
|
this.onReadEmitter.fire({ message });
|
||||||
|
requestMessage();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
requestMessage();
|
||||||
|
this.state = { config };
|
||||||
|
console.info(
|
||||||
|
`<<< Serial monitor connection created for ${Board.toString(
|
||||||
|
config.board,
|
||||||
|
{ useFqbn: false }
|
||||||
|
)} on port ${Port.toString(config.port)}.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.onConnectionChangedEmitter.fire(this.state);
|
||||||
|
return Status.isOK(connectStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
async disconnect(): Promise<Status> {
|
||||||
|
if (!this.connected) {
|
||||||
|
return Status.OK;
|
||||||
|
}
|
||||||
|
const stateCopy = deepClone(this.state);
|
||||||
|
if (!stateCopy) {
|
||||||
|
return Status.OK;
|
||||||
|
}
|
||||||
|
console.log('>>> Disposing existing monitor connection...');
|
||||||
|
const status = await this.monitorService.disconnect();
|
||||||
|
if (Status.isOK(status)) {
|
||||||
|
console.log(
|
||||||
|
`<<< Disposed connection. Was: ${MonitorConnection.State.toString(
|
||||||
|
stateCopy
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
console.warn(
|
||||||
|
`<<< Could not dispose connection. Activate connection: ${MonitorConnection.State.toString(
|
||||||
|
stateCopy
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.state = undefined;
|
||||||
|
this.onConnectionChangedEmitter.fire(this.state);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends the data to the connected serial monitor.
|
||||||
|
* The desired EOL is appended to `data`, you do not have to add it.
|
||||||
|
* It is a NOOP if connected.
|
||||||
|
*/
|
||||||
|
async send(data: string): Promise<Status> {
|
||||||
|
if (!this.connected) {
|
||||||
|
return Status.NOT_CONNECTED;
|
||||||
|
}
|
||||||
|
return new Promise<Status>((resolve) => {
|
||||||
|
this.monitorService
|
||||||
|
.send(data + this.monitorModel.lineEnding)
|
||||||
|
.then(() => resolve(Status.OK));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get onConnectionChanged(): Event<MonitorConnection.State | undefined> {
|
||||||
|
return this.onConnectionChangedEmitter.event;
|
||||||
|
}
|
||||||
|
|
||||||
|
get onRead(): Event<{ message: string }> {
|
||||||
|
return this.onReadEmitter.event;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async handleBoardConfigChange(
|
||||||
|
boardsConfig: BoardsConfig.Config
|
||||||
|
): Promise<void> {
|
||||||
|
if (this.autoConnect) {
|
||||||
|
if (
|
||||||
|
this.boardsServiceProvider.canUploadTo(boardsConfig, {
|
||||||
|
silent: false,
|
||||||
|
})
|
||||||
|
) {
|
||||||
|
// Instead of calling `getAttachedBoards` and filtering for `AttachedSerialBoard` we have to check the available ports.
|
||||||
|
// The connected board might be unknown. See: https://github.com/arduino/arduino-pro-ide/issues/127#issuecomment-563251881
|
||||||
|
this.boardsService.getAvailablePorts().then((ports) => {
|
||||||
|
if (
|
||||||
|
ports.some((port) => Port.equals(port, boardsConfig.selectedPort))
|
||||||
|
) {
|
||||||
|
new Promise<void>((resolve) => {
|
||||||
|
// First, disconnect if connected.
|
||||||
|
if (this.connected) {
|
||||||
|
this.disconnect().then(() => resolve());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
}).then(() => {
|
||||||
|
// Then (re-)connect.
|
||||||
|
const { selectedBoard: board, selectedPort: port } = boardsConfig;
|
||||||
|
const { baudRate } = this.monitorModel;
|
||||||
|
this.connect({ board, port, baudRate });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace MonitorConnection {
|
export namespace MonitorConnection {
|
||||||
|
export interface State {
|
||||||
|
readonly config: MonitorConfig;
|
||||||
|
}
|
||||||
|
|
||||||
export interface State {
|
export namespace State {
|
||||||
readonly config: MonitorConfig;
|
export function toString(state: State): string {
|
||||||
|
const { config } = state;
|
||||||
|
const { board, port } = config;
|
||||||
|
return `${Board.toString(board)} ${Port.toString(port)}`;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
export namespace State {
|
|
||||||
export function toString(state: State): string {
|
|
||||||
const { config } = state;
|
|
||||||
const { board, port } = config;
|
|
||||||
return `${Board.toString(board)} ${Port.toString(port)}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,119 +1,144 @@
|
|||||||
import { injectable, inject } from 'inversify';
|
import { injectable, inject } from 'inversify';
|
||||||
import { Emitter, Event } from '@theia/core/lib/common/event';
|
import { Emitter, Event } from '@theia/core/lib/common/event';
|
||||||
import { MonitorConfig } from '../../common/protocol/monitor-service';
|
import { MonitorConfig } from '../../common/protocol/monitor-service';
|
||||||
import { FrontendApplicationContribution, LocalStorageService } from '@theia/core/lib/browser';
|
import {
|
||||||
|
FrontendApplicationContribution,
|
||||||
|
LocalStorageService,
|
||||||
|
} from '@theia/core/lib/browser';
|
||||||
import { BoardsServiceProvider } from '../boards/boards-service-provider';
|
import { BoardsServiceProvider } from '../boards/boards-service-provider';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class MonitorModel implements FrontendApplicationContribution {
|
export class MonitorModel implements FrontendApplicationContribution {
|
||||||
|
protected static STORAGE_ID = 'arduino-monitor-model';
|
||||||
|
|
||||||
protected static STORAGE_ID = 'arduino-monitor-model';
|
@inject(LocalStorageService)
|
||||||
|
protected readonly localStorageService: LocalStorageService;
|
||||||
|
|
||||||
@inject(LocalStorageService)
|
@inject(BoardsServiceProvider)
|
||||||
protected readonly localStorageService: LocalStorageService;
|
protected readonly boardsServiceClient: BoardsServiceProvider;
|
||||||
|
|
||||||
@inject(BoardsServiceProvider)
|
protected readonly onChangeEmitter: Emitter<
|
||||||
protected readonly boardsServiceClient: BoardsServiceProvider;
|
MonitorModel.State.Change<keyof MonitorModel.State>
|
||||||
|
>;
|
||||||
|
protected _autoscroll: boolean;
|
||||||
|
protected _timestamp: boolean;
|
||||||
|
protected _baudRate: MonitorConfig.BaudRate;
|
||||||
|
protected _lineEnding: MonitorModel.EOL;
|
||||||
|
|
||||||
protected readonly onChangeEmitter: Emitter<MonitorModel.State.Change<keyof MonitorModel.State>>;
|
constructor() {
|
||||||
protected _autoscroll: boolean;
|
this._autoscroll = true;
|
||||||
protected _timestamp: boolean;
|
this._timestamp = false;
|
||||||
protected _baudRate: MonitorConfig.BaudRate;
|
this._baudRate = MonitorConfig.BaudRate.DEFAULT;
|
||||||
protected _lineEnding: MonitorModel.EOL;
|
this._lineEnding = MonitorModel.EOL.DEFAULT;
|
||||||
|
this.onChangeEmitter = new Emitter<
|
||||||
|
MonitorModel.State.Change<keyof MonitorModel.State>
|
||||||
|
>();
|
||||||
|
}
|
||||||
|
|
||||||
constructor() {
|
onStart(): void {
|
||||||
this._autoscroll = true;
|
this.localStorageService
|
||||||
this._timestamp = false;
|
.getData<MonitorModel.State>(MonitorModel.STORAGE_ID)
|
||||||
this._baudRate = MonitorConfig.BaudRate.DEFAULT;
|
.then((state) => {
|
||||||
this._lineEnding = MonitorModel.EOL.DEFAULT;
|
if (state) {
|
||||||
this.onChangeEmitter = new Emitter<MonitorModel.State.Change<keyof MonitorModel.State>>();
|
this.restoreState(state);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
onStart(): void {
|
get onChange(): Event<MonitorModel.State.Change<keyof MonitorModel.State>> {
|
||||||
this.localStorageService.getData<MonitorModel.State>(MonitorModel.STORAGE_ID).then(state => {
|
return this.onChangeEmitter.event;
|
||||||
if (state) {
|
}
|
||||||
this.restoreState(state);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
get onChange(): Event<MonitorModel.State.Change<keyof MonitorModel.State>> {
|
get autoscroll(): boolean {
|
||||||
return this.onChangeEmitter.event;
|
return this._autoscroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
get autoscroll(): boolean {
|
toggleAutoscroll(): void {
|
||||||
return this._autoscroll;
|
this._autoscroll = !this._autoscroll;
|
||||||
}
|
this.storeState();
|
||||||
|
this.storeState().then(() =>
|
||||||
|
this.onChangeEmitter.fire({
|
||||||
|
property: 'autoscroll',
|
||||||
|
value: this._autoscroll,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
toggleAutoscroll(): void {
|
get timestamp(): boolean {
|
||||||
this._autoscroll = !this._autoscroll;
|
return this._timestamp;
|
||||||
this.storeState();
|
}
|
||||||
this.storeState().then(() => this.onChangeEmitter.fire({ property: 'autoscroll', value: this._autoscroll }));
|
|
||||||
}
|
|
||||||
|
|
||||||
get timestamp(): boolean {
|
toggleTimestamp(): void {
|
||||||
return this._timestamp;
|
this._timestamp = !this._timestamp;
|
||||||
}
|
this.storeState().then(() =>
|
||||||
|
this.onChangeEmitter.fire({
|
||||||
|
property: 'timestamp',
|
||||||
|
value: this._timestamp,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
toggleTimestamp(): void {
|
get baudRate(): MonitorConfig.BaudRate {
|
||||||
this._timestamp = !this._timestamp;
|
return this._baudRate;
|
||||||
this.storeState().then(() => this.onChangeEmitter.fire({ property: 'timestamp', value: this._timestamp }));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
get baudRate(): MonitorConfig.BaudRate {
|
set baudRate(baudRate: MonitorConfig.BaudRate) {
|
||||||
return this._baudRate;
|
this._baudRate = baudRate;
|
||||||
}
|
this.storeState().then(() =>
|
||||||
|
this.onChangeEmitter.fire({
|
||||||
|
property: 'baudRate',
|
||||||
|
value: this._baudRate,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
set baudRate(baudRate: MonitorConfig.BaudRate) {
|
get lineEnding(): MonitorModel.EOL {
|
||||||
this._baudRate = baudRate;
|
return this._lineEnding;
|
||||||
this.storeState().then(() => this.onChangeEmitter.fire({ property: 'baudRate', value: this._baudRate }));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
get lineEnding(): MonitorModel.EOL {
|
set lineEnding(lineEnding: MonitorModel.EOL) {
|
||||||
return this._lineEnding;
|
this._lineEnding = lineEnding;
|
||||||
}
|
this.storeState().then(() =>
|
||||||
|
this.onChangeEmitter.fire({
|
||||||
|
property: 'lineEnding',
|
||||||
|
value: this._lineEnding,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
set lineEnding(lineEnding: MonitorModel.EOL) {
|
protected restoreState(state: MonitorModel.State): void {
|
||||||
this._lineEnding = lineEnding;
|
this._autoscroll = state.autoscroll;
|
||||||
this.storeState().then(() => this.onChangeEmitter.fire({ property: 'lineEnding', value: this._lineEnding }));
|
this._timestamp = state.timestamp;
|
||||||
}
|
this._baudRate = state.baudRate;
|
||||||
|
this._lineEnding = state.lineEnding;
|
||||||
protected restoreState(state: MonitorModel.State): void {
|
}
|
||||||
this._autoscroll = state.autoscroll;
|
|
||||||
this._timestamp = state.timestamp;
|
|
||||||
this._baudRate = state.baudRate;
|
|
||||||
this._lineEnding = state.lineEnding;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async storeState(): Promise<void> {
|
|
||||||
return this.localStorageService.setData(MonitorModel.STORAGE_ID, {
|
|
||||||
autoscroll: this._autoscroll,
|
|
||||||
timestamp: this._timestamp,
|
|
||||||
baudRate: this._baudRate,
|
|
||||||
lineEnding: this._lineEnding
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
protected async storeState(): Promise<void> {
|
||||||
|
return this.localStorageService.setData(MonitorModel.STORAGE_ID, {
|
||||||
|
autoscroll: this._autoscroll,
|
||||||
|
timestamp: this._timestamp,
|
||||||
|
baudRate: this._baudRate,
|
||||||
|
lineEnding: this._lineEnding,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace MonitorModel {
|
export namespace MonitorModel {
|
||||||
|
export interface State {
|
||||||
export interface State {
|
autoscroll: boolean;
|
||||||
autoscroll: boolean;
|
timestamp: boolean;
|
||||||
timestamp: boolean;
|
baudRate: MonitorConfig.BaudRate;
|
||||||
baudRate: MonitorConfig.BaudRate;
|
lineEnding: EOL;
|
||||||
lineEnding: EOL;
|
}
|
||||||
}
|
export namespace State {
|
||||||
export namespace State {
|
export interface Change<K extends keyof State> {
|
||||||
export interface Change<K extends keyof State> {
|
readonly property: K;
|
||||||
readonly property: K;
|
readonly value: State[K];
|
||||||
readonly value: State[K];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export type EOL = '' | '\n' | '\r' | '\r\n';
|
|
||||||
export namespace EOL {
|
|
||||||
export const DEFAULT: EOL = '\n';
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export type EOL = '' | '\n' | '\r' | '\r\n';
|
||||||
|
export namespace EOL {
|
||||||
|
export const DEFAULT: EOL = '\n';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,16 @@
|
|||||||
import { injectable } from 'inversify';
|
import { injectable } from 'inversify';
|
||||||
import { Emitter } from '@theia/core/lib/common/event';
|
import { Emitter } from '@theia/core/lib/common/event';
|
||||||
import { MonitorServiceClient, MonitorReadEvent, MonitorError } from '../../common/protocol/monitor-service';
|
import {
|
||||||
|
MonitorServiceClient,
|
||||||
|
MonitorError,
|
||||||
|
} from '../../common/protocol/monitor-service';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class MonitorServiceClientImpl implements MonitorServiceClient {
|
export class MonitorServiceClientImpl implements MonitorServiceClient {
|
||||||
|
protected readonly onErrorEmitter = new Emitter<MonitorError>();
|
||||||
|
readonly onError = this.onErrorEmitter.event;
|
||||||
|
|
||||||
protected readonly onReadEmitter = new Emitter<MonitorReadEvent>();
|
notifyError(error: MonitorError): void {
|
||||||
protected readonly onErrorEmitter = new Emitter<MonitorError>();
|
this.onErrorEmitter.fire(error);
|
||||||
readonly onRead = this.onReadEmitter.event;
|
}
|
||||||
readonly onError = this.onErrorEmitter.event;
|
|
||||||
|
|
||||||
notifyRead(event: MonitorReadEvent): void {
|
|
||||||
this.onReadEmitter.fire(event);
|
|
||||||
const { data } = event;
|
|
||||||
console.debug(`Received data: ${data}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
notifyError(error: MonitorError): void {
|
|
||||||
this.onErrorEmitter.fire(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,135 +3,154 @@ import { injectable, inject } from 'inversify';
|
|||||||
import { AbstractViewContribution } from '@theia/core/lib/browser';
|
import { AbstractViewContribution } from '@theia/core/lib/browser';
|
||||||
import { MonitorWidget } from './monitor-widget';
|
import { MonitorWidget } from './monitor-widget';
|
||||||
import { MenuModelRegistry, Command, CommandRegistry } from '@theia/core';
|
import { MenuModelRegistry, Command, CommandRegistry } from '@theia/core';
|
||||||
import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
|
import {
|
||||||
|
TabBarToolbarContribution,
|
||||||
|
TabBarToolbarRegistry,
|
||||||
|
} from '@theia/core/lib/browser/shell/tab-bar-toolbar';
|
||||||
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
|
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
|
||||||
import { MonitorModel } from './monitor-model';
|
import { MonitorModel } from './monitor-model';
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
|
|
||||||
export namespace SerialMonitor {
|
export namespace SerialMonitor {
|
||||||
export namespace Commands {
|
export namespace Commands {
|
||||||
export const AUTOSCROLL: Command = {
|
export const AUTOSCROLL: Command = {
|
||||||
id: 'serial-monitor-autoscroll',
|
id: 'serial-monitor-autoscroll',
|
||||||
label: 'Autoscroll'
|
label: 'Autoscroll',
|
||||||
}
|
};
|
||||||
export const TIMESTAMP: Command = {
|
export const TIMESTAMP: Command = {
|
||||||
id: 'serial-monitor-timestamp',
|
id: 'serial-monitor-timestamp',
|
||||||
label: 'Timestamp'
|
label: 'Timestamp',
|
||||||
}
|
};
|
||||||
export const CLEAR_OUTPUT: Command = {
|
export const CLEAR_OUTPUT: Command = {
|
||||||
id: 'serial-monitor-clear-output',
|
id: 'serial-monitor-clear-output',
|
||||||
label: 'Clear Output',
|
label: 'Clear Output',
|
||||||
iconClass: 'clear-all'
|
iconClass: 'clear-all',
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class MonitorViewContribution extends AbstractViewContribution<MonitorWidget> implements TabBarToolbarContribution {
|
export class MonitorViewContribution
|
||||||
|
extends AbstractViewContribution<MonitorWidget>
|
||||||
|
implements TabBarToolbarContribution
|
||||||
|
{
|
||||||
|
static readonly TOGGLE_SERIAL_MONITOR = MonitorWidget.ID + ':toggle';
|
||||||
|
static readonly TOGGLE_SERIAL_MONITOR_TOOLBAR =
|
||||||
|
MonitorWidget.ID + ':toggle-toolbar';
|
||||||
|
|
||||||
static readonly TOGGLE_SERIAL_MONITOR = MonitorWidget.ID + ':toggle';
|
@inject(MonitorModel) protected readonly model: MonitorModel;
|
||||||
static readonly TOGGLE_SERIAL_MONITOR_TOOLBAR = MonitorWidget.ID + ':toggle-toolbar';
|
|
||||||
|
|
||||||
@inject(MonitorModel) protected readonly model: MonitorModel;
|
constructor() {
|
||||||
|
super({
|
||||||
|
widgetId: MonitorWidget.ID,
|
||||||
|
widgetName: 'Serial Monitor',
|
||||||
|
defaultWidgetOptions: {
|
||||||
|
area: 'bottom',
|
||||||
|
},
|
||||||
|
toggleCommandId: MonitorViewContribution.TOGGLE_SERIAL_MONITOR,
|
||||||
|
toggleKeybinding: 'CtrlCmd+Shift+M',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
constructor() {
|
registerMenus(menus: MenuModelRegistry): void {
|
||||||
super({
|
if (this.toggleCommand) {
|
||||||
widgetId: MonitorWidget.ID,
|
menus.registerMenuAction(ArduinoMenus.TOOLS__MAIN_GROUP, {
|
||||||
widgetName: 'Serial Monitor',
|
commandId: this.toggleCommand.id,
|
||||||
defaultWidgetOptions: {
|
label: 'Serial Monitor',
|
||||||
area: 'bottom'
|
order: '5',
|
||||||
},
|
});
|
||||||
toggleCommandId: MonitorViewContribution.TOGGLE_SERIAL_MONITOR,
|
|
||||||
toggleKeybinding: 'CtrlCmd+Shift+M'
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
registerMenus(menus: MenuModelRegistry): void {
|
registerToolbarItems(registry: TabBarToolbarRegistry): void {
|
||||||
if (this.toggleCommand) {
|
registry.registerItem({
|
||||||
menus.registerMenuAction(ArduinoMenus.TOOLS__MAIN_GROUP, {
|
id: 'monitor-autoscroll',
|
||||||
commandId: this.toggleCommand.id,
|
render: () => this.renderAutoScrollButton(),
|
||||||
label: 'Serial Monitor',
|
isVisible: (widget) => widget instanceof MonitorWidget,
|
||||||
order: '5'
|
onDidChange: this.model.onChange as any, // XXX: it's a hack. See: https://github.com/eclipse-theia/theia/pull/6696/
|
||||||
});
|
});
|
||||||
|
registry.registerItem({
|
||||||
|
id: 'monitor-timestamp',
|
||||||
|
render: () => this.renderTimestampButton(),
|
||||||
|
isVisible: (widget) => widget instanceof MonitorWidget,
|
||||||
|
onDidChange: this.model.onChange as any, // XXX: it's a hack. See: https://github.com/eclipse-theia/theia/pull/6696/
|
||||||
|
});
|
||||||
|
registry.registerItem({
|
||||||
|
id: SerialMonitor.Commands.CLEAR_OUTPUT.id,
|
||||||
|
command: SerialMonitor.Commands.CLEAR_OUTPUT.id,
|
||||||
|
tooltip: 'Clear Output',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
registerCommands(commands: CommandRegistry): void {
|
||||||
|
commands.registerCommand(SerialMonitor.Commands.CLEAR_OUTPUT, {
|
||||||
|
isEnabled: (widget) => widget instanceof MonitorWidget,
|
||||||
|
isVisible: (widget) => widget instanceof MonitorWidget,
|
||||||
|
execute: (widget) => {
|
||||||
|
if (widget instanceof MonitorWidget) {
|
||||||
|
widget.clearConsole();
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
});
|
||||||
registerToolbarItems(registry: TabBarToolbarRegistry): void {
|
if (this.toggleCommand) {
|
||||||
registry.registerItem({
|
commands.registerCommand(this.toggleCommand, {
|
||||||
id: 'monitor-autoscroll',
|
execute: () => this.toggle(),
|
||||||
render: () => this.renderAutoScrollButton(),
|
});
|
||||||
isVisible: widget => widget instanceof MonitorWidget,
|
commands.registerCommand(
|
||||||
onDidChange: this.model.onChange as any // XXX: it's a hack. See: https://github.com/eclipse-theia/theia/pull/6696/
|
{ id: MonitorViewContribution.TOGGLE_SERIAL_MONITOR_TOOLBAR },
|
||||||
});
|
{
|
||||||
registry.registerItem({
|
isVisible: (widget) =>
|
||||||
id: 'monitor-timestamp',
|
ArduinoToolbar.is(widget) && widget.side === 'right',
|
||||||
render: () => this.renderTimestampButton(),
|
execute: () => this.toggle(),
|
||||||
isVisible: widget => widget instanceof MonitorWidget,
|
|
||||||
onDidChange: this.model.onChange as any // XXX: it's a hack. See: https://github.com/eclipse-theia/theia/pull/6696/
|
|
||||||
});
|
|
||||||
registry.registerItem({
|
|
||||||
id: SerialMonitor.Commands.CLEAR_OUTPUT.id,
|
|
||||||
command: SerialMonitor.Commands.CLEAR_OUTPUT.id,
|
|
||||||
tooltip: 'Clear Output'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
registerCommands(commands: CommandRegistry): void {
|
|
||||||
commands.registerCommand(SerialMonitor.Commands.CLEAR_OUTPUT, {
|
|
||||||
isEnabled: widget => widget instanceof MonitorWidget,
|
|
||||||
isVisible: widget => widget instanceof MonitorWidget,
|
|
||||||
execute: widget => {
|
|
||||||
if (widget instanceof MonitorWidget) {
|
|
||||||
widget.clearConsole();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (this.toggleCommand) {
|
|
||||||
commands.registerCommand(this.toggleCommand, { execute: () => this.toggle() });
|
|
||||||
commands.registerCommand({ id: MonitorViewContribution.TOGGLE_SERIAL_MONITOR_TOOLBAR }, {
|
|
||||||
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'right',
|
|
||||||
execute: () => this.toggle()
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected async toggle(): Promise<void> {
|
protected async toggle(): Promise<void> {
|
||||||
const widget = this.tryGetWidget();
|
const widget = this.tryGetWidget();
|
||||||
if (widget) {
|
if (widget) {
|
||||||
widget.dispose();
|
widget.dispose();
|
||||||
} else {
|
} else {
|
||||||
await this.openView({ activate: true, reveal: true });
|
await this.openView({ activate: true, reveal: true });
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected renderAutoScrollButton(): React.ReactNode {
|
protected renderAutoScrollButton(): React.ReactNode {
|
||||||
return <React.Fragment key='autoscroll-toolbar-item'>
|
return (
|
||||||
<div
|
<React.Fragment key="autoscroll-toolbar-item">
|
||||||
title='Toggle Autoscroll'
|
<div
|
||||||
className={`item enabled fa fa-angle-double-down arduino-monitor ${this.model.autoscroll ? 'toggled' : ''}`}
|
title="Toggle Autoscroll"
|
||||||
onClick={this.toggleAutoScroll}
|
className={`item enabled fa fa-angle-double-down arduino-monitor ${
|
||||||
></div>
|
this.model.autoscroll ? 'toggled' : ''
|
||||||
</React.Fragment>;
|
}`}
|
||||||
}
|
onClick={this.toggleAutoScroll}
|
||||||
|
></div>
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected readonly toggleAutoScroll = () => this.doToggleAutoScroll();
|
protected readonly toggleAutoScroll = () => this.doToggleAutoScroll();
|
||||||
protected async doToggleAutoScroll(): Promise<void> {
|
protected async doToggleAutoScroll(): Promise<void> {
|
||||||
this.model.toggleAutoscroll();
|
this.model.toggleAutoscroll();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected renderTimestampButton(): React.ReactNode {
|
protected renderTimestampButton(): React.ReactNode {
|
||||||
return <React.Fragment key='line-ending-toolbar-item'>
|
return (
|
||||||
<div
|
<React.Fragment key="line-ending-toolbar-item">
|
||||||
title='Toggle Timestamp'
|
<div
|
||||||
className={`item enabled fa fa-clock-o arduino-monitor ${this.model.timestamp ? 'toggled' : ''}`}
|
title="Toggle Timestamp"
|
||||||
onClick={this.toggleTimestamp}
|
className={`item enabled fa fa-clock-o arduino-monitor ${
|
||||||
></div>
|
this.model.timestamp ? 'toggled' : ''
|
||||||
</React.Fragment>;
|
}`}
|
||||||
}
|
onClick={this.toggleTimestamp}
|
||||||
|
></div>
|
||||||
protected readonly toggleTimestamp = () => this.doToggleTimestamp();
|
</React.Fragment>
|
||||||
protected async doToggleTimestamp(): Promise<void> {
|
);
|
||||||
this.model.toggleTimestamp();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
protected readonly toggleTimestamp = () => this.doToggleTimestamp();
|
||||||
|
protected async doToggleTimestamp(): Promise<void> {
|
||||||
|
this.model.toggleTimestamp();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,16 @@ import { OptionsType } from 'react-select/src/types';
|
|||||||
import { isOSX } from '@theia/core/lib/common/os';
|
import { isOSX } from '@theia/core/lib/common/os';
|
||||||
import { Event, Emitter } from '@theia/core/lib/common/event';
|
import { Event, Emitter } from '@theia/core/lib/common/event';
|
||||||
import { Key, KeyCode } from '@theia/core/lib/browser/keys';
|
import { Key, KeyCode } from '@theia/core/lib/browser/keys';
|
||||||
import { DisposableCollection, Disposable } from '@theia/core/lib/common/disposable'
|
import {
|
||||||
import { ReactWidget, Message, Widget, MessageLoop } from '@theia/core/lib/browser/widgets';
|
DisposableCollection,
|
||||||
|
Disposable,
|
||||||
|
} from '@theia/core/lib/common/disposable';
|
||||||
|
import {
|
||||||
|
ReactWidget,
|
||||||
|
Message,
|
||||||
|
Widget,
|
||||||
|
MessageLoop,
|
||||||
|
} from '@theia/core/lib/browser/widgets';
|
||||||
import { Board, Port } from '../../common/protocol/boards-service';
|
import { Board, Port } from '../../common/protocol/boards-service';
|
||||||
import { MonitorConfig } from '../../common/protocol/monitor-service';
|
import { MonitorConfig } from '../../common/protocol/monitor-service';
|
||||||
import { ArduinoSelect } from '../widgets/arduino-select';
|
import { ArduinoSelect } from '../widgets/arduino-select';
|
||||||
@@ -16,326 +24,371 @@ import { MonitorServiceClientImpl } from './monitor-service-client-impl';
|
|||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class MonitorWidget extends ReactWidget {
|
export class MonitorWidget extends ReactWidget {
|
||||||
|
static readonly ID = 'serial-monitor';
|
||||||
|
|
||||||
static readonly ID = 'serial-monitor';
|
@inject(MonitorModel)
|
||||||
|
protected readonly monitorModel: MonitorModel;
|
||||||
|
|
||||||
@inject(MonitorModel)
|
@inject(MonitorConnection)
|
||||||
protected readonly monitorModel: MonitorModel;
|
protected readonly monitorConnection: MonitorConnection;
|
||||||
|
|
||||||
@inject(MonitorConnection)
|
@inject(MonitorServiceClientImpl)
|
||||||
protected readonly monitorConnection: MonitorConnection;
|
protected readonly monitorServiceClient: MonitorServiceClientImpl;
|
||||||
|
|
||||||
@inject(MonitorServiceClientImpl)
|
protected widgetHeight: number;
|
||||||
protected readonly monitorServiceClient: MonitorServiceClientImpl;
|
|
||||||
|
|
||||||
protected widgetHeight: number;
|
/**
|
||||||
|
* Do not touch or use it. It is for setting the focus on the `input` after the widget activation.
|
||||||
|
*/
|
||||||
|
protected focusNode: HTMLElement | undefined;
|
||||||
|
/**
|
||||||
|
* Guard against re-rendering the view after the close was requested.
|
||||||
|
* See: https://github.com/eclipse-theia/theia/issues/6704
|
||||||
|
*/
|
||||||
|
protected closing = false;
|
||||||
|
protected readonly clearOutputEmitter = new Emitter<void>();
|
||||||
|
|
||||||
/**
|
constructor() {
|
||||||
* Do not touch or use it. It is for setting the focus on the `input` after the widget activation.
|
super();
|
||||||
*/
|
this.id = MonitorWidget.ID;
|
||||||
protected focusNode: HTMLElement | undefined;
|
this.title.label = 'Serial Monitor';
|
||||||
/**
|
this.title.iconClass = 'monitor-tab-icon';
|
||||||
* Guard against re-rendering the view after the close was requested.
|
this.title.closable = true;
|
||||||
* See: https://github.com/eclipse-theia/theia/issues/6704
|
this.scrollOptions = undefined;
|
||||||
*/
|
this.toDispose.push(this.clearOutputEmitter);
|
||||||
protected closing = false;
|
this.toDispose.push(
|
||||||
protected readonly clearOutputEmitter = new Emitter<void>();
|
Disposable.create(() => {
|
||||||
|
this.monitorConnection.autoConnect = false;
|
||||||
constructor() {
|
if (this.monitorConnection.connected) {
|
||||||
super();
|
this.monitorConnection.disconnect();
|
||||||
this.id = MonitorWidget.ID;
|
|
||||||
this.title.label = 'Serial Monitor';
|
|
||||||
this.title.iconClass = 'monitor-tab-icon';
|
|
||||||
this.title.closable = true;
|
|
||||||
this.scrollOptions = undefined;
|
|
||||||
this.toDispose.push(this.clearOutputEmitter);
|
|
||||||
this.toDispose.push(Disposable.create(() => {
|
|
||||||
this.monitorConnection.autoConnect = false;
|
|
||||||
if (this.monitorConnection.connected) {
|
|
||||||
this.monitorConnection.disconnect();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
@postConstruct()
|
|
||||||
protected init(): void {
|
|
||||||
this.update();
|
|
||||||
this.toDispose.push(this.monitorConnection.onConnectionChanged(() => this.clearConsole()));
|
|
||||||
}
|
|
||||||
|
|
||||||
clearConsole(): void {
|
|
||||||
this.clearOutputEmitter.fire(undefined);
|
|
||||||
this.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
dispose(): void {
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected onAfterAttach(msg: Message): void {
|
|
||||||
super.onAfterAttach(msg);
|
|
||||||
this.monitorConnection.autoConnect = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
onCloseRequest(msg: Message): void {
|
|
||||||
this.closing = true;
|
|
||||||
super.onCloseRequest(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected onUpdateRequest(msg: Message): void {
|
|
||||||
// TODO: `this.isAttached`
|
|
||||||
// See: https://github.com/eclipse-theia/theia/issues/6704#issuecomment-562574713
|
|
||||||
if (!this.closing && this.isAttached) {
|
|
||||||
super.onUpdateRequest(msg);
|
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected onResize(msg: Widget.ResizeMessage): void {
|
@postConstruct()
|
||||||
super.onResize(msg);
|
protected init(): void {
|
||||||
this.widgetHeight = msg.height;
|
this.update();
|
||||||
this.update();
|
this.toDispose.push(
|
||||||
}
|
this.monitorConnection.onConnectionChanged(() => this.clearConsole())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected onActivateRequest(msg: Message): void {
|
clearConsole(): void {
|
||||||
super.onActivateRequest(msg);
|
this.clearOutputEmitter.fire(undefined);
|
||||||
(this.focusNode || this.node).focus();
|
this.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected onFocusResolved = (element: HTMLElement | undefined) => {
|
dispose(): void {
|
||||||
if (this.closing || !this.isAttached) {
|
super.dispose();
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
this.focusNode = element;
|
|
||||||
requestAnimationFrame(() => MessageLoop.sendMessage(this, Widget.Msg.ActivateRequest));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected get lineEndings(): OptionsType<SelectOption<MonitorModel.EOL>> {
|
protected onAfterAttach(msg: Message): void {
|
||||||
return [
|
super.onAfterAttach(msg);
|
||||||
{
|
this.monitorConnection.autoConnect = true;
|
||||||
label: 'No Line Ending',
|
}
|
||||||
value: ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'New Line',
|
|
||||||
value: '\n'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Carriage Return',
|
|
||||||
value: '\r'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Both NL & CR',
|
|
||||||
value: '\r\n'
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected get baudRates(): OptionsType<SelectOption<MonitorConfig.BaudRate>> {
|
onCloseRequest(msg: Message): void {
|
||||||
const baudRates: Array<MonitorConfig.BaudRate> = [300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200];
|
this.closing = true;
|
||||||
return baudRates.map(baudRate => ({ label: baudRate + ' baud', value: baudRate }));
|
super.onCloseRequest(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render(): React.ReactNode {
|
protected onUpdateRequest(msg: Message): void {
|
||||||
const { baudRates, lineEndings } = this;
|
// TODO: `this.isAttached`
|
||||||
const lineEnding = lineEndings.find(item => item.value === this.monitorModel.lineEnding) || lineEndings[1]; // Defaults to `\n`.
|
// See: https://github.com/eclipse-theia/theia/issues/6704#issuecomment-562574713
|
||||||
const baudRate = baudRates.find(item => item.value === this.monitorModel.baudRate) || baudRates[4]; // Defaults to `9600`.
|
if (!this.closing && this.isAttached) {
|
||||||
return <div className='serial-monitor'>
|
super.onUpdateRequest(msg);
|
||||||
<div className='head'>
|
}
|
||||||
<div className='send'>
|
}
|
||||||
<SerialMonitorSendInput
|
|
||||||
monitorConfig={this.monitorConnection.monitorConfig}
|
protected onResize(msg: Widget.ResizeMessage): void {
|
||||||
resolveFocus={this.onFocusResolved}
|
super.onResize(msg);
|
||||||
onSend={this.onSend} />
|
this.widgetHeight = msg.height;
|
||||||
</div>
|
this.update();
|
||||||
<div className='config'>
|
}
|
||||||
<div className='select'>
|
|
||||||
<ArduinoSelect
|
protected onActivateRequest(msg: Message): void {
|
||||||
maxMenuHeight={this.widgetHeight - 40}
|
super.onActivateRequest(msg);
|
||||||
options={lineEndings}
|
(this.focusNode || this.node).focus();
|
||||||
defaultValue={lineEnding}
|
}
|
||||||
onChange={this.onChangeLineEnding} />
|
|
||||||
</div>
|
protected onFocusResolved = (element: HTMLElement | undefined) => {
|
||||||
<div className='select'>
|
if (this.closing || !this.isAttached) {
|
||||||
<ArduinoSelect
|
return;
|
||||||
className='select'
|
}
|
||||||
maxMenuHeight={this.widgetHeight - 40}
|
this.focusNode = element;
|
||||||
options={baudRates}
|
requestAnimationFrame(() =>
|
||||||
defaultValue={baudRate}
|
MessageLoop.sendMessage(this, Widget.Msg.ActivateRequest)
|
||||||
onChange={this.onChangeBaudRate} />
|
);
|
||||||
</div>
|
};
|
||||||
</div>
|
|
||||||
|
protected get lineEndings(): OptionsType<SelectOption<MonitorModel.EOL>> {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
label: 'No Line Ending',
|
||||||
|
value: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'New Line',
|
||||||
|
value: '\n',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Carriage Return',
|
||||||
|
value: '\r',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Both NL & CR',
|
||||||
|
value: '\r\n',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected get baudRates(): OptionsType<SelectOption<MonitorConfig.BaudRate>> {
|
||||||
|
const baudRates: Array<MonitorConfig.BaudRate> = [
|
||||||
|
300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200,
|
||||||
|
];
|
||||||
|
return baudRates.map((baudRate) => ({
|
||||||
|
label: baudRate + ' baud',
|
||||||
|
value: baudRate,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render(): React.ReactNode {
|
||||||
|
const { baudRates, lineEndings } = this;
|
||||||
|
const lineEnding =
|
||||||
|
lineEndings.find((item) => item.value === this.monitorModel.lineEnding) ||
|
||||||
|
lineEndings[1]; // Defaults to `\n`.
|
||||||
|
const baudRate =
|
||||||
|
baudRates.find((item) => item.value === this.monitorModel.baudRate) ||
|
||||||
|
baudRates[4]; // Defaults to `9600`.
|
||||||
|
return (
|
||||||
|
<div className="serial-monitor">
|
||||||
|
<div className="head">
|
||||||
|
<div className="send">
|
||||||
|
<SerialMonitorSendInput
|
||||||
|
monitorConfig={this.monitorConnection.monitorConfig}
|
||||||
|
resolveFocus={this.onFocusResolved}
|
||||||
|
onSend={this.onSend}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="config">
|
||||||
|
<div className="select">
|
||||||
|
<ArduinoSelect
|
||||||
|
maxMenuHeight={this.widgetHeight - 40}
|
||||||
|
options={lineEndings}
|
||||||
|
defaultValue={lineEnding}
|
||||||
|
onChange={this.onChangeLineEnding}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className='body'>
|
<div className="select">
|
||||||
<SerialMonitorOutput
|
<ArduinoSelect
|
||||||
monitorModel={this.monitorModel}
|
className="select"
|
||||||
monitorConnection={this.monitorConnection}
|
maxMenuHeight={this.widgetHeight - 40}
|
||||||
clearConsoleEvent={this.clearOutputEmitter.event} />
|
options={baudRates}
|
||||||
|
defaultValue={baudRate}
|
||||||
|
onChange={this.onChangeBaudRate}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>;
|
</div>
|
||||||
}
|
</div>
|
||||||
|
<div className="body">
|
||||||
|
<SerialMonitorOutput
|
||||||
|
monitorModel={this.monitorModel}
|
||||||
|
monitorConnection={this.monitorConnection}
|
||||||
|
clearConsoleEvent={this.clearOutputEmitter.event}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected readonly onSend = (value: string) => this.doSend(value);
|
protected readonly onSend = (value: string) => this.doSend(value);
|
||||||
protected async doSend(value: string): Promise<void> {
|
protected async doSend(value: string): Promise<void> {
|
||||||
this.monitorConnection.send(value);
|
this.monitorConnection.send(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected readonly onChangeLineEnding = (option: SelectOption<MonitorModel.EOL>) => {
|
protected readonly onChangeLineEnding = (
|
||||||
this.monitorModel.lineEnding = option.value;
|
option: SelectOption<MonitorModel.EOL>
|
||||||
}
|
) => {
|
||||||
|
this.monitorModel.lineEnding = option.value;
|
||||||
protected readonly onChangeBaudRate = (option: SelectOption<MonitorConfig.BaudRate>) => {
|
};
|
||||||
this.monitorModel.baudRate = option.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
protected readonly onChangeBaudRate = (
|
||||||
|
option: SelectOption<MonitorConfig.BaudRate>
|
||||||
|
) => {
|
||||||
|
this.monitorModel.baudRate = option.value;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace SerialMonitorSendInput {
|
export namespace SerialMonitorSendInput {
|
||||||
export interface Props {
|
export interface Props {
|
||||||
readonly monitorConfig?: MonitorConfig;
|
readonly monitorConfig?: MonitorConfig;
|
||||||
readonly onSend: (text: string) => void;
|
readonly onSend: (text: string) => void;
|
||||||
readonly resolveFocus: (element: HTMLElement | undefined) => void;
|
readonly resolveFocus: (element: HTMLElement | undefined) => void;
|
||||||
}
|
}
|
||||||
export interface State {
|
export interface State {
|
||||||
text: string;
|
text: string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SerialMonitorSendInput extends React.Component<SerialMonitorSendInput.Props, SerialMonitorSendInput.State> {
|
export class SerialMonitorSendInput extends React.Component<
|
||||||
|
SerialMonitorSendInput.Props,
|
||||||
|
SerialMonitorSendInput.State
|
||||||
|
> {
|
||||||
|
constructor(props: Readonly<SerialMonitorSendInput.Props>) {
|
||||||
|
super(props);
|
||||||
|
this.state = { text: '' };
|
||||||
|
this.onChange = this.onChange.bind(this);
|
||||||
|
this.onSend = this.onSend.bind(this);
|
||||||
|
this.onKeyDown = this.onKeyDown.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
constructor(props: Readonly<SerialMonitorSendInput.Props>) {
|
render(): React.ReactNode {
|
||||||
super(props);
|
return (
|
||||||
this.state = { text: '' };
|
<input
|
||||||
this.onChange = this.onChange.bind(this);
|
ref={this.setRef}
|
||||||
this.onSend = this.onSend.bind(this);
|
type="text"
|
||||||
this.onKeyDown = this.onKeyDown.bind(this);
|
className={`theia-input ${this.props.monitorConfig ? '' : 'warning'}`}
|
||||||
|
placeholder={this.placeholder}
|
||||||
|
value={this.state.text}
|
||||||
|
onChange={this.onChange}
|
||||||
|
onKeyDown={this.onKeyDown}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected get placeholder(): string {
|
||||||
|
const { monitorConfig } = this.props;
|
||||||
|
if (!monitorConfig) {
|
||||||
|
return 'Not connected. Select a board and a port to connect automatically.';
|
||||||
}
|
}
|
||||||
|
const { board, port } = monitorConfig;
|
||||||
|
return `Message (${
|
||||||
|
isOSX ? '⌘' : 'Ctrl'
|
||||||
|
}+Enter to send message to '${Board.toString(board, {
|
||||||
|
useFqbn: false,
|
||||||
|
})}' on '${Port.toString(port)}')`;
|
||||||
|
}
|
||||||
|
|
||||||
render(): React.ReactNode {
|
protected setRef = (element: HTMLElement | null) => {
|
||||||
return <input
|
if (this.props.resolveFocus) {
|
||||||
ref={this.setRef}
|
this.props.resolveFocus(element || undefined);
|
||||||
type='text'
|
|
||||||
className={`theia-input ${this.props.monitorConfig ? '' : 'warning'}`}
|
|
||||||
placeholder={this.placeholder}
|
|
||||||
value={this.state.text}
|
|
||||||
onChange={this.onChange}
|
|
||||||
onKeyDown={this.onKeyDown} />
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
protected get placeholder(): string {
|
protected onChange(event: React.ChangeEvent<HTMLInputElement>): void {
|
||||||
const { monitorConfig } = this.props;
|
this.setState({ text: event.target.value });
|
||||||
if (!monitorConfig) {
|
}
|
||||||
return 'Not connected. Select a board and a port to connect automatically.'
|
|
||||||
}
|
protected onSend(): void {
|
||||||
const { board, port } = monitorConfig;
|
this.props.onSend(this.state.text);
|
||||||
return `Message (${isOSX ? '⌘' : 'Ctrl'}+Enter to send message to '${Board.toString(board, { useFqbn: false })}' on '${Port.toString(port)}')`;
|
this.setState({ text: '' });
|
||||||
|
}
|
||||||
|
|
||||||
|
protected onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
|
||||||
|
const keyCode = KeyCode.createKeyCode(event.nativeEvent);
|
||||||
|
if (keyCode) {
|
||||||
|
const { key, meta, ctrl } = keyCode;
|
||||||
|
if (key === Key.ENTER && ((isOSX && meta) || (!isOSX && ctrl))) {
|
||||||
|
this.onSend();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
protected setRef = (element: HTMLElement | null) => {
|
|
||||||
if (this.props.resolveFocus) {
|
|
||||||
this.props.resolveFocus(element || undefined);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected onChange(event: React.ChangeEvent<HTMLInputElement>): void {
|
|
||||||
this.setState({ text: event.target.value });
|
|
||||||
}
|
|
||||||
|
|
||||||
protected onSend(): void {
|
|
||||||
this.props.onSend(this.state.text);
|
|
||||||
this.setState({ text: '' });
|
|
||||||
}
|
|
||||||
|
|
||||||
protected onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
|
|
||||||
const keyCode = KeyCode.createKeyCode(event.nativeEvent);
|
|
||||||
if (keyCode) {
|
|
||||||
const { key, meta, ctrl } = keyCode;
|
|
||||||
if (key === Key.ENTER && ((isOSX && meta) || (!isOSX && ctrl))) {
|
|
||||||
this.onSend();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace SerialMonitorOutput {
|
export namespace SerialMonitorOutput {
|
||||||
export interface Props {
|
export interface Props {
|
||||||
readonly monitorModel: MonitorModel;
|
readonly monitorModel: MonitorModel;
|
||||||
readonly monitorConnection: MonitorConnection;
|
readonly monitorConnection: MonitorConnection;
|
||||||
readonly clearConsoleEvent: Event<void>;
|
readonly clearConsoleEvent: Event<void>;
|
||||||
}
|
}
|
||||||
export interface State {
|
export interface State {
|
||||||
content: string;
|
content: string;
|
||||||
timestamp: boolean;
|
timestamp: boolean;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SerialMonitorOutput extends React.Component<SerialMonitorOutput.Props, SerialMonitorOutput.State> {
|
export class SerialMonitorOutput extends React.Component<
|
||||||
|
SerialMonitorOutput.Props,
|
||||||
|
SerialMonitorOutput.State
|
||||||
|
> {
|
||||||
|
/**
|
||||||
|
* Do not touch it. It is used to be able to "follow" the serial monitor log.
|
||||||
|
*/
|
||||||
|
protected anchor: HTMLElement | null;
|
||||||
|
protected toDisposeBeforeUnmount = new DisposableCollection();
|
||||||
|
|
||||||
/**
|
constructor(props: Readonly<SerialMonitorOutput.Props>) {
|
||||||
* Do not touch it. It is used to be able to "follow" the serial monitor log.
|
super(props);
|
||||||
*/
|
this.state = {
|
||||||
protected anchor: HTMLElement | null;
|
content: '',
|
||||||
protected toDisposeBeforeUnmount = new DisposableCollection();
|
timestamp: this.props.monitorModel.timestamp,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
constructor(props: Readonly<SerialMonitorOutput.Props>) {
|
render(): React.ReactNode {
|
||||||
super(props);
|
return (
|
||||||
this.state = { content: '', timestamp: this.props.monitorModel.timestamp };
|
<React.Fragment>
|
||||||
}
|
<div style={{ whiteSpace: 'pre', fontFamily: 'monospace' }}>
|
||||||
|
{this.state.content}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{ float: 'left', clear: 'both' }}
|
||||||
|
ref={(element) => {
|
||||||
|
this.anchor = element;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
render(): React.ReactNode {
|
componentDidMount(): void {
|
||||||
return <React.Fragment>
|
this.scrollToBottom();
|
||||||
<div style={({ whiteSpace: 'pre', fontFamily: 'monospace' })}>
|
this.toDisposeBeforeUnmount.pushAll([
|
||||||
{this.state.content}
|
this.props.monitorConnection.onRead(({ message }) => {
|
||||||
</div>
|
const rawLines = message.split('\n');
|
||||||
<div style={{ float: 'left', clear: 'both' }} ref={element => { this.anchor = element; }} />
|
const lines: string[] = [];
|
||||||
</React.Fragment>;
|
const timestamp = () =>
|
||||||
}
|
this.state.timestamp
|
||||||
|
? `${dateFormat(new Date(), 'H:M:ss.l')} -> `
|
||||||
componentDidMount(): void {
|
: '';
|
||||||
this.scrollToBottom();
|
for (let i = 0; i < rawLines.length; i++) {
|
||||||
this.toDisposeBeforeUnmount.pushAll([
|
if (i === 0 && this.state.content.length !== 0) {
|
||||||
this.props.monitorConnection.onRead(({ data }) => {
|
lines.push(rawLines[i]);
|
||||||
const rawLines = data.split('\n');
|
} else {
|
||||||
const lines: string[] = []
|
lines.push(timestamp() + rawLines[i]);
|
||||||
const timestamp = () => this.state.timestamp ? `${dateFormat(new Date(), 'H:M:ss.l')} -> ` : '';
|
}
|
||||||
for (let i = 0; i < rawLines.length; i++) {
|
|
||||||
if (i === 0 && this.state.content.length !== 0) {
|
|
||||||
lines.push(rawLines[i]);
|
|
||||||
} else {
|
|
||||||
lines.push(timestamp() + rawLines[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const content = this.state.content + lines.join('\n');
|
|
||||||
this.setState({ content });
|
|
||||||
}),
|
|
||||||
this.props.clearConsoleEvent(() => this.setState({ content: '' })),
|
|
||||||
this.props.monitorModel.onChange(({ property }) => {
|
|
||||||
if (property === 'timestamp') {
|
|
||||||
const { timestamp } = this.props.monitorModel;
|
|
||||||
this.setState({ timestamp });
|
|
||||||
}
|
|
||||||
})
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
componentDidUpdate(): void {
|
|
||||||
this.scrollToBottom();
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillUnmount(): void {
|
|
||||||
// TODO: "Your preferred browser's local storage is almost full." Discard `content` before saving layout?
|
|
||||||
this.toDisposeBeforeUnmount.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected scrollToBottom(): void {
|
|
||||||
if (this.props.monitorModel.autoscroll && this.anchor) {
|
|
||||||
this.anchor.scrollIntoView();
|
|
||||||
}
|
}
|
||||||
}
|
const content = this.state.content + lines.join('\n');
|
||||||
|
this.setState({ content });
|
||||||
|
}),
|
||||||
|
this.props.clearConsoleEvent(() => this.setState({ content: '' })),
|
||||||
|
this.props.monitorModel.onChange(({ property }) => {
|
||||||
|
if (property === 'timestamp') {
|
||||||
|
const { timestamp } = this.props.monitorModel;
|
||||||
|
this.setState({ timestamp });
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate(): void {
|
||||||
|
this.scrollToBottom();
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount(): void {
|
||||||
|
// TODO: "Your preferred browser's local storage is almost full." Discard `content` before saving layout?
|
||||||
|
this.toDisposeBeforeUnmount.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected scrollToBottom(): void {
|
||||||
|
if (this.props.monitorModel.autoscroll && this.anchor) {
|
||||||
|
this.anchor.scrollIntoView();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SelectOption<T> {
|
export interface SelectOption<T> {
|
||||||
readonly label: string;
|
readonly label: string;
|
||||||
readonly value: T;
|
readonly value: T;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,96 +3,118 @@ import { Emitter } from '@theia/core/lib/common/event';
|
|||||||
import { JsonRpcProxy } from '@theia/core/lib/common/messaging/proxy-factory';
|
import { JsonRpcProxy } from '@theia/core/lib/common/messaging/proxy-factory';
|
||||||
import { DisposableCollection } from '@theia/core/lib/common/disposable';
|
import { DisposableCollection } from '@theia/core/lib/common/disposable';
|
||||||
import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application';
|
import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application';
|
||||||
import { NotificationServiceClient, NotificationServiceServer } from '../common/protocol/notification-service';
|
import {
|
||||||
import { AttachedBoardsChangeEvent, BoardsPackage, LibraryPackage, Config, Sketch } from '../common/protocol';
|
NotificationServiceClient,
|
||||||
|
NotificationServiceServer,
|
||||||
|
} from '../common/protocol/notification-service';
|
||||||
|
import {
|
||||||
|
AttachedBoardsChangeEvent,
|
||||||
|
BoardsPackage,
|
||||||
|
LibraryPackage,
|
||||||
|
Config,
|
||||||
|
Sketch,
|
||||||
|
} from '../common/protocol';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class NotificationCenter implements NotificationServiceClient, FrontendApplicationContribution {
|
export class NotificationCenter
|
||||||
|
implements NotificationServiceClient, FrontendApplicationContribution
|
||||||
|
{
|
||||||
|
@inject(NotificationServiceServer)
|
||||||
|
protected readonly server: JsonRpcProxy<NotificationServiceServer>;
|
||||||
|
|
||||||
@inject(NotificationServiceServer)
|
protected readonly indexUpdatedEmitter = new Emitter<void>();
|
||||||
protected readonly server: JsonRpcProxy<NotificationServiceServer>;
|
protected readonly daemonStartedEmitter = new Emitter<void>();
|
||||||
|
protected readonly daemonStoppedEmitter = new Emitter<void>();
|
||||||
|
protected readonly configChangedEmitter = new Emitter<{
|
||||||
|
config: Config | undefined;
|
||||||
|
}>();
|
||||||
|
protected readonly platformInstalledEmitter = new Emitter<{
|
||||||
|
item: BoardsPackage;
|
||||||
|
}>();
|
||||||
|
protected readonly platformUninstalledEmitter = new Emitter<{
|
||||||
|
item: BoardsPackage;
|
||||||
|
}>();
|
||||||
|
protected readonly libraryInstalledEmitter = new Emitter<{
|
||||||
|
item: LibraryPackage;
|
||||||
|
}>();
|
||||||
|
protected readonly libraryUninstalledEmitter = new Emitter<{
|
||||||
|
item: LibraryPackage;
|
||||||
|
}>();
|
||||||
|
protected readonly attachedBoardsChangedEmitter =
|
||||||
|
new Emitter<AttachedBoardsChangeEvent>();
|
||||||
|
protected readonly recentSketchesChangedEmitter = new Emitter<{
|
||||||
|
sketches: Sketch[];
|
||||||
|
}>();
|
||||||
|
|
||||||
protected readonly indexUpdatedEmitter = new Emitter<void>();
|
protected readonly toDispose = new DisposableCollection(
|
||||||
protected readonly daemonStartedEmitter = new Emitter<void>();
|
this.indexUpdatedEmitter,
|
||||||
protected readonly daemonStoppedEmitter = new Emitter<void>();
|
this.daemonStartedEmitter,
|
||||||
protected readonly configChangedEmitter = new Emitter<{ config: Config | undefined }>();
|
this.daemonStoppedEmitter,
|
||||||
protected readonly platformInstalledEmitter = new Emitter<{ item: BoardsPackage }>();
|
this.configChangedEmitter,
|
||||||
protected readonly platformUninstalledEmitter = new Emitter<{ item: BoardsPackage }>();
|
this.platformInstalledEmitter,
|
||||||
protected readonly libraryInstalledEmitter = new Emitter<{ item: LibraryPackage }>();
|
this.platformUninstalledEmitter,
|
||||||
protected readonly libraryUninstalledEmitter = new Emitter<{ item: LibraryPackage }>();
|
this.libraryInstalledEmitter,
|
||||||
protected readonly attachedBoardsChangedEmitter = new Emitter<AttachedBoardsChangeEvent>();
|
this.libraryUninstalledEmitter,
|
||||||
protected readonly recentSketchesChangedEmitter = new Emitter<{ sketches: Sketch[] }>();
|
this.attachedBoardsChangedEmitter
|
||||||
|
);
|
||||||
|
|
||||||
protected readonly toDispose = new DisposableCollection(
|
readonly onIndexUpdated = this.indexUpdatedEmitter.event;
|
||||||
this.indexUpdatedEmitter,
|
readonly onDaemonStarted = this.daemonStartedEmitter.event;
|
||||||
this.daemonStartedEmitter,
|
readonly onDaemonStopped = this.daemonStoppedEmitter.event;
|
||||||
this.daemonStoppedEmitter,
|
readonly onConfigChanged = this.configChangedEmitter.event;
|
||||||
this.configChangedEmitter,
|
readonly onPlatformInstalled = this.platformInstalledEmitter.event;
|
||||||
this.platformInstalledEmitter,
|
readonly onPlatformUninstalled = this.platformUninstalledEmitter.event;
|
||||||
this.platformUninstalledEmitter,
|
readonly onLibraryInstalled = this.libraryInstalledEmitter.event;
|
||||||
this.libraryInstalledEmitter,
|
readonly onLibraryUninstalled = this.libraryUninstalledEmitter.event;
|
||||||
this.libraryUninstalledEmitter,
|
readonly onAttachedBoardsChanged = this.attachedBoardsChangedEmitter.event;
|
||||||
this.attachedBoardsChangedEmitter
|
readonly onRecentSketchesChanged = this.recentSketchesChangedEmitter.event;
|
||||||
);
|
|
||||||
|
|
||||||
readonly onIndexUpdated = this.indexUpdatedEmitter.event;
|
@postConstruct()
|
||||||
readonly onDaemonStarted = this.daemonStartedEmitter.event;
|
protected init(): void {
|
||||||
readonly onDaemonStopped = this.daemonStoppedEmitter.event;
|
this.server.setClient(this);
|
||||||
readonly onConfigChanged = this.configChangedEmitter.event;
|
}
|
||||||
readonly onPlatformInstalled = this.platformInstalledEmitter.event;
|
|
||||||
readonly onPlatformUninstalled = this.platformUninstalledEmitter.event;
|
|
||||||
readonly onLibraryInstalled = this.libraryInstalledEmitter.event;
|
|
||||||
readonly onLibraryUninstalled = this.libraryUninstalledEmitter.event;
|
|
||||||
readonly onAttachedBoardsChanged = this.attachedBoardsChangedEmitter.event;
|
|
||||||
readonly onRecentSketchesChanged = this.recentSketchesChangedEmitter.event;
|
|
||||||
|
|
||||||
@postConstruct()
|
onStop(): void {
|
||||||
protected init(): void {
|
this.toDispose.dispose();
|
||||||
this.server.setClient(this);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
onStop(): void {
|
notifyIndexUpdated(): void {
|
||||||
this.toDispose.dispose();
|
this.indexUpdatedEmitter.fire();
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyIndexUpdated(): void {
|
notifyDaemonStarted(): void {
|
||||||
this.indexUpdatedEmitter.fire();
|
this.daemonStartedEmitter.fire();
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyDaemonStarted(): void {
|
notifyDaemonStopped(): void {
|
||||||
this.daemonStartedEmitter.fire();
|
this.daemonStoppedEmitter.fire();
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyDaemonStopped(): void {
|
notifyConfigChanged(event: { config: Config | undefined }): void {
|
||||||
this.daemonStoppedEmitter.fire();
|
this.configChangedEmitter.fire(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyConfigChanged(event: { config: Config | undefined }): void {
|
notifyPlatformInstalled(event: { item: BoardsPackage }): void {
|
||||||
this.configChangedEmitter.fire(event);
|
this.platformInstalledEmitter.fire(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyPlatformInstalled(event: { item: BoardsPackage }): void {
|
notifyPlatformUninstalled(event: { item: BoardsPackage }): void {
|
||||||
this.platformInstalledEmitter.fire(event);
|
this.platformUninstalledEmitter.fire(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyPlatformUninstalled(event: { item: BoardsPackage }): void {
|
notifyLibraryInstalled(event: { item: LibraryPackage }): void {
|
||||||
this.platformUninstalledEmitter.fire(event);
|
this.libraryInstalledEmitter.fire(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyLibraryInstalled(event: { item: LibraryPackage }): void {
|
notifyLibraryUninstalled(event: { item: LibraryPackage }): void {
|
||||||
this.libraryInstalledEmitter.fire(event);
|
this.libraryUninstalledEmitter.fire(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyLibraryUninstalled(event: { item: LibraryPackage }): void {
|
notifyAttachedBoardsChanged(event: AttachedBoardsChangeEvent): void {
|
||||||
this.libraryUninstalledEmitter.fire(event);
|
this.attachedBoardsChangedEmitter.fire(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyAttachedBoardsChanged(event: AttachedBoardsChangeEvent): void {
|
|
||||||
this.attachedBoardsChangedEmitter.fire(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
notifyRecentSketchesChanged(event: { sketches: Sketch[] }): void {
|
|
||||||
this.recentSketchesChangedEmitter.fire(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
notifyRecentSketchesChanged(event: { sketches: Sketch[] }): void {
|
||||||
|
this.recentSketchesChangedEmitter.fire(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
import { inject, injectable } from 'inversify';
|
|
||||||
import { OutputContribution } from '@theia/output/lib/browser/output-contribution';
|
|
||||||
import { OutputChannelManager } from '@theia/output/lib/common/output-channel';
|
|
||||||
import { OutputService, OutputMessage } from '../common/protocol/output-service';
|
|
||||||
|
|
||||||
@injectable()
|
|
||||||
export class OutputServiceImpl implements OutputService {
|
|
||||||
|
|
||||||
@inject(OutputContribution)
|
|
||||||
protected outputContribution: OutputContribution;
|
|
||||||
|
|
||||||
@inject(OutputChannelManager)
|
|
||||||
protected outputChannelManager: OutputChannelManager;
|
|
||||||
|
|
||||||
append(message: OutputMessage): void {
|
|
||||||
const { chunk } = message;
|
|
||||||
const channel = this.outputChannelManager.getChannel(`Arduino`);
|
|
||||||
channel.show({ preserveFocus: true });
|
|
||||||
channel.append(chunk);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
36
arduino-ide-extension/src/browser/response-service-impl.ts
Normal file
36
arduino-ide-extension/src/browser/response-service-impl.ts
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import { inject, injectable } from 'inversify';
|
||||||
|
import { Emitter } from '@theia/core/lib/common/event';
|
||||||
|
import { OutputContribution } from '@theia/output/lib/browser/output-contribution';
|
||||||
|
import { OutputChannelManager } from '@theia/output/lib/common/output-channel';
|
||||||
|
import {
|
||||||
|
ResponseService,
|
||||||
|
OutputMessage,
|
||||||
|
ProgressMessage,
|
||||||
|
} from '../common/protocol/response-service';
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class ResponseServiceImpl implements ResponseService {
|
||||||
|
@inject(OutputContribution)
|
||||||
|
protected outputContribution: OutputContribution;
|
||||||
|
|
||||||
|
@inject(OutputChannelManager)
|
||||||
|
protected outputChannelManager: OutputChannelManager;
|
||||||
|
|
||||||
|
protected readonly progressDidChangeEmitter = new Emitter<ProgressMessage>();
|
||||||
|
readonly onProgressDidChange = this.progressDidChangeEmitter.event;
|
||||||
|
|
||||||
|
appendToOutput(message: OutputMessage): void {
|
||||||
|
const { chunk } = message;
|
||||||
|
const channel = this.outputChannelManager.getChannel('Arduino');
|
||||||
|
channel.show({ preserveFocus: true });
|
||||||
|
channel.append(chunk);
|
||||||
|
}
|
||||||
|
|
||||||
|
clearArduinoChannel(): void {
|
||||||
|
this.outputChannelManager.getChannel('Arduino').clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
reportProgress(progress: ProgressMessage): void {
|
||||||
|
this.progressDidChangeEmitter.fire(progress);
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
37
arduino-ide-extension/src/browser/storage-wrapper.ts
Normal file
37
arduino-ide-extension/src/browser/storage-wrapper.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import { injectable, inject } from 'inversify';
|
||||||
|
import { StorageService } from '@theia/core/lib/browser/storage-service';
|
||||||
|
import {
|
||||||
|
Command,
|
||||||
|
CommandContribution,
|
||||||
|
CommandRegistry,
|
||||||
|
} from '@theia/core/lib/common/command';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a workaround to break cycles in the dependency injection. Provides commands for `setData` and `getData`.
|
||||||
|
*/
|
||||||
|
@injectable()
|
||||||
|
export class StorageWrapper implements CommandContribution {
|
||||||
|
@inject(StorageService)
|
||||||
|
protected storageService: StorageService;
|
||||||
|
|
||||||
|
registerCommands(commands: CommandRegistry): void {
|
||||||
|
commands.registerCommand(StorageWrapper.Commands.GET_DATA, {
|
||||||
|
execute: (key: string, defaultValue?: any) =>
|
||||||
|
this.storageService.getData(key, defaultValue),
|
||||||
|
});
|
||||||
|
commands.registerCommand(StorageWrapper.Commands.SET_DATA, {
|
||||||
|
execute: (key: string, value: any) =>
|
||||||
|
this.storageService.setData(key, value),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export namespace StorageWrapper {
|
||||||
|
export namespace Commands {
|
||||||
|
export const SET_DATA: Command = {
|
||||||
|
id: 'arduino-store-wrapper-set',
|
||||||
|
};
|
||||||
|
export const GET_DATA: Command = {
|
||||||
|
id: 'arduino-store-wrapper-get',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
1
arduino-ide-extension/src/browser/style/account-icon.svg
Normal file
1
arduino-ide-extension/src/browser/style/account-icon.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" width="1em" height="1em" style="-ms-transform: rotate(360deg); -webkit-transform: rotate(360deg); transform: rotate(360deg);" preserveAspectRatio="xMidYMid meet" viewBox="0 0 16 16"><g fill="#626262"><path d="M16 7.992C16 3.58 12.416 0 8 0S0 3.58 0 7.992c0 2.43 1.104 4.62 2.832 6.09c.016.016.032.016.032.032c.144.112.288.224.448.336c.08.048.144.111.224.175A7.98 7.98 0 0 0 8.016 16a7.98 7.98 0 0 0 4.48-1.375c.08-.048.144-.111.224-.16c.144-.111.304-.223.448-.335c.016-.016.032-.016.032-.032c1.696-1.487 2.8-3.676 2.8-6.106zm-8 7.001c-1.504 0-2.88-.48-4.016-1.279c.016-.128.048-.255.08-.383a4.17 4.17 0 0 1 .416-.991c.176-.304.384-.576.64-.816c.24-.24.528-.463.816-.639c.304-.176.624-.304.976-.4A4.15 4.15 0 0 1 8 10.342a4.185 4.185 0 0 1 2.928 1.166c.368.368.656.8.864 1.295c.112.288.192.592.24.911A7.03 7.03 0 0 1 8 14.993zm-2.448-7.4a2.49 2.49 0 0 1-.208-1.024c0-.351.064-.703.208-1.023c.144-.32.336-.607.576-.847c.24-.24.528-.431.848-.575c.32-.144.672-.208 1.024-.208c.368 0 .704.064 1.024.208c.32.144.608.336.848.575c.24.24.432.528.576.847c.144.32.208.672.208 1.023c0 .368-.064.704-.208 1.023a2.84 2.84 0 0 1-.576.848a2.84 2.84 0 0 1-.848.575a2.715 2.715 0 0 1-2.064 0a2.84 2.84 0 0 1-.848-.575a2.526 2.526 0 0 1-.56-.848zm7.424 5.306c0-.032-.016-.048-.016-.08a5.22 5.22 0 0 0-.688-1.406a4.883 4.883 0 0 0-1.088-1.135a5.207 5.207 0 0 0-1.04-.608a2.82 2.82 0 0 0 .464-.383a4.2 4.2 0 0 0 .624-.784a3.624 3.624 0 0 0 .528-1.934a3.71 3.71 0 0 0-.288-1.47a3.799 3.799 0 0 0-.816-1.199a3.845 3.845 0 0 0-1.2-.8a3.72 3.72 0 0 0-1.472-.287a3.72 3.72 0 0 0-1.472.288a3.631 3.631 0 0 0-1.2.815a3.84 3.84 0 0 0-.8 1.199a3.71 3.71 0 0 0-.288 1.47c0 .352.048.688.144 1.007c.096.336.224.64.4.927c.16.288.384.544.624.784c.144.144.304.271.48.383a5.12 5.12 0 0 0-1.04.624c-.416.32-.784.703-1.088 1.119a4.999 4.999 0 0 0-.688 1.406c-.016.032-.016.064-.016.08C1.776 11.636.992 9.91.992 7.992C.992 4.14 4.144.991 8 .991s7.008 3.149 7.008 7.001a6.96 6.96 0 0 1-2.032 4.907z"/></g></svg>
|
||||||
|
After Width: | Height: | Size: 2.0 KiB |
@@ -1,5 +1,5 @@
|
|||||||
div#select-board-dialog {
|
div#select-board-dialog {
|
||||||
margin: 5px 20px 50px 20px;
|
margin: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
div#select-board-dialog .selectBoardContainer .body {
|
div#select-board-dialog .selectBoardContainer .body {
|
||||||
@@ -7,8 +7,8 @@ div#select-board-dialog .selectBoardContainer .body {
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.dialogContent.select-board-dialog > div.head {
|
.select-board-dialog .head {
|
||||||
padding-left: 21px;
|
margin: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.dialogContent.select-board-dialog > div.head .title {
|
div.dialogContent.select-board-dialog > div.head .title {
|
||||||
@@ -16,11 +16,7 @@ div.dialogContent.select-board-dialog > div.head .title {
|
|||||||
letter-spacing: .02em;
|
letter-spacing: .02em;
|
||||||
font-size: 1.2em;
|
font-size: 1.2em;
|
||||||
color: var(--theia-arduino-branding-primary);
|
color: var(--theia-arduino-branding-primary);
|
||||||
margin: 17px 0;
|
margin-bottom: 10px;
|
||||||
}
|
|
||||||
|
|
||||||
div#select-board-dialog .selectBoardContainer .head .text {
|
|
||||||
margin-bottom: 21px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
div#select-board-dialog .selectBoardContainer .body .list .item.selected {
|
div#select-board-dialog .selectBoardContainer .body .list .item.selected {
|
||||||
@@ -57,6 +53,8 @@ div#select-board-dialog .selectBoardContainer .body .list .item.selected i {
|
|||||||
#select-board-dialog .selectBoardContainer .body .container {
|
#select-board-dialog .selectBoardContainer .body .container {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
padding: 0px 10px 0px 0px;
|
padding: 0px 10px 0px 0px;
|
||||||
|
min-width: 240px;
|
||||||
|
max-width: 240px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#select-board-dialog .selectBoardContainer .body .left.container .content {
|
#select-board-dialog .selectBoardContainer .body .left.container .content {
|
||||||
@@ -82,15 +80,17 @@ div#select-board-dialog .selectBoardContainer .body .list .item.selected i {
|
|||||||
color: var(--theia-arduino-branding-secondary);
|
color: var(--theia-arduino-branding-secondary);
|
||||||
padding: 10px 5px 10px 10px;
|
padding: 10px 5px 10px 10px;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
/* The max, min-height comes from `.body .list` 265px + 47px top padding - 2 * 10px top padding */
|
/* The max, min-height comes from `.body .list` 200px + 47px top padding - 2 * 10px top padding */
|
||||||
max-height: 292px;
|
max-height: 227px;
|
||||||
min-height: 292px;
|
min-height: 227px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#select-board-dialog .selectBoardContainer .body .list .item {
|
#select-board-dialog .selectBoardContainer .body .list .item {
|
||||||
padding: 10px 5px 10px 10px;
|
padding: 10px 5px 10px 10px;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: end;
|
justify-content: end;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow-x: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
#select-board-dialog .selectBoardContainer .body .list .item .selected-icon {
|
#select-board-dialog .selectBoardContainer .body .list .item .selected-icon {
|
||||||
@@ -114,9 +114,17 @@ div#select-board-dialog .selectBoardContainer .body .list .item.selected i {
|
|||||||
background: var(--theia-secondaryButton-hoverBackground);
|
background: var(--theia-secondaryButton-hoverBackground);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#select-board-dialog .selectBoardContainer .body .list .label {
|
||||||
|
max-width: 215px;
|
||||||
|
width: 215px;
|
||||||
|
white-space: pre;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
#select-board-dialog .selectBoardContainer .body .list {
|
#select-board-dialog .selectBoardContainer .body .list {
|
||||||
max-height: 265px;
|
max-height: 200px;
|
||||||
min-height: 265px;
|
min-height: 200px;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,14 +140,8 @@ div#select-board-dialog .selectBoardContainer .body .list .item.selected i {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.p-Widget.dialogOverlay .dialogContent.select-board-dialog {
|
.p-Widget.dialogOverlay .dialogContent.select-board-dialog {
|
||||||
width: 740px;
|
width: 500px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.dialogControl {
|
|
||||||
margin: 0 20px 30px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.arduino-boards-toolbar-item-container {
|
.arduino-boards-toolbar-item-container {
|
||||||
margin-left: 3px;
|
margin-left: 3px;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
.certificate-uploader-dialog {
|
||||||
|
width: 600px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.certificate-uploader-dialog .theia-select {
|
||||||
|
border: none !important;
|
||||||
|
}
|
||||||
|
.certificate-uploader-dialog .arduino-select__control {
|
||||||
|
height: 31px;
|
||||||
|
background: var(--theia-menubar-selectionBackground) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.certificate-uploader-dialog .dialogRow > button{
|
||||||
|
margin-right: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.certificate-uploader-dialog .certificate-list {
|
||||||
|
border: 1px solid #BDC7C7;
|
||||||
|
border-radius: 2px;;
|
||||||
|
background: var(--theia-menubar-selectionBackground) !important;
|
||||||
|
overflow: auto;
|
||||||
|
height: 120px;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
.certificate-uploader-dialog .certificate-list .certificate-row {
|
||||||
|
display: flex;
|
||||||
|
padding: 6px 10px 5px 10px
|
||||||
|
}
|
||||||
|
.certificate-uploader-dialog .certificate-list .certificate-row:hover {
|
||||||
|
background-color: var(--theia-list-activeSelectionBackground);
|
||||||
|
}
|
||||||
|
|
||||||
|
.certificate-uploader-dialog .upload-status {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
.certificate-uploader-dialog .success {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
color: #1DA086;
|
||||||
|
}
|
||||||
|
|
||||||
|
.certificate-uploader-dialog .warn {
|
||||||
|
color: #C11F09;
|
||||||
|
}
|
||||||
|
|
||||||
|
.certificate-uploader-dialog .status-icon {
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.certificate-uploader-dialog .add-cert-btn {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
.certificate-uploader-dialog .add-cert-btn .caret {
|
||||||
|
margin-left: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.certificate-add {
|
||||||
|
padding: 16px;
|
||||||
|
background-color: var(--theia-list-hoverBackground);
|
||||||
|
border-radius: 3px;
|
||||||
|
border: 1px solid #BDC7C7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.certificate-add input {
|
||||||
|
margin-top: 12px;
|
||||||
|
padding: 0 12px;
|
||||||
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M3.54383 11.5H0.612583C0.129139 9.86839 0.129139 8.13161 0.612583 6.5H3.54383C3.42911 7.32835 3.37272 8.16374 3.37508 9C3.37272 9.83626 3.42911 10.6716 3.54383 11.5Z" fill="#616161"/>
|
||||||
|
<path d="M3.775 12.75C4.08097 14.3119 4.72054 15.7893 5.65 17.0812C3.6488 16.2492 2.02597 14.7065 1.09375 12.75H3.775Z" fill="#616161"/>
|
||||||
|
<path d="M3.775 5.25001H1.09375C2.02597 3.29347 3.6488 1.75079 5.65 0.918762C4.72054 2.21073 4.08097 3.68814 3.775 5.25001Z" fill="#616161"/>
|
||||||
|
<path d="M8.375 0.34375V5.25H5.0625C5.69375 2.6875 6.93125 0.775 8.375 0.34375Z" fill="#616161"/>
|
||||||
|
<path d="M4.81248 6.5H8.37498V11.5H4.81248C4.56251 9.84271 4.56251 8.15729 4.81248 6.5Z" fill="#616161"/>
|
||||||
|
<path d="M5.0625 12.75H8.375V17.6562C6.93125 17.225 5.69375 15.3125 5.0625 12.75Z" fill="#616161"/>
|
||||||
|
<path d="M12.9375 12.75C12.3125 15.3125 11.0625 17.225 9.625 17.6562V12.75H12.9375Z" fill="#616161"/>
|
||||||
|
<path d="M12.9375 5.25H9.625V0.34375C11.0688 0.775 12.3063 2.6875 12.9375 5.25Z" fill="#616161"/>
|
||||||
|
<path d="M13.1875 11.5H9.625V6.5H13.1875C13.3115 7.32757 13.3742 8.16318 13.375 9C13.3742 9.83682 13.3115 10.6724 13.1875 11.5Z" fill="#616161"/>
|
||||||
|
<path d="M14.2251 12.75H16.9063C15.9741 14.7065 14.3513 16.2492 12.3501 17.0812C13.2796 15.7893 13.9191 14.3119 14.2251 12.75Z" fill="#616161"/>
|
||||||
|
<path d="M14.2251 5.25001C13.9191 3.68814 13.2796 2.21073 12.3501 0.918762C14.3513 1.75079 15.9741 3.29347 16.9063 5.25001H14.2251Z" fill="#616161"/>
|
||||||
|
<path d="M17.7503 9C17.7517 9.84653 17.6296 10.6887 17.3878 11.5H14.4565C14.5713 10.6716 14.6277 9.83626 14.6253 9C14.6277 8.16374 14.5713 7.32835 14.4565 6.5H17.3878C17.6296 7.31126 17.7517 8.15347 17.7503 9Z" fill="#616161"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 1.7 KiB |
184
arduino-ide-extension/src/browser/style/cloud-sketchbook.css
Normal file
184
arduino-ide-extension/src/browser/style/cloud-sketchbook.css
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
.sign-in-title {
|
||||||
|
margin: 20px 0;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.sign-in-desc {
|
||||||
|
margin: 20px;
|
||||||
|
line-height: 150%;
|
||||||
|
}
|
||||||
|
.sign-in-cta {
|
||||||
|
margin-left: 0 !important;
|
||||||
|
}
|
||||||
|
.sign-in-learnmore {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.cloud-sketchbook-tree-icon {
|
||||||
|
background: url("./cloud-sketchbook-tree-icon.svg") center center no-repeat;
|
||||||
|
width: var(--theia-icon-size);
|
||||||
|
height: var(--theia-icon-size);
|
||||||
|
background-size: auto 90%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sketchbook-trees-container
|
||||||
|
.p-TabBar[data-orientation="horizontal"]
|
||||||
|
> .p-TabBar-content {
|
||||||
|
justify-content: center;
|
||||||
|
border-bottom: 1px solid var(--theia-tree-indentGuidesStroke);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sketchbook-trees-container
|
||||||
|
.p-Widget.p-TabBar.p-DockPanel-tabBar
|
||||||
|
> ul
|
||||||
|
> li.p-TabBar-tab
|
||||||
|
> div.p-TabBar-tabLabel {
|
||||||
|
display: none;
|
||||||
|
width: 0px;
|
||||||
|
max-width: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sketchbook-trees-container
|
||||||
|
.p-Widget.p-TabBar.p-DockPanel-tabBar
|
||||||
|
> ul
|
||||||
|
> li.p-TabBar-tab
|
||||||
|
> div.p-TabBar-tabCloseIcon {
|
||||||
|
display: none;
|
||||||
|
width: 0px;
|
||||||
|
max-width: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sketchbook-trees-container
|
||||||
|
.p-TabBar[data-orientation="horizontal"]
|
||||||
|
.p-TabBar-tab {
|
||||||
|
min-width: 55px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sketchbook-trees-container
|
||||||
|
.p-Widget.p-TabBar.p-DockPanel-tabBar
|
||||||
|
> ul
|
||||||
|
> li.p-TabBar-tab {
|
||||||
|
padding-left: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sketchbook-trees-container
|
||||||
|
.p-Widget.p-TabBar.p-DockPanel-tabBar
|
||||||
|
> ul
|
||||||
|
> li.p-TabBar-tab.p-mod-current {
|
||||||
|
border-bottom: 2px solid var(--theia-statusBar-background);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sketchbook-trees-container .center {
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cloud-sketchbook-welcome {
|
||||||
|
flex-direction: column;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cloud-sketchbook-welcome > .item {
|
||||||
|
align-items: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cloud-sketchbook-welcome > .item .link {
|
||||||
|
cursor: pointer;
|
||||||
|
color: var(--theia-arduino-branding-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.pull-sketch-icon {
|
||||||
|
background: url("./pull-sketch-icon.svg") center center no-repeat;
|
||||||
|
width: var(--theia-icon-size);
|
||||||
|
height: var(--theia-icon-size);
|
||||||
|
}
|
||||||
|
|
||||||
|
.push-sketch-icon {
|
||||||
|
background: url("./push-sketch-icon.svg") center center no-repeat;
|
||||||
|
width: var(--theia-icon-size);
|
||||||
|
height: var(--theia-icon-size);
|
||||||
|
}
|
||||||
|
|
||||||
|
.account-icon {
|
||||||
|
background: url("./account-icon.svg") center center no-repeat;
|
||||||
|
width: var(--theia-icon-size);
|
||||||
|
height: var(--theia-icon-size);
|
||||||
|
border-radius: 50%;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.account-icon > img {
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.connected-status-icon {
|
||||||
|
background: url("./connected-status-icon.svg") center center no-repeat;
|
||||||
|
width: var(--theia-icon-size);
|
||||||
|
height: var(--theia-icon-size);
|
||||||
|
}
|
||||||
|
|
||||||
|
.offline-status-icon {
|
||||||
|
background: url("./offline-status-icon.svg") center center no-repeat;
|
||||||
|
width: var(--theia-icon-size);
|
||||||
|
height: var(--theia-icon-size);
|
||||||
|
}
|
||||||
|
|
||||||
|
.refresh-icon {
|
||||||
|
background: url("./refresh-icon.svg") center center no-repeat;
|
||||||
|
width: var(--theia-icon-size);
|
||||||
|
height: var(--theia-icon-size);
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes rotating {
|
||||||
|
from {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.rotating {
|
||||||
|
animation: rotating 1s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cloud-connection-status {
|
||||||
|
border-top: 1px solid var(--theia-tree-indentGuidesStroke);
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cloud-connection-status .item {
|
||||||
|
padding: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cloud-connection-status .status {
|
||||||
|
flex-grow: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cloud-connection-status .actions {
|
||||||
|
border-left: 1px solid var(--theia-tree-indentGuidesStroke);
|
||||||
|
border-right: 1px solid var(--theia-tree-indentGuidesStroke);
|
||||||
|
}
|
||||||
|
|
||||||
|
.composite-node {
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column-reverse;
|
||||||
|
}
|
||||||
|
|
||||||
|
.composite-node .tree-container {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.arduino-share-sketch-dialog .sketch-link {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.arduino-share-sketch-dialog .sketch-link input {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.arduino-share-sketch-dialog .sketch-link-embed textarea {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user