77
88import { ipcMain as ipc , app } from 'electron' ;
99import { TPromise , TValueCallback } from 'vs/base/common/winjs.base' ;
10- import { ReadyState , VSCodeWindow } from 'vs/code/electron-main/window' ;
1110import { IEnvironmentService } from 'vs/platform/environment/common/environment' ;
12- import { ILogService } from 'vs/code /common/log' ;
13- import { IStorageService } from 'vs/code /node/storage' ;
11+ import { ILogService } from 'vs/platform/log /common/log' ;
12+ import { IStorageService } from 'vs/platform/storage /node/storage' ;
1413import Event , { Emitter } from 'vs/base/common/event' ;
1514import { createDecorator } from 'vs/platform/instantiation/common/instantiation' ;
15+ import { ICodeWindow , ReadyState } from "vs/platform/windows/common/windows" ;
1616
1717export const ILifecycleService = createDecorator < ILifecycleService > ( 'lifecycleService' ) ;
1818
@@ -43,12 +43,12 @@ export interface ILifecycleService {
4343 * is called even when the window prevents the closing. We want an event that truly fires
4444 * before the window gets closed for real.
4545 */
46- onBeforeWindowClose : Event < VSCodeWindow > ;
46+ onBeforeWindowClose : Event < ICodeWindow > ;
4747
4848 ready ( ) : void ;
49- registerWindow ( vscodeWindow : VSCodeWindow ) : void ;
49+ registerWindow ( codeWindow : ICodeWindow ) : void ;
5050
51- unload ( vscodeWindow : VSCodeWindow , reason : UnloadReason ) : TPromise < boolean /* veto */ > ;
51+ unload ( codeWindow : ICodeWindow , reason : UnloadReason ) : TPromise < boolean /* veto */ > ;
5252
5353 relaunch ( options ?: { addArgs ?: string [ ] , removeArgs ?: string [ ] } ) ;
5454
@@ -74,8 +74,8 @@ export class LifecycleService implements ILifecycleService {
7474 private _onBeforeQuit = new Emitter < void > ( ) ;
7575 onBeforeQuit : Event < void > = this . _onBeforeQuit . event ;
7676
77- private _onBeforeWindowClose = new Emitter < VSCodeWindow > ( ) ;
78- onBeforeWindowClose : Event < VSCodeWindow > = this . _onBeforeWindowClose . event ;
77+ private _onBeforeWindowClose = new Emitter < ICodeWindow > ( ) ;
78+ onBeforeWindowClose : Event < ICodeWindow > = this . _onBeforeWindowClose . event ;
7979
8080 constructor (
8181 @IEnvironmentService private environmentService : IEnvironmentService ,
@@ -132,11 +132,11 @@ export class LifecycleService implements ILifecycleService {
132132 } ) ;
133133 }
134134
135- public registerWindow ( vscodeWindow : VSCodeWindow ) : void {
135+ public registerWindow ( codeWindow : ICodeWindow ) : void {
136136
137137 // Window Before Closing: Main -> Renderer
138- vscodeWindow . win . on ( 'close' , ( e ) => {
139- const windowId = vscodeWindow . id ;
138+ codeWindow . onClose ( e => {
139+ const windowId = codeWindow . id ;
140140 this . logService . log ( 'Lifecycle#window-before-close' , windowId ) ;
141141
142142 // The window already acknowledged to be closed
@@ -150,11 +150,11 @@ export class LifecycleService implements ILifecycleService {
150150
151151 // Otherwise prevent unload and handle it from window
152152 e . preventDefault ( ) ;
153- this . unload ( vscodeWindow , UnloadReason . CLOSE ) . done ( veto => {
153+ this . unload ( codeWindow , UnloadReason . CLOSE ) . done ( veto => {
154154 if ( ! veto ) {
155155 this . windowToCloseRequest [ windowId ] = true ;
156- this . _onBeforeWindowClose . fire ( vscodeWindow ) ;
157- vscodeWindow . win . close ( ) ;
156+ this . _onBeforeWindowClose . fire ( codeWindow ) ;
157+ codeWindow . close ( ) ;
158158 } else {
159159 this . quitRequested = false ;
160160 delete this . windowToCloseRequest [ windowId ] ;
@@ -163,14 +163,14 @@ export class LifecycleService implements ILifecycleService {
163163 } ) ;
164164 }
165165
166- public unload ( vscodeWindow : VSCodeWindow , reason : UnloadReason ) : TPromise < boolean /* veto */ > {
166+ public unload ( codeWindow : ICodeWindow , reason : UnloadReason ) : TPromise < boolean /* veto */ > {
167167
168168 // Always allow to unload a window that is not yet ready
169- if ( vscodeWindow . readyState !== ReadyState . READY ) {
169+ if ( codeWindow . readyState !== ReadyState . READY ) {
170170 return TPromise . as < boolean > ( false ) ;
171171 }
172172
173- this . logService . log ( 'Lifecycle#unload()' , vscodeWindow . id ) ;
173+ this . logService . log ( 'Lifecycle#unload()' , codeWindow . id ) ;
174174
175175 return new TPromise < boolean > ( ( c ) => {
176176 const oneTimeEventToken = this . oneTimeListenerTokenGenerator ++ ;
@@ -193,7 +193,7 @@ export class LifecycleService implements ILifecycleService {
193193 c ( true ) ; // veto
194194 } ) ;
195195
196- vscodeWindow . send ( 'vscode:beforeUnload' , { okChannel, cancelChannel, reason : this . quitRequested ? UnloadReason . QUIT : reason } ) ;
196+ codeWindow . send ( 'vscode:beforeUnload' , { okChannel, cancelChannel, reason : this . quitRequested ? UnloadReason . QUIT : reason } ) ;
197197 } ) ;
198198 }
199199
0 commit comments