@@ -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 ) {
@@ -497,6 +498,10 @@ class GitpodPortViewProvider implements vscode.WebviewViewProvider {
497
498
if ( ! port ) { return ; }
498
499
if ( message . command === 'urlCopy' && port . status . exposed ) {
499
500
await vscode . env . clipboard . writeText ( port . status . exposed . url ) ;
501
+ this . context . fireAnalyticsEvent ( {
502
+ eventName : 'vscode_execute_command_gitpod_ports' ,
503
+ properties : { action : 'urlCopy' , isWebview : true , userOverride : String ( isUserOverrideSetting ( 'gitpod.experimental.portsView.enabled' ) ) }
504
+ } ) ;
500
505
return ;
501
506
}
502
507
vscode . commands . executeCommand ( 'gitpod.ports.' + message . command , { port, isWebview : true } ) ;
@@ -516,8 +521,20 @@ function getNonce() {
516
521
517
522
interface PortItem { port : GitpodWorkspacePort ; isWebview ?: boolean }
518
523
519
- function registerPorts ( context : GitpodExtensionContext ) : void {
520
- const isPortsViewExperimentEnable = vscode . workspace . getConfiguration ( 'gitpod.experimental.portsView' ) . get < boolean > ( 'enabled' ) ;
524
+ async function registerPorts ( context : GitpodExtensionContext ) : Promise < void > {
525
+
526
+ const isSaaSGitpod = context . info . getGitpodHost ( ) === 'https://gitpod.io' ;
527
+ const packageJSON = context . extension . packageJSON ;
528
+ const experiments = new ExperimentalSettings ( process . env [ 'GITPOD_CONFIGCAT_SDK_KEY' ] ?? packageJSON . configcatKey , packageJSON . version , context . logger ) ;
529
+ context . subscriptions . push ( experiments ) ;
530
+ async function getPortsViewExperimentEnable ( ) : Promise < boolean > {
531
+ const ret = isSaaSGitpod
532
+ ? ( await experiments . get < boolean > ( 'gitpod.experimental.portsView.enabled' , ( await context . user ) . id , { team_ids : ( await context . userTeams ) . map ( e => e . id ) . join ( ',' ) , } ) ) !
533
+ : vscode . workspace . getConfiguration ( 'gitpod' ) . get < boolean > ( 'experimental.portsView.enabled' ) ! ;
534
+ return ret ;
535
+ }
536
+
537
+ const isPortsViewExperimentEnable = await getPortsViewExperimentEnable ( ) ;
521
538
522
539
const portMap = new Map < number , GitpodWorkspacePort > ( ) ;
523
540
const tunnelMap = new Map < number , vscode . TunnelDescription > ( ) ;
@@ -577,6 +594,7 @@ function registerPorts(context: GitpodExtensionContext): void {
577
594
}
578
595
} ) ;
579
596
}
597
+
580
598
context . subscriptions . push ( observePortsStatus ( ) ) ;
581
599
context . subscriptions . push ( vscode . commands . registerCommand ( 'gitpod.resolveExternalPort' , ( portNumber : number ) => {
582
600
// eslint-disable-next-line no-async-promise-executor
@@ -616,14 +634,14 @@ function registerPorts(context: GitpodExtensionContext): void {
616
634
context . subscriptions . push ( vscode . commands . registerCommand ( 'gitpod.ports.makePrivate' , ( { port, isWebview } : PortItem ) => {
617
635
context . fireAnalyticsEvent ( {
618
636
eventName : 'vscode_execute_command_gitpod_ports' ,
619
- properties : { action : 'private' , isWebview : ! ! isWebview }
637
+ properties : { action : 'private' , isWebview : ! ! isWebview , userOverride : String ( isUserOverrideSetting ( 'gitpod.experimental.portsView.enabled' ) ) }
620
638
} ) ;
621
639
return port . setPortVisibility ( 'private' ) ;
622
640
} ) ) ;
623
641
context . subscriptions . push ( vscode . commands . registerCommand ( 'gitpod.ports.makePublic' , ( { port, isWebview } : PortItem ) => {
624
642
context . fireAnalyticsEvent ( {
625
643
eventName : 'vscode_execute_command_gitpod_ports' ,
626
- properties : { action : 'public' , isWebview : ! ! isWebview }
644
+ properties : { action : 'public' , isWebview : ! ! isWebview , userOverride : String ( isUserOverrideSetting ( 'gitpod.experimental.portsView.enabled' ) ) }
627
645
} ) ;
628
646
return port . setPortVisibility ( 'public' ) ;
629
647
} ) ) ;
@@ -636,14 +654,14 @@ function registerPorts(context: GitpodExtensionContext): void {
636
654
context . subscriptions . push ( vscode . commands . registerCommand ( 'gitpod.ports.preview' , ( { port, isWebview } : PortItem ) => {
637
655
context . fireAnalyticsEvent ( {
638
656
eventName : 'vscode_execute_command_gitpod_ports' ,
639
- properties : { action : 'preview' , isWebview : ! ! isWebview }
657
+ properties : { action : 'preview' , isWebview : ! ! isWebview , userOverride : String ( isUserOverrideSetting ( 'gitpod.experimental.portsView.enabled' ) ) }
640
658
} ) ;
641
659
return openPreview ( port ) ;
642
660
} ) ) ;
643
661
context . subscriptions . push ( vscode . commands . registerCommand ( 'gitpod.ports.openBrowser' , ( { port, isWebview } : PortItem ) => {
644
662
context . fireAnalyticsEvent ( {
645
663
eventName : 'vscode_execute_command_gitpod_ports' ,
646
- properties : { action : 'openBrowser' , isWebview : ! ! isWebview }
664
+ properties : { action : 'openBrowser' , isWebview : ! ! isWebview , userOverride : String ( isUserOverrideSetting ( 'gitpod.experimental.portsView.enabled' ) ) }
647
665
} ) ;
648
666
return openExternal ( port ) ;
649
667
} ) ) ;
@@ -657,7 +675,7 @@ function registerPorts(context: GitpodExtensionContext): void {
657
675
658
676
const portsStatusBarItem = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Right ) ;
659
677
context . subscriptions . push ( portsStatusBarItem ) ;
660
- function updateStatusBar ( ) : void {
678
+ async function updateStatusBar ( ) : Promise < void > {
661
679
const exposedPorts : number [ ] = [ ] ;
662
680
663
681
for ( const port of portMap . values ( ) ) {
@@ -679,8 +697,8 @@ function registerPorts(context: GitpodExtensionContext): void {
679
697
680
698
portsStatusBarItem . text = text ;
681
699
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' ;
700
+
701
+ portsStatusBarItem . command = ( await getPortsViewExperimentEnable ( ) ) ? 'gitpod.portsView.focus' : 'gitpod.ports.reveal' ;
684
702
portsStatusBarItem . show ( ) ;
685
703
}
686
704
updateStatusBar ( ) ;
@@ -820,11 +838,11 @@ function registerPorts(context: GitpodExtensionContext): void {
820
838
vscode . commands . executeCommand ( 'gitpod.api.connectLocalApp' , apiPort ) ;
821
839
}
822
840
} ) ) ;
823
- vscode . workspace . onDidChangeConfiguration ( ( e : vscode . ConfigurationChangeEvent ) => {
841
+ vscode . workspace . onDidChangeConfiguration ( async ( e : vscode . ConfigurationChangeEvent ) => {
824
842
if ( ! e . affectsConfiguration ( 'gitpod.experimental.portsView.enabled' ) ) {
825
843
return ;
826
844
}
827
- const isPortsViewExperimentEnable = vscode . workspace . getConfiguration ( 'gitpod.experimental.portsView' ) . get < boolean > ( 'enabled' ) ;
845
+ const isPortsViewExperimentEnable = await getPortsViewExperimentEnable ( ) ;
828
846
vscode . commands . executeCommand ( 'setContext' , 'gitpod.portsView.visible' , isPortsViewExperimentEnable ) ;
829
847
gitpodWorkspaceTreeDataProvider . updateIsPortsViewExperimentEnable ( isPortsViewExperimentEnable ?? false ) ;
830
848
updateStatusBar ( ) ;
0 commit comments