Skip to content

Commit f0704a6

Browse files
committed
Conditionally reinstate explorer refresh
It was originally introduced to fix #256
1 parent c6ae912 commit f0704a6

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

src/api/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,11 @@ export class AtelierAPI {
343343
authRequestMap.delete(target);
344344
if (this.wsOrFile && !checkingConnection) {
345345
setTimeout(() => {
346-
checkConnection(password ? true : false, typeof this.wsOrFile === "object" ? this.wsOrFile : undefined);
346+
checkConnection(
347+
password ? true : false,
348+
typeof this.wsOrFile === "object" ? this.wsOrFile : undefined,
349+
true
350+
);
347351
}, 500);
348352
}
349353
throw { statusCode: response.status, message: response.statusText };
@@ -425,7 +429,7 @@ export class AtelierAPI {
425429
workspaceState.update(this.configName + ":host", undefined);
426430
workspaceState.update(this.configName + ":port", undefined);
427431
if (!checkingConnection) {
428-
setTimeout(checkConnection, 30000);
432+
setTimeout(() => checkConnection(false, undefined, true), 30000);
429433
}
430434
} else if (error.code === "EPROTO") {
431435
// This can happen if https was configured but didn't work

src/commands/serverActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export async function serverActions(): Promise<void> {
5353
return connConfig.update("conn", { ...targetConfig, active: !active }, target);
5454
}
5555
case "refreshConnection": {
56-
await checkConnection(true);
56+
await checkConnection(true, undefined, true);
5757
break;
5858
}
5959
default:

src/extension.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,11 @@ export function getResolvedConnectionSpec(key: string, dflt: any): any {
231231
*/
232232
export const cspApps: Map<string, string[]> = new Map();
233233

234-
export async function checkConnection(clearCookies = false, uri?: vscode.Uri): Promise<void> {
234+
export async function checkConnection(
235+
clearCookies = false,
236+
uri?: vscode.Uri,
237+
triggerRefreshes?: boolean
238+
): Promise<void> {
235239
// Do nothing if already checking the connection
236240
if (checkingConnection) {
237241
return;
@@ -418,10 +422,18 @@ export async function checkConnection(clearCookies = false, uri?: vscode.Uri): P
418422
})
419423
.finally(() => {
420424
checkingConnection = false;
421-
setTimeout(() => {
422-
explorerProvider.refresh();
423-
projectsExplorerProvider.refresh();
424-
}, 20);
425+
if (triggerRefreshes) {
426+
setTimeout(() => {
427+
explorerProvider.refresh();
428+
projectsExplorerProvider.refresh();
429+
// Refreshing Files Explorer also switches to it, so only do this if the uri is part of the workspace,
430+
// otherwise files opened from ObjectScript Explorer (objectscript:// or isfs:// depending on the "objectscript.serverSideEditing" setting)
431+
// will cause an unwanted switch.
432+
if (uri && schemas.includes(uri.scheme) && vscode.workspace.getWorkspaceFolder(uri)) {
433+
vscode.commands.executeCommand("workbench.files.action.refreshFilesExplorer");
434+
}
435+
}, 20);
436+
}
425437
});
426438
}
427439

@@ -594,7 +606,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
594606
try {
595607
await resolveConnectionSpec(serverName);
596608
} finally {
597-
await checkConnection(true, uri);
609+
await checkConnection(true, uri, true);
598610
}
599611
} catch (_) {
600612
// Ignore any failure
@@ -1060,7 +1072,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
10601072
refreshFilesExplorer = true;
10611073
}
10621074
try {
1063-
await checkConnection(true, folder.uri);
1075+
await checkConnection(true, folder.uri, true);
10641076
} catch (_) {
10651077
continue;
10661078
}

0 commit comments

Comments
 (0)