feat: support mobile update checks

This commit is contained in:
Bohdan Triapitsyn
2026-07-07 13:39:50 +03:00
parent d45cae485c
commit 4a62a2aeab
14 changed files with 78 additions and 16 deletions
+24 -4
View File
@@ -12,6 +12,9 @@ import {
isWebRuntime,
} from '@/lib/desktop';
import { runtimeFetch } from '@/lib/runtime-fetch';
import { getClientPlatform, isCapacitorApp } from '@/lib/platform';
declare const __APP_VERSION__: string | undefined;
type UpdateState = {
checking: boolean;
@@ -21,7 +24,7 @@ type UpdateState = {
info: UpdateInfo | null;
progress: UpdateProgress | null;
error: string | null;
runtimeType: 'desktop' | 'web' | 'vscode' | null;
runtimeType: 'desktop' | 'web' | 'vscode' | 'mobile' | null;
lastChecked: number | null;
nextCheckInSec: number | null;
};
@@ -34,7 +37,7 @@ interface UpdateStore extends UpdateState {
reset: () => void;
}
type ClientRuntime = 'desktop' | 'web' | 'vscode';
type ClientRuntime = 'desktop' | 'web' | 'vscode' | 'mobile';
function detectDeviceClass(): 'mobile' | 'tablet' | 'desktop' | 'unknown' {
if (typeof window === 'undefined') return 'unknown';
@@ -64,7 +67,9 @@ function detectArch(): 'arm64' | 'x64' | 'unknown' {
return 'unknown';
}
function detectPlatform(): 'macos' | 'windows' | 'linux' | 'web' {
function detectPlatform(): 'macos' | 'windows' | 'linux' | 'web' | 'android' | 'ios' {
const clientPlatform = getClientPlatform();
if (clientPlatform === 'android' || clientPlatform === 'ios') return clientPlatform;
if (typeof navigator === 'undefined') return 'web';
const platform = (navigator.platform || '').toLowerCase();
if (platform.includes('mac')) return 'macos';
@@ -93,6 +98,12 @@ function mapRuntimeParams(runtime: ClientRuntime): URLSearchParams {
return params;
}
if (runtime === 'mobile') {
params.set('appType', 'mobile-capacitor');
params.set('instanceMode', 'remote');
return params;
}
params.set('appType', 'web');
params.set('instanceMode', 'unknown');
return params;
@@ -121,6 +132,8 @@ async function checkForWebUpdates(runtime: ClientRuntime, currentVersion?: strin
version: data.version,
currentVersion: data.currentVersion ?? 'unknown',
body: data.body,
releaseUrl: data.releaseUrl,
downloadUrl: data.downloadUrl,
nextSuggestedCheckInSec:
typeof data.nextSuggestedCheckInSec === 'number' && Number.isFinite(data.nextSuggestedCheckInSec)
? data.nextSuggestedCheckInSec
@@ -134,7 +147,10 @@ async function checkForWebUpdates(runtime: ClientRuntime, currentVersion?: strin
}
}
function detectRuntimeType(): 'desktop' | 'web' | 'vscode' | null {
function detectRuntimeType(): 'desktop' | 'web' | 'vscode' | 'mobile' | null {
if (isCapacitorApp()) {
return 'mobile';
}
if (isElectronShell()) {
return 'desktop';
}
@@ -186,6 +202,10 @@ export const useUpdateStore = create<UpdateStore>()((set, get) => ({
} else if (runtime === 'vscode') {
const vscodeInfo = await checkForWebUpdates('vscode');
suggestedSec = vscodeInfo?.nextSuggestedCheckInSec ?? null;
} else if (runtime === 'mobile') {
const appVersion = typeof __APP_VERSION__ !== 'undefined' ? __APP_VERSION__ : undefined;
info = await checkForWebUpdates('mobile', appVersion);
suggestedSec = info?.nextSuggestedCheckInSec ?? null;
}
set({