Skip to content

Commit

Permalink
electron: restore previous workspace
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
vince-fugnitto committed Aug 30, 2021
1 parent 0226158 commit c4fff9e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/browser/window/window-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/electron-main/electron-main-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ export class ElectronMainApplication {
}

protected async handleMainCommand(params: ElectronMainExecutionParams, options: ElectronMainCommandOptions): Promise<void> {
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;
Expand Down
3 changes: 2 additions & 1 deletion packages/workspace/src/browser/workspace-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class WorkspaceService implements FrontendApplicationContribution {
protected async doGetDefaultWorkspaceUri(): Promise<string | undefined> {

// 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;
}
Expand Down Expand Up @@ -213,6 +213,7 @@ export class WorkspaceService implements FrontendApplicationContribution {
this.setURLFragment('');
}
this.updateTitle();
await this.server.setMostRecentlyUsedWorkspace(this._workspace?.resource.toString() || '');
await this.updateWorkspace();
}

Expand Down
13 changes: 2 additions & 11 deletions packages/workspace/src/node/default-workspace-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,10 @@ export class DefaultWorkspaceServer implements WorkspaceServer {

async setMostRecentlyUsedWorkspace(uri: string): Promise<void> {
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
});
}

Expand Down

0 comments on commit c4fff9e

Please sign in to comment.