add: auto update launcher
This commit is contained in:
@ -25,7 +25,36 @@ class AppUpdater {
|
||||
constructor() {
|
||||
log.transports.file.level = 'info';
|
||||
autoUpdater.logger = log;
|
||||
|
||||
const server = 'https://git.popa-popa.ru/DIKER/popa-launcher';
|
||||
|
||||
// Для Gitea нужно указать конкретную структуру URL
|
||||
// Обратите внимание на использование пути /download/
|
||||
autoUpdater.setFeedURL({
|
||||
provider: 'generic',
|
||||
url: `${server}/releases/download/latest`, // Укажите конкретную версию
|
||||
channel: 'latest',
|
||||
});
|
||||
|
||||
// Проверка обновлений
|
||||
autoUpdater.checkForUpdatesAndNotify();
|
||||
|
||||
// Периодическая проверка обновлений (каждый час)
|
||||
setInterval(
|
||||
() => {
|
||||
autoUpdater.checkForUpdatesAndNotify();
|
||||
},
|
||||
60 * 60 * 1000,
|
||||
);
|
||||
|
||||
// Обработчики событий обновления
|
||||
autoUpdater.on('update-downloaded', () => {
|
||||
log.info('Обновление загружено. Будет установлено при перезапуске.');
|
||||
// Можно отправить событие в renderer для уведомления пользователя
|
||||
if (mainWindow) {
|
||||
mainWindow.webContents.send('update-available');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -160,3 +189,7 @@ app
|
||||
});
|
||||
})
|
||||
.catch(console.log);
|
||||
|
||||
ipcMain.handle('install-update', () => {
|
||||
autoUpdater.quitAndInstall();
|
||||
});
|
||||
|
@ -9,7 +9,9 @@ export type Channels =
|
||||
| 'close-app'
|
||||
| 'minimize-app'
|
||||
| 'save-pack-config'
|
||||
| 'load-pack-config';
|
||||
| 'load-pack-config'
|
||||
| 'update-available'
|
||||
| 'install-update';
|
||||
|
||||
const electronHandler = {
|
||||
ipcRenderer: {
|
||||
@ -28,7 +30,7 @@ const electronHandler = {
|
||||
once(channel: Channels, func: (...args: unknown[]) => void) {
|
||||
ipcRenderer.once(channel, (_event, ...args) => func(...args));
|
||||
},
|
||||
invoke(channel: string, ...args: unknown[]) {
|
||||
invoke(channel: Channels, ...args: unknown[]): Promise<any> {
|
||||
return ipcRenderer.invoke(channel, ...args);
|
||||
},
|
||||
},
|
||||
|
@ -11,6 +11,7 @@ import './App.css';
|
||||
import TopBar from './components/TopBar';
|
||||
import { Box } from '@mui/material';
|
||||
import MinecraftBackround from './components/MinecraftBackround';
|
||||
import { Notifier } from './components/Notifier';
|
||||
|
||||
// Переместите launchOptions сюда, вне компонентов
|
||||
const launchOptions = {
|
||||
@ -94,6 +95,7 @@ const App = () => {
|
||||
>
|
||||
<MinecraftBackround />
|
||||
<TopBar onRegister={handleRegister} />
|
||||
<Notifier />
|
||||
<Routes>
|
||||
<Route path="/login" element={<Login />} />
|
||||
<Route
|
||||
|
63
src/renderer/components/Notifier.tsx
Normal file
63
src/renderer/components/Notifier.tsx
Normal file
@ -0,0 +1,63 @@
|
||||
import { Alert, Box, Snackbar, Button } from '@mui/material';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
export const Notifier = () => {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [message, setMessage] = useState('');
|
||||
const [severity, setSeverity] = useState<
|
||||
'error' | 'warning' | 'info' | 'success'
|
||||
>('info');
|
||||
const [hasUpdateAvailable, setHasUpdateAvailable] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
// Слушаем событие о наличии обновления
|
||||
window.electron.ipcRenderer.on('update-available', () => {
|
||||
setMessage('Доступно новое обновление');
|
||||
setSeverity('info');
|
||||
setHasUpdateAvailable(true);
|
||||
setOpen(true);
|
||||
});
|
||||
|
||||
return () => {
|
||||
// Отписываемся от события при размонтировании
|
||||
window.electron.ipcRenderer.removeAllListeners('update-available');
|
||||
};
|
||||
}, []);
|
||||
|
||||
const handleClose = () => {
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
const handleUpdate = () => {
|
||||
window.electron.ipcRenderer.invoke('install-update');
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Snackbar
|
||||
open={open}
|
||||
autoHideDuration={hasUpdateAvailable ? null : 6000}
|
||||
onClose={handleClose}
|
||||
>
|
||||
<Alert
|
||||
severity={severity}
|
||||
action={
|
||||
hasUpdateAvailable && (
|
||||
<>
|
||||
<Button color="primary" size="small" onClick={handleUpdate}>
|
||||
Обновить сейчас
|
||||
</Button>
|
||||
<Button color="secondary" size="small" onClick={handleClose}>
|
||||
Позже
|
||||
</Button>
|
||||
</>
|
||||
)
|
||||
}
|
||||
>
|
||||
{message}
|
||||
</Alert>
|
||||
</Snackbar>
|
||||
</Box>
|
||||
);
|
||||
};
|
@ -6,7 +6,7 @@
|
||||
http-equiv="Content-Security-Policy"
|
||||
content="script-src 'self' 'unsafe-inline'"
|
||||
/>
|
||||
<title>Hello Electron React!</title>
|
||||
<title>popa-launcher</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
Reference in New Issue
Block a user