-
-
Notifications
You must be signed in to change notification settings - Fork 435
/
Copy pathshell-layout-restorer.ts
60 lines (55 loc) · 2.13 KB
/
shell-layout-restorer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { injectable } from 'inversify';
import { ShellLayoutRestorer as TheiaShellLayoutRestorer } from '@theia/core/lib/browser/shell/shell-layout-restorer';
import { inject } from '@theia/core/shared/inversify';
import { ApplicationShell } from '@theia/core/lib/browser/shell/application-shell';
@injectable()
export class ShellLayoutRestorer extends TheiaShellLayoutRestorer {
@inject(ApplicationShell)
protected readonly shell: ApplicationShell;
// Workaround for https://github.com/eclipse-theia/theia/issues/6579.
async storeLayoutAsync(): Promise<void> {
if (this.shouldStoreLayout) {
try {
this.logger.info('>>> Storing the layout...');
const layoutData = this.shell.getLayoutData();
const serializedLayoutData = this.deflate(layoutData);
await this.storageService.setData(
this.storageKey,
serializedLayoutData
);
this.logger.info('<<< The layout has been successfully stored.');
} catch (error) {
await this.storageService.setData(this.storageKey, undefined);
this.logger.error('Error during serialization of layout data', error);
}
}
}
async restoreLayout(): Promise<boolean> {
this.logger.info('>>> Restoring the layout state...');
const serializedLayoutData = await this.storageService.getData<string>(
this.storageKey
);
if (serializedLayoutData === undefined) {
this.logger.info('<<< Nothing to restore.');
return false;
}
const layoutData = await this.inflate(serializedLayoutData);
// workaround to remove duplicated tabs
const filesUri: string[] = [];
if ((layoutData as any)?.mainPanel?.main?.widgets) {
(layoutData as any).mainPanel.main.widgets = (
layoutData as any
).mainPanel.main.widgets.filter((widget: any) => {
const uri = widget.getResourceUri().toString();
if (filesUri.includes(uri)) {
return false;
}
filesUri.push(uri);
return true;
});
}
await this.shell.setLayoutData(layoutData);
this.logger.info('<<< The layout has been successfully restored.');
return true;
}
}