@@ -12,6 +12,8 @@ import { UserContext } from "../user-context";
12
12
import { trackEvent } from "../Analytics" ;
13
13
import SelectIDE from "./SelectIDE" ;
14
14
import { PageWithSettingsSubMenu } from "./PageWithSettingsSubMenu" ;
15
+ import CheckBox from "../components/CheckBox" ;
16
+ import { WorkspaceTimeoutDuration } from "@gitpod/gitpod-protocol" ;
15
17
16
18
type Theme = "light" | "dark" | "system" ;
17
19
@@ -47,6 +49,32 @@ export default function Preferences() {
47
49
}
48
50
} ;
49
51
52
+ const [ disabledClosedTimeout , setDisabledClosedTimeout ] = useState < boolean > (
53
+ user ?. additionalData ?. disabledClosedTimeout ?? false ,
54
+ ) ;
55
+ const actuallySetDisabledClosedTimeout = async ( value : boolean ) => {
56
+ try {
57
+ const additionalData = user ?. additionalData || { } ;
58
+ additionalData . disabledClosedTimeout = value ;
59
+ await getGitpodService ( ) . server . updateLoggedInUser ( { additionalData } ) ;
60
+ setDisabledClosedTimeout ( value ) ;
61
+ } catch ( e ) {
62
+ alert ( "Cannot set custom workspace timeout: " + e . message ) ;
63
+ }
64
+ } ;
65
+
66
+ const [ workspaceTimeout , setWorkspaceTimeout ] = useState < string > ( user ?. additionalData ?. workspaceTimeout ?? "" ) ;
67
+ const actuallySetWorkspaceTimeout = async ( value : string ) => {
68
+ try {
69
+ const timeout = WorkspaceTimeoutDuration . validate ( value ) ;
70
+ const additionalData = user ?. additionalData || { } ;
71
+ additionalData . workspaceTimeout = timeout ;
72
+ await getGitpodService ( ) . server . updateLoggedInUser ( { additionalData } ) ;
73
+ } catch ( e ) {
74
+ alert ( "Cannot set custom workspace timeout: " + e . message ) ;
75
+ }
76
+ } ;
77
+
50
78
return (
51
79
< div >
52
80
< PageWithSettingsSubMenu >
@@ -142,6 +170,42 @@ export default function Preferences() {
142
170
</ p >
143
171
</ div >
144
172
</ div >
173
+
174
+ < h3 className = "mt-12" > Inactivity Timeout </ h3 >
175
+ < p className = "text-base text-gray-500 dark:text-gray-400" >
176
+ By default, workspaces stop following 30 minutes without user input (e.g. keystrokes or terminal
177
+ input commands). You can increase the workspace timeout up to a maximum of 24 hours.
178
+ </ p >
179
+ < div className = "mt-4 max-w-xl" >
180
+ < h4 > Default Inactivity Timeout</ h4 >
181
+ < span className = "flex" >
182
+ < input
183
+ type = "text"
184
+ className = "w-96 h-9"
185
+ value = { workspaceTimeout }
186
+ placeholder = "timeout time, such as 30m, 1h, max 24h"
187
+ onChange = { ( e ) => setWorkspaceTimeout ( e . target . value ) }
188
+ />
189
+ < button
190
+ className = "secondary ml-2"
191
+ onClick = { ( ) => actuallySetWorkspaceTimeout ( workspaceTimeout ) }
192
+ >
193
+ Save Changes
194
+ </ button >
195
+ </ span >
196
+ < div className = "mt-1" >
197
+ < p className = "text-gray-500 dark:text-gray-400" >
198
+ Use minutes or hours, like < strong > 30m</ strong > or < strong > 2h</ strong > .
199
+ </ p >
200
+ </ div >
201
+
202
+ < CheckBox
203
+ title = "Keep workspace running"
204
+ desc = { < span > Don't change workspace inactivity timeout when closing the editor.</ span > }
205
+ checked = { disabledClosedTimeout }
206
+ onChange = { ( e ) => actuallySetDisabledClosedTimeout ( e . target . checked ) }
207
+ />
208
+ </ div >
145
209
</ PageWithSettingsSubMenu >
146
210
</ div >
147
211
) ;
0 commit comments