Skip to content

Commit 3938dae

Browse files
committed
Ensure persistent context state by saving checked files and websites to both workspace and global storage
1 parent 73bce94 commit 3938dae

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎packages/vscode/src/context/providers/websites-provider.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,21 @@ export class WebsitesProvider
162162
CONTEXT_CHECKED_URLS_STATE_KEY,
163163
checked_urls
164164
)
165+
await this.context.globalState.update(
166+
CONTEXT_CHECKED_URLS_STATE_KEY,
167+
checked_urls
168+
)
165169
}
166170

167171
public load_checked_websites_state(): void {
168-
const checked_urls = this.context.workspaceState.get<string[]>(
172+
let checked_urls = this.context.workspaceState.get<string[]>(
169173
CONTEXT_CHECKED_URLS_STATE_KEY
170174
)
175+
if (!checked_urls) {
176+
checked_urls = this.context.globalState.get<string[]>(
177+
CONTEXT_CHECKED_URLS_STATE_KEY
178+
)
179+
}
171180
if (checked_urls) {
172181
for (const url of checked_urls) {
173182
this._checked_websites.set(url, vscode.TreeItemCheckboxState.Checked)

‎packages/vscode/src/context/providers/workspace-provider.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,21 @@ export class WorkspaceProvider
8888
CONTEXT_CHECKED_PATHS_STATE_KEY,
8989
checked_paths
9090
)
91+
await this.context.globalState.update(
92+
CONTEXT_CHECKED_PATHS_STATE_KEY,
93+
checked_paths
94+
)
9195
}
9296

9397
public load_checked_files_state(): void {
94-
const persisted_checked_paths = this.context.workspaceState.get<string[]>(
98+
let persisted_checked_paths = this.context.workspaceState.get<string[]>(
9599
CONTEXT_CHECKED_PATHS_STATE_KEY
96100
)
101+
if (!persisted_checked_paths) {
102+
persisted_checked_paths = this.context.globalState.get<string[]>(
103+
CONTEXT_CHECKED_PATHS_STATE_KEY
104+
)
105+
}
97106
if (persisted_checked_paths && persisted_checked_paths.length > 0) {
98107
this.set_checked_files(persisted_checked_paths)
99108
}

0 commit comments

Comments
 (0)