@@ -93,55 +93,66 @@ export class AudioRecorder {
93
93
: null
94
94
: null
95
95
if ( match ) {
96
- const html = await (
97
- await fetch ( `https://www.aha-music.com/${ match . acr_id } ` )
98
- ) . text ( )
99
- const parser = new ACRPageParser ( html )
100
- match . spotify_id = parser . getSpotifyId ( )
101
- match . youtube_id = parser . getYoutubeId ( )
102
- match . deezer_id = parser . getDeezerId ( )
103
96
let thumbnail : string | null = null
104
97
let title : string | null = null
105
98
try {
99
+ chrome . runtime . sendMessage ( {
100
+ type : 'START_FETCHING_METADATA'
101
+ } )
102
+ const html = await (
103
+ await fetch ( `https://www.aha-music.com/${ match . acr_id } ` )
104
+ ) . text ( )
105
+ const parser = new ACRPageParser ( html )
106
+ match . spotify_id = parser . getSpotifyId ( )
107
+ match . youtube_id = parser . getYoutubeId ( )
108
+ match . deezer_id = parser . getDeezerId ( )
106
109
if ( match . spotify_id ) {
107
110
const response = await SpotifyOEmbedClient . oembed (
108
111
match . spotify_id
109
112
)
110
113
thumbnail = response . thumbnail_url
111
114
title = response . title
112
115
}
113
- } catch {
116
+ chrome . runtime . sendMessage ( {
117
+ type : 'STOP_FETCHING_METADATA'
118
+ } )
119
+ const entry = this . buildLocalMatch ( { match, thumbnail, title } )
120
+ StorageHelper . get < SongSerializedState > ( SONG_STORAGE_KEY ) . then (
121
+ state => {
122
+ StorageHelper . set < SongSerializedState > ( SONG_STORAGE_KEY , {
123
+ history : [ entry , ...state . history . slice ( 0 , MAX_MATCHES_ENTRY ) ]
124
+ } ) . then ( ( ) => {
125
+ if (
126
+ chrome . extension . getViews ( { type : 'popup' } ) . length === 0
127
+ ) {
128
+ window . unreadMatches ++
129
+ chrome . browserAction . setBadgeText ( {
130
+ text : window . unreadMatches . toString ( )
131
+ } )
132
+ chrome . tabs . sendMessage ( tabs [ 0 ] . id ! , {
133
+ type : 'ON_BG_RECORDING_STOP' ,
134
+ payload : { match : entry }
135
+ } )
136
+ }
137
+ chrome . runtime . sendMessage ( {
138
+ type : 'MATCH_FOUND' ,
139
+ payload : {
140
+ match : entry
141
+ }
142
+ } )
143
+ } )
144
+ }
145
+ )
146
+ } catch ( e ) {
147
+ chrome . runtime . sendMessage ( {
148
+ type : 'STOP_FETCHING_METADATA'
149
+ } )
114
150
console . log (
115
151
'An error occured while fetching informations from Spotify'
116
152
)
117
153
thumbnail = null
118
154
title = null
119
155
}
120
- const entry = this . buildLocalMatch ( { match, thumbnail, title } )
121
- StorageHelper . get < SongSerializedState > ( SONG_STORAGE_KEY ) . then (
122
- state => {
123
- StorageHelper . set < SongSerializedState > ( SONG_STORAGE_KEY , {
124
- history : [ entry , ...state . history . slice ( 0 , MAX_MATCHES_ENTRY ) ]
125
- } ) . then ( ( ) => {
126
- if ( chrome . extension . getViews ( { type : 'popup' } ) . length === 0 ) {
127
- window . unreadMatches ++
128
- chrome . browserAction . setBadgeText ( {
129
- text : window . unreadMatches . toString ( )
130
- } )
131
- chrome . tabs . sendMessage ( tabs [ 0 ] . id ! , {
132
- type : 'ON_BG_RECORDING_STOP' ,
133
- payload : { match : entry }
134
- } )
135
- }
136
- chrome . runtime . sendMessage ( {
137
- type : 'MATCH_FOUND' ,
138
- payload : {
139
- match : entry
140
- }
141
- } )
142
- } )
143
- }
144
- )
145
156
} else {
146
157
if ( chrome . extension . getViews ( { type : 'popup' } ) . length === 0 ) {
147
158
chrome . tabs . sendMessage ( tabs [ 0 ] . id ! , {
0 commit comments