Skip to content

Commit d192726

Browse files
committed
Simplify dashboard
1 parent d832f61 commit d192726

File tree

14 files changed

+199
-298
lines changed

14 files changed

+199
-298
lines changed

src/browser/pages/app.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
name="viewport"
77
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"
88
/>
9-
<meta http-equiv="Content-Security-Policy" content="style-src 'self'; manifest-src 'self'; img-src 'self' data:;" />
10-
<title>code-server — {{APP_NAME}}</title>
9+
<meta
10+
http-equiv="Content-Security-Policy"
11+
content="style-src 'self' 'unsafe-inline'; manifest-src 'self'; img-src 'self' data:;"
12+
/>
13+
<title>code-server</title>
1114
<link rel="icon" href="{{BASE}}/static/{{COMMIT}}/src/browser/media/favicon.ico" type="image/x-icon" />
1215
<link
1316
rel="manifest"
@@ -20,6 +23,6 @@
2023
</head>
2124
<body>
2225
<script src="{{BASE}}/static/{{COMMIT}}/dist/register.js"></script>
23-
<script src="{{BASE}}/static/{{COMMIT}}/dist/app.js"></script>
26+
<script src="{{BASE}}/static/{{COMMIT}}/dist/pages/app.js"></script>
2427
</body>
2528
</html>

src/browser/pages/app.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { getOptions } from "../../common/util"
1+
import { getOptions, normalize } from "../../common/util"
2+
import { ApiEndpoint } from "../../common/http"
23

34
import "./app.css"
45
import "./error.css"
@@ -9,4 +10,29 @@ import "./update.css"
910

1011
const options = getOptions()
1112

12-
console.log(options)
13+
const isInput = (el: Element): el is HTMLInputElement => {
14+
return !!(el as HTMLInputElement).name
15+
}
16+
17+
document.querySelectorAll("form").forEach((form) => {
18+
if (!form.classList.contains("-x11")) {
19+
return
20+
}
21+
form.addEventListener("submit", (event) => {
22+
event.preventDefault()
23+
const values: { [key: string]: string } = {}
24+
Array.from(form.elements).forEach((element) => {
25+
if (isInput(element)) {
26+
values[element.name] = element.value
27+
}
28+
})
29+
fetch(normalize(`${options.base}/api/${ApiEndpoint.process}`), {
30+
method: "POST",
31+
body: JSON.stringify(values),
32+
})
33+
})
34+
})
35+
36+
// TEMP: Until we can get the real ready event.
37+
const event = new CustomEvent("ide-ready")
38+
window.dispatchEvent(event)

src/browser/pages/global.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ button {
7171
padding: 40px;
7272
}
7373

74+
.card-box > .content > .none {
75+
margin: 2px 0;
76+
}
77+
7478
.card-box + .card-box {
7579
margin-top: 26px;
7680
}
81+
82+
canvas {
83+
top: 0;
84+
left: 0;
85+
}

src/browser/pages/home.css

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
margin: 2px 0;
88
}
99

10-
.block-row > .item.-row {
11-
display: flex;
10+
.block-row > button.item {
11+
background: none;
12+
border: none;
13+
cursor: pointer;
14+
text-align: left;
1215
}
1316

1417
.block-row > .item > .sub {
@@ -34,6 +37,7 @@
3437

3538
.block-row > .item > .icon.-missing {
3639
background-color: rgba(87, 114, 245, 0.2);
40+
display: inline-block;
3741
text-align: center;
3842
}
3943

src/browser/pages/home.html

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
name="viewport"
77
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"
88
/>
9-
<meta http-equiv="Content-Security-Policy" content="style-src 'self'; manifest-src 'self'; img-src 'self' data:;" />
9+
<meta http-equiv="Content-Security-Policy" content="style-src 'self' 'unsafe-inline'; manifest-src 'self'; img-src 'self' data:;" />
1010
<title>code-server</title>
1111
<link rel="icon" href="{{BASE}}/static/{{COMMIT}}/src/browser/media/favicon.ico" type="image/x-icon" />
1212
<link
@@ -22,44 +22,24 @@
2222
<div class="center-container">
2323
<div class="card-box">
2424
<div class="header">
25-
<h2 class="main">Running</h2>
26-
<div class="sub">Currently running applications.</div>
27-
</div>
28-
<div class="content">
29-
{{APP_LIST:RUNNING}}
30-
</div>
31-
</div>
32-
33-
<div class="card-box">
34-
<div class="header">
35-
<h2 class="main">Recent</h2>
36-
<div class="sub">Choose a recent directory or workspace to launch below.</div>
25+
<h2 class="main">Editors</h2>
26+
<div class="sub">Choose an editor to launch below.</div>
3727
</div>
3828
<div class="content">
39-
{{APP_LIST:RECENT_PROJECTS}}
29+
{{APP_LIST:EDITORS}}
4030
</div>
4131
</div>
4232

4333
<div class="card-box">
4434
<div class="header">
45-
<h2 class="main">Editors</h2>
46-
<div class="sub">Choose an editor to launch below.</div>
35+
<h2 class="main">Other</h2>
36+
<div class="sub">Choose an application to launch below.</div>
4737
</div>
4838
<div class="content">
49-
{{APP_LIST:EDITORS}}
39+
{{APP_LIST:OTHER}}
5040
</div>
5141
</div>
5242

53-
<!-- <div class="card-box"> -->
54-
<!-- <div class="header"> -->
55-
<!-- <h2 class="main">Other</h2> -->
56-
<!-- <div class="sub">Choose an application to launch below.</div> -->
57-
<!-- </div> -->
58-
<!-- <div class="content"> -->
59-
<!-- {{APP_LIST:OTHER}} -->
60-
<!-- </div> -->
61-
<!-- </div> -->
62-
6343
<div class="card-box">
6444
<div class="header">
6545
<h2 class="main">Version</h2>
@@ -71,5 +51,6 @@ <h2 class="main">Version</h2>
7151
</div>
7252
</div>
7353
<script src="{{BASE}}/static/{{COMMIT}}/dist/register.js"></script>
54+
<script src="{{BASE}}/static/{{COMMIT}}/dist/pages/app.js"></script>
7455
</body>
7556
</html>

src/common/api.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ export interface Application {
77
readonly icon?: string
88
readonly installed?: boolean
99
readonly name: string
10+
/**
11+
* Path if this is a browser app (like VS Code).
12+
*/
1013
readonly path?: string
11-
readonly sessionId?: string
14+
/**
15+
* PID if this is a process.
16+
*/
17+
readonly pid?: number
1218
readonly version?: string
1319
}
1420

@@ -17,30 +23,25 @@ export interface ApplicationsResponse {
1723
}
1824

1925
export enum SessionError {
20-
NotFound = 4000,
21-
FailedToStart,
22-
Starting,
23-
InvalidState,
24-
Unknown,
26+
FailedToStart = 4000,
27+
Starting = 4001,
28+
InvalidState = 4002,
29+
Unknown = 4003,
2530
}
2631

2732
export interface SessionResponse {
2833
/**
29-
* Whether the session was created or an existing one was returned.
34+
* Whether the process was spawned or an existing one was returned.
3035
*/
3136
created: boolean
32-
sessionId: string
37+
pid: number
3338
}
3439

3540
export interface RecentResponse {
3641
readonly paths: string[]
3742
readonly workspaces: string[]
3843
}
3944

40-
export interface RunningResponse {
41-
readonly applications: ReadonlyArray<Application>
42-
}
43-
4445
export interface HealthRequest {
4546
readonly event: "health"
4647
}

src/common/http.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ export class HttpError extends Error {
1717

1818
export enum ApiEndpoint {
1919
applications = "/applications",
20+
process = "/process",
2021
recent = "/recent",
2122
run = "/run",
22-
running = "/running",
23-
session = "/session",
2423
status = "/status",
2524
}

src/common/util.ts

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { logger } from "@coder/logger"
1+
import { logger, field } from "@coder/logger"
22

33
export interface Options {
44
base: string
55
commit: string
66
logLevel: number
7-
sessionId?: string
7+
pid?: number
88
}
99

1010
/**
@@ -34,34 +34,44 @@ export const normalize = (url: string, keepTrailing = false): string => {
3434
}
3535

3636
/**
37-
* Get options embedded in the HTML from the server.
37+
* Get options embedded in the HTML or query params.
3838
*/
3939
export const getOptions = <T extends Options>(): T => {
40-
if (typeof document === "undefined") {
41-
return {} as T
42-
}
43-
const el = document.getElementById("coder-options")
40+
let options: T
4441
try {
42+
const el = document.getElementById("coder-options")
4543
if (!el) {
4644
throw new Error("no options element")
4745
}
4846
const value = el.getAttribute("data-settings")
4947
if (!value) {
5048
throw new Error("no options value")
5149
}
52-
const options = JSON.parse(value)
53-
if (typeof options.logLevel !== "undefined") {
54-
logger.level = options.logLevel
55-
}
56-
const parts = window.location.pathname.replace(/^\//g, "").split("/")
57-
parts[parts.length - 1] = options.base
58-
const url = new URL(window.location.origin + "/" + parts.join("/"))
59-
return {
50+
options = JSON.parse(value)
51+
} catch (error) {
52+
options = {} as T
53+
}
54+
55+
const params = new URLSearchParams(location.search)
56+
const queryOpts = params.get("options")
57+
if (queryOpts) {
58+
options = {
6059
...options,
61-
base: normalize(url.pathname, true),
60+
...JSON.parse(queryOpts),
6261
}
63-
} catch (error) {
64-
logger.warn(error.message)
65-
return {} as T
6662
}
63+
64+
if (typeof options.logLevel !== "undefined") {
65+
logger.level = options.logLevel
66+
}
67+
if (options.base) {
68+
const parts = location.pathname.replace(/^\//g, "").split("/")
69+
parts[parts.length - 1] = options.base
70+
const url = new URL(location.origin + "/" + parts.join("/"))
71+
options.base = normalize(url.pathname, true)
72+
}
73+
74+
logger.debug("got options", field("options", options))
75+
76+
return options
6777
}

0 commit comments

Comments
 (0)