agent-ecosystem/src/renderer/store/slices/updateSlice.ts
matt 7fa2f96ed4 feat(http): implement HTTP server and route handlers for configuration, notifications, projects, sessions, and SSH management
- Introduced an HTTP server to facilitate communication with the application.
- Added route handlers for managing application configuration, including getting and updating settings.
- Implemented notification operations with routes for retrieving, marking, and deleting notifications.
- Created project and session management routes to list projects, sessions, and their details.
- Developed SSH connection management routes for connecting, disconnecting, and retrieving SSH state and configuration.
- Enhanced the application architecture to support real-time event streaming via Server-Sent Events (SSE).

This commit significantly expands the application's capabilities by integrating an HTTP server and various management routes, improving user interaction and functionality.
2026-02-12 15:04:56 +09:00

83 lines
2.1 KiB
TypeScript

/**
* Update slice - manages OTA auto-update state and actions.
*/
import { api } from '@renderer/api';
import { createLogger } from '@shared/utils/logger';
import type { AppState } from '../types';
import type { StateCreator } from 'zustand';
const logger = createLogger('Store:update');
// =============================================================================
// Slice Interface
// =============================================================================
export interface UpdateSlice {
// State
updateStatus:
| 'idle'
| 'checking'
| 'available'
| 'not-available'
| 'downloading'
| 'downloaded'
| 'error';
availableVersion: string | null;
releaseNotes: string | null;
downloadProgress: number;
updateError: string | null;
showUpdateDialog: boolean;
showUpdateBanner: boolean;
// Actions
checkForUpdates: () => void;
downloadUpdate: () => void;
installUpdate: () => void;
dismissUpdateDialog: () => void;
dismissUpdateBanner: () => void;
}
// =============================================================================
// Slice Creator
// =============================================================================
export const createUpdateSlice: StateCreator<AppState, [], [], UpdateSlice> = (set) => ({
// Initial state
updateStatus: 'idle',
availableVersion: null,
releaseNotes: null,
downloadProgress: 0,
updateError: null,
showUpdateDialog: false,
showUpdateBanner: false,
checkForUpdates: () => {
set({ updateStatus: 'checking', updateError: null });
api.updater.check().catch((error) => {
logger.error('Failed to check for updates:', error);
});
},
downloadUpdate: () => {
set({ showUpdateDialog: false, showUpdateBanner: true, downloadProgress: 0 });
api.updater.download().catch((error) => {
logger.error('Failed to download update:', error);
});
},
installUpdate: () => {
api.updater.install().catch((error) => {
logger.error('Failed to install update:', error);
});
},
dismissUpdateDialog: () => {
set({ showUpdateDialog: false });
},
dismissUpdateBanner: () => {
set({ showUpdateBanner: false });
},
});