Skip to content

Commit

Permalink
Retain PIO Home state when switching between tabs // Resolve #32
Browse files Browse the repository at this point in the history
  • Loading branch information
ivankravets committed May 5, 2018
1 parent 0d69b29 commit e08f43b
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 76 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/lib/
*.vsix
yarn.lock
*.dict
.vscode/settings.json
13 changes: 0 additions & 13 deletions .vscode/settings.json

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "platformio-ide",
"version": "0.14.2",
"version": "0.15.0-beta.4",
"publisher": "platformio",
"engines": {
"vscode": "^1.18.0"
"vscode": "^1.23.0"
},
"license": "Apache-2.0",
"displayName": "PlatformIO IDE",
"description": "Development environment for IoT, Arduino, ARM mbed, Espressif (ESP8266/ESP32), STM32, PIC32, nRF51/nRF52, FPGA, CMSIS, SPL, AVR, Samsung ARTIK, libOpenCM3",
"categories": [
"Programming Languages",
"Debuggers",
"Languages",
"Other"
],
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export const IS_OSX = process.platform == 'darwin';
export const IS_LINUX = !IS_WINDOWS && !IS_OSX;

export const AUTO_REBUILD_DELAY = 3000;
export const PIO_CORE_MIN_VERSION = '3.5.2-rc.3';
export const PIO_CORE_MIN_VERSION = '3.5.2';
68 changes: 59 additions & 9 deletions src/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,63 @@ import { extension } from './main';
import vscode from 'vscode';


export class HomeContentProvider {
export default class PIOHome {

static shutdownServer() {
pioNodeHelpers.home.shutdownServer();
constructor() {
this._currentPanel = null;
}

toggle() {
if (this._currentPanel) {
this._currentPanel.reveal(vscode.ViewColumn.One);
} else {
this._currentPanel = this.newPanel();
}
}

async newPanel() {
const panel = vscode.window.createWebviewPanel(
'pioHome',
extension.getEnterpriseSetting('pioHomeTitle', 'PIO Home'),
vscode.ViewColumn.One,
{
enableScripts: true,
retainContextWhenHidden: true
}
);
panel.onDidDispose(this.onPanelDisposed.bind(this));
panel.webview.html = this.getLoadingContent();
this.getWebviewContent().then(html => panel.webview.html = html );
return panel;
}

async provideTextDocumentContent(uri) {
getTheme() {
const workbench = vscode.workspace.getConfiguration('workbench') || {};
return (workbench.colorTheme || '').toLowerCase().includes('light') ? 'light' : 'dark';
}

getLoadingContent() {
const theme = this.getTheme();
return `<!DOCTYPE html>
<html lang="en">
<body style="background-color: ${theme === 'light' ? '#FFF' : '#1E1E1E' }">
Loading...
</body>
</html>`;
}

async getWebviewContent() {
const params = await pioNodeHelpers.home.ensureServerStarted({
onIDECommand: (command, params) => {
if (command === 'open_project') {
vscode.commands.executeCommand('vscode.openFolder', vscode.Uri.file(params));
}
}
});
const start = `/${ uri.authority }`;
const workbench = vscode.workspace.getConfiguration('workbench') || {};
const theme = (workbench.colorTheme || '').toLowerCase().includes('light') ? 'light' : 'dark';
return `
<html>
const start = '/';
const theme = this.getTheme();
return `<!DOCTYPE html>
<html lang="en">
<body style="margin: 0; padding: 0; height: 100%; overflow: hidden; background-color: ${theme === 'light' ? '#FFF' : '#1E1E1E' }">
<iframe src="${ pioNodeHelpers.home.getFrontendUri(params.host, params.port, {
start,
Expand All @@ -46,4 +84,16 @@ export class HomeContentProvider {
`;
}

onPanelDisposed() {
this._currentPanel = null;
}

shutdownServer() {
pioNodeHelpers.home.shutdownServer();
}

dispose() {
this.shutdownServer();
}

}
89 changes: 39 additions & 50 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import * as pioNodeHelpers from 'platformio-node-helpers';

import { getIDEVersion, isPIOProject } from './utils';

import { HomeContentProvider } from './home';
import InstallationManager from './installer/manager';
import PIOHome from './home';
import PIOTasksProvider from './tasks';
import PIOTerminal from './terminal';
import ProjectIndexer from './project/indexer';
Expand All @@ -21,21 +21,28 @@ import vscode from 'vscode';
class PlatformIOVSCodeExtension {

constructor() {
this.pioTerm = new PIOTerminal();
this.context = null;
this.pioTerm = null;
this.pioHome = null;

this._context = null;
this._isMonitorRun = false;
this._enterpriseSettings = undefined;
}

async activate(context) {
this._context = context;
this.context = context;
const hasPIOProject = this.workspaceHasPIOProject();

if (this.getConfig().get('activateOnlyOnPlatformIOProject') && !hasPIOProject) {
return;
}

this.pioTerm = new PIOTerminal();
this.pioHome = new PIOHome();

this.context.subscriptions.push(this.pioTerm);
this.context.subscriptions.push(this.pioHome);

pioNodeHelpers.misc.patchOSEnviron({
caller: 'vscode',
useBuiltinPIOCore: this.getConfig().get('useBuiltinPIOCore'),
Expand Down Expand Up @@ -80,7 +87,7 @@ class PlatformIOVSCodeExtension {
return ext.exports.settings;
}

getEnterpriseSetting(id, defaultValue=undefined) {
getEnterpriseSetting(id, defaultValue = undefined) {
if (!this._enterpriseSettings) {
this._enterpriseSettings = this.loadEnterpriseSettings();
}
Expand All @@ -103,7 +110,7 @@ class PlatformIOVSCodeExtension {
message: 'Checking PlatformIO Core installation...',
});

const im = new InstallationManager(this._context.globalState);
const im = new InstallationManager(this.context.globalState);
if (im.locked()) {
vscode.window.showInformationMessage(
'PlatformIO IDE installation has been suspended, because PlatformIO '
Expand All @@ -114,11 +121,11 @@ class PlatformIOVSCodeExtension {
progress.report({
message: 'Installing PlatformIO IDE...',
});
const outputChannel = vscode.window.createOutputChannel('PlatformIO Instalation');
const outputChannel = vscode.window.createOutputChannel('PlatformIO Installation');
outputChannel.show();

outputChannel.appendLine('Installing PlatformIO Core...');
outputChannel.appendLine('Please don\'t close this window and don\'t '
outputChannel.appendLine('Please do not close this window and do not '
+ 'open other folders until this process is completed.');

try {
Expand Down Expand Up @@ -153,30 +160,18 @@ class PlatformIOVSCodeExtension {
}

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

this._context.subscriptions.push(vscode.commands.registerCommand(
this.context.subscriptions.push(vscode.commands.registerCommand(
'platformio-ide.build',
async () => {
vscode.commands.executeCommand(
'workbench.action.tasks.runTask',
`PlatformIO: ${this.getConfig().get('defaultToolbarBuildAction') === 'pre-debug' ? 'Pre-Debug' : 'Build'}`);
}
() => vscode.commands.executeCommand(
'workbench.action.tasks.runTask',
`PlatformIO: ${this.getConfig().get('defaultToolbarBuildAction') === 'pre-debug' ? 'Pre-Debug' : 'Build'}`
)
));
this._context.subscriptions.push(vscode.commands.registerCommand(
this.context.subscriptions.push(vscode.commands.registerCommand(
'platformio-ide.upload',
async () => {
await this.terminateMonitorTask();
Expand All @@ -189,42 +184,38 @@ class PlatformIOVSCodeExtension {
vscode.commands.executeCommand('workbench.action.tasks.runTask', task);
}
));
this._context.subscriptions.push(vscode.commands.registerCommand(
this.context.subscriptions.push(vscode.commands.registerCommand(
'platformio-ide.remote',
async () => {
vscode.commands.executeCommand('workbench.action.tasks.runTask', 'PlatformIO: Remote');
}
() => vscode.commands.executeCommand('workbench.action.tasks.runTask', 'PlatformIO: Remote')
));
this._context.subscriptions.push(vscode.commands.registerCommand(
this.context.subscriptions.push(vscode.commands.registerCommand(
'platformio-ide.test',
async () => {
await this.terminateMonitorTask();
vscode.commands.executeCommand('workbench.action.tasks.runTask', 'PlatformIO: Test');
}
));
this._context.subscriptions.push(vscode.commands.registerCommand(
this.context.subscriptions.push(vscode.commands.registerCommand(
'platformio-ide.clean',
async () => {
vscode.commands.executeCommand('workbench.action.tasks.runTask', 'PlatformIO: Clean');
}
() => vscode.commands.executeCommand('workbench.action.tasks.runTask', 'PlatformIO: Clean')
));
this._context.subscriptions.push(vscode.commands.registerCommand(
this.context.subscriptions.push(vscode.commands.registerCommand(
'platformio-ide.serialMonitor',
async () => {
await this.terminateMonitorTask();
this._isMonitorRun = true;
vscode.commands.executeCommand('workbench.action.tasks.runTask', 'PlatformIO: Monitor');
}
));
this._context.subscriptions.push(vscode.commands.registerCommand(
this.context.subscriptions.push(vscode.commands.registerCommand(
'platformio-ide.newTerminal',
() => this.pioTerm.new().show()
));
this._context.subscriptions.push(vscode.commands.registerCommand(
this.context.subscriptions.push(vscode.commands.registerCommand(
'platformio-ide.updateCore',
() => this.pioTerm.sendText('pio update')
));
this._context.subscriptions.push(vscode.commands.registerCommand(
this.context.subscriptions.push(vscode.commands.registerCommand(
'platformio-ide.upgradeCore',
() => this.pioTerm.sendText('pio upgrade')
));
Expand All @@ -244,7 +235,7 @@ class PlatformIOVSCodeExtension {
}

initTasksProvider() {
this._context.subscriptions.push(new PIOTasksProvider(vscode.workspace.rootPath));
this.context.subscriptions.push(new PIOTasksProvider(vscode.workspace.rootPath));
}

initStatusBar({ filterCommands, ignoreCommands }) {
Expand All @@ -259,7 +250,7 @@ class PlatformIOVSCodeExtension {
['$(plug)', 'PlatformIO: Serial Monitor', 'platformio-ide.serialMonitor'],
['$(terminal)', 'PlatformIO: New Terminal', 'platformio-ide.newTerminal']
]
.filter(item => (!filterCommands || filterCommands.includes(item[2])) && (!ignoreCommands || !ignoreCommands.includes(item[2])) )
.filter(item => (!filterCommands || filterCommands.includes(item[2])) && (!ignoreCommands || !ignoreCommands.includes(item[2])))
.reverse()
.forEach((item, index) => {
const [text, tooltip, command] = item;
Expand All @@ -268,26 +259,24 @@ class PlatformIOVSCodeExtension {
sbItem.tooltip = tooltip;
sbItem.command = command;
sbItem.show();
this._context.subscriptions.push(sbItem);
this.context.subscriptions.push(sbItem);
});
}

initProjectIndexer() {
const indexer = new ProjectIndexer(vscode.workspace.rootPath);
this._context.subscriptions.push(indexer);
this._context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(() => indexer.toggle()));
indexer.toggle();
this._context.subscriptions.push(vscode.commands.registerCommand(
this.context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(() => indexer.toggle()));
this.context.subscriptions.push(vscode.commands.registerCommand(
'platformio-ide.rebuildProjectIndex',
() => indexer.doRebuild({
verbose: true
})
));
this.context.subscriptions.push(indexer);
indexer.toggle();
}

deactivate() {
this.pioTerm.dispose();
HomeContentProvider.shutdownServer();
}
}

Expand Down

0 comments on commit e08f43b

Please sign in to comment.