@@ -25,6 +25,7 @@ import { getManifest } from './util/extensionManagmentUtill';
25
25
import { GitpodWorkspacePort , PortInfo , iconStatusMap } from './util/port' ;
26
26
import { registerReleaseNotesView , RELEASE_NOTES_LAST_READ_KEY } from './releaseNote' ;
27
27
import { registerWelcomeWalkthroughContribution , WELCOME_WALKTROUGH_KEY } from './welcomeWalktrough' ;
28
+ import { ExperimentalSettings , isUserOverrideSetting } from './experiments' ;
28
29
29
30
let gitpodContext : GitpodExtensionContext | undefined ;
30
31
export async function activate ( context : vscode . ExtensionContext ) {
@@ -516,8 +517,8 @@ function getNonce() {
516
517
517
518
interface PortItem { port : GitpodWorkspacePort ; isWebview ?: boolean }
518
519
519
- function registerPorts ( context : GitpodExtensionContext ) : void {
520
- const isPortsViewExperimentEnable = vscode . workspace . getConfiguration ( 'gitpod.experimental.portsView' ) . get < boolean > ( 'enabled' ) ;
520
+ async function registerPorts ( context : GitpodExtensionContext ) : Promise < void > {
521
+ const isPortsViewExperimentEnable = await getPortsViewExperimentEnable ( ) ;
521
522
522
523
const portMap = new Map < number , GitpodWorkspacePort > ( ) ;
523
524
const tunnelMap = new Map < number , vscode . TunnelDescription > ( ) ;
@@ -577,6 +578,27 @@ function registerPorts(context: GitpodExtensionContext): void {
577
578
}
578
579
} ) ;
579
580
}
581
+
582
+ const packageJSON = context . extension . packageJSON ;
583
+ const experiments = new ExperimentalSettings ( packageJSON . configcatKey , packageJSON . version , context . logger ) ;
584
+ context . subscriptions . push ( experiments ) ;
585
+
586
+ const isSaaSGitpod = context . info . getGitpodHost ( ) === 'https://gitpod.io' ;
587
+ async function getPortsViewExperimentEnable ( ) : Promise < boolean > {
588
+ const isEnabled = isSaaSGitpod
589
+ ? ( await experiments . get < boolean > ( 'gitpod.experimental.portsView.enabled' , ( await context . user ) . id ) ) !
590
+ : vscode . workspace . getConfiguration ( 'gitpod' ) . get < boolean > ( 'experimental.portsView.enabled' ) ! ;
591
+ const userOverride = isUserOverrideSetting ( 'gitpod.remote.useLocalApp' ) ;
592
+ context . fireAnalyticsEvent ( {
593
+ eventName : 'vscode_experimental_ports_view' ,
594
+ properties : {
595
+ enabled : isEnabled ,
596
+ userOverride,
597
+ }
598
+ } ) ;
599
+ return isEnabled ;
600
+ }
601
+
580
602
context . subscriptions . push ( observePortsStatus ( ) ) ;
581
603
context . subscriptions . push ( vscode . commands . registerCommand ( 'gitpod.resolveExternalPort' , ( portNumber : number ) => {
582
604
// eslint-disable-next-line no-async-promise-executor
@@ -657,7 +679,7 @@ function registerPorts(context: GitpodExtensionContext): void {
657
679
658
680
const portsStatusBarItem = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Right ) ;
659
681
context . subscriptions . push ( portsStatusBarItem ) ;
660
- function updateStatusBar ( ) : void {
682
+ async function updateStatusBar ( ) : Promise < void > {
661
683
const exposedPorts : number [ ] = [ ] ;
662
684
663
685
for ( const port of portMap . values ( ) ) {
@@ -679,8 +701,8 @@ function registerPorts(context: GitpodExtensionContext): void {
679
701
680
702
portsStatusBarItem . text = text ;
681
703
portsStatusBarItem . tooltip = tooltip ;
682
- const isPortsViewExperimentEnable = vscode . workspace . getConfiguration ( 'gitpod.experimental.portsView' ) . get < boolean > ( 'enabled' ) ;
683
- portsStatusBarItem . command = isPortsViewExperimentEnable ? 'gitpod.portsView.focus' : 'gitpod.ports.reveal' ;
704
+
705
+ portsStatusBarItem . command = ( await getPortsViewExperimentEnable ( ) ) ? 'gitpod.portsView.focus' : 'gitpod.ports.reveal' ;
684
706
portsStatusBarItem . show ( ) ;
685
707
}
686
708
updateStatusBar ( ) ;
@@ -820,11 +842,11 @@ function registerPorts(context: GitpodExtensionContext): void {
820
842
vscode . commands . executeCommand ( 'gitpod.api.connectLocalApp' , apiPort ) ;
821
843
}
822
844
} ) ) ;
823
- vscode . workspace . onDidChangeConfiguration ( ( e : vscode . ConfigurationChangeEvent ) => {
845
+ vscode . workspace . onDidChangeConfiguration ( async ( e : vscode . ConfigurationChangeEvent ) => {
824
846
if ( ! e . affectsConfiguration ( 'gitpod.experimental.portsView.enabled' ) ) {
825
847
return ;
826
848
}
827
- const isPortsViewExperimentEnable = vscode . workspace . getConfiguration ( 'gitpod.experimental.portsView' ) . get < boolean > ( 'enabled' ) ;
849
+ const isPortsViewExperimentEnable = await getPortsViewExperimentEnable ( ) ;
828
850
vscode . commands . executeCommand ( 'setContext' , 'gitpod.portsView.visible' , isPortsViewExperimentEnable ) ;
829
851
gitpodWorkspaceTreeDataProvider . updateIsPortsViewExperimentEnable ( isPortsViewExperimentEnable ?? false ) ;
830
852
updateStatusBar ( ) ;
0 commit comments