Skip to content

Commit 206b65f

Browse files
authored
Merge pull request #58 from bcmi-labs/use-sketch-as-ws
Use sketch folder as workspace
2 parents 59553bf + 6d590cd commit 206b65f

27 files changed

+418
-181
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ build/
66
downloads/
77
!electron/build/
88
src-gen/
9-
arduino-ide-*/webpack.config.js
9+
browser-app/webpack.config.js
10+
electron-app/webpack.config.js
1011
.DS_Store
1112
/workspace/static
1213
# switching from `electron` to `browser` in dev mode.

.gitpod.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ports:
88
tasks:
99
- init: >
1010
yarn &&
11-
yarn --cwd ./arduino-ide-browser start
11+
yarn --cwd ./browser-app start
1212
1313
github:
1414
prebuilds:

.vscode/launch.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"type": "node",
1515
"request": "launch",
1616
"name": "Launch Backend",
17-
"program": "${workspaceRoot}/arduino-ide-browser/src-gen/backend/main.js",
17+
"program": "${workspaceRoot}/browser-app/src-gen/backend/main.js",
1818
"args": [
1919
"--hostname=0.0.0.0",
2020
"--port=3000",
@@ -26,8 +26,8 @@
2626
},
2727
"sourceMaps": true,
2828
"outFiles": [
29-
"${workspaceRoot}/arduino-ide-browser/src-gen/backend/*.js",
30-
"${workspaceRoot}/arduino-ide-browser/lib/**/*.js",
29+
"${workspaceRoot}/browser-app/src-gen/backend/*.js",
30+
"${workspaceRoot}/browser-app/lib/**/*.js",
3131
"${workspaceRoot}/arduino-ide-extension/*/lib/**/*.js"
3232
],
3333
"smartStep": true,

.vscode/tasks.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"version": "2.0.0",
55
"tasks": [
66
{
7-
"label": "Arduino-PoC - Start Browser Example",
7+
"label": "Arduino Editor - Start Browser Example",
88
"type": "shell",
9-
"command": "yarn --cwd ./arduino-ide-browser start",
9+
"command": "yarn --cwd ./browser-app start",
1010
"group": "build",
1111
"presentation": {
1212
"reveal": "always",
@@ -15,7 +15,7 @@
1515
}
1616
},
1717
{
18-
"label": "Arduino-PoC - Watch Theia Extension",
18+
"label": "Arduino Editor - Watch Theia Extension",
1919
"type": "shell",
2020
"command": "yarn --cwd ./arduino-ide-extension watch",
2121
"group": "build",
@@ -26,9 +26,9 @@
2626
}
2727
},
2828
{
29-
"label": "Arduino-PoC - Watch Browser Example",
29+
"label": "Arduino Editor - Watch Browser Example",
3030
"type": "shell",
31-
"command": "yarn --cwd ./arduino-ide-browser watch",
31+
"command": "yarn --cwd ./browser-app watch",
3232
"group": "build",
3333
"presentation": {
3434
"reveal": "always",
@@ -37,11 +37,11 @@
3737
}
3838
},
3939
{
40-
"label": "Arduino-PoC - Watch All",
40+
"label": "Arduino Editor - Watch All",
4141
"type": "shell",
4242
"dependsOn": [
43-
"Arduino-PoC - Watch Theia Extension",
44-
"Arduino-PoC - Watch Browser Example"
43+
"Arduino Editor - Watch Theia Extension",
44+
"Arduino Editor - Watch Browser Example"
4545
]
4646
}
4747
]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ git clone https://github.com/bcmi-labs/arduino-editor
1717
cd arduino-editor
1818
yarn
1919
yarn rebuild:electron
20-
yarn --cwd arduino-ide-electron start
20+
yarn --cwd electron-app start
2121
```
2222

2323
If you want to switch back to the browser-based example, execute the following in the repository root
@@ -26,7 +26,7 @@ yarn rebuild:browser
2626
```
2727
Then you can start the browser example again:
2828
```
29-
yarn --cwd arduino-ide-browser start
29+
yarn --cwd browser-app start
3030
```
3131

3232
## Arduino-PoC Electron Application

arduino-ide-extension/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
"@theia/core": "next",
1313
"@theia/editor": "next",
1414
"@theia/filesystem": "next",
15+
"@theia/git": "next",
1516
"@theia/languages": "next",
1617
"@theia/markers": "next",
1718
"@theia/monaco": "next",
1819
"@theia/outline-view": "next",
1920
"@theia/workspace": "next",
2021
"@theia/navigator": "next",
2122
"@theia/terminal": "next",
22-
"@theia/git": "next",
2323
"@theia/search-in-workspace": "next",
2424
"@types/ps-tree": "^1.1.0",
2525
"@types/which": "^1.3.1",
@@ -40,11 +40,12 @@
4040
},
4141
"devDependencies": {
4242
"decompress": "^4.2.0",
43-
"decompress-tarbz2": "^4.1.1",
43+
"decompress-targz": "^4.1.1",
4444
"decompress-unzip": "^4.0.1",
4545
"download": "^7.1.0",
4646
"grpc-tools": "^1.7.3",
4747
"grpc_tools_node_protoc_ts": "^2.5.0",
48+
"moment": "^2.24.0",
4849
"ncp": "^2.0.0",
4950
"rimraf": "^2.6.1",
5051
"shelljs": "^0.8.3",

arduino-ide-extension/scripts/download-cli.js

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
// @ts-check
2-
// The links to the downloads as of today (11.08.) are the followings:
3-
// - https://downloads.arduino.cc/arduino-cli/nightly/arduino-cli-nightly-latest-${FILE_NAME}
4-
// - https://downloads.arduino.cc/arduino-cli/arduino-cli-latest-${FILE_NAME}
2+
// The links to the downloads as of today (02.09.) are the followings:
3+
// In order to get the latest nightly build for your platform use the following links replacing <DATE> with the current date, using the format YYYYMMDD (i.e for 2019/Aug/06 use 20190806 )
4+
// Linux 64 bit: https://downloads.arduino.cc/arduino-cli/nightly/arduino-cli_nightly-<DATE>_Linux_64bit.tar.gz
5+
// Linux ARM 64 bit: https://downloads.arduino.cc/arduino-cli/nightly/arduino-cli_nightly-<DATE>_Linux_ARM64.tar.gz
6+
// Windows 64 bit: https://downloads.arduino.cc/arduino-cli/nightly/arduino-cli_nightly-<DATE>_Windows_64bit.zip
7+
// Mac OSX: https://downloads.arduino.cc/arduino-cli/nightly/arduino-cli_nightly-<DATE>_macOS_64bit.tar.gz
8+
// [...]
9+
// redirecting to latest generated builds by replacing latest with the latest available build date, using the format YYYYMMDD (i.e for 2019/Aug/06 latest is replaced with 20190806
510

611
(async () => {
712

8-
const DEFAULT_VERSION = 'nightly';
13+
const DEFAULT_VERSION = 'latest'; // require('moment')().format('YYYYMMDD');
914

1015
const os = require('os');
1116
const fs = require('fs');
@@ -14,7 +19,7 @@
1419
const download = require('download');
1520
const decompress = require('decompress');
1621
const unzip = require('decompress-unzip');
17-
const untarbz = require('decompress-tarbz2');
22+
const untargz = require('decompress-targz');
1823

1924
process.on('unhandledRejection', (reason, _) => {
2025
shell.echo(String(reason));
@@ -31,11 +36,7 @@
3136
.option('cli-version', {
3237
alias: 'cv',
3338
default: DEFAULT_VERSION,
34-
choices: [
35-
// 'latest', // TODO: How do we get the source for `latest`. Currently, `latest` is the `0.3.7-alpha.preview`.
36-
'nightly'
37-
],
38-
describe: `The version of the 'arduino-cli' to download. Defaults to ${DEFAULT_VERSION}.`
39+
describe: `The version of the 'arduino-cli' to download with the YYYYMMDD format, or 'latest'. Defaults to ${DEFAULT_VERSION}.`
3940
})
4041
.option('force-download', {
4142
alias: 'fd',
@@ -68,13 +69,12 @@
6869

6970
const suffix = (() => {
7071
switch (platform) {
71-
case 'darwin': return 'macosx.zip';
72-
case 'win32': return 'windows.zip';
72+
case 'darwin': return 'macOS_64bit.tar.gz';
73+
case 'win32': return 'Windows_64bit.zip';
7374
case 'linux': {
7475
switch (arch) {
75-
case 'arm64': return 'linuxarm.tar.bz2';
76-
case 'x32': return 'linux32.tar.bz2';
77-
case 'x64': return 'linux64.tar.bz2';
76+
case 'arm64': return 'Linux_ARM64.tar.gz';
77+
case 'x64': return 'Linux_64bit.tar.gz';
7878
default: return undefined;
7979
}
8080
}
@@ -86,24 +86,29 @@
8686
shell.exit(1);
8787
}
8888

89-
const url = `https://downloads.arduino.cc/arduino-cli/${version === 'nightly' ? 'nightly/' : ''}arduino-cli-${version}-latest-${suffix}`;
89+
const url = `https://downloads.arduino.cc/arduino-cli/nightly/arduino-cli_nightly-${version}_${suffix}`;
9090
shell.echo(`>>> Downloading 'arduino-cli' from '${url}'...`);
9191
const data = await download(url);
9292
shell.echo(`<<< Download succeeded.`);
9393
shell.echo('>>> Decompressing CLI...');
9494
const files = await decompress(data, downloads, {
9595
plugins: [
9696
unzip(),
97-
untarbz()
97+
untargz()
9898
]
9999
});
100-
shell.echo('<<< Decompressing succeeded.');
101-
102-
if (files.length !== 1) {
100+
if (files.length === 0) {
103101
shell.echo('Error ocurred when decompressing the CLI.');
104102
shell.exit(1);
105103
}
106-
if (shell.mv('-f', path.join(downloads, files[0].path), cli).code !== 0) {
104+
const cliIndex = files.findIndex(f => f.path.startsWith('arduino-cli'));
105+
if (cliIndex === -1) {
106+
shell.echo('The downloaded artifact does not contains the CLI.');
107+
shell.exit(1);
108+
}
109+
shell.echo('<<< Decompressing succeeded.');
110+
111+
if (shell.mv('-f', path.join(downloads, files[cliIndex].path), cli).code !== 0) {
107112
shell.echo(`Could not move file to ${cli}.`);
108113
shell.exit(1);
109114
}

arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import { BoardsConfigDialog } from './boards/boards-config-dialog';
4646
import { BoardsToolBarItem } from './boards/boards-toolbar-item';
4747
import { BoardsConfig } from './boards/boards-config';
4848
import { MonitorService } from '../common/protocol/monitor-service';
49+
import { ConfigService } from '../common/protocol/config-service';
4950

5051
export namespace ArduinoMenus {
5152
export const SKETCH = [...MAIN_MENU_BAR, '3_sketch'];
@@ -133,21 +134,19 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
133134

134135
@inject(LabelProvider)
135136
protected readonly labelProvider: LabelProvider;
136-
137+
137138
@inject(QuickOpenService)
138139
protected readonly quickOpenService: QuickOpenService;
139140

141+
@inject(WorkspaceService)
142+
protected readonly workspaceService: WorkspaceService;
143+
144+
@inject(ConfigService)
145+
protected readonly configService: ConfigService;
146+
140147
protected boardsToolbarItem: BoardsToolBarItem | null;
141148
protected wsSketchCount: number = 0;
142149

143-
constructor(@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService) {
144-
this.workspaceService.onWorkspaceChanged(() => {
145-
if (this.workspaceService.workspace) {
146-
this.registerSketchesInMenu(this.menuRegistry);
147-
}
148-
})
149-
}
150-
151150
@postConstruct()
152151
protected async init(): Promise<void> {
153152
// This is a hack. Otherwise, the backend services won't bind.
@@ -161,6 +160,8 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
161160
}
162161
this.boardsServiceClient.onBoardsConfigChanged(updateStatusBar);
163162
updateStatusBar(this.boardsServiceClient.boardsConfig);
163+
164+
this.registerSketchesInMenu(this.menuRegistry);
164165
}
165166

166167
registerToolbarItems(registry: TabBarToolbarRegistry): void {
@@ -453,21 +454,32 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
453454
}
454455

455456
protected async getWorkspaceSketches(): Promise<Sketch[]> {
456-
const sketches = this.sketches.getSketches(this.workspaceService.workspace);
457+
458+
let sketches: Sketch[] = [];
459+
const config = await this.configService.getConfiguration();
460+
const stat = await this.fileSystem.getFileStat(config.sketchDirUri);
461+
if (!!stat) {
462+
sketches = await this.sketches.getSketches(stat);
463+
}
457464
return sketches;
458465
}
459466

460467
protected async openSketchFilesInNewWindow(uri: string) {
461468
const url = new URL(window.location.href);
462469
const currentSketch = url.searchParams.get('sketch');
463470
// Nothing to do if we want to open the same sketch which is already opened.
464-
if (!!currentSketch && new URI(currentSketch).toString() === new URI(uri).toString()) {
465-
this.messageService.info(`The '${this.labelProvider.getLongName(new URI(uri))}' is already opened.`);
471+
const sketchUri = new URI(uri);
472+
if (!!currentSketch && new URI(currentSketch).toString() === sketchUri.toString()) {
473+
this.messageService.info(`The '${this.labelProvider.getLongName(sketchUri)}' is already opened.`);
466474
// NOOP.
467475
return;
468476
}
469477
// Preserve the current window if the `sketch` is not in the `searchParams`.
470478
url.searchParams.set('sketch', uri);
479+
const hash = await this.fileSystem.getFsPath(sketchUri.toString());
480+
if (hash) {
481+
url.hash = hash;
482+
}
471483
if (!currentSketch) {
472484
setTimeout(() => window.location.href = url.toString(), 100);
473485
return;
@@ -543,25 +555,6 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
543555
return undefined;
544556
}
545557

546-
// private async onNoBoardsInstalled() {
547-
// const action = await this.messageService.info("You have no boards installed. Use the boards manager to install one.", "Open Boards Manager");
548-
// if (!action) {
549-
// return;
550-
// }
551-
552-
// this.boardsListWidgetFrontendContribution.openView({ reveal: true });
553-
// }
554-
555-
// private async onUnknownBoard() {
556-
// const action = await this.messageService.warn("There's a board connected for which you need to install software." +
557-
// " If this were not a PoC we would offer you the right package now.", "Open Boards Manager");
558-
// if (!action) {
559-
// return;
560-
// }
561-
562-
// this.boardsListWidgetFrontendContribution.openView({ reveal: true });
563-
// }
564-
565558
private isArduinoToolbar(maybeToolbarWidget: any): boolean {
566559
if (maybeToolbarWidget instanceof ArduinoToolbar) {
567560
return true;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import { LibraryItemRenderer } from './library/library-item-renderer';
5656
import { BoardItemRenderer } from './boards/boards-item-renderer';
5757
import { MonitorServiceClientImpl } from './monitor/monitor-service-client-impl';
5858
import { MonitorServicePath, MonitorService, MonitorServiceClient } from '../common/protocol/monitor-service';
59+
import { ConfigService, ConfigServicePath } from '../common/protocol/config-service';
5960
const ElementQueries = require('css-element-queries/src/ElementQueries');
6061

6162
if (!ARDUINO_PRO_MODE) {
@@ -96,6 +97,9 @@ export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Un
9697
// Sketch list service
9798
bind(SketchesService).toDynamicValue(context => WebSocketConnectionProvider.createProxy(context.container, SketchesServicePath)).inSingletonScope();
9899

100+
// Config service
101+
bind(ConfigService).toDynamicValue(context => WebSocketConnectionProvider.createProxy(context.container, ConfigServicePath)).inSingletonScope();
102+
99103
// Boards service
100104
bind(BoardsService).toDynamicValue(context => {
101105
const connection = context.container.get(WebSocketConnectionProvider);

arduino-ide-extension/src/browser/arduino-workspace-service.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { WorkspaceServer } from "@theia/workspace/lib/common";
44
import { FileSystem, FileStat } from "@theia/filesystem/lib/common";
55
import URI from "@theia/core/lib/common/uri";
66
import { SketchFactory } from "./sketch-factory";
7+
import { ConfigService } from "../common/protocol/config-service";
78

89
/**
910
* This is workaround to have custom frontend binding for the default workspace, although we
@@ -21,16 +22,14 @@ export class AWorkspaceService extends WorkspaceService {
2122
@inject(SketchFactory)
2223
protected readonly sketchFactory: SketchFactory;
2324

25+
@inject(ConfigService)
26+
protected readonly configService: ConfigService;
27+
2428
protected async getDefaultWorkspacePath(): Promise<string | undefined> {
2529
let result = await super.getDefaultWorkspacePath();
2630
if (!result) {
27-
const userHome = await this.fileSystem.getCurrentUserHome();
28-
if (!userHome) {
29-
return;
30-
}
31-
32-
// The backend has created this location if it was missing.
33-
result = new URI(userHome.uri).resolve('Arduino-PoC').resolve('Sketches').toString();
31+
const config = await this.configService.getConfiguration();
32+
result = config.sketchDirUri;
3433
}
3534

3635
const stat = await this.fileSystem.getFileStat(result);

0 commit comments

Comments
 (0)