Skip to content

feat: persist route query to local #1920

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

Merged
merged 3 commits into from
Jul 31, 2020
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
9 changes: 4 additions & 5 deletions src/node/app/vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
Expand Down
10 changes: 7 additions & 3 deletions src/node/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down Expand Up @@ -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)
}
Expand All @@ -55,6 +58,7 @@ export interface CoderSettings extends UpdateSettings {
url: string
workspace: boolean
}
query: Route["query"]
}

/**
Expand Down