Skip to content

Commit cbf7c95

Browse files
authored
Merge pull request #1920 from fxxjdedd/patch-1
feat: persist route query to local
2 parents 8021385 + ecb9bb2 commit cbf7c95

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/node/app/vscode.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,10 @@ export class VscodeHttpProvider extends HttpProvider {
183183
}),
184184
])
185185

186-
if (startPath) {
187-
settings.write({
188-
lastVisited: startPath,
189-
})
190-
}
186+
settings.write({
187+
lastVisited: startPath || lastVisited, // If startpath is undefined, then fallback to lastVisited
188+
query: route.query,
189+
})
191190

192191
if (!this.isDev) {
193192
response.content = response.content.replace(/<!-- PROD_ONLY/g, "").replace(/END_PROD_ONLY -->/g, "")

src/node/settings.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as fs from "fs-extra"
22
import * as path from "path"
33
import { extend, paths } from "./util"
44
import { logger } from "@coder/logger"
5+
import { Route } from "./http"
56

67
export type Settings = { [key: string]: Settings | string | boolean | number }
78

@@ -29,11 +30,13 @@ export class SettingsProvider<T> {
2930

3031
/**
3132
* Write settings combined with current settings. On failure log a warning.
32-
* Objects will be merged and everything else will be replaced.
33+
* Settings can be shallow or deep merged.
3334
*/
34-
public async write(settings: Partial<T>): Promise<void> {
35+
public async write(settings: Partial<T>, shallow = true): Promise<void> {
3536
try {
36-
await fs.writeFile(this.settingsPath, JSON.stringify(extend(await this.read(), settings), null, 2))
37+
const oldSettings = await this.read()
38+
const nextSettings = shallow ? Object.assign({}, oldSettings, settings) : extend(oldSettings, settings)
39+
await fs.writeFile(this.settingsPath, JSON.stringify(nextSettings, null, 2))
3740
} catch (error) {
3841
logger.warn(error.message)
3942
}
@@ -55,6 +58,7 @@ export interface CoderSettings extends UpdateSettings {
5558
url: string
5659
workspace: boolean
5760
}
61+
query: Route["query"]
5862
}
5963

6064
/**

0 commit comments

Comments
 (0)