Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

electron: restore previous workspace #9995

Merged
merged 1 commit into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 3 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,8 @@ 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) {
// Note: `window.location.hash` includes leading "#" if non-empty.
if (window.location.hash === `#${DEFAULT_WINDOW_HASH}`) {
window.location.hash = '';
return undefined;
}
Expand Down Expand Up @@ -213,6 +214,7 @@ export class WorkspaceService implements FrontendApplicationContribution {
this.setURLFragment('');
}
this.updateTitle();
await this.server.setMostRecentlyUsedWorkspace(this._workspace ? this._workspace.resource.toString() : '');
await this.updateWorkspace();
}

Expand Down
15 changes: 2 additions & 13 deletions packages/workspace/src/node/default-workspace-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,9 @@ 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);
this.writeToUserHome({
recentRoots: listUri
});
const recentRoots = Array.from(new Set([uri, ...await this.getRecentWorkspaces()]));
this.writeToUserHome({ recentRoots });
}

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