Check updates daily instead of every time

Also add a way to force a check.
This commit is contained in:
Asher
2020-02-14 16:41:42 -06:00
parent db54f78e8e
commit 0ec83f8736
5 changed files with 105 additions and 41 deletions

View File

@ -1,6 +1,7 @@
import * as fs from "fs-extra"
import * as path from "path"
import { extend, xdgLocalDir } from "./util"
import { logger } from "@coder/logger"
import { extend } from "./util"
export type Settings = { [key: string]: Settings | string | boolean | number }
@ -32,9 +33,28 @@ export class SettingsProvider<T> {
*/
public async write(settings: Partial<T>): Promise<void> {
try {
await fs.writeFile(this.settingsPath, JSON.stringify(extend(this.read(), settings)))
await fs.writeFile(this.settingsPath, JSON.stringify(extend(await this.read(), settings), null, 2))
} catch (error) {
logger.warn(error.message)
}
}
}
/**
* Global code-server settings.
*/
export interface CoderSettings {
lastVisited: {
url: string
workspace: boolean
}
update: {
checked: number
version: string
}
}
/**
* Global code-server settings file.
*/
export const settings = new SettingsProvider<CoderSettings>(path.join(xdgLocalDir, "coder.json"))