@@ -2,22 +2,14 @@ import * as vscode from "vscode";
22import * as fs from "fs" ;
33import * as path from "path" ;
44
5- let idleFilePath : string
6- let terminalActivityInterval : NodeJS . Timeout | undefined
7- const LOG_PREFIX = "[sagemaker-idle-extension]"
8- const CHECK_INTERVAL = 60000 ; // 60 seconds interval
5+ let idleFilePath : string ;
96
107export function activate ( context : vscode . ExtensionContext ) {
118 initializeIdleFilePath ( ) ;
129 registerEventListeners ( context ) ;
13- startMonitoringTerminalActivity ( ) ;
1410}
1511
16- export function deactivate ( ) {
17- if ( terminalActivityInterval ) {
18- clearInterval ( terminalActivityInterval )
19- }
20- }
12+ export function deactivate ( ) { }
2113
2214/**
2315 * Initializes the file path where the idle timestamp will be stored.
@@ -28,7 +20,7 @@ function initializeIdleFilePath() {
2820 idleFilePath = path . join ( tmpDirectory , ".sagemaker-last-active-timestamp" ) ;
2921
3022 // Set initial lastActivetimestamp
31- updateLastActivityTimestamp ( )
23+ updateLastActivityTimestamp ( ) ;
3224}
3325
3426/**
@@ -56,52 +48,6 @@ function registerEventListeners(context: vscode.ExtensionContext) {
5648 ) ;
5749}
5850
59- /**
60- * Starts monitoring terminal activity by setting an interval to check for activity in the /dev/pts directory.
61- */
62- const startMonitoringTerminalActivity = ( ) => {
63- terminalActivityInterval = setInterval ( checkTerminalActivity , CHECK_INTERVAL ) ;
64- } ;
65-
66-
67- /**
68- * Checks for terminal activity by reading the /dev/pts directory and comparing modification times of the files.
69- *
70- * The /dev/pts directory is used in Unix-like operating systems to represent pseudo-terminal (PTY) devices.
71- * Each active terminal session is assigned a PTY device. These devices are represented as files within the /dev/pts directory.
72- * When a terminal session has activity, such as when a user inputs commands or output is written to the terminal,
73- * the modification time (mtime) of the corresponding PTY device file is updated. By monitoring the modification
74- * times of the files in the /dev/pts directory, we can detect terminal activity.
75- *
76- * If activity is detected (i.e., if any PTY device file was modified within the CHECK_INTERVAL), this function
77- * updates the last activity timestamp.
78- */
79- const checkTerminalActivity = ( ) => {
80- fs . readdir ( "/dev/pts" , ( err , files ) => {
81- if ( err ) {
82- console . error ( `${ LOG_PREFIX } Error reading /dev/pts directory:` , err ) ;
83- return ;
84- }
85-
86- const now = Date . now ( ) ;
87- const activityDetected = files . some ( ( file ) => {
88- const filePath = path . join ( "/dev/pts" , file ) ;
89- try {
90- const stats = fs . statSync ( filePath ) ;
91- const mtime = new Date ( stats . mtime ) . getTime ( ) ;
92- return now - mtime < CHECK_INTERVAL ;
93- } catch ( error ) {
94- console . error ( `${ LOG_PREFIX } Error reading file stats:` , error ) ;
95- return false ;
96- }
97- } ) ;
98-
99- if ( activityDetected ) {
100- updateLastActivityTimestamp ( ) ;
101- }
102- } ) ;
103- } ;
104-
10551/**
10652 * Updates the last activity timestamp by recording the current timestamp in the idle file and
10753 * refreshing the status bar. The timestamp should be in ISO 8601 format and set to the UTC timezone.
0 commit comments