@@ -15,6 +15,10 @@ const extensionVersion = extension.packageJSON.version;
1515// telemetry reporter
1616let reporter : TelemetryReporter ;
1717
18+ // Token expiration check interval (in milliseconds) - check every 60 seconds
19+ const TOKEN_CHECK_INTERVAL = 60000 ;
20+ let tokenExpirationTimer : NodeJS . Timeout | undefined ;
21+
1822// this method is called when your extension is activated
1923// your extension is activated the very first time the command is executed
2024export function activate ( context : vscode . ExtensionContext ) {
@@ -29,6 +33,9 @@ export function activate(context: vscode.ExtensionContext) {
2933 registerTreeDataProviders ( context , reporter ) ;
3034 registerCommands ( context , reporter ) ;
3135
36+ // Start periodic token expiration check
37+ startTokenExpirationCheck ( context ) ;
38+
3239 let dataverseToolsPublicApi = {
3340 currentConnectionToken ( ) {
3441 const dvHelper = new DataverseHelper ( context ) ;
@@ -41,5 +48,57 @@ export function activate(context: vscode.ExtensionContext) {
4148
4249// this method is called when your extension is deactivated
4350export function deactivate ( ) {
51+ if ( tokenExpirationTimer ) {
52+ clearInterval ( tokenExpirationTimer ) ;
53+ }
4454 reporter . dispose ( ) ;
4555}
56+
57+ /**
58+ * Start periodic token expiration check
59+ */
60+ function startTokenExpirationCheck ( context : vscode . ExtensionContext ) {
61+ let lastNotifiedExpiration = false ;
62+
63+ tokenExpirationTimer = setInterval ( ( ) => {
64+ const dvHelper = new DataverseHelper ( context ) ;
65+ const isExpired = dvHelper . isCurrentConnectionTokenExpired ( ) ;
66+
67+ if ( isExpired && ! lastNotifiedExpiration ) {
68+ // Get current connection to create tree item for reconnect
69+ const conn = dvHelper . getCurrentWorkspaceConnection ( ) ;
70+
71+ // Show notification to user
72+ vscode . window . showWarningMessage (
73+ "Your Dataverse connection token has expired. Please reconnect to continue working." ,
74+ "Reconnect"
75+ ) . then ( selection => {
76+ if ( selection === "Reconnect" && conn ) {
77+ // Create a tree item with the connection name to pass to the command
78+ const connItem = {
79+ label : conn . connectionName ,
80+ desc : conn . userName ,
81+ collapsibleState : vscode . TreeItemCollapsibleState . Collapsed ,
82+ level : 2 ,
83+ current : true ,
84+ expired : true
85+ } ;
86+ vscode . commands . executeCommand ( "dvdt.explorer.connections.connectDataverse" , connItem ) ;
87+ }
88+ } ) ;
89+
90+ lastNotifiedExpiration = true ;
91+
92+ // Refresh the connection tree to show expired icon
93+ vscode . commands . executeCommand ( "dvdt.explorer.connections.refreshConnection" ) ;
94+
95+ // Update status bar to show expired state
96+ if ( conn ) {
97+ vscode . commands . executeCommand ( "dvdt.explorer.connections.updateStatusBar" , conn ) ;
98+ }
99+ } else if ( ! isExpired ) {
100+ // Reset notification flag when token is refreshed
101+ lastNotifiedExpiration = false ;
102+ }
103+ } , TOKEN_CHECK_INTERVAL ) ;
104+ }
0 commit comments