@@ -14,7 +14,7 @@ import { dirname, join } from 'vs/base/common/path';
14
14
import { basename , extUriBiasedIgnorePathCase , joinPath , originalFSPath } from 'vs/base/common/resources' ;
15
15
import { withNullAsUndefined } from 'vs/base/common/types' ;
16
16
import { URI } from 'vs/base/common/uri' ;
17
- import { Promises , readdirSync , rimrafSync , writeFileSync } from 'vs/base/node/pfs' ;
17
+ import { Promises , rimrafSync , writeFileSync } from 'vs/base/node/pfs' ;
18
18
import { localize } from 'vs/nls' ;
19
19
import { IBackupMainService } from 'vs/platform/backup/electron-main/backup' ;
20
20
import { IDialogMainService } from 'vs/platform/dialogs/electron-main/dialogMainService' ;
@@ -51,7 +51,7 @@ export interface IWorkspacesManagementMainService {
51
51
deleteUntitledWorkspace ( workspace : IWorkspaceIdentifier ) : Promise < void > ;
52
52
deleteUntitledWorkspaceSync ( workspace : IWorkspaceIdentifier ) : void ;
53
53
54
- getUntitledWorkspacesSync ( ) : IUntitledWorkspaceInfo [ ] ;
54
+ getUntitledWorkspaces ( ) : IUntitledWorkspaceInfo [ ] ;
55
55
isUntitledWorkspace ( workspace : IWorkspaceIdentifier ) : boolean ;
56
56
57
57
resolveLocalWorkspaceSync ( path : URI ) : IResolvedWorkspace | undefined ;
@@ -64,14 +64,16 @@ export class WorkspacesManagementMainService extends Disposable implements IWork
64
64
65
65
declare readonly _serviceBrand : undefined ;
66
66
67
- private readonly untitledWorkspacesHome = this . environmentMainService . untitledWorkspacesHome ; // local URI that contains all untitled workspaces
68
-
69
67
private readonly _onDidDeleteUntitledWorkspace = this . _register ( new Emitter < IWorkspaceIdentifier > ( ) ) ;
70
68
readonly onDidDeleteUntitledWorkspace : Event < IWorkspaceIdentifier > = this . _onDidDeleteUntitledWorkspace . event ;
71
69
72
70
private readonly _onDidEnterWorkspace = this . _register ( new Emitter < IWorkspaceEnteredEvent > ( ) ) ;
73
71
readonly onDidEnterWorkspace : Event < IWorkspaceEnteredEvent > = this . _onDidEnterWorkspace . event ;
74
72
73
+ private readonly untitledWorkspacesHome = this . environmentMainService . untitledWorkspacesHome ; // local URI that contains all untitled workspaces
74
+
75
+ private untitledWorkspaces : IUntitledWorkspaceInfo [ ] = [ ] ;
76
+
75
77
constructor (
76
78
@IEnvironmentMainService private readonly environmentMainService : IEnvironmentMainService ,
77
79
@ILogService private readonly logService : ILogService ,
@@ -83,6 +85,30 @@ export class WorkspacesManagementMainService extends Disposable implements IWork
83
85
super ( ) ;
84
86
}
85
87
88
+ async initialize ( ) : Promise < void > {
89
+
90
+ // Reset
91
+ this . untitledWorkspaces = [ ] ;
92
+
93
+ // Resolve untitled workspaces
94
+ try {
95
+ const untitledWorkspacePaths = ( await Promises . readdir ( this . untitledWorkspacesHome . fsPath ) ) . map ( folder => joinPath ( this . untitledWorkspacesHome , folder , UNTITLED_WORKSPACE_NAME ) ) ;
96
+ for ( const untitledWorkspacePath of untitledWorkspacePaths ) {
97
+ const workspace = getWorkspaceIdentifier ( untitledWorkspacePath ) ;
98
+ const resolvedWorkspace = await this . resolveLocalWorkspace ( untitledWorkspacePath ) ;
99
+ if ( ! resolvedWorkspace ) {
100
+ await this . deleteUntitledWorkspace ( workspace ) ;
101
+ } else {
102
+ this . untitledWorkspaces . push ( { workspace, remoteAuthority : resolvedWorkspace . remoteAuthority } ) ;
103
+ }
104
+ }
105
+ } catch ( error ) {
106
+ if ( error . code !== 'ENOENT' ) {
107
+ this . logService . warn ( `Unable to read folders in ${ this . untitledWorkspacesHome } (${ error } ).` ) ;
108
+ }
109
+ }
110
+ }
111
+
86
112
resolveLocalWorkspaceSync ( uri : URI ) : IResolvedWorkspace | undefined {
87
113
return this . doResolveLocalWorkspace ( uri , path => readFileSync ( path , 'utf8' ) ) ;
88
114
}
@@ -158,6 +184,8 @@ export class WorkspacesManagementMainService extends Disposable implements IWork
158
184
await Promises . mkdir ( dirname ( configPath ) , { recursive : true } ) ;
159
185
await Promises . writeFile ( configPath , JSON . stringify ( storedWorkspace , null , '\t' ) ) ;
160
186
187
+ this . untitledWorkspaces . push ( { workspace, remoteAuthority } ) ;
188
+
161
189
return workspace ;
162
190
}
163
191
@@ -168,6 +196,8 @@ export class WorkspacesManagementMainService extends Disposable implements IWork
168
196
mkdirSync ( dirname ( configPath ) , { recursive : true } ) ;
169
197
writeFileSync ( configPath , JSON . stringify ( storedWorkspace , null , '\t' ) ) ;
170
198
199
+ this . untitledWorkspaces . push ( { workspace, remoteAuthority } ) ;
200
+
171
201
return workspace ;
172
202
}
173
203
@@ -204,8 +234,8 @@ export class WorkspacesManagementMainService extends Disposable implements IWork
204
234
// Delete from disk
205
235
this . doDeleteUntitledWorkspaceSync ( workspace ) ;
206
236
237
+ // unset workspace from profiles
207
238
if ( this . userDataProfilesMainService . isEnabled ( ) ) {
208
- // unset workspace from profiles
209
239
this . userDataProfilesMainService . unsetWorkspace ( workspace ) ;
210
240
}
211
241
@@ -229,31 +259,16 @@ export class WorkspacesManagementMainService extends Disposable implements IWork
229
259
if ( existsSync ( workspaceStoragePath ) ) {
230
260
writeFileSync ( join ( workspaceStoragePath , 'obsolete' ) , '' ) ;
231
261
}
262
+
263
+ // Remove from list
264
+ this . untitledWorkspaces = this . untitledWorkspaces . filter ( untitledWorkspace => untitledWorkspace . workspace . id !== workspace . id ) ;
232
265
} catch ( error ) {
233
266
this . logService . warn ( `Unable to delete untitled workspace ${ configPath } (${ error } ).` ) ;
234
267
}
235
268
}
236
269
237
- getUntitledWorkspacesSync ( ) : IUntitledWorkspaceInfo [ ] {
238
- const untitledWorkspaces : IUntitledWorkspaceInfo [ ] = [ ] ;
239
- try {
240
- const untitledWorkspacePaths = readdirSync ( this . untitledWorkspacesHome . fsPath ) . map ( folder => joinPath ( this . untitledWorkspacesHome , folder , UNTITLED_WORKSPACE_NAME ) ) ;
241
- for ( const untitledWorkspacePath of untitledWorkspacePaths ) {
242
- const workspace = getWorkspaceIdentifier ( untitledWorkspacePath ) ;
243
- const resolvedWorkspace = this . resolveLocalWorkspaceSync ( untitledWorkspacePath ) ;
244
- if ( ! resolvedWorkspace ) {
245
- this . doDeleteUntitledWorkspaceSync ( workspace ) ;
246
- } else {
247
- untitledWorkspaces . push ( { workspace, remoteAuthority : resolvedWorkspace . remoteAuthority } ) ;
248
- }
249
- }
250
- } catch ( error ) {
251
- if ( error . code !== 'ENOENT' ) {
252
- this . logService . warn ( `Unable to read folders in ${ this . untitledWorkspacesHome } (${ error } ).` ) ;
253
- }
254
- }
255
-
256
- return untitledWorkspaces ;
270
+ getUntitledWorkspaces ( ) : IUntitledWorkspaceInfo [ ] {
271
+ return this . untitledWorkspaces ;
257
272
}
258
273
259
274
async enterWorkspace ( window : ICodeWindow , windows : ICodeWindow [ ] , path : URI ) : Promise < IEnterWorkspaceResult | undefined > {
0 commit comments