- Added functionality for automatic update checks in the settings page, allowing users to enable or disable this feature. - Integrated app version display and update availability notifications. - Updated settings store to manage auto-check updates state and handle version migration. - Enhanced layout with a new card for update settings, improving user experience and accessibility.
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
'use client';
|
|
|
|
import { useEffect, useState } from 'react';
|
|
import { UpdateDialog } from '@/components/modals/update-dialog';
|
|
import { useAppUpdater } from '@/hooks/use-app-updater';
|
|
import { useSettingsStore } from '@/store/settings-store';
|
|
|
|
export function AppUpdaterProvider() {
|
|
const { updateAvailable, checkUpdate } = useAppUpdater();
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
const [hasChecked, setHasChecked] = useState(false);
|
|
const autoCheckEnabled = useSettingsStore((state) => state.autoCheckUpdates ?? true);
|
|
|
|
useEffect(() => {
|
|
if (!autoCheckEnabled || hasChecked) return;
|
|
|
|
// Verificar após um delay para não interferir no carregamento inicial
|
|
const timer = setTimeout(() => {
|
|
checkUpdate().then(() => {
|
|
setHasChecked(true);
|
|
});
|
|
}, 5000); // 5 segundos após o app carregar
|
|
|
|
return () => clearTimeout(timer);
|
|
}, [autoCheckEnabled, hasChecked, checkUpdate]);
|
|
|
|
useEffect(() => {
|
|
if (updateAvailable && !isOpen) {
|
|
setIsOpen(true);
|
|
}
|
|
}, [updateAvailable, isOpen]);
|
|
|
|
return (
|
|
<UpdateDialog
|
|
open={isOpen}
|
|
onOpenChange={setIsOpen}
|
|
/>
|
|
);
|
|
}
|
|
|