Skip to content

Commit 98b5bec

Browse files
author
Eric Amodio
committed
Fixes issue w/ the firstOpen setting on the web
Adds a safety-net check for Codespaces until the fix can be verified
1 parent c23285f commit 98b5bec

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

src/vs/platform/storage/browser/storageService.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,11 @@ export class BrowserStorageService extends Disposable implements IStorageService
6363

6464
// Workspace Storage
6565
this.workspaceStorageFile = joinPath(stateRoot, `${payload.id}.json`);
66+
6667
this.workspaceStorageDatabase = this._register(new FileStorageDatabase(this.workspaceStorageFile, false /* do not watch for external changes */, this.fileService));
6768
this.workspaceStorage = this._register(new Storage(this.workspaceStorageDatabase));
6869
this._register(this.workspaceStorage.onDidChangeStorage(key => this._onDidChangeStorage.fire({ key, scope: StorageScope.WORKSPACE })));
6970

70-
const firstOpen = this.workspaceStorage.getBoolean(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN);
71-
if (firstOpen === undefined) {
72-
this.workspaceStorage.set(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN, !(await this.fileService.exists(this.workspaceStorageFile)));
73-
} else if (firstOpen) {
74-
this.workspaceStorage.set(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN, false);
75-
}
76-
7771
// Global Storage
7872
this.globalStorageFile = joinPath(stateRoot, 'global.json');
7973
this.globalStorageDatabase = this._register(new FileStorageDatabase(this.globalStorageFile, true /* watch for external changes */, this.fileService));
@@ -86,6 +80,15 @@ export class BrowserStorageService extends Disposable implements IStorageService
8680
this.globalStorage.init()
8781
]);
8882

83+
// Check to see if this is the first time we are "opening" this workspace
84+
const firstOpen = this.workspaceStorage.getBoolean(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN);
85+
if (firstOpen === undefined) {
86+
// NOTE@eamodio We can't reliably check to see if a workspace was added before this setting was introduced, so just pretend it is the first time
87+
this.workspaceStorage.set(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN, true);
88+
} else if (firstOpen) {
89+
this.workspaceStorage.set(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN, false);
90+
}
91+
8992
// In the browser we do not have support for long running unload sequences. As such,
9093
// we cannot ask for saving state in that moment, because that would result in a
9194
// long running operation.

src/vs/platform/storage/node/storageService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export class NativeStorageService extends Disposable implements IStorageService
105105
);
106106
await workspaceStorage.init();
107107

108+
// Check to see if this is the first time we are "opening" this workspace
108109
const firstOpen = workspaceStorage.getBoolean(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN);
109110
if (firstOpen === undefined) {
110111
workspaceStorage.set(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN, !result.wasCreated);

src/vs/workbench/browser/layout.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,8 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
568568
return;
569569
}
570570

571-
const firstOpen = storageService.getBoolean(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN, StorageScope.WORKSPACE);
571+
// The `firstRun` flag check is a safety-net hack for Codespaces, until we can verify the first open fix
572+
const firstOpen = (storageService.getBoolean(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN, StorageScope.WORKSPACE) || (defaultLayout as { firstRun: boolean })?.firstRun);
572573
if (!firstOpen) {
573574
return;
574575
}
@@ -790,7 +791,8 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
790791

791792
private getInitialFilesToOpen(): { filesToOpenOrCreate?: IPath[], filesToDiff?: IPath[] } | undefined {
792793
const defaultLayout = this.environmentService.options?.defaultLayout;
793-
if (defaultLayout?.editors?.length && this.storageService.getBoolean(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN, StorageScope.WORKSPACE)) {
794+
// The `firstRun` flag check is a safety-net hack for Codespaces, until we can verify the first open fix
795+
if (defaultLayout?.editors?.length && (this.storageService.getBoolean(WorkspaceStorageSettings.WORKSPACE_FIRST_OPEN, StorageScope.WORKSPACE) || (defaultLayout as { firstRun: boolean })?.firstRun)) {
794796
this._openedDefaultEditors = true;
795797

796798
return {

0 commit comments

Comments
 (0)