This repository was archived by the owner on Jul 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
[Live Share] Allow developers to specify a profile to use when hosting Live Share sessions #4
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ba4288d
Initial Live Share support
lostintangent a7b1c1d
Initial Live Share support
lostintangent 2cab0a7
Misc. cleanup
lostintangent eb72f38
Simplifying LS code
lostintangent 96f0906
Add documentation
lostintangent 8ab0c2f
Fixing ESLint error
lostintangent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,42 @@ | ||
import * as vscode from "vscode"; | ||
import * as vsls from "vsls"; | ||
import Config from "./config"; | ||
|
||
export async function initialize( | ||
context: vscode.ExtensionContext, | ||
config: Config, | ||
activateProfileHandler: (profile: string) => void | ||
) { | ||
// Check to see if the end-user has the Live Share | ||
// extension installed, and if not, exit early. | ||
const liveShare = await vsls.getApi(); | ||
if (!liveShare) { | ||
return; | ||
} | ||
|
||
// Begin listening for the beginning and end of Live | ||
// Share sessions, in case we need to switch profiles. | ||
liveShare.onDidChangeSession(e => { | ||
// If the end-user never set a Live Share profile, then | ||
// there's nothing we need to do. Note that we're calling | ||
// this here, instead of as part of the activation flow, | ||
// so that the end-user can set their profile any time | ||
// and have it take effect immediately. | ||
const liveShareProfile = config.getLiveShareProfile(); | ||
if (!liveShareProfile) { | ||
return; | ||
} | ||
|
||
if (e.session.id) { | ||
activateProfileHandler(liveShareProfile); | ||
} else { | ||
const previousProfile = config.getPreviousProfile(); | ||
if (!previousProfile) { | ||
return; | ||
} | ||
|
||
config.setPreviousProfile(undefined); | ||
activateProfileHandler(previousProfile); | ||
} | ||
}) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the churn in this file are refactorings that allowed the profile selection code to be re-used. I split the
selectProfile
method intoselectProfile
(which is the command handler),promptProfile
(which handles displaying the UI), andactivateProfile
(which actually activates the profile).This allows the
Select Live Share Profile
command handler to re-use the profile prompting code, without actually activating the selected profile (since it's simply setting a profile for future use, as opposed to immediately activating it).