Skip to content

Commit

Permalink
Integrate new PIO Home 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ivankravets committed Aug 9, 2017
1 parent 1341ae5 commit 24ef585
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 16 deletions.
13 changes: 8 additions & 5 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
"transform-class-properties"
],
"presets": [
["env", {
"targets": {
"node": "7.4"
[
"env",
{
"targets": {
"node": "7.4"
}
}
}]
]
],
"sourceMap": "inline"
}
}
13 changes: 13 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"files.exclude": {
"lib": true
},
"search.exclude": {
"**/lib/**": true
},
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/lib/*": true,
"**/node_modules/**": true
}
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes

## 0.6.0 (2017-08-??)

* Integrate new PIO Home 2.0

## 0.5.3 (2017-08-05)

* Ignore broken a node-tar(3.1.9) package which blocks PIO Core installer
Expand Down
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
"main": "./lib/main",
"contributes": {
"commands": [
{
"command": "platformio-ide.showHome",
"title": "Home",
"category": "PlatformIO"
},
{
"command": "platformio-ide.build",
"title": "Build",
Expand Down Expand Up @@ -97,11 +102,6 @@
"title": "New Terminal",
"category": "PlatformIO"
},
{
"command": "platformio-ide.libraryManager",
"title": "Library Manager",
"category": "PlatformIO"
},
{
"command": "platformio-ide.updateCore",
"title": "Update installed platforms, packages and libraries",
Expand Down Expand Up @@ -171,6 +171,11 @@
"type": "object",
"title": "PlatformIO IDE configuration",
"properties": {
"platformio-ide.showHomeOnStartup": {
"type": "boolean",
"default": true,
"description": "Show PIO Home on startup"
},
"platformio-ide.useBuiltinPIOCore": {
"type": "boolean",
"default": true,
Expand Down Expand Up @@ -229,6 +234,7 @@
"request": "^2.81.0",
"semver": "^5.3.0",
"tar": "3.1.8",
"tcp-port-used": "^0.1.2",
"tmp": "^0.0.31"
},
"extensionDependencies": [
Expand Down
55 changes: 55 additions & 0 deletions src/home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Copyright (c) 2017-present PlatformIO <contact@platformio.org>
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*/

import spawn from 'cross-spawn';
import tcpPortUsed from 'tcp-port-used';


export class HomeContentProvider {

static HTTP_HOST = 'localhost';
static HTTP_PORT = 8008;

async provideTextDocumentContent(uri) {
await this.ensureServerStarted();
return `
<html>
<body style="margin: 0; padding: 0; height: 100%; overflow: hidden; background-color: #fff">
<iframe src="http://${ HomeContentProvider.HTTP_HOST }:${ HomeContentProvider.HTTP_PORT}?start=/${uri.authority}" width="100%" height="100%" frameborder="0" style="position:absolute; left: 0; right: 0; bottom: 0; top: 0px;" />
</body>
</html>
`;
}

isServerStarted() {
return new Promise(resolve => {
tcpPortUsed.check(HomeContentProvider.HTTP_PORT, HomeContentProvider.HTTP_HOST)
.then(inUse => {
resolve(inUse);
}, () => {
return resolve(false);
});
});
}

async ensureServerStarted() {
if (await this.isServerStarted()) {
return;
}
return new Promise(resolve => {
spawn('platformio', ['home', '--no-open']);
tcpPortUsed.waitUntilUsed(HomeContentProvider.HTTP_PORT)
.then(() => {
resolve(true);
}, () => {
return resolve(false);
});
});
}

}
24 changes: 18 additions & 6 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* the root directory of this source tree.
*/

import { HomeContentProvider } from './home';
import InstallationManager from './installer/manager';
import PIOTasksProvider from './tasks';
import PIOTerminal from './terminal';
Expand All @@ -18,9 +19,11 @@ import vscode from 'vscode';
class PlatformIOVSCodeExtension {

constructor() {
this.config = vscode.workspace.getConfiguration('platformio-ide');
this.pioTerm = new PIOTerminal();

this._context = null;
this._isMonitorRun = false;
this.pioTerm = new PIOTerminal();
}

async activate(context) {
Expand All @@ -31,6 +34,10 @@ class PlatformIOVSCodeExtension {

await this.startInstaller();

if (this.config.get('showHomeOnStartup')) {
vscode.commands.executeCommand('platformio-ide.showHome');
}

if (!vscode.workspace.rootPath) {
return;
}
Expand Down Expand Up @@ -86,6 +93,13 @@ class PlatformIOVSCodeExtension {
}

registerCommands() {
// PIO Home
this._context.subscriptions.push(vscode.workspace.registerTextDocumentContentProvider('platformio-home', new HomeContentProvider()));
this._context.subscriptions.push(vscode.commands.registerCommand(
'platformio-ide.showHome',
() => vscode.commands.executeCommand('vscode.previewHtml', vscode.Uri.parse('platformio-home://'), vscode.ViewColumn.One, 'PIO Home')
));

this._context.subscriptions.push(vscode.commands.registerCommand(
'platformio-ide.initProject',
initCommand
Expand All @@ -103,8 +117,7 @@ class PlatformIOVSCodeExtension {
await this.terminateMonitorTask();

let task = 'PlatformIO: Upload';
const config = vscode.workspace.getConfiguration('platformio-ide');
if(config.get('forceUploadAndMonitor')) {
if (this.config.get('forceUploadAndMonitor')) {
task = 'PlatformIO: Upload and Monitor';
this._isMonitorRun = true;
}
Expand Down Expand Up @@ -150,7 +163,7 @@ class PlatformIOVSCodeExtension {
}
try {
await vscode.commands.executeCommand('workbench.action.tasks.terminate');
} catch(err) {
} catch (err) {
console.error(err);
}
this._isMonitorRun = false;
Expand All @@ -163,12 +176,11 @@ class PlatformIOVSCodeExtension {

initStatusBar() {
const items = [
['$(home)', 'PlatformIO: Home', 'platformio-ide.showHome'],
['$(check)', 'PlatformIO: Build', 'platformio-ide.build'],
['$(arrow-right)', 'PlatformIO: Upload', 'platformio-ide.upload'],
['$(trashcan)', 'PlatformIO: Clean', 'platformio-ide.clean'],
['$(checklist)', 'PlatformIO: Run a Task', 'workbench.action.tasks.runTask'],

This comment has been minimized.

Copy link
@jeremypoulter

jeremypoulter Aug 12, 2017

Is this intentional? see #33

This comment has been minimized.

Copy link
@ivankravets

ivankravets Aug 12, 2017

Author Member

I think better is to save space in bottom bar. VSCode recently added separate menu.

['$(file-code)', 'PlatformIO: Initialize or update project', 'platformio-ide.initProject'],
['$(code)', 'PlatformIO: Library Manager', 'platformio-ide.libraryManager'],
['$(plug)', 'PlatformIO: Serial Monitor', 'platformio-ide.serialMonitor'],
['$(terminal)', 'PlatformIO: New Terminal', 'platformio-ide.newTerminal']
];
Expand Down

0 comments on commit 24ef585

Please sign in to comment.