@@ -5,7 +5,7 @@ import { dispatch, watch } from '../store';
55import { RootState } from '../store/rootReducer' ;
66import { ROOT_WINDOW_ICON_CHANGED } from '../ui/actions' ;
77
8- handle ( 'servers/fetch-info' , async ( urlHref ) : Promise < [ urlHref : string , version : string ] > => {
8+ export const fetchInfo = async ( urlHref : string ) : Promise < [ urlHref : string , version : string ] > => {
99 const url = new URL ( urlHref ) ;
1010
1111 const { username, password } = url ;
@@ -15,25 +15,31 @@ handle('servers/fetch-info', async (urlHref): Promise<[urlHref: string, version:
1515 headers . append ( 'Authorization' , `Basic ${ btoa ( `${ username } :${ password } ` ) } ` ) ;
1616 }
1717
18- const endpoint = new URL ( 'api/info' , url ) ;
18+ const homeResponse = await fetch ( url . href , { headers } ) ;
1919
20- const response = await fetch ( endpoint . href , { headers } ) ;
20+ if ( ! homeResponse . ok ) {
21+ throw new Error ( homeResponse . statusText ) ;
22+ }
23+
24+ const endpoint = new URL ( 'api/info' , homeResponse . url ) ;
25+
26+ const apiInfoResponse = await fetch ( endpoint . href , { headers } ) ;
2127
22- if ( ! response . ok ) {
23- throw new Error ( response . statusText ) ;
28+ if ( ! apiInfoResponse . ok ) {
29+ throw new Error ( apiInfoResponse . statusText ) ;
2430 }
2531
2632 const responseBody : {
2733 success : boolean ;
2834 version : string ;
29- } = await response . json ( ) ;
35+ } = await apiInfoResponse . json ( ) ;
3036
3137 if ( ! responseBody . success ) {
3238 throw new Error ( ) ;
3339 }
3440
35- return [ new URL ( '../.. ' , response . url ) . href , responseBody . version ] ;
36- } ) ;
41+ return [ new URL ( '..' , apiInfoResponse . url ) . href , responseBody . version ] ;
42+ } ;
3743
3844type RootWindowIconParams = {
3945 badge : '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '+9' | '•' | undefined ;
@@ -240,10 +246,14 @@ const updateRootWindowIconForWindows = async ({ badge, favicon }: RootWindowIcon
240246 } ) ;
241247} ;
242248
243- if ( process . platform === 'linux' ) {
244- watch ( selectBadgeAndFavicon , updateRootWindowIconForLinux ) ;
245- }
249+ export default ( ) : void => {
250+ handle ( 'servers/fetch-info' , fetchInfo ) ;
246251
247- if ( process . platform === 'win32' ) {
248- watch ( selectBadgeAndFavicon , updateRootWindowIconForWindows ) ;
249- }
252+ if ( process . platform === 'linux' ) {
253+ watch ( selectBadgeAndFavicon , updateRootWindowIconForLinux ) ;
254+ }
255+
256+ if ( process . platform === 'win32' ) {
257+ watch ( selectBadgeAndFavicon , updateRootWindowIconForWindows ) ;
258+ }
259+ } ;
0 commit comments