2
2
* Copyright (c) Gitpod. All rights reserved.
3
3
*--------------------------------------------------------------------------------------------*/
4
4
5
- import { GitpodClient , GitpodServer , GitpodServiceImpl } from '@gitpod/gitpod-protocol/lib/gitpod-service' ;
5
+ import { GitpodClient , GitpodServer , GitpodServiceImpl , WorkspaceTimeoutDuration } from '@gitpod/gitpod-protocol/lib/gitpod-service' ;
6
6
import { JsonRpcProxyFactory } from '@gitpod/gitpod-protocol/lib/messaging/proxy-factory' ;
7
7
import { NavigatorContext } from '@gitpod/gitpod-protocol/lib/protocol' ;
8
8
import { ErrorCodes } from '@gitpod/gitpod-protocol/lib/messaging/error' ;
@@ -239,7 +239,7 @@ export async function registerWorkspaceCommands(context: GitpodExtensionContext)
239
239
return context . gitpod . server . stopWorkspace ( context . info . workspaceId ) ;
240
240
} ) ) ;
241
241
context . subscriptions . push ( vscode . commands . registerCommand ( 'gitpod.upgradeSubscription' , ( ) => {
242
- const url = new GitpodHostUrl ( context . info . gitpodHost ) . asUpgradeSubscription ( ) . toString ( ) ;
242
+ const url = new GitpodHostUrl ( context . info . gitpodHost ) . asBilling ( ) . toString ( ) ;
243
243
context . fireAnalyticsEvent ( {
244
244
eventName : 'vscode_execute_command_gitpod_open_link' ,
245
245
properties : { url }
@@ -387,12 +387,36 @@ export async function registerWorkspaceTimeout(context: GitpodExtensionContext):
387
387
}
388
388
} ) ;
389
389
try {
390
- const result = await context . gitpod . server . setWorkspaceTimeout ( context . info . workspaceId , '180m' ) ;
391
- if ( result . resetTimeoutOnWorkspaces ?. length > 0 ) {
392
- vscode . window . showWarningMessage ( 'Workspace timeout has been extended to three hours. This reset the workspace timeout for other workspaces.' ) ;
393
- } else {
394
- vscode . window . showInformationMessage ( 'Workspace timeout has been extended to three hours.' ) ;
390
+ await context . gitpod . server . setWorkspaceTimeout ( context . info . workspaceId , '180m' ) ;
391
+ vscode . window . showWarningMessage ( `Workspace timeout has been extended to 180m.` ) ;
392
+ } catch ( err ) {
393
+ vscode . window . showErrorMessage ( `Cannot extend workspace timeout: ${ err . toString ( ) } ` ) ;
394
+ }
395
+ } ) ) ;
396
+
397
+
398
+ context . subscriptions . push ( vscode . commands . registerCommand ( 'gitpod.setWorkspaceTimeout' , async ( ) => {
399
+ const timeout = await vscode . window . showInputBox ( {
400
+ placeHolder : 'Please input the timeout time, such as 30m, 1h, 2h, 3h' ,
401
+ validateInput : ( value : string ) => {
402
+ if ( ! WorkspaceTimeoutDuration . validate ( value ) ) {
403
+ return 'Please input the timeout time, such as 30m, 1h, 2h, 3h' ;
404
+ }
405
+ return '' ;
406
+ }
407
+ } ) ;
408
+ if ( ! timeout ) {
409
+ return ;
410
+ }
411
+ context . fireAnalyticsEvent ( {
412
+ eventName : 'vscode_execute_command_gitpod_workspace' ,
413
+ properties : {
414
+ action : 'configure-timeout'
395
415
}
416
+ } ) ;
417
+ try {
418
+ const { humanReadableDuration } = await context . gitpod . server . setWorkspaceTimeout ( context . info . workspaceId , timeout ) ;
419
+ vscode . window . showWarningMessage ( `Workspace timeout has been extended to ${ humanReadableDuration ?? timeout } .` ) ;
396
420
} catch ( err ) {
397
421
vscode . window . showErrorMessage ( `Cannot extend workspace timeout: ${ err . toString ( ) } ` ) ;
398
422
}
@@ -405,18 +429,20 @@ export async function registerWorkspaceTimeout(context: GitpodExtensionContext):
405
429
406
430
const listener = await context . instanceListener ;
407
431
const extendTimeoutStatusBarItem = vscode . window . createStatusBarItem ( 'gitpod.extendTimeout' , vscode . StatusBarAlignment . Right , - 100 ) ;
408
- extendTimeoutStatusBarItem . name = 'Click to extend the workspace timeout.' ;
432
+ extendTimeoutStatusBarItem . name = 'Extend the workspace timeout.' ;
409
433
context . subscriptions . push ( extendTimeoutStatusBarItem ) ;
410
434
extendTimeoutStatusBarItem . text = '$(watch)' ;
411
- extendTimeoutStatusBarItem . command = 'gitpod.ExtendTimeout ' ;
435
+ extendTimeoutStatusBarItem . command = 'gitpod.setWorkspaceTimeout ' ;
412
436
const update = ( ) => {
413
437
const instance = listener . info . latestInstance ;
414
438
if ( ! instance ) {
415
439
extendTimeoutStatusBarItem . hide ( ) ;
416
440
return ;
417
441
}
418
442
extendTimeoutStatusBarItem . tooltip = `Workspace Timeout: ${ instance . status . timeout } . Click to extend.` ;
419
- extendTimeoutStatusBarItem . color = instance . status . timeout === '180m' ? new vscode . ThemeColor ( 'notificationsWarningIcon.foreground' ) : undefined ;
443
+
444
+ // TODO: query default timeout, currently all paid plan default timeout is 60m.
445
+ extendTimeoutStatusBarItem . color = instance . status . timeout !== '60m' ? new vscode . ThemeColor ( 'notificationsWarningIcon.foreground' ) : undefined ;
420
446
extendTimeoutStatusBarItem . show ( ) ;
421
447
} ;
422
448
update ( ) ;
0 commit comments