Archived
1
0

Merge pull request #1920 from fxxjdedd/patch-1

feat: persist route query to local
This commit is contained in:
Asher 2020-07-31 11:36:25 -05:00 committed by GitHub
commit cbf7c9556c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 8 deletions

View File

@ -183,11 +183,10 @@ export class VscodeHttpProvider extends HttpProvider {
}),
])
if (startPath) {
settings.write({
lastVisited: startPath,
})
}
settings.write({
lastVisited: startPath || lastVisited, // If startpath is undefined, then fallback to lastVisited
query: route.query,
})
if (!this.isDev) {
response.content = response.content.replace(/<!-- PROD_ONLY/g, "").replace(/END_PROD_ONLY -->/g, "")

View File

@ -2,6 +2,7 @@ import * as fs from "fs-extra"
import * as path from "path"
import { extend, paths } from "./util"
import { logger } from "@coder/logger"
import { Route } from "./http"
export type Settings = { [key: string]: Settings | string | boolean | number }
@ -29,11 +30,13 @@ export class SettingsProvider<T> {
/**
* Write settings combined with current settings. On failure log a warning.
* Objects will be merged and everything else will be replaced.
* Settings can be shallow or deep merged.
*/
public async write(settings: Partial<T>): Promise<void> {
public async write(settings: Partial<T>, shallow = true): Promise<void> {
try {
await fs.writeFile(this.settingsPath, JSON.stringify(extend(await this.read(), settings), null, 2))
const oldSettings = await this.read()
const nextSettings = shallow ? Object.assign({}, oldSettings, settings) : extend(oldSettings, settings)
await fs.writeFile(this.settingsPath, JSON.stringify(nextSettings, null, 2))
} catch (error) {
logger.warn(error.message)
}
@ -55,6 +58,7 @@ export interface CoderSettings extends UpdateSettings {
url: string
workspace: boolean
}
query: Route["query"]
}
/**