File tree Expand file tree Collapse file tree 14 files changed +130
-5
lines changed Expand file tree Collapse file tree 14 files changed +130
-5
lines changed Original file line number Diff line number Diff line change
1
+ load ("@npm_bazel_typescript//:index.bzl" , "ts_library" )
2
+
3
+ package (default_visibility = ["//visibility:public" ])
4
+
5
+ ts_library (
6
+ name = "favicon" ,
7
+ srcs = glob (["*.ts" ]),
8
+ deps = [
9
+ ],
10
+ )
Original file line number Diff line number Diff line change
1
+ export enum IconType {
2
+ Default ,
3
+ Success ,
4
+ Failure ,
5
+ InProgress ,
6
+ Unknown ,
7
+ }
8
+
9
+ class FaviconService {
10
+ getDefaultFavicon ( ) {
11
+ if ( window . matchMedia && window . matchMedia ( '(prefers-color-scheme: dark)' ) ?. matches ) {
12
+ return "/favicon/favicon_white.svg"
13
+ }
14
+ return "/favicon/favicon_black.svg" ;
15
+ }
16
+
17
+ getFaviconForType ( type : IconType ) {
18
+ switch ( type ) {
19
+ case IconType . Success :
20
+ return "/favicon/favicon_green.svg"
21
+ case IconType . Failure :
22
+ return "/favicon/favicon_red.svg"
23
+ case IconType . InProgress :
24
+ return "/favicon/favicon_blue.svg"
25
+ case IconType . Unknown :
26
+ return "/favicon/favicon_grey.svg"
27
+ default :
28
+ return this . getDefaultFavicon ( ) ;
29
+ }
30
+ }
31
+
32
+ setFaviconForType ( type : IconType ) {
33
+ document . getElementById ( "favicon" ) ?. setAttribute ( "href" , this . getFaviconForType ( type ) )
34
+ }
35
+
36
+ setDefaultFavicon ( ) {
37
+ this . setFaviconForType ( IconType . Default ) ;
38
+ }
39
+ }
40
+
41
+ export default new FaviconService ( ) ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ ts_library(
9
9
"//app/auth" ,
10
10
"//app/capabilities" ,
11
11
"//app/docs" ,
12
+ "//app/favicon" ,
12
13
"//app/format" ,
13
14
"//app/router" ,
14
15
"//app/service" ,
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import moment from 'moment';
4
4
import rpcService from '../service/rpc_service'
5
5
import authService , { User } from '../auth/auth_service' ;
6
6
import capabilities from '../capabilities/capabilities' ;
7
+ import faviconService from '../favicon/favicon' ;
7
8
8
9
import InvocationModel from './invocation_model'
9
10
@@ -85,13 +86,13 @@ export default class InvocationComponent extends React.Component {
85
86
showInProgressScreen = response . invocation [ 0 ] . event . length == 0 ;
86
87
this . fetchUpdatedProgress ( ) ;
87
88
}
88
-
89
89
this . setState ( {
90
90
inProgress : showInProgressScreen ,
91
91
model : InvocationModel . modelFromInvocations ( response . invocation as invocation . Invocation [ ] ) ,
92
92
loading : false
93
93
} ) ;
94
94
document . title = `${ this . state . model . getUser ( true ) } ${ this . state . model . getCommand ( ) } ${ this . state . model . getPattern ( ) } | BuildBuddy` ;
95
+ faviconService . setFaviconForType ( this . state . model . getFaviconType ( ) ) ;
95
96
} ) . catch ( ( error : any ) => {
96
97
console . error ( error ) ;
97
98
this . setState ( {
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { invocation } from '../../proto/invocation_ts_proto';
4
4
import { build_event_stream } from '../../proto/build_event_stream_ts_proto' ;
5
5
import { command_line } from '../../proto/command_line_ts_proto' ;
6
6
import format from '../format/format' ;
7
+ import { IconType } from '../favicon/favicon' ;
7
8
8
9
export default class InvocationModel {
9
10
invocations : invocation . Invocation [ ] = [ ] ;
@@ -298,6 +299,20 @@ export default class InvocationModel {
298
299
return this . finished . exitCode . code == 0 ? "success" : "failure" ;
299
300
}
300
301
302
+ getFaviconType ( ) {
303
+ let invocationStatus = this . invocations . find ( ( ) => true ) ?. invocationStatus ;
304
+ if ( invocationStatus == invocation . Invocation . InvocationStatus . DISCONNECTED_INVOCATION_STATUS ) {
305
+ return IconType . Unknown ;
306
+ }
307
+ if ( ! this . started ) {
308
+ return IconType . Unknown ;
309
+ }
310
+ if ( ! this . finished ) {
311
+ return IconType . InProgress ;
312
+ }
313
+ return this . finished . exitCode . code == 0 ? IconType . Success : IconType . Failure ;
314
+ }
315
+
301
316
getStatusIcon ( ) {
302
317
let invocationStatus = this . invocations . find ( ( ) => true ) ?. invocationStatus ;
303
318
if ( invocationStatus == invocation . Invocation . InvocationStatus . DISCONNECTED_INVOCATION_STATUS ) {
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ ts_library(
9
9
"//app/auth" ,
10
10
"//app/capabilities" ,
11
11
"//app/docs" ,
12
+ "//app/favicon" ,
12
13
"//app/footer" ,
13
14
"//app/invocation" ,
14
15
"//app/menu" ,
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import capabilities from '../capabilities/capabilities'
7
7
import router , { Path } from '../router/router' ;
8
8
import authService , { AuthService } from '../auth/auth_service' ;
9
9
import { User } from '../auth/auth_service' ;
10
+ import faviconService from '../favicon/favicon' ;
10
11
11
12
const viewModeKey = "VIEW_MODE" ;
12
13
const denseModeValue = "DENSE" ;
@@ -38,9 +39,13 @@ export default class RootComponent extends React.Component {
38
39
authService . userStream . addListener ( AuthService . userEventName , ( user : User ) => {
39
40
this . setState ( { ...this . state , user } )
40
41
} ) ;
42
+ faviconService . setDefaultFavicon ( ) ;
41
43
}
42
44
43
45
handlePathChange ( ) {
46
+ if ( this . state . path != window . location . pathname ) {
47
+ faviconService . setDefaultFavicon ( ) ;
48
+ }
44
49
this . setState ( {
45
50
hash : window . location . hash ,
46
51
path : window . location . pathname ,
You can’t perform that action at this time.
0 commit comments