Skip to content

Commit 1a54f6b

Browse files
committed
Merge remote-tracking branch 'origin/restructure' into anmol-restructure
2 parents eb3cf30 + 0ec83f8 commit 1a54f6b

16 files changed

+615
-50
lines changed

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
},
1919
"devDependencies": {
2020
"@coder/nbin": "^1.2.7",
21+
"@types/adm-zip": "^0.4.32",
2122
"@types/fs-extra": "^8.0.1",
2223
"@types/mocha": "^5.2.7",
2324
"@types/node": "^12.12.7",
2425
"@types/parcel-bundler": "^1.12.1",
2526
"@types/pem": "^1.9.5",
2627
"@types/safe-compare": "^1.1.0",
27-
"@types/tar-fs": "^1.16.1",
28-
"@types/tar-stream": "^1.6.1",
28+
"@types/semver": "^7.1.0",
29+
"@types/tar-fs": "^1.16.2",
2930
"@types/ws": "^6.0.4",
3031
"@typescript-eslint/eslint-plugin": "^2.0.0",
3132
"@typescript-eslint/parser": "^2.0.0",
@@ -49,12 +50,14 @@
4950
},
5051
"dependencies": {
5152
"@coder/logger": "1.1.11",
53+
"adm-zip": "^0.4.14",
5254
"fs-extra": "^8.1.0",
5355
"httpolyglot": "^0.1.2",
5456
"pem": "^1.14.2",
5557
"safe-compare": "^1.1.4",
58+
"semver": "^7.1.3",
59+
"tar": "^6.0.1",
5660
"tar-fs": "^2.0.0",
57-
"tar-stream": "^2.1.0",
5861
"ws": "^7.2.0"
5962
}
6063
}

src/browser/pages/app.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import "./error.css"
55
import "./global.css"
66
import "./home.css"
77
import "./login.css"
8+
import "./update.css"
89

910
const options = getOptions()
1011
const parts = window.location.pathname.replace(/^\//g, "").split("/")

src/browser/pages/global.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ body {
1717

1818
button {
1919
font-family: inherit;
20+
font-size: inherit;
2021
}
2122

2223
.center-container {

src/browser/pages/home.css

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,61 @@
1-
.app-lists {
2-
max-width: 400px;
1+
.info-blocks {
2+
max-width: 500px;
33
width: 100%;
44
}
55

6-
.app-list > .header {
7-
margin: 1rem 0;
6+
.info-block > .header {
7+
font-size: 1.3rem;
8+
margin: 1.5rem 0;
89
}
910

10-
.app-list > .none {
11+
.info-block > .none {
1112
color: #b6b6b6;
1213
}
1314

14-
.app-list + .app-list {
15+
.info-block + .info-block {
1516
border-top: 1px solid #666;
1617
margin-top: 1rem;
1718
}
1819

19-
.app-row {
20+
.block-row {
2021
display: flex;
2122
}
2223

23-
.app-row > .open {
24-
color: #b6b6b6;
25-
cursor: pointer;
26-
display: flex;
24+
.block-row > .item {
25+
color: #c4c4c4;
2726
flex: 1;
27+
}
28+
29+
.block-row > .item.-row {
30+
display: flex;
31+
}
32+
33+
.block-row > .item > .sub {
34+
color: #888;
35+
}
36+
37+
.block-row .-link {
38+
cursor: pointer;
2839
text-decoration: none;
2940
}
3041

31-
.app-row > .open:hover {
42+
.block-row .-link:hover {
3243
color: #fafafa;
3344
}
3445

35-
.app-row > .open > .icon {
46+
.block-row > .item > .icon {
3647
height: 1rem;
3748
margin-right: 5px;
3849
width: 1rem;
3950
}
4051

41-
.app-row > .open > .icon.-missing {
52+
.block-row > .item > .icon.-missing {
4253
background-color: #eee;
4354
color: #b6b6b6;
4455
text-align: center;
4556
}
4657

47-
.app-row > .open > .icon.-missing::after {
58+
.block-row > .item > .icon.-missing::after {
4859
content: "?";
4960
font-size: 0.7rem;
5061
vertical-align: middle;

src/browser/pages/home.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,23 @@
2020
</head>
2121
<body>
2222
<div class="center-container">
23-
<div class="app-lists">
24-
<div class="app-list">
23+
<div class="info-blocks">
24+
<div class="info-block">
2525
<h2 class="header">Running Applications</h2>
2626
{{APP_LIST:RUNNING}}
2727
</div>
2828

29-
<div class="app-list">
29+
<div class="info-block">
30+
<h2 class="header">Update</h2>
31+
{{UPDATE:NAME}}
32+
</div>
33+
34+
<div class="info-block">
3035
<h2 class="header">Editors</h2>
3136
{{APP_LIST:EDITORS}}
3237
</div>
3338

34-
<div class="app-list">
39+
<div class="info-block">
3540
<h2 class="header">Other</h2>
3641
{{APP_LIST:OTHER}}
3742
</div>

src/browser/pages/update.css

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.update-form {
2+
text-align: center;
3+
}
4+
5+
.update-form > .apply {
6+
background-color: transparent;
7+
color: #b6b6b6;
8+
cursor: pointer;
9+
border: 1px solid #b6b6b6;
10+
box-sizing: border-box;
11+
padding: 1rem 2rem;
12+
}
13+
14+
.update-form > .apply:hover {
15+
color: #fafafa;
16+
border-color: #fafafa;
17+
}
18+
19+
.update-form > .current {
20+
margin-top: 1rem;
21+
}
22+
23+
.update-form > .links {
24+
margin-top: 1rem;
25+
}
26+
27+
.update-form > .links > .link {
28+
color: #b6b6b6;
29+
text-decoration: none;
30+
}
31+
32+
.update-form > .links > .link:hover {
33+
color: #fcfcfc;
34+
text-decoration: underline;
35+
}
36+
37+
.update-form > .error {
38+
color: red;
39+
margin-top: 1rem;
40+
}

src/browser/pages/update.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta
6+
name="viewport"
7+
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"
8+
/>
9+
<meta http-equiv="Content-Security-Policy" content="style-src 'self'; manifest-src 'self'; img-src 'self' data:;" />
10+
<title>code-server</title>
11+
<link rel="icon" href="{{BASE}}/static-{{COMMIT}}/src/browser/media/favicon.ico" type="image/x-icon" />
12+
<link
13+
rel="manifest"
14+
href="{{BASE}}/static-{{COMMIT}}/src/browser/media/manifest.json"
15+
crossorigin="use-credentials"
16+
/>
17+
<link rel="apple-touch-icon" href="{{BASE}}/static-{{COMMIT}}/src/browser/media/code-server.png" />
18+
<link href="{{BASE}}/static-{{COMMIT}}/dist/app.css" rel="stylesheet" />
19+
</head>
20+
<body>
21+
<div class="center-container">
22+
<form class="update-form" method="post">
23+
<h2 class="header">Update</h2>
24+
{{UPDATE_STATUS}} {{ERROR}}
25+
<div class="links">
26+
<a class="link" href="{{BASE}}">go home</a>
27+
</div>
28+
</form>
29+
</div>
30+
</body>
31+
</html>

src/node/app/app.ts

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ import { HttpCode, HttpError } from "../../common/http"
66
import { Options } from "../../common/util"
77
import { HttpProvider, HttpProviderOptions, HttpResponse, Route } from "../http"
88
import { ApiHttpProvider } from "./api"
9+
import { UpdateHttpProvider } from "./update"
910

1011
/**
1112
* Top-level and fallback HTTP provider.
1213
*/
1314
export class MainHttpProvider extends HttpProvider {
14-
public constructor(options: HttpProviderOptions, private readonly api: ApiHttpProvider) {
15+
public constructor(
16+
options: HttpProviderOptions,
17+
private readonly api: ApiHttpProvider,
18+
private readonly update: UpdateHttpProvider,
19+
) {
1520
super(options)
1621
}
1722

@@ -77,13 +82,14 @@ export class MainHttpProvider extends HttpProvider {
7782
response.content = response.content
7883
.replace(/{{COMMIT}}/g, this.options.commit)
7984
.replace(/{{BASE}}/g, this.base(route))
80-
.replace(/{{APP_LIST:RUNNING}}/g, this.getAppRows(recent.running))
85+
.replace(/{{UPDATE:NAME}}/, await this.getUpdate())
86+
.replace(/{{APP_LIST:RUNNING}}/, this.getAppRows(recent.running))
8187
.replace(
82-
/{{APP_LIST:EDITORS}}/g,
88+
/{{APP_LIST:EDITORS}}/,
8389
this.getAppRows(apps.filter((app) => app.categories && app.categories.includes("Editor"))),
8490
)
8591
.replace(
86-
/{{APP_LIST:OTHER}}/g,
92+
/{{APP_LIST:OTHER}}/,
8793
this.getAppRows(apps.filter((app) => !app.categories || !app.categories.includes("Editor"))),
8894
)
8995
return response
@@ -94,8 +100,8 @@ export class MainHttpProvider extends HttpProvider {
94100
response.content = response.content
95101
.replace(/{{COMMIT}}/g, this.options.commit)
96102
.replace(/{{BASE}}/g, this.base(route))
97-
.replace(/{{APP_NAME}}/g, name)
98-
.replace(/"{{OPTIONS}}"/g, `'${JSON.stringify(options)}'`)
103+
.replace(/{{APP_NAME}}/, name)
104+
.replace(/"{{OPTIONS}}"/, `'${JSON.stringify(options)}'`)
99105
return response
100106
}
101107

@@ -108,8 +114,8 @@ export class MainHttpProvider extends HttpProvider {
108114
}
109115

110116
private getAppRow(app: Application): string {
111-
return `<div class="app-row">
112-
<a class="open" href=".${app.path}">
117+
return `<div class="block-row">
118+
<a class="item -row -link" href=".${app.path}">
113119
${
114120
app.icon
115121
? `<img class="icon" src="data:image/png;base64,${app.icon}"></img>`
@@ -127,4 +133,46 @@ export class MainHttpProvider extends HttpProvider {
127133
}
128134
</div>`
129135
}
136+
137+
private async getUpdate(): Promise<string> {
138+
if (!this.update.enabled) {
139+
return "Updates are disabled"
140+
}
141+
142+
const humanize = (time: number): string => {
143+
const d = new Date(time)
144+
const pad = (t: number): string => (t < 10 ? "0" : "") + t
145+
return (
146+
`${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}` +
147+
` ${pad(d.getHours())}:${pad(d.getMinutes())}`
148+
)
149+
}
150+
151+
const update = await this.update.getUpdate()
152+
if (this.update.isLatestVersion(update)) {
153+
return `<div class="block-row">
154+
<div class="item">
155+
${update.version}
156+
<div class="sub">Up to date</div>
157+
</div>
158+
<div class="item">
159+
${humanize(update.checked)}
160+
<a class="sub -link" href="./update/check">Check now</a>
161+
</div>
162+
<div class="item" >Current: ${this.update.currentVersion}</div>
163+
</div>`
164+
}
165+
166+
return `<div class="block-row">
167+
<a class="item -link" href="./update">
168+
${update.version}
169+
<div class="sub">Out of date</div>
170+
</a>
171+
<div class="item">
172+
${humanize(update.checked)}
173+
<a class="sub -link" href="./update/check">Check now</a>
174+
</div>
175+
<div class="item" >Current: ${this.update.currentVersion}</div>
176+
</div>`
177+
}
130178
}

src/node/app/login.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export class LoginHttpProvider extends HttpProvider {
5050
response.content = response.content
5151
.replace(/{{COMMIT}}/g, this.options.commit)
5252
.replace(/{{BASE}}/g, this.base(route))
53-
.replace(/{{VALUE}}/g, value || "")
54-
.replace(/{{ERROR}}/g, error ? `<div class="error">${error.message}</div>` : "")
53+
.replace(/{{VALUE}}/, value || "")
54+
.replace(/{{ERROR}}/, error ? `<div class="error">${error.message}</div>` : "")
5555
return response
5656
}
5757

0 commit comments

Comments
 (0)