Skip to content

Commit

Permalink
Merge pull request #107 from warrenbuckley/feature/vsliveshare
Browse files Browse the repository at this point in the history
VSLiveShare - Auto shares IIS Express as a shared server in a LiveShare session
  • Loading branch information
Warren Buckley authored Jul 14, 2020
2 parents c4933f9 + 41d50cb commit aab8105
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 13 deletions.
89 changes: 89 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 30 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,55 @@
"configuration": {
"title": "IIS Express",
"properties": {
"iisexpress.iisExpressPath" : {
"iisexpress.iisExpressPath": {
"title": "Path to IISExpress.exe",
"examples": [
"C:\\Program Files\\IIS Express\\iisexpress.exe",
"C:\\Program Files (x86)\\IIS Express\\iisexpress.exe"
],
"markdownDescription": "An absolute path to **IISExpress.exe** such as `C:\\Program Files\\IIS Express\\iisexpress.exe`",
"markdownDescription": "An absolute path to **IISExpress.exe** such as `C:\\Program Files\\IIS Express\\iisexpress.exe`",
"default": null,
"type": ["string", "null"]
"type": [
"string",
"null"
]
},
"iisexpress.appcmdPath" : {
"iisexpress.appcmdPath": {
"title": "Path to AppCmd.exe",
"examples": [
"C:\\Program Files\\IIS Express\\appcmd.exe",
"C:\\Program Files (x86)\\IIS Express\\appcmd.exe"
],
"markdownDescription": "An absolute path to **appcmd.exe** such as `C:\\Program Files\\IIS Express\\appcmd.exe`",
"markdownDescription": "An absolute path to **appcmd.exe** such as `C:\\Program Files\\IIS Express\\appcmd.exe`",
"default": null,
"type": ["string","null"]
"type": [
"string",
"null"
]
},
"iisexpress.autoLaunchBrowser" : {
"iisexpress.autoLaunchBrowser": {
"title": "Auto launch browser",
"markdownDescription": "An option to disable or enable the browser from launching the site when IIS Express starts. By default this is **true**",
"markdownDescription": "An option to disable or enable the browser from launching the site when IIS Express starts. By default this is **true**",
"default": true,
"type": "boolean"
},
"iisexpress.openInBrowser": {
"title": "Open in browser",
"markdownDescription": "Decide which browser to auto launch the site with when `iisexpress.autoLaunchBrowser` is set to **true**",
"markdownEnumDescriptions": ["Open in `Default Browser`", "Open in `Chrome`", "Open in `Edge`", "Open in `Firefox`", "Open in `Opera`"],
"enum": ["default", "chrome", "msedge", "firefox", "opera"],
"markdownEnumDescriptions": [
"Open in `Default Browser`",
"Open in `Chrome`",
"Open in `Edge`",
"Open in `Firefox`",
"Open in `Opera`"
],
"enum": [
"default",
"chrome",
"msedge",
"firefox",
"opera"
],
"default": "default"
}
}
Expand Down Expand Up @@ -139,6 +157,7 @@
"dependencies": {
"iconv-lite": "^0.6.2",
"jsonfile": "^6.0.1",
"uuid": "^8.2.0"
"uuid": "^8.2.0",
"vsls": "^1.0.2426"
}
}
31 changes: 29 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ import * as iis from './IISExpress';
import * as verify from './verification';
import * as settings from './settings';

import * as vsls from 'vsls';

let iisProc:iis.IIS;

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
export async function activate(context: vscode.ExtensionContext) {

// This will check if the user has VS LiveShare installed & return its API to us
// If not then this will be null
const liveshare = await vsls.getApi();
let liveShareServer:vscode.Disposable;

//Registering a command so we can assign a direct keybinding to it (without opening quick launch)
var startSite = vscode.commands.registerCommand('extension.iis-express.start',async () => {
Expand All @@ -35,6 +40,20 @@ export function activate(context: vscode.ExtensionContext) {
//Start Website...
//Pass settings - just in case its changed between session
iisProc.startWebsite(settings.getSettings());

// Ensure user has liveshare extension
if(liveshare != null){
if((liveshare.session.id !== null) && (liveshare.session.role === vsls.Role.Host)){
const portNumber = settings.getSettings().port;

// This will prompt the LiveShare Host to share the IIS Server Port
liveShareServer = await liveshare.shareServer({ displayName: `IIS Express:${portNumber}`, port: portNumber });

// Push the disposable VSCode into the subscriptions
// so VSCode can dispose them if we forget to or when the extension is deactivated
context.subscriptions.push(liveShareServer);
}
}
});

//Registering a command so we can assign a direct keybinding to it (without opening quick launch)
Expand All @@ -57,6 +76,14 @@ export function activate(context: vscode.ExtensionContext) {

//Stop Website...
iisProc.stopWebsite();

// Ensure user has liveshare extension
if(liveshare != null){
if((liveshare.session.id !== null) && (liveshare.session.role === vsls.Role.Host) && (liveShareServer != null)){
// Kill off the live share server if its running
liveShareServer.dispose();
}
}
});

//Registering a command so we can assign a direct keybinding to it (without opening quick launch)
Expand Down Expand Up @@ -105,7 +132,7 @@ export function activate(context: vscode.ExtensionContext) {
iisProc.restartSite(settings.getSettings());
});

//Push the commands
//Push the commands & any other VSCode disposables
context.subscriptions.push(startSite, stopSite, openSite, restartSite);
}

Expand Down

0 comments on commit aab8105

Please sign in to comment.