CI/CD / preconditions (pull_request) Successful in 1s
Native JavaScript checks / Native launcher and release tests (pull_request) Successful in 1m2s
macOS checks / Native Rust tests and unsigned build (pull_request) Successful in 1m38s
CI/CD / test_and_check_app (pull_request) Successful in 6m47s
CI/CD / Publish immutable image (pull_request) Skipped
70 lines
2.1 KiB
TypeScript
70 lines
2.1 KiB
TypeScript
import type { NativeAppState, NativeUpdates } from '@/types/native-app';
|
|
|
|
export function isNativeAppState(value: unknown): value is NativeAppState {
|
|
if (!value || typeof value !== 'object') {
|
|
return false;
|
|
}
|
|
const state = value as NativeAppState;
|
|
if (
|
|
state.apiVersion !== 1 ||
|
|
!['macos', 'ios'].includes(state.platform) ||
|
|
typeof state.version !== 'string' ||
|
|
typeof state.workspace !== 'string' ||
|
|
!Array.isArray(state.capabilities) ||
|
|
!state.capabilities.includes('workspace')
|
|
) {
|
|
return false;
|
|
}
|
|
try {
|
|
if (new URL(state.workspace).protocol !== 'https:') {
|
|
return false;
|
|
}
|
|
} catch {
|
|
return false;
|
|
}
|
|
if (!state.capabilities.includes('updates')) {
|
|
return state.updates === undefined;
|
|
}
|
|
if (state.platform !== 'macos' || !state.updates) {
|
|
return false;
|
|
}
|
|
const updates = state.updates;
|
|
return (
|
|
[
|
|
'idle',
|
|
'checking',
|
|
'available',
|
|
'current',
|
|
'downloading',
|
|
'verifying',
|
|
'installing',
|
|
'restarting',
|
|
'error',
|
|
].includes(updates.phase) &&
|
|
typeof updates.currentVersion === 'string' &&
|
|
typeof updates.build === 'string' &&
|
|
(updates.version === null || typeof updates.version === 'string') &&
|
|
(updates.notes === null || typeof updates.notes === 'string') &&
|
|
(updates.error === null || typeof updates.error === 'string') &&
|
|
Number.isFinite(updates.downloaded) &&
|
|
updates.downloaded >= 0 &&
|
|
(updates.total === null ||
|
|
(Number.isFinite(updates.total) && updates.total >= 0)) &&
|
|
typeof updates.preferences?.automatic === 'boolean' &&
|
|
[1, 6, 24].includes(updates.preferences.intervalHours)
|
|
);
|
|
}
|
|
|
|
export function updateIsBusy(updates?: NativeUpdates): boolean {
|
|
return (
|
|
!!updates &&
|
|
[
|
|
'checking',
|
|
'downloading',
|
|
'verifying',
|
|
'installing',
|
|
'restarting',
|
|
].includes(updates.phase)
|
|
);
|
|
}
|