Fix: blocking HTTP requests that would freeze the panel. (#1007)

This commit is contained in:
Jas Singh
2025-06-14 13:12:37 -07:00
committed by GitHub
parent 20532ee760
commit de272def02
2 changed files with 19 additions and 4 deletions

View File

@@ -161,16 +161,30 @@ class HttpClient {
* @param message - Prepared Soup message to send * @param message - Prepared Soup message to send
* @param options - Request configuration options * @param options - Request configuration options
*/ */
private _sendRequest( private async _sendRequest(
resolve: (value: RestResponse | PromiseLike<RestResponse>) => void, resolve: (value: RestResponse | PromiseLike<RestResponse>) => void,
reject: (reason?: unknown) => void, reject: (reason?: unknown) => void,
message: Soup.Message, message: Soup.Message,
options: RequestOptions, options: RequestOptions,
): void { ): Promise<void> {
const cancellable = options.signal ?? null; const cancellable = options.signal ?? null;
try { 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 { const {
response: responseText, response: responseText,

View File

@@ -293,7 +293,8 @@ export default class WeatherService {
`${provider.baseUrl}?location=${formattedLocation}&key=${weatherKey}`; `${provider.baseUrl}?location=${formattedLocation}&key=${weatherKey}`;
try { 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) { if (response.data && provider.adapter) {
const transformedData = provider.adapter.toStandardFormat(response.data); const transformedData = provider.adapter.toStandardFormat(response.data);