77import { TPromise } from 'vs/base/common/winjs.base' ;
88import Severity from 'vs/base/common/severity' ;
99import { toErrorMessage } from 'vs/base/common/errorMessage' ;
10- import { ILifecycleService , ShutdownEvent , ShutdownReason } from 'vs/platform/lifecycle/common/lifecycle' ;
10+ import { ILifecycleService , ShutdownEvent , ShutdownReason , StartupKind } from 'vs/platform/lifecycle/common/lifecycle' ;
1111import { IMessageService } from 'vs/platform/message/common/message' ;
12+ import { IStorageService , StorageScope } from 'vs/platform/storage/common/storage' ;
1213import { IWindowIPCService } from 'vs/workbench/services/window/electron-browser/windowService' ;
1314import { ipcRenderer as ipc } from 'electron' ;
1415import Event , { Emitter } from 'vs/base/common/event' ;
1516
1617export class LifecycleService implements ILifecycleService {
1718
19+ private static readonly _lastShutdownReasonKey = 'lifecyle.lastShutdownReason' ;
20+
1821 public _serviceBrand : any ;
1922
20- private _onWillShutdown = new Emitter < ShutdownEvent > ( ) ;
21- private _onShutdown = new Emitter < ShutdownReason > ( ) ;
23+ private readonly _onWillShutdown = new Emitter < ShutdownEvent > ( ) ;
24+ private readonly _onShutdown = new Emitter < ShutdownReason > ( ) ;
25+ private readonly _startupKind : StartupKind ;
2226
2327 private _willShutdown : boolean ;
2428
2529 constructor (
26- @IMessageService private messageService : IMessageService ,
27- @IWindowIPCService private windowService : IWindowIPCService
30+ @IMessageService private _messageService : IMessageService ,
31+ @IWindowIPCService private _windowService : IWindowIPCService ,
32+ @IStorageService private _storageService : IStorageService
2833 ) {
29- this . registerListeners ( ) ;
34+ this . _registerListeners ( ) ;
35+
36+ const lastShutdownReason = this . _storageService . getInteger ( LifecycleService . _lastShutdownReasonKey , StorageScope . WORKSPACE ) ;
37+ this . _storageService . remove ( LifecycleService . _lastShutdownReasonKey , StorageScope . WORKSPACE ) ;
38+ if ( lastShutdownReason === ShutdownReason . RELOAD ) {
39+ this . _startupKind = StartupKind . ReloadedWindow ;
40+ } else if ( lastShutdownReason === ShutdownReason . LOAD ) {
41+ this . _startupKind = StartupKind . ReopenedWindow ;
42+ } else {
43+ this . _startupKind = StartupKind . NewWindow ;
44+ }
45+ console . log ( this . startupKind ) ;
46+ }
47+
48+ public get startupKind ( ) : StartupKind {
49+ return this . _startupKind ;
3050 }
3151
3252 public get willShutdown ( ) : boolean {
@@ -41,16 +61,18 @@ export class LifecycleService implements ILifecycleService {
4161 return this . _onShutdown . event ;
4262 }
4363
44- private registerListeners ( ) : void {
45- const windowId = this . windowService . getWindowId ( ) ;
64+ private _registerListeners ( ) : void {
65+ const windowId = this . _windowService . getWindowId ( ) ;
4666
4767 // Main side indicates that window is about to unload, check for vetos
4868 ipc . on ( 'vscode:beforeUnload' , ( event , reply : { okChannel : string , cancelChannel : string , reason : ShutdownReason } ) => {
4969 this . _willShutdown = true ;
70+ this . _storageService . store ( LifecycleService . _lastShutdownReasonKey , JSON . stringify ( reply . reason ) , StorageScope . WORKSPACE ) ;
5071
5172 // trigger onWillShutdown events and veto collecting
5273 this . onBeforeUnload ( reply . reason ) . done ( veto => {
5374 if ( veto ) {
75+ this . _storageService . remove ( LifecycleService . _lastShutdownReasonKey , StorageScope . WORKSPACE ) ;
5476 this . _willShutdown = false ; // reset this flag since the shutdown has been vetoed!
5577 ipc . send ( reply . cancelChannel , windowId ) ;
5678 } else {
@@ -92,11 +114,11 @@ export class LifecycleService implements ILifecycleService {
92114 }
93115 } , err => {
94116 // error, treated like a veto, done
95- this . messageService . show ( Severity . Error , toErrorMessage ( err ) ) ;
117+ this . _messageService . show ( Severity . Error , toErrorMessage ( err ) ) ;
96118 lazyValue = true ;
97119 } ) ) ;
98120 }
99121 }
100122 return TPromise . join ( promises ) . then ( ( ) => lazyValue ) ;
101123 }
102- }
124+ }
0 commit comments