Type the updater API and the Tauri global. [skip build]
This commit is contained in:
@@ -1,20 +1,7 @@
|
||||
import React, { useState, useEffect, useCallback } from 'react';
|
||||
import { Box, Text } from 'folds';
|
||||
import * as css from './UpdateNotification.css';
|
||||
|
||||
interface UpdateInfo {
|
||||
version: string;
|
||||
releaseNotes?: string;
|
||||
releaseDate?: string;
|
||||
mock?: boolean;
|
||||
}
|
||||
|
||||
interface DownloadProgress {
|
||||
percent: number;
|
||||
transferred: number;
|
||||
total: number;
|
||||
mock?: boolean;
|
||||
}
|
||||
import type { DownloadProgress, UpdateInfo } from '../../../ext';
|
||||
|
||||
type UpdaterPhase = 'idle' | 'checking' | 'available' | 'downloading' | 'ready';
|
||||
|
||||
@@ -26,7 +13,7 @@ export function UpdateNotification() {
|
||||
const [hovered, setHovered] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const { electron } = window as any;
|
||||
const { electron } = window;
|
||||
if (!electron?.updater) return undefined;
|
||||
|
||||
const { updater } = electron;
|
||||
@@ -72,7 +59,7 @@ export function UpdateNotification() {
|
||||
const handleCheck = useCallback(async () => {
|
||||
setPhase('checking');
|
||||
try {
|
||||
const result = await (window as any).electron.updater.checkForUpdates();
|
||||
const result = await window.electron?.updater?.checkForUpdates();
|
||||
if (!result?.success) {
|
||||
setPhase('idle');
|
||||
}
|
||||
@@ -89,7 +76,7 @@ export function UpdateNotification() {
|
||||
setPhase('downloading');
|
||||
setDownloadProgress(0);
|
||||
try {
|
||||
await (window as any).electron.updater.downloadUpdate();
|
||||
await window.electron?.updater?.downloadUpdate();
|
||||
} catch {
|
||||
setPhase('available');
|
||||
}
|
||||
@@ -97,7 +84,7 @@ export function UpdateNotification() {
|
||||
|
||||
const handleInstall = useCallback(async () => {
|
||||
try {
|
||||
await (window as any).electron.updater.installUpdate();
|
||||
await window.electron?.updater?.installUpdate();
|
||||
if (isMock) {
|
||||
setPhase('idle');
|
||||
setUpdateInfo(null);
|
||||
@@ -114,7 +101,7 @@ export function UpdateNotification() {
|
||||
setDownloadProgress(0);
|
||||
}, []);
|
||||
|
||||
if (typeof window === 'undefined' || !(window as any).electron?.updater) {
|
||||
if (typeof window === 'undefined' || !window.electron?.updater) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user