@@ -31,12 +31,13 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
3131import { mnemonicButtonLabel } from 'vs/base/common/labels' ;
3232import { Schemas } from 'vs/base/common/network' ;
3333import { normalizeNFC } from 'vs/base/common/normalization' ;
34- import { URI , UriComponents } from 'vs/base/common/uri' ;
34+ import { URI } from 'vs/base/common/uri' ;
3535import { Queue , timeout } from 'vs/base/common/async' ;
3636import { exists } from 'vs/base/node/pfs' ;
3737import { getComparisonKey , isEqual , normalizePath , basename as resourcesBasename , fsPath } from 'vs/base/common/resources' ;
3838import { endsWith } from 'vs/base/common/strings' ;
3939import { getRemoteAuthority } from 'vs/platform/remote/common/remoteHosts' ;
40+ import { IWindowsState , restoreWindowsState , WindowsStateStoreData , IWindowState , getWindowsStateStoreData } from 'vs/code/electron-main/windowsState' ;
4041
4142const enum WindowError {
4243 UNRESPONSIVE = 1 ,
@@ -47,40 +48,6 @@ interface INewWindowState extends ISingleWindowState {
4748 hasDefaultState ?: boolean ;
4849}
4950
50- interface IWindowState {
51- workspace ?: IWorkspaceIdentifier ;
52- folderUri ?: URI ;
53- backupPath : string ;
54- remoteAuthority ?: string ;
55- uiState : ISingleWindowState ;
56- }
57-
58- interface IWindowsState {
59- lastActiveWindow ?: IWindowState ;
60- lastPluginDevelopmentHostWindow ?: IWindowState ;
61- openedWindows : IWindowState [ ] ;
62- }
63-
64- interface ISerializedWindowsState {
65- lastActiveWindow ?: ISerializedWindowState ;
66- lastPluginDevelopmentHostWindow ?: ISerializedWindowState ;
67- openedWindows : ISerializedWindowState [ ] ;
68- }
69-
70- interface ISerializedWindowState {
71- workspaceIdentifier ?: { id : string ; configURIPath : string } ;
72- folder ?: string ;
73- backupPath : string ;
74- remoteAuthority ?: string ;
75- uiState : ISingleWindowState ;
76-
77- // deprecated
78- folderUri ?: UriComponents ;
79- folderPath ?: string ;
80- workspace ?: { id : string ; configPath : string } ;
81-
82- }
83-
8451type RestoreWindowsSetting = 'all' | 'folders' | 'one' | 'none' ;
8552
8653interface IOpenBrowserWindowOptions {
@@ -177,7 +144,9 @@ export class WindowsManager implements IWindowsMainService {
177144 @IWorkspacesMainService private readonly workspacesMainService : IWorkspacesMainService ,
178145 @IInstantiationService private readonly instantiationService : IInstantiationService
179146 ) {
180- this . windowsState = this . getWindowsState ( ) ;
147+ const windowsStateStoreData = this . stateService . getItem < WindowsStateStoreData > ( WindowsManager . windowsStateStorageKey ) ;
148+
149+ this . windowsState = restoreWindowsState ( windowsStateStoreData ) ;
181150 if ( ! Array . isArray ( this . windowsState . openedWindows ) ) {
182151 this . windowsState . openedWindows = [ ] ;
183152 }
@@ -186,39 +155,6 @@ export class WindowsManager implements IWindowsMainService {
186155 this . workspacesManager = new WorkspacesManager ( workspacesMainService , backupMainService , environmentService , historyMainService , this ) ;
187156 }
188157
189- private getWindowsState ( ) : IWindowsState {
190- const result : IWindowsState = { openedWindows : [ ] } ;
191- const windowsState = this . stateService . getItem < ISerializedWindowsState > ( WindowsManager . windowsStateStorageKey ) || { openedWindows : [ ] } ;
192-
193- if ( windowsState . lastActiveWindow ) {
194- result . lastActiveWindow = this . deserialize ( windowsState . lastActiveWindow ) ;
195- }
196- if ( windowsState . lastPluginDevelopmentHostWindow ) {
197- result . lastPluginDevelopmentHostWindow = this . deserialize ( windowsState . lastPluginDevelopmentHostWindow ) ;
198- }
199- if ( Array . isArray ( windowsState . openedWindows ) ) {
200- result . openedWindows = windowsState . openedWindows . map ( windowState => this . deserialize ( windowState ) ) ;
201- }
202- return result ;
203- }
204-
205- private deserialize ( windowState : ISerializedWindowState ) : IWindowState {
206- const result : IWindowState = { backupPath : windowState . backupPath , remoteAuthority : windowState . remoteAuthority , uiState : windowState . uiState } ;
207- if ( windowState . folder ) {
208- result . folderUri = URI . parse ( windowState . folder ) ;
209- } else if ( windowState . folderUri ) {
210- result . folderUri = URI . revive ( windowState . folderUri ) ;
211- } else if ( windowState . folderPath ) {
212- result . folderUri = URI . file ( windowState . folderPath ) ;
213- }
214- if ( windowState . workspaceIdentifier ) {
215- result . workspace = { id : windowState . workspaceIdentifier . id , configPath : URI . parse ( windowState . workspaceIdentifier . configURIPath ) } ;
216- } else if ( windowState . workspace ) {
217- result . workspace = { id : windowState . workspace . id , configPath : URI . file ( windowState . workspace . configPath ) } ;
218- }
219- return result ;
220- }
221-
222158 ready ( initialUserEnv : IProcessEnvironment ) : void {
223159 this . initialUserEnv = initialUserEnv ;
224160
@@ -337,25 +273,7 @@ export class WindowsManager implements IWindowsMainService {
337273 }
338274
339275 // Persist
340- this . stateService . setItem ( WindowsManager . windowsStateStorageKey , this . serializeWindowsState ( currentWindowsState ) ) ;
341- }
342-
343- private serializeWindowsState ( windowsState : IWindowsState ) : ISerializedWindowsState {
344- return {
345- lastActiveWindow : windowsState . lastActiveWindow && this . serialize ( windowsState . lastActiveWindow ) ,
346- lastPluginDevelopmentHostWindow : windowsState . lastPluginDevelopmentHostWindow && this . serialize ( windowsState . lastPluginDevelopmentHostWindow ) ,
347- openedWindows : windowsState . openedWindows . map ( ws => this . serialize ( ws ) )
348- } ;
349- }
350-
351- private serialize ( windowState : IWindowState ) : ISerializedWindowState {
352- return {
353- workspaceIdentifier : windowState . workspace && { id : windowState . workspace . id , configURIPath : windowState . workspace . configPath . toString ( ) } ,
354- folder : windowState . folderUri && windowState . folderUri . toString ( ) ,
355- backupPath : windowState . backupPath ,
356- remoteAuthority : windowState . remoteAuthority ,
357- uiState : windowState . uiState
358- } ;
276+ this . stateService . setItem ( WindowsManager . windowsStateStorageKey , getWindowsStateStoreData ( currentWindowsState ) ) ;
359277 }
360278
361279 // See note on #onBeforeShutdown() for details how these events are flowing
0 commit comments