Fix: blocking HTTP requests that would freeze the panel. (#1007)
This commit is contained in:
@@ -161,16 +161,30 @@ class HttpClient {
|
||||
* @param message - Prepared Soup message to send
|
||||
* @param options - Request configuration options
|
||||
*/
|
||||
private _sendRequest(
|
||||
private async _sendRequest(
|
||||
resolve: (value: RestResponse | PromiseLike<RestResponse>) => void,
|
||||
reject: (reason?: unknown) => void,
|
||||
message: Soup.Message,
|
||||
options: RequestOptions,
|
||||
): void {
|
||||
): Promise<void> {
|
||||
const cancellable = options.signal ?? null;
|
||||
|
||||
try {
|
||||
const bytes = this._session.send_and_read(message, cancellable);
|
||||
const bytes = await new Promise<GLib.Bytes | null>((resolveAsync, rejectAsync) => {
|
||||
this._session.send_and_read_async(
|
||||
message,
|
||||
GLib.PRIORITY_DEFAULT,
|
||||
cancellable,
|
||||
(_, result) => {
|
||||
try {
|
||||
const bytes = this._session.send_and_read_finish(result);
|
||||
resolveAsync(bytes);
|
||||
} catch (error) {
|
||||
rejectAsync(error);
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
const {
|
||||
response: responseText,
|
||||
|
||||
@@ -293,7 +293,8 @@ export default class WeatherService {
|
||||
`${provider.baseUrl}?location=${formattedLocation}&key=${weatherKey}`;
|
||||
|
||||
try {
|
||||
const response = await httpClient.get(url);
|
||||
const WEATHER_FETCH_TIMEOUT_MS = 10000;
|
||||
const response = await httpClient.get(url, { timeout: WEATHER_FETCH_TIMEOUT_MS });
|
||||
|
||||
if (response.data && provider.adapter) {
|
||||
const transformedData = provider.adapter.toStandardFormat(response.data);
|
||||
|
||||
Reference in New Issue
Block a user