提交 b782c3a6 编写于 作者: B Benjamin Pasero

storage - avoid storage access on shutdown

上级 e7bfb7b0
...@@ -199,7 +199,6 @@ export class StorageService extends Disposable implements IStorageService { ...@@ -199,7 +199,6 @@ export class StorageService extends Disposable implements IStorageService {
'workbench.panelpart.activepanelid', 'workbench.panelpart.activepanelid',
'workbench.zenmode.active', 'workbench.zenmode.active',
'workbench.centerededitorlayout.active', 'workbench.centerededitorlayout.active',
'workbench.sidebar.restore',
'workbench.sidebar.hidden', 'workbench.sidebar.hidden',
'workbench.panel.hidden', 'workbench.panel.hidden',
'workbench.panel.location', 'workbench.panel.location',
......
...@@ -72,7 +72,7 @@ import { ProgressService2 } from 'vs/workbench/services/progress/browser/progres ...@@ -72,7 +72,7 @@ import { ProgressService2 } from 'vs/workbench/services/progress/browser/progres
import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService'; import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
import { ITextModelService } from 'vs/editor/common/services/resolverService'; import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { ShutdownReason, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle'; import { LifecyclePhase, StartupKind } from 'vs/platform/lifecycle/common/lifecycle';
import { LifecycleService } from 'vs/platform/lifecycle/electron-browser/lifecycleService'; import { LifecycleService } from 'vs/platform/lifecycle/electron-browser/lifecycleService';
import { IWindowService, IWindowConfiguration, IPath, MenuBarVisibility, getTitleBarStyle } from 'vs/platform/windows/common/windows'; import { IWindowService, IWindowConfiguration, IPath, MenuBarVisibility, getTitleBarStyle } from 'vs/platform/windows/common/windows';
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar'; import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
...@@ -171,7 +171,6 @@ export class Workbench extends Disposable implements IPartService { ...@@ -171,7 +171,6 @@ export class Workbench extends Disposable implements IPartService {
private static readonly sidebarHiddenStorageKey = 'workbench.sidebar.hidden'; private static readonly sidebarHiddenStorageKey = 'workbench.sidebar.hidden';
private static readonly menubarVisibilityConfigurationKey = 'window.menuBarVisibility'; private static readonly menubarVisibilityConfigurationKey = 'window.menuBarVisibility';
private static readonly sidebarRestoreStorageKey = 'workbench.sidebar.restore';
private static readonly panelHiddenStorageKey = 'workbench.panel.hidden'; private static readonly panelHiddenStorageKey = 'workbench.panel.hidden';
private static readonly zenModeActiveStorageKey = 'workbench.zenmode.active'; private static readonly zenModeActiveStorageKey = 'workbench.zenmode.active';
private static readonly centeredEditorLayoutActiveStorageKey = 'workbench.centerededitorlayout.active'; private static readonly centeredEditorLayoutActiveStorageKey = 'workbench.centerededitorlayout.active';
...@@ -476,8 +475,8 @@ export class Workbench extends Disposable implements IPartService { ...@@ -476,8 +475,8 @@ export class Workbench extends Disposable implements IPartService {
private registerListeners(): void { private registerListeners(): void {
// Lifecycle // Storage
this._register(this.lifecycleService.onBeforeShutdown(e => this.saveState(e.reason))); this._register(this.storageService.onWillSaveState(() => this.saveState()));
// Listen to visible editor changes // Listen to visible editor changes
this._register(this.editorService.onDidVisibleEditorsChange(() => this.onDidVisibleEditorsChange())); this._register(this.editorService.onDidVisibleEditorsChange(() => this.onDidVisibleEditorsChange()));
...@@ -758,8 +757,10 @@ export class Workbench extends Disposable implements IPartService { ...@@ -758,8 +757,10 @@ export class Workbench extends Disposable implements IPartService {
perf.mark('didRestorePanel'); perf.mark('didRestorePanel');
} }
// Restore Zen Mode if active // Restore Zen Mode if active and supported for restore on startup
if (this.storageService.getBoolean(Workbench.zenModeActiveStorageKey, StorageScope.WORKSPACE, false)) { const zenConfig = this.configurationService.getValue<IZenModeSettings>('zenMode');
const wasZenActive = this.storageService.getBoolean(Workbench.zenModeActiveStorageKey, StorageScope.WORKSPACE, false);
if (wasZenActive && (zenConfig.restore || this.lifecycleService.startupKind === StartupKind.ReloadedWindow)) {
this.toggleZenMode(true, true); this.toggleZenMode(true, true);
} }
...@@ -802,12 +803,8 @@ export class Workbench extends Disposable implements IPartService { ...@@ -802,12 +803,8 @@ export class Workbench extends Disposable implements IPartService {
return true; // always restore sidebar when we are in development mode return true; // always restore sidebar when we are in development mode
} }
const restore = this.storageService.getBoolean(Workbench.sidebarRestoreStorageKey, StorageScope.WORKSPACE); // always restore sidebar when the window was reloaded
if (restore) { return this.lifecycleService.startupKind === StartupKind.ReloadedWindow;
this.storageService.remove(Workbench.sidebarRestoreStorageKey, StorageScope.WORKSPACE); // only support once
}
return restore;
} }
private resolveEditorsToOpen(): Thenable<IResourceEditor[]> | IResourceEditor[] { private resolveEditorsToOpen(): Thenable<IResourceEditor[]> | IResourceEditor[] {
...@@ -1121,23 +1118,10 @@ export class Workbench extends Disposable implements IPartService { ...@@ -1121,23 +1118,10 @@ export class Workbench extends Disposable implements IPartService {
return this.instantiationService; return this.instantiationService;
} }
private saveState(reason: ShutdownReason): void { private saveState(): void {
if (this.zenMode.active) {
// Restore sidebar if we are being shutdown as a matter of a reload
if (reason === ShutdownReason.RELOAD) {
this.storageService.store(Workbench.sidebarRestoreStorageKey, true, StorageScope.WORKSPACE);
}
// Preserve zen mode only on reload. Real quit gets out of zen mode so novice users do not get stuck in zen mode.
const zenConfig = this.configurationService.getValue<IZenModeSettings>('zenMode');
const restoreZenMode = this.zenMode.active && (zenConfig.restore || reason === ShutdownReason.RELOAD);
if (restoreZenMode) {
this.storageService.store(Workbench.zenModeActiveStorageKey, true, StorageScope.WORKSPACE); this.storageService.store(Workbench.zenModeActiveStorageKey, true, StorageScope.WORKSPACE);
} else { } else {
if (this.zenMode.active) {
this.toggleZenMode(true);
}
this.storageService.remove(Workbench.zenModeActiveStorageKey, StorageScope.WORKSPACE); this.storageService.remove(Workbench.zenModeActiveStorageKey, StorageScope.WORKSPACE);
} }
} }
......
...@@ -175,7 +175,7 @@ export class HistoryService extends Disposable implements IHistoryService { ...@@ -175,7 +175,7 @@ export class HistoryService extends Disposable implements IHistoryService {
this._register(this.editorService.onDidActiveEditorChange(() => this.onActiveEditorChanged())); this._register(this.editorService.onDidActiveEditorChange(() => this.onActiveEditorChanged()));
this._register(this.editorService.onDidOpenEditorFail(event => this.remove(event.editor))); this._register(this.editorService.onDidOpenEditorFail(event => this.remove(event.editor)));
this._register(this.editorService.onDidCloseEditor(event => this.onEditorClosed(event))); this._register(this.editorService.onDidCloseEditor(event => this.onEditorClosed(event)));
this._register(this.storageService.onWillSaveState(reason => this.saveState())); this._register(this.storageService.onWillSaveState(() => this.saveState()));
this._register(this.fileService.onFileChanges(event => this.onFileChanges(event))); this._register(this.fileService.onFileChanges(event => this.onFileChanges(event)));
this._register(this.resourceFilter.onExpressionChange(() => this.handleExcludesChange())); this._register(this.resourceFilter.onExpressionChange(() => this.handleExcludesChange()));
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册