Skip to content

Commit f56e95e

Browse files
authored
Merge pull request microsoft#104933 from microsoft/sandy081/globalIsNew
support isNew with global scope
2 parents b6ff910 + 89ba5a0 commit f56e95e

4 files changed

Lines changed: 38 additions & 24 deletions

File tree

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle';
77
import { Emitter } from 'vs/base/common/event';
8-
import { IWorkspaceStorageChangeEvent, IStorageService, StorageScope, IWillSaveStateEvent, WillSaveStateReason, logStorage } from 'vs/platform/storage/common/storage';
8+
import { IWorkspaceStorageChangeEvent, IStorageService, StorageScope, IWillSaveStateEvent, WillSaveStateReason, logStorage, IS_NEW_KEY } from 'vs/platform/storage/common/storage';
99
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1010
import { IWorkspaceInitializationPayload } from 'vs/platform/workspaces/common/workspaces';
1111
import { IFileService, FileChangeType } from 'vs/platform/files/common/files';
@@ -20,8 +20,6 @@ export class BrowserStorageService extends Disposable implements IStorageService
2020

2121
declare readonly _serviceBrand: undefined;
2222

23-
private static readonly WORKSPACE_IS_NEW_KEY = '__$__isNewStorageMarker';
24-
2523
private readonly _onDidChangeStorage = this._register(new Emitter<IWorkspaceStorageChangeEvent>());
2624
readonly onDidChangeStorage = this._onDidChangeStorage.event;
2725

@@ -82,12 +80,20 @@ export class BrowserStorageService extends Disposable implements IStorageService
8280
this.globalStorage.init()
8381
]);
8482

85-
// Check to see if this is the first time we are "opening" this workspace
86-
const firstOpen = this.workspaceStorage.getBoolean(BrowserStorageService.WORKSPACE_IS_NEW_KEY);
83+
// Check to see if this is the first time we are "opening" the application
84+
const firstOpen = this.globalStorage.getBoolean(IS_NEW_KEY);
8785
if (firstOpen === undefined) {
88-
this.workspaceStorage.set(BrowserStorageService.WORKSPACE_IS_NEW_KEY, true);
86+
this.globalStorage.set(IS_NEW_KEY, true);
8987
} else if (firstOpen) {
90-
this.workspaceStorage.set(BrowserStorageService.WORKSPACE_IS_NEW_KEY, false);
88+
this.globalStorage.set(IS_NEW_KEY, false);
89+
}
90+
91+
// Check to see if this is the first time we are "opening" this workspace
92+
const firstWorkspaceOpen = this.workspaceStorage.getBoolean(IS_NEW_KEY);
93+
if (firstWorkspaceOpen === undefined) {
94+
this.workspaceStorage.set(IS_NEW_KEY, true);
95+
} else if (firstWorkspaceOpen) {
96+
this.workspaceStorage.set(IS_NEW_KEY, false);
9197
}
9298

9399
// In the browser we do not have support for long running unload sequences. As such,
@@ -189,8 +195,8 @@ export class BrowserStorageService extends Disposable implements IStorageService
189195
this.dispose();
190196
}
191197

192-
isNew(scope: StorageScope.WORKSPACE): boolean {
193-
return this.getBoolean(BrowserStorageService.WORKSPACE_IS_NEW_KEY, scope) === true;
198+
isNew(scope: StorageScope): boolean {
199+
return this.getBoolean(IS_NEW_KEY, scope) === true;
194200
}
195201

196202
dispose(): void {

src/vs/platform/storage/common/storage.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { Disposable } from 'vs/base/common/lifecycle';
99
import { isUndefinedOrNull } from 'vs/base/common/types';
1010
import { IWorkspaceInitializationPayload } from 'vs/platform/workspaces/common/workspaces';
1111

12+
export const IS_NEW_KEY = '__$__isNewStorageMarker';
13+
1214
export const IStorageService = createDecorator<IStorageService>('storageService');
1315

1416
export enum WillSaveStateReason {
@@ -104,12 +106,11 @@ export interface IStorageService {
104106
migrate(toWorkspace: IWorkspaceInitializationPayload): Promise<void>;
105107

106108
/**
107-
* Wether the storage for the given scope was created during this session or
109+
* Whether the storage for the given scope was created during this session or
108110
* existed before.
109111
*
110-
* Note: currently only implemented for `WORKSPACE` scope.
111112
*/
112-
isNew(scope: StorageScope.WORKSPACE): boolean;
113+
isNew(scope: StorageScope): boolean;
113114

114115
/**
115116
* Allows to flush state, e.g. in cases where a shutdown is

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { INativeEnvironmentService } from 'vs/platform/environment/node/environm
1212
import { SQLiteStorageDatabase, ISQLiteStorageDatabaseLoggingOptions } from 'vs/base/parts/storage/node/storage';
1313
import { Storage, IStorage, InMemoryStorageDatabase } from 'vs/base/parts/storage/common/storage';
1414
import { join } from 'vs/base/common/path';
15+
import { IS_NEW_KEY } from 'vs/platform/storage/common/storage';
1516

1617
export const IStorageMainService = createDecorator<IStorageMainService>('storageMainService');
1718

@@ -135,15 +136,23 @@ export class StorageMainService extends Disposable implements IStorageMainServic
135136
return this.initializePromise;
136137
}
137138

138-
private doInitialize(): Promise<void> {
139+
private async doInitialize(): Promise<void> {
139140
this.storage.dispose();
140141
this.storage = new Storage(new SQLiteStorageDatabase(this.storagePath, {
141142
logging: this.createLogginOptions()
142143
}));
143144

144145
this._register(this.storage.onDidChangeStorage(key => this._onDidChangeStorage.fire({ key })));
145146

146-
return this.storage.init();
147+
await this.storage.init();
148+
149+
// Check to see if this is the first time we are "opening" the application
150+
const firstOpen = this.storage.getBoolean(IS_NEW_KEY);
151+
if (firstOpen === undefined) {
152+
this.storage.set(IS_NEW_KEY, true);
153+
} else if (firstOpen) {
154+
this.storage.set(IS_NEW_KEY, false);
155+
}
147156
}
148157

149158
get(key: string, fallbackValue: string): string;

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle';
77
import { Emitter } from 'vs/base/common/event';
88
import { ILogService, LogLevel } from 'vs/platform/log/common/log';
9-
import { IWorkspaceStorageChangeEvent, IStorageService, StorageScope, IWillSaveStateEvent, WillSaveStateReason, logStorage } from 'vs/platform/storage/common/storage';
9+
import { IWorkspaceStorageChangeEvent, IStorageService, StorageScope, IWillSaveStateEvent, WillSaveStateReason, logStorage, IS_NEW_KEY } from 'vs/platform/storage/common/storage';
1010
import { SQLiteStorageDatabase, ISQLiteStorageDatabaseLoggingOptions } from 'vs/base/parts/storage/node/storage';
1111
import { Storage, IStorageDatabase, IStorage, StorageHint } from 'vs/base/parts/storage/common/storage';
1212
import { mark } from 'vs/base/common/performance';
@@ -25,8 +25,6 @@ export class NativeStorageService extends Disposable implements IStorageService
2525
private static readonly WORKSPACE_STORAGE_NAME = 'state.vscdb';
2626
private static readonly WORKSPACE_META_NAME = 'workspace.json';
2727

28-
private static readonly WORKSPACE_IS_NEW_KEY = '__$__isNewStorageMarker';
29-
3028
private readonly _onDidChangeStorage = this._register(new Emitter<IWorkspaceStorageChangeEvent>());
3129
readonly onDidChangeStorage = this._onDidChangeStorage.event;
3230

@@ -108,11 +106,11 @@ export class NativeStorageService extends Disposable implements IStorageService
108106
await workspaceStorage.init();
109107

110108
// Check to see if this is the first time we are "opening" this workspace
111-
const firstOpen = workspaceStorage.getBoolean(NativeStorageService.WORKSPACE_IS_NEW_KEY);
112-
if (firstOpen === undefined) {
113-
workspaceStorage.set(NativeStorageService.WORKSPACE_IS_NEW_KEY, result.wasCreated);
114-
} else if (firstOpen) {
115-
workspaceStorage.set(NativeStorageService.WORKSPACE_IS_NEW_KEY, false);
109+
const firstWorkspaceOpen = workspaceStorage.getBoolean(IS_NEW_KEY);
110+
if (firstWorkspaceOpen === undefined) {
111+
workspaceStorage.set(IS_NEW_KEY, result.wasCreated);
112+
} else if (firstWorkspaceOpen) {
113+
workspaceStorage.set(IS_NEW_KEY, false);
116114
}
117115
} finally {
118116
mark('didInitWorkspaceStorage');
@@ -281,7 +279,7 @@ export class NativeStorageService extends Disposable implements IStorageService
281279
return this.createWorkspaceStorage(newWorkspaceStoragePath).init();
282280
}
283281

284-
isNew(scope: StorageScope.WORKSPACE): boolean {
285-
return this.getBoolean(NativeStorageService.WORKSPACE_IS_NEW_KEY, scope) === true;
282+
isNew(scope: StorageScope): boolean {
283+
return this.getBoolean(IS_NEW_KEY, scope) === true;
286284
}
287285
}

0 commit comments

Comments
 (0)