FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
code-server/src/node/settings.ts at asher/enable-webkit · coder/code-server · GitHub
coder
code-server
Repository navigation
Code
Issues
144
(144)
Pull requests
14
(14)
Discussions
Actions
Projects
Security and quality
1
(1)
Insights
Expand file tree
Breadcrumbs
code-server
/
src
/
node
/
settings.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
56 lines (50 loc) · 1.39 KB
Breadcrumbs
code-server
/
src
/
node
/
settings.ts
Copy path
File metadata and controls
56 lines (50 loc) · 1.39 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import
{
logger
}
from
"@coder/logger"
import
type
{
ParsedQs
}
from
"qs"
import
{
promises
as
fs
}
from
"fs"
export
type
Settings
=
{
[
key
:
string
]
:
Settings
|
string
|
boolean
|
number
}
/**
* Provides read and write access to settings.
*/
export
class
SettingsProvider
<
T
>
{
public
constructor
(
private
readonly
settingsPath
:
string
)
{
}
/**
* Read settings from the file. On a failure return last known settings and
* log a warning.
*/
public
async
read
(
)
:
Promise
<
T
>
{
try
{
const
raw
=
(
await
fs
.
readFile
(
this
.
settingsPath
,
"utf8"
)
)
.
trim
(
)
return
raw
?
JSON
.
parse
(
raw
)
:
(
{
}
as
T
)
}
catch
(
error
:
any
)
{
if
(
error
.
code
!==
"ENOENT"
)
{
logger
.
warn
(
error
.
message
)
}
}
return
{
}
as
T
}
/**
* Write settings combined with current settings. On failure log a warning.
* Settings will be merged shallowly.
*/
public
async
write
(
settings
:
Partial
<
T
>
)
:
Promise
<
void
>
{
try
{
const
oldSettings
=
await
this
.
read
(
)
const
nextSettings
=
{
...
oldSettings
,
...
settings
}
await
fs
.
writeFile
(
this
.
settingsPath
,
JSON
.
stringify
(
nextSettings
,
null
,
2
)
)
}
catch
(
error
:
any
)
{
logger
.
warn
(
error
.
message
)
}
}
}
export
interface
UpdateSettings
{
update
:
{
checked
:
number
version
:
string
}
}
/**
* Global code-server settings.
*/
export
interface
CoderSettings
extends
UpdateSettings
{
query
?:
ParsedQs
}
Back
|
FazBrowse Home
|
New Git URL