Change:
zen mode vscode, start vscode that zen mode properly is not restored excepted centered layout. Centered layout should also be inactive (since is )
acutally your change from that commit caused this. You removed that the zen mode gets out of zen mode when you are exiting. Let me look into a fix
the idea is to only write to local storage from and not . Is writing any data to local storage? If not, this change seems fine.
it is writing data to local storage. I just need to write it before the workbench goes down. So I will react on instead of . That event will only get fired once before the workbench shuts down?
yeah currently that is right. In the future when we decide to store state more periodically we might decide to call this method more often though to preserve state even if Code is crashing. I do not understand why you have to leave Zen mode on shutdown because you will restore it on the next startup, no? Given that, I suggest to NOT leave Zen mode on shutdown but rather simply NOT restore it on next startup. Isn't that easier?
thanks for clarification. I can not simply NOT restore it on next startup since the subsets of zen mode will have written state to storage. Example: User enters zen mode -zen mode tells Sidebar hide yourself. Sidebar writes that into storage Next vscode start -zen mode is not restored, Sidebar is still hidden because he wrote into storage once we activated zen mode. Due to how the feature is designed it needs to explicitly tell the underlying parts to hide or show. We could change this, but that would require that every underlying part is aware of zen mode which might overcomplicate things. Suggestions on how to tackle this are also welcome Thanks
got it. I pushed a change so that carries a with a reason you can ask for. On shutdown that reason will be set and so you can do the same things as before. As long as you are not running async code that accesses storage late, things should be fine. The goal should be that storage layer gets accessed either: when changes happen (e.g. workbench layout does that) or (which currently only fires on shutdown but might fire periodically later)
this works. However there was a corner case for the reload since we were restoring zen mode always on reload and in your event i was not getting if it is a reload or regular shutdown Though fixed it by not auto restoring zen mode on reload. I think this is perfectly fine. Users should set zenMode.restore to true if they want this
thank you

Discussion:
import { getServices } from 'vs/platform/instantiation/common/extensions'; import { Position, Parts, IPartService, ILayoutOptions, IDimension, PositionToString } from 'vs/workbench/services/part/common/partService'; import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace'; <del> import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage'; </del> <ins> import { IStorageService, StorageScope, IWillSaveStateEvent, WillSaveStateReason } from 'vs/platform/storage/common/storage'; </ins> import { ContextMenuService as NativeContextMenuService } from 'vs/workbench/services/contextview/electron-browser/contextmenuService'; import { ContextMenuService as HTMLContextMenuService } from 'vs/platform/contextview/browser/contextMenuService'; import { WorkbenchKeybindingService } from 'vs/workbench/services/keybinding/electron-browser/keybindingService';

private registerListeners(): void { // Storage <del> this._register(this.storageService.onWillSaveState(() => this.saveState())); </del> <ins> this._register(this.storageService.onWillSaveState(e => this.saveState(e))); </ins> // Listen to visible editor changes this._register(this.editorService.onDidVisibleEditorsChange(() => this.onDidVisibleEditorsChange()));

// Restore Zen Mode if active and supported for restore on startup const zenConfig = this.configurationService.getValue<IZenModeSettings>('zenMode'); const wasZenActive = this.storageService.getBoolean(Workbench.zenModeActiveStorageKey, StorageScope.WORKSPACE, false); <del> if (wasZenActive && (zenConfig.restore || this.lifecycleService.startupKind === StartupKind.ReloadedWindow)) { </del> <ins> if (wasZenActive && zenConfig.restore) { </ins> this.toggleZenMode(true, true); }

return this.instantiationService; } <del> private saveState(): void { </del> <ins> private saveState(e: IWillSaveStateEvent): void { </ins> if (this.zenMode.active) { this.storageService.store(Workbench.zenModeActiveStorageKey, true, StorageScope.WORKSPACE); } else { this.storageService.remove(Workbench.zenModeActiveStorageKey, StorageScope.WORKSPACE); } <ins> if (e.reason === WillSaveStateReason.SHUTDOWN && this.zenMode.active) { const zenConfig = this.configurationService.getValue<IZenModeSettings>('zenMode'); if (!zenConfig.restore) { // We will not restore zen mode, need to clear all zen mode state changes this.toggleZenMode(true); } } </ins> } dispose(): void {