Skip to content

Commit 1d72798

Browse files
author
Benjamin Pasero
committed
save participants do not run on shutdown
1 parent 6fc7710 commit 1d72798

4 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/vs/platform/lifecycle/common/lifecycle.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ export interface ILifecycleService {
3232

3333
_serviceBrand: any;
3434

35+
/**
36+
* A flag indicating if the application is in the process of shutting down. This will be true
37+
* before the onWillShutdown event is fired and false if the shutdown is being vetoed.
38+
*/
39+
willShutdown: boolean;
40+
3541
/**
3642
* Fired before shutdown happens. Allows listeners to veto against the
3743
* shutdown.
@@ -47,6 +53,7 @@ export interface ILifecycleService {
4753

4854
export const NullLifecycleService: ILifecycleService = {
4955
_serviceBrand: null,
56+
willShutdown: false,
5057
onWillShutdown: () => ({ dispose() { } }),
5158
onShutdown: () => ({ dispose() { } })
5259
};

src/vs/test/utils/servicesTestUtils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,8 @@ export class TestLifecycleService implements ILifecycleService {
607607

608608
public _serviceBrand: any;
609609

610+
public willShutdown: boolean;
611+
610612
private _onWillShutdown = new Emitter<ShutdownEvent>();
611613
private _onShutdown = new Emitter<void>();
612614

src/vs/workbench/parts/files/common/editors/textFileEditorModel.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import diagnostics = require('vs/base/common/diagnostics');
1717
import types = require('vs/base/common/types');
1818
import {IModelContentChangedEvent} from 'vs/editor/common/editorCommon';
1919
import {IMode} from 'vs/editor/common/modes';
20+
import {ILifecycleService} from 'vs/platform/lifecycle/common/lifecycle';
2021
import {ITextFileService, IAutoSaveConfiguration, ModelState, ITextFileEditorModel, ISaveErrorHandler, ISaveParticipant, StateChange} from 'vs/workbench/parts/files/common/files';
2122
import {EncodingMode, EditorModel} from 'vs/workbench/common/editor';
2223
import {BaseTextEditorModel} from 'vs/workbench/common/editor/textEditorModel';
@@ -64,6 +65,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
6465
@IModeService modeService: IModeService,
6566
@IModelService modelService: IModelService,
6667
@IFileService private fileService: IFileService,
68+
@ILifecycleService private lifecycleService: ILifecycleService,
6769
@IInstantiationService private instantiationService: IInstantiationService,
6870
@ITelemetryService private telemetryService: ITelemetryService,
6971
@ITextFileService private textFileService: ITextFileService
@@ -441,9 +443,11 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
441443
// A save participant can still change the model now and since we are so close to saving
442444
// we do not want to trigger another auto save or similar, so we block this
443445
// In addition we update our version right after in case it changed because of a model change
446+
// We DO NOT run any save participant if we are in the shutdown phase and files are being
447+
// saved as a result of that.
444448
let saveParticipantPromise = TPromise.as(versionId);
445449

446-
if (TextFileEditorModel.saveParticipant) {
450+
if (TextFileEditorModel.saveParticipant && !this.lifecycleService.willShutdown) {
447451
saveParticipantPromise = TPromise.as(undefined).then(() => {
448452
this.blockModelContentChange = true;
449453
return TextFileEditorModel.saveParticipant.participate(this, { isAutoSaved });

src/vs/workbench/services/lifecycle/electron-browser/lifecycleService.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,19 @@ export class LifecycleService implements ILifecycleService {
2020
private _onWillShutdown = new Emitter<ShutdownEvent>();
2121
private _onShutdown = new Emitter<void>();
2222

23+
private _willShutdown: boolean;
24+
2325
constructor(
2426
@IMessageService private messageService: IMessageService,
2527
@IWindowService private windowService: IWindowService
2628
) {
2729
this.registerListeners();
2830
}
2931

32+
public get willShutdown(): boolean {
33+
return this._willShutdown;
34+
}
35+
3036
public get onWillShutdown(): Event<ShutdownEvent> {
3137
return this._onWillShutdown.event;
3238
}
@@ -40,8 +46,12 @@ export class LifecycleService implements ILifecycleService {
4046

4147
// Main side indicates that window is about to unload, check for vetos
4248
ipc.on('vscode:beforeUnload', (event, reply: { okChannel: string, cancelChannel: string }) => {
49+
this._willShutdown = true;
50+
51+
// trigger onWillShutdown events and veto collecting
4352
this.onBeforeUnload().done(veto => {
4453
if (veto) {
54+
this._willShutdown = false; // reset this flag since the shutdown has been vetoed!
4555
ipc.send(reply.cancelChannel, windowId);
4656
} else {
4757
this._onShutdown.fire();

0 commit comments

Comments
 (0)