mirror of
https://github.com/lone-cloud/gerbil
synced 2026-06-03 19:54:44 -07:00
retry new kcpp version checks if internet is unavailable, better logging for audio issues
This commit is contained in:
parent
07c3d4c9af
commit
13759e573e
4 changed files with 29 additions and 7 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { GITHUB_API } from '@/constants';
|
import { GITHUB_API } from '@/constants';
|
||||||
|
import { withRetry } from '@/utils/logger';
|
||||||
import { compareVersions } from '@/utils/version';
|
import { compareVersions } from '@/utils/version';
|
||||||
|
|
||||||
interface AppUpdateInfo {
|
interface AppUpdateInfo {
|
||||||
|
|
@ -61,8 +62,8 @@ export const useAppUpdateChecker = () => {
|
||||||
try {
|
try {
|
||||||
const currentVersion = await window.electronAPI.app.getVersion();
|
const currentVersion = await window.electronAPI.app.getVersion();
|
||||||
|
|
||||||
const response = await fetch(
|
const response = await withRetry(() =>
|
||||||
`${GITHUB_API.BASE_URL}/repos/${GITHUB_API.GERBIL_REPO}/releases/latest`,
|
fetch(`${GITHUB_API.BASE_URL}/repos/${GITHUB_API.GERBIL_REPO}/releases/latest`),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import type {
|
||||||
ReleaseWithStatus,
|
ReleaseWithStatus,
|
||||||
} from '@/types/electron';
|
} from '@/types/electron';
|
||||||
import { sortDownloadsByType } from '@/utils/assets';
|
import { sortDownloadsByType } from '@/utils/assets';
|
||||||
import { logError, safeExecute } from '@/utils/logger';
|
import { logError, safeExecute, withRetry } from '@/utils/logger';
|
||||||
import { filterAssetsByPlatform } from '@/utils/platform';
|
import { filterAssetsByPlatform } from '@/utils/platform';
|
||||||
import { getROCmDownload } from '@/utils/rocm';
|
import { getROCmDownload } from '@/utils/rocm';
|
||||||
|
|
||||||
|
|
@ -154,7 +154,7 @@ export const useKoboldBackendsStore = create<KoboldBackendsState>((set, get) =>
|
||||||
const platform = await window.electronAPI.kobold.getPlatform();
|
const platform = await window.electronAPI.kobold.getPlatform();
|
||||||
set({ platform, loadingPlatform: false });
|
set({ platform, loadingPlatform: false });
|
||||||
|
|
||||||
const downloads = await fetchDownloads(platform);
|
const downloads = await withRetry(() => fetchDownloads(platform));
|
||||||
set({ availableDownloads: downloads });
|
set({ availableDownloads: downloads });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logError('Failed to initialize store:', error as Error);
|
logError('Failed to initialize store:', error as Error);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,21 @@ export const logError = (message: string, error: Error) => {
|
||||||
window.electronAPI.logs.logError(message, error);
|
window.electronAPI.logs.logError(message, error);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const withRetry = async <T>(operation: () => Promise<T>, retries = 3, delayMs = 3000) => {
|
||||||
|
let lastError: unknown;
|
||||||
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
||||||
|
try {
|
||||||
|
return await operation();
|
||||||
|
} catch (error) {
|
||||||
|
lastError = error;
|
||||||
|
if (attempt < retries) {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw lastError;
|
||||||
|
};
|
||||||
|
|
||||||
export const safeExecute = async <T>(operation: () => Promise<T>, errorMessage: string) => {
|
export const safeExecute = async <T>(operation: () => Promise<T>, errorMessage: string) => {
|
||||||
try {
|
try {
|
||||||
return await operation();
|
return await operation();
|
||||||
|
|
|
||||||
|
|
@ -38,14 +38,18 @@ export const initializeAudio = async () => {
|
||||||
audio.pause();
|
audio.pause();
|
||||||
audio.currentTime = 0;
|
audio.currentTime = 0;
|
||||||
audio.volume = 0.5;
|
audio.volume = 0.5;
|
||||||
} catch {}
|
} catch (err) {
|
||||||
|
window.electronAPI.logs.logError(`Failed to init audio for ${soundUrl}: ${String(err)}`);
|
||||||
|
}
|
||||||
|
|
||||||
audioCache.set(soundUrl, audio);
|
audioCache.set(soundUrl, audio);
|
||||||
});
|
});
|
||||||
|
|
||||||
await Promise.allSettled(initPromises);
|
await Promise.allSettled(initPromises);
|
||||||
audioInitialized = true;
|
audioInitialized = true;
|
||||||
} catch {}
|
} catch (err) {
|
||||||
|
window.electronAPI.logs.logError(`initializeAudio failed: ${String(err)}`);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const playSound = async (soundUrl: string, volume = 0.5) => {
|
export const playSound = async (soundUrl: string, volume = 0.5) => {
|
||||||
|
|
@ -63,5 +67,7 @@ export const playSound = async (soundUrl: string, volume = 0.5) => {
|
||||||
audio.volume = volume;
|
audio.volume = volume;
|
||||||
audio.currentTime = 0;
|
audio.currentTime = 0;
|
||||||
await audio.play();
|
await audio.play();
|
||||||
} catch {}
|
} catch (err) {
|
||||||
|
window.electronAPI.logs.logError(`playSound failed for ${soundUrl}: ${String(err)}`);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue