fix: update check for desktop app

This commit is contained in:
Bohdan Triapitsyn
2026-07-15 14:02:12 +03:00
parent 00e002413d
commit 53d2dde87a
4 changed files with 44 additions and 5 deletions
+31 -2
View File
@@ -39,6 +39,23 @@ interface UpdateStore extends UpdateState {
type ClientRuntime = 'desktop' | 'web' | 'vscode' | 'mobile';
const CLIENT_INSTALL_ID_KEY = 'openchamber.update-install-id';
function getClientInstallId(): string | undefined {
if (typeof window === 'undefined' || typeof crypto.randomUUID !== 'function') return undefined;
try {
const existing = window.localStorage.getItem(CLIENT_INSTALL_ID_KEY)?.trim();
if (existing) return existing;
const installId = crypto.randomUUID();
window.localStorage.setItem(CLIENT_INSTALL_ID_KEY, installId);
return installId;
} catch {
return undefined;
}
}
function detectDeviceClass(): 'mobile' | 'tablet' | 'desktop' | 'unknown' {
if (typeof window === 'undefined') return 'unknown';
try {
@@ -86,6 +103,10 @@ function mapRuntimeParams(runtime: ClientRuntime): URLSearchParams {
params.set('deviceClass', detectDeviceClass());
params.set('arch', detectArch());
params.set('platform', detectPlatform());
if (shouldReportUsage && (runtime === 'desktop' || runtime === 'mobile')) {
const installId = getClientInstallId();
if (installId) params.set('installId', installId);
}
if (runtime === 'desktop') {
params.set('appType', 'desktop-electron');
params.set('instanceMode', isDesktopLocalOriginActive() ? 'local' : 'remote');
@@ -186,13 +207,21 @@ export const useUpdateStore = create<UpdateStore>()((set, get) => ({
let suggestedSec: number | null = null;
if (runtime === 'desktop') {
const desktopInfo = await checkForDesktopUpdates();
const appVersion = typeof __APP_VERSION__ !== 'undefined' ? __APP_VERSION__ : undefined;
const [desktopResult, apiResult] = await Promise.allSettled([
checkForDesktopUpdates(),
checkForWebUpdates('desktop', appVersion),
]);
const desktopInfo = desktopResult.status === 'fulfilled' ? desktopResult.value : null;
suggestedSec = apiResult.status === 'fulfilled'
? (apiResult.value?.nextSuggestedCheckInSec ?? null)
: null;
set({
checking: false,
available: desktopInfo?.available ?? false,
info: desktopInfo,
lastChecked: Date.now(),
nextCheckInSec: null,
nextCheckInSec: suggestedSec,
});
return suggestedSec;