-
-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1341ae5
commit 24ef585
Showing
6 changed files
with
109 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"files.exclude": { | ||
"lib": true | ||
}, | ||
"search.exclude": { | ||
"**/lib/**": true | ||
}, | ||
"files.watcherExclude": { | ||
"**/.git/objects/**": true, | ||
"**/lib/*": true, | ||
"**/node_modules/**": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
}); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -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) { | ||
|
@@ -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; | ||
} | ||
|
@@ -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 | ||
|
@@ -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; | ||
} | ||
|
@@ -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; | ||
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ivankravets
Author
Member
|
||
['$(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'] | ||
]; | ||
|
Is this intentional? see #33