@@ -247,7 +247,7 @@ Index: sagemaker-code-editor/vscode/src/vs/server/node/webClientServer.ts
247247 import * as path from 'path';
248248 import * as http from 'http';
249249 import * as url from 'url';
250- @@ -91,8 +93,47 @@ export async function serveFile(filePath
250+ @@ -91,8 +93,41 @@ export async function serveFile(filePath
251251 }
252252 }
253253
@@ -266,52 +266,46 @@ Index: sagemaker-code-editor/vscode/src/vs/server/node/webClientServer.ts
266266+ * If activity is detected (i.e., if any PTY device file was modified within the CHECK_INTERVAL), this function
267267+ * updates the last activity timestamp.
268268+ */
269- + const checkTerminalActivity = (idleFilePath: string) => {
270- + fs.readdir('/dev/pts', (err, files) => {
271- + if (err) {
272- + console.error('Error reading /dev/pts directory:', err);
273- + return;
274- + }
275- +
269+ + function checkTerminalActivity(idleFilePath: string) {
270+ + try {
271+ + const files: string[] = fs.readdirSync('/dev/pts');
276272+ const now = new Date();
277- + const activityDetected = files.some((file) => {
273+ +
274+ + const activityDetected = files.some((file: string) => {
278275+ const filePath = path.join('/dev/pts', file);
279- + try {
280- + const stats = fs.statSync(filePath);
281- + const mtime = new Date(stats.mtime).getTime();
282- + return now.getTime() - mtime < CHECK_INTERVAL;
283- + } catch (error) {
284- + console.error('Error reading file stats:', error);
285- + return false;
286- + }
276+ + const stats = fs.statSync(filePath);
277+ + const mtime = new Date(stats.mtime).getTime();
278+ + return now.getTime() - mtime < CHECK_INTERVAL;
287279+ });
288280+
289281+ if (activityDetected) {
290282+ fs.writeFileSync(idleFilePath, now.toISOString());
291283+ }
292- + });
293- + };
284+ + } catch (err) {
285+ + console.error('Error checking terminal activity:', err);
286+ + }
287+ + }
294288+
295289 export class WebClientServer {
296290
297291 private readonly _webExtensionResourceUrlTemplate: URI | undefined;
298- @@ -100,6 +141 ,7 @@ export class WebClientServer {
292+ @@ -100,6 +135 ,7 @@ export class WebClientServer {
299293 private readonly _staticRoute: string;
300294 private readonly _callbackRoute: string;
301295 private readonly _webExtensionRoute: string;
302296+ private readonly _idleRoute: string;
303297
304298 constructor(
305299 private readonly _connectionToken: ServerConnectionToken,
306- @@ -115,6 +157 ,7 @@ export class WebClientServer {
300+ @@ -115,6 +151 ,7 @@ export class WebClientServer {
307301 this._staticRoute = `${serverRootPath}/static`;
308302 this._callbackRoute = `${serverRootPath}/callback`;
309303 this._webExtensionRoute = `${serverRootPath}/web-extension-resource`;
310304+ this._idleRoute = '/api/idle';
311305 }
312306
313307 /**
314- @@ -132,6 +175 ,9 @@ export class WebClientServer {
308+ @@ -132,6 +169 ,9 @@ export class WebClientServer {
315309 if (pathname === this._basePath) {
316310 return this._handleRoot(req, res, parsedUrl);
317311 }
@@ -321,7 +315,7 @@ Index: sagemaker-code-editor/vscode/src/vs/server/node/webClientServer.ts
321315 if (pathname === this._callbackRoute) {
322316 // callback support
323317 return this._handleCallback(res);
324- @@ -451,6 +497 ,33 @@ export class WebClientServer {
318+ @@ -451,6 +491 ,33 @@ export class WebClientServer {
325319 });
326320 return void res.end(data);
327321 }
0 commit comments