@@ -6,12 +6,17 @@ import { HttpCode, HttpError } from "../../common/http"
6
6
import { Options } from "../../common/util"
7
7
import { HttpProvider , HttpProviderOptions , HttpResponse , Route } from "../http"
8
8
import { ApiHttpProvider } from "./api"
9
+ import { UpdateHttpProvider } from "./update"
9
10
10
11
/**
11
12
* Top-level and fallback HTTP provider.
12
13
*/
13
14
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
+ ) {
15
20
super ( options )
16
21
}
17
22
@@ -77,13 +82,14 @@ export class MainHttpProvider extends HttpProvider {
77
82
response . content = response . content
78
83
. replace ( / { { COMMIT} } / g, this . options . commit )
79
84
. replace ( / { { BASE} } / g, this . base ( route ) )
80
- . replace ( / { { APP_ L I S T : R U N N I N G } } / g, this . getAppRows ( recent . running ) )
85
+ . replace ( / { { UPDATE:N A M E } } / , await this . getUpdate ( ) )
86
+ . replace ( / { { APP_ L I S T : R U N N I N G } } / , this . getAppRows ( recent . running ) )
81
87
. replace (
82
- / { { APP_ L I S T : E D I T O R S } } / g ,
88
+ / { { APP_ L I S T : E D I T O R S } } / ,
83
89
this . getAppRows ( apps . filter ( ( app ) => app . categories && app . categories . includes ( "Editor" ) ) )
84
90
)
85
91
. replace (
86
- / { { APP_ L I S T : O T H E R } } / g ,
92
+ / { { APP_ L I S T : O T H E R } } / ,
87
93
this . getAppRows ( apps . filter ( ( app ) => ! app . categories || ! app . categories . includes ( "Editor" ) ) )
88
94
)
89
95
return response
@@ -94,8 +100,8 @@ export class MainHttpProvider extends HttpProvider {
94
100
response . content = response . content
95
101
. replace ( / { { COMMIT} } / g, this . options . commit )
96
102
. replace ( / { { BASE} } / g, this . base ( route ) )
97
- . replace ( / { { APP_ N A M E } } / g , name )
98
- . replace ( / " { { O P T I O N S } } " / g , `'${ JSON . stringify ( options ) } '` )
103
+ . replace ( / { { APP_ N A M E } } / , name )
104
+ . replace ( / " { { O P T I O N S } } " / , `'${ JSON . stringify ( options ) } '` )
99
105
return response
100
106
}
101
107
@@ -108,8 +114,8 @@ export class MainHttpProvider extends HttpProvider {
108
114
}
109
115
110
116
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 -link " href=".${ app . path } ">
113
119
${
114
120
app . icon
115
121
? `<img class="icon" src="data:image/png;base64,${ app . icon } "></img>`
@@ -127,4 +133,23 @@ export class MainHttpProvider extends HttpProvider {
127
133
}
128
134
</div>`
129
135
}
136
+
137
+ private async getUpdate ( ) : Promise < string > {
138
+ if ( ! this . update . enabled ) {
139
+ return "Updates are disabled"
140
+ }
141
+
142
+ const update = await this . update . getUpdate ( )
143
+ if ( ! update ) {
144
+ return `<div class="block-row">
145
+ <span class="item">No updates available</span>
146
+ <span class="current" >Current: ${ this . update . currentVersion } </span>
147
+ </div>`
148
+ }
149
+
150
+ return `<div class="block-row">
151
+ <a class="item -link" href="./update">Update available: ${ update . version } </a>
152
+ <span class="current" >Current: ${ this . update . currentVersion } </span>
153
+ </div>`
154
+ }
130
155
}
0 commit comments