diff --git a/packages/core/src/browser/window/window-service.ts b/packages/core/src/browser/window/window-service.ts index e06d903e7c67a..7286a8e8a7116 100644 --- a/packages/core/src/browser/window/window-service.ts +++ b/packages/core/src/browser/window/window-service.ts @@ -26,9 +26,9 @@ export interface NewWindowOptions { export const WindowService = Symbol('WindowService'); /** - * The window hash value that is used to spawn a new default window. + * The window hash value that is used to spawn a new default window. */ -export const DEFAULT_WINDOW_HASH: string = '#!empty'; +export const DEFAULT_WINDOW_HASH: string = '!empty'; export interface WindowService { diff --git a/packages/core/src/electron-main/electron-main-application.ts b/packages/core/src/electron-main/electron-main-application.ts index a2050bd5cf9a9..67ddc09dbb1f2 100644 --- a/packages/core/src/electron-main/electron-main-application.ts +++ b/packages/core/src/electron-main/electron-main-application.ts @@ -290,7 +290,9 @@ export class ElectronMainApplication { } protected async handleMainCommand(params: ElectronMainExecutionParams, options: ElectronMainCommandOptions): Promise { - if (options.file === undefined) { + if (params.secondInstance === false) { + await this.openWindowWithWorkspace(''); // restore previous workspace. + } else if (options.file === undefined) { await this.openDefaultWindow(); } else { let workspacePath: string | undefined; diff --git a/packages/workspace/src/browser/workspace-service.ts b/packages/workspace/src/browser/workspace-service.ts index 159f26f285cc6..3050f168343b8 100644 --- a/packages/workspace/src/browser/workspace-service.ts +++ b/packages/workspace/src/browser/workspace-service.ts @@ -130,7 +130,7 @@ export class WorkspaceService implements FrontendApplicationContribution { protected async doGetDefaultWorkspaceUri(): Promise { // If an empty window is explicitly requested do not restore a previous workspace. - if (window.location.hash === DEFAULT_WINDOW_HASH) { + if (window.location.hash === `#${DEFAULT_WINDOW_HASH}`) { window.location.hash = ''; return undefined; } @@ -213,6 +213,7 @@ export class WorkspaceService implements FrontendApplicationContribution { this.setURLFragment(''); } this.updateTitle(); + await this.server.setMostRecentlyUsedWorkspace(this._workspace?.resource.toString() || ''); await this.updateWorkspace(); } diff --git a/packages/workspace/src/node/default-workspace-server.ts b/packages/workspace/src/node/default-workspace-server.ts index 409c8bce601fd..075ad3b8e4eb6 100644 --- a/packages/workspace/src/node/default-workspace-server.ts +++ b/packages/workspace/src/node/default-workspace-server.ts @@ -92,19 +92,10 @@ export class DefaultWorkspaceServer implements WorkspaceServer { async setMostRecentlyUsedWorkspace(uri: string): Promise { this.root = new Deferred(); - const listUri: string[] = []; - const oldListUri = await this.getRecentWorkspaces(); - listUri.push(uri); - if (oldListUri) { - oldListUri.forEach(element => { - if (element !== uri && element.length > 0) { - listUri.push(element); - } - }); - } this.root.resolve(uri); + const recentRoots = Array.from(new Set([uri, ...await this.getRecentWorkspaces()])); this.writeToUserHome({ - recentRoots: listUri + recentRoots }); }