Skip to content

Commit 8df0418

Browse files
vince-fugnittoRomanNikitenko
authored andcommitted
electron: restore previous workspace (#9995)
The commit fixes logic when determining whether to open a default window or existing workspace on electron startup. The update now correctly restores the workspace which would previously never restore properly. Signed-off-by: vince-fugnitto <vincent.fugnitto@ericsson.com>
1 parent c477cd8 commit 8df0418

File tree

4 files changed

+10
-17
lines changed

4 files changed

+10
-17
lines changed

packages/core/src/browser/window/window-service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ export interface NewWindowOptions {
2626
export const WindowService = Symbol('WindowService');
2727

2828
/**
29-
* The window hash value that is used to spawn a new default window.
29+
* The window hash value that is used to spawn a new default window.
3030
*/
31-
export const DEFAULT_WINDOW_HASH: string = '#!empty';
31+
export const DEFAULT_WINDOW_HASH: string = '!empty';
3232

3333
export interface WindowService {
3434

packages/core/src/electron-main/electron-main-application.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,9 @@ export class ElectronMainApplication {
290290
}
291291

292292
protected async handleMainCommand(params: ElectronMainExecutionParams, options: ElectronMainCommandOptions): Promise<void> {
293-
if (options.file === undefined) {
293+
if (params.secondInstance === false) {
294+
await this.openWindowWithWorkspace(''); // restore previous workspace.
295+
} else if (options.file === undefined) {
294296
await this.openDefaultWindow();
295297
} else {
296298
let workspacePath: string | undefined;

packages/workspace/src/browser/workspace-service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ export class WorkspaceService implements FrontendApplicationContribution {
130130
protected async doGetDefaultWorkspaceUri(): Promise<string | undefined> {
131131

132132
// If an empty window is explicitly requested do not restore a previous workspace.
133-
if (window.location.hash === DEFAULT_WINDOW_HASH) {
133+
// Note: `window.location.hash` includes leading "#" if non-empty.
134+
if (window.location.hash === `#${DEFAULT_WINDOW_HASH}`) {
134135
window.location.hash = '';
135136
return undefined;
136137
}
@@ -213,6 +214,7 @@ export class WorkspaceService implements FrontendApplicationContribution {
213214
this.setURLFragment('');
214215
}
215216
this.updateTitle();
217+
await this.server.setMostRecentlyUsedWorkspace(this._workspace ? this._workspace.resource.toString() : '');
216218
await this.updateWorkspace();
217219
}
218220

packages/workspace/src/node/default-workspace-server.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,9 @@ export class DefaultWorkspaceServer implements WorkspaceServer {
9292

9393
async setMostRecentlyUsedWorkspace(uri: string): Promise<void> {
9494
this.root = new Deferred();
95-
const listUri: string[] = [];
96-
const oldListUri = await this.getRecentWorkspaces();
97-
listUri.push(uri);
98-
if (oldListUri) {
99-
oldListUri.forEach(element => {
100-
if (element !== uri && element.length > 0) {
101-
listUri.push(element);
102-
}
103-
});
104-
}
10595
this.root.resolve(uri);
106-
this.writeToUserHome({
107-
recentRoots: listUri
108-
});
96+
const recentRoots = Array.from(new Set([uri, ...await this.getRecentWorkspaces()]));
97+
this.writeToUserHome({ recentRoots });
10998
}
11099

111100
async getRecentWorkspaces(): Promise<string[]> {

0 commit comments

Comments
 (0)