Skip to content

Commit 2aa298a

Browse files
authored
💄
1 parent ba19b49 commit 2aa298a

File tree

1 file changed

+41
-37
lines changed

1 file changed

+41
-37
lines changed

src/vs/workbench/services/workingCopy/electron-sandbox/workingCopyBackupTracker.ts

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ export class NativeWorkingCopyBackupTracker extends WorkingCopyBackupTracker imp
114114
// Trigger backup if configured and enabled for shutdown reason
115115
let backups: IWorkingCopy[] = [];
116116
let backupError: Error | undefined = undefined;
117-
const copiesToBackup = await this.shouldBackupBeforeShutdown(reason, modifiedWorkingCopies);
118-
if (copiesToBackup.length > 0) {
117+
const modifiedWorkingCopiesToBackup = await this.shouldBackupBeforeShutdown(reason, modifiedWorkingCopies);
118+
if (modifiedWorkingCopiesToBackup.length > 0) {
119119
try {
120-
const backupResult = await this.backupBeforeShutdown(copiesToBackup);
120+
const backupResult = await this.backupBeforeShutdown(modifiedWorkingCopiesToBackup);
121121
backups = backupResult.backups;
122122
backupError = backupResult.error;
123123

@@ -163,47 +163,51 @@ export class NativeWorkingCopyBackupTracker extends WorkingCopyBackupTracker imp
163163
}
164164

165165
private async shouldBackupBeforeShutdown(reason: ShutdownReason, modifiedWorkingCopies: readonly IWorkingCopy[]): Promise<readonly IWorkingCopy[]> {
166-
167166
if (!this.filesConfigurationService.isHotExitEnabled) {
168167
return []; // never backup when hot exit is disabled via settings
169-
} else if (this.environmentService.isExtensionDevelopment) {
168+
}
169+
170+
if (this.environmentService.isExtensionDevelopment) {
170171
return modifiedWorkingCopies; // always backup closing extension development window without asking to speed up debugging
171-
} else {
172-
173-
// When quit is requested skip the confirm callback and attempt to backup all workspaces.
174-
// When quit is not requested the confirm callback should be shown when the window being
175-
// closed is the only VS Code window open, except for on Mac where hot exit is only
176-
// ever activated when quit is requested.
177-
178-
switch (reason) {
179-
case ShutdownReason.CLOSE:
180-
if (this.contextService.getWorkbenchState() !== WorkbenchState.EMPTY && this.filesConfigurationService.hotExitConfiguration === HotExitConfiguration.ON_EXIT_AND_WINDOW_CLOSE) {
181-
return modifiedWorkingCopies; // backup if a folder is open and onExitAndWindowClose is configured
182-
} else if (await this.nativeHostService.getWindowCount() > 1 || isMacintosh) {
183-
if (this.contextService.getWorkbenchState() !== WorkbenchState.EMPTY && this.filesConfigurationService.hotExitConfiguration !== HotExitConfiguration.OFF) {
184-
return modifiedWorkingCopies.filter(wc => wc.capabilities & WorkingCopyCapabilities.Scratchpad); // only backup scratchpad working copies
185-
}
186-
return []; // do not backup if a window is closed that does not cause quitting of the application
187-
} else {
188-
return modifiedWorkingCopies; // backup if last window is closed on win/linux where the application quits right after
189-
}
190-
case ShutdownReason.QUIT:
191-
return modifiedWorkingCopies; // backup because next start we restore all backups
172+
}
173+
174+
switch (reason) {
192175

193-
case ShutdownReason.RELOAD:
194-
return modifiedWorkingCopies; // backup because after window reload, backups restore
176+
// Window Close
177+
case ShutdownReason.CLOSE:
178+
if (this.contextService.getWorkbenchState() !== WorkbenchState.EMPTY && this.filesConfigurationService.hotExitConfiguration === HotExitConfiguration.ON_EXIT_AND_WINDOW_CLOSE) {
179+
return modifiedWorkingCopies; // backup if a workspace/folder is open and onExitAndWindowClose is configured
180+
}
195181

196-
case ShutdownReason.LOAD:
182+
if (isMacintosh || await this.nativeHostService.getWindowCount() > 1) {
197183
if (this.contextService.getWorkbenchState() !== WorkbenchState.EMPTY) {
198-
if (this.filesConfigurationService.hotExitConfiguration === HotExitConfiguration.ON_EXIT_AND_WINDOW_CLOSE) {
199-
return modifiedWorkingCopies; // backup if a folder is open and onExitAndWindowClose is configured
200-
} else {
201-
return modifiedWorkingCopies.filter(wc => wc.capabilities & WorkingCopyCapabilities.Scratchpad); // only backup scratchpads because we are switching contexts
202-
}
203-
} else {
204-
return []; // do not backup because we are switching contexts with no folder open
184+
return modifiedWorkingCopies.filter(modifiedWorkingCopy => modifiedWorkingCopy.capabilities & WorkingCopyCapabilities.Scratchpad); // backup scratchpads automatically to avoid user confirmation
205185
}
206-
}
186+
187+
return []; // do not backup if a window is closed that does not cause quitting of the application
188+
}
189+
190+
return modifiedWorkingCopies; // backup if last window is closed on win/linux where the application quits right after
191+
192+
// Application Quit
193+
case ShutdownReason.QUIT:
194+
return modifiedWorkingCopies; // backup because next start we restore all backups
195+
196+
// Window Reload
197+
case ShutdownReason.RELOAD:
198+
return modifiedWorkingCopies; // backup because after window reload, backups restore
199+
200+
// Workspace Change
201+
case ShutdownReason.LOAD:
202+
if (this.contextService.getWorkbenchState() !== WorkbenchState.EMPTY) {
203+
if (this.filesConfigurationService.hotExitConfiguration === HotExitConfiguration.ON_EXIT_AND_WINDOW_CLOSE) {
204+
return modifiedWorkingCopies; // backup if a workspace/folder is open and onExitAndWindowClose is configured
205+
}
206+
207+
return modifiedWorkingCopies.filter(modifiedWorkingCopy => modifiedWorkingCopy.capabilities & WorkingCopyCapabilities.Scratchpad); // backup scratchpads automatically to avoid user confirmation
208+
}
209+
210+
return []; // do not backup because we are switching contexts with no workspace/folder open
207211
}
208212
}
209213

0 commit comments

Comments
 (0)