feat: rebuild portable auto-update flow

This commit is contained in:
Misaka
2026-03-20 21:20:28 +08:00
parent 5e50a8fbcf
commit 6ad9463e73
29 changed files with 2333 additions and 13 deletions

View File

@@ -22,6 +22,11 @@ import type {
import type { IpcResult } from '../main/ipc'
import type { LogLevel } from '../shared/ipc-channels'
import type { CleanerConfig } from '../main/types/config.schema'
import type {
DownloadReleaseRequest,
UpdateDialogCatalog,
UpdateStatus
} from '../main/types/update.types'
export interface ResolverAPI {
resolve: (input: ResolverInput) => Promise<IpcResult<ResolverResponse>>
@@ -120,6 +125,16 @@ export interface LoggerAPI {
log: (level: LogLevel, message: string, context?: Record<string, unknown>) => void
}
export interface UpdateAPI {
getStatus: () => Promise<IpcResult<UpdateStatus>>
checkNow: () => Promise<IpcResult<UpdateStatus>>
getCatalog: () => Promise<IpcResult<UpdateDialogCatalog>>
getChangelog: (release: DownloadReleaseRequest) => Promise<IpcResult<string>>
downloadRelease: (release: DownloadReleaseRequest) => Promise<IpcResult<UpdateStatus>>
installDownloaded: () => Promise<IpcResult<void>>
onStatusChanged: (callback: (data: UpdateStatus) => void) => () => void
}
export interface ProcessAPI {
versions: {
electron: string
@@ -146,6 +161,7 @@ declare global {
config: ConfigAPI
logger: LoggerAPI
report: ReportAPI
update: UpdateAPI
}
api: unknown
}

View File

@@ -13,6 +13,8 @@ import type {
import type { IpcResult } from '../main/ipc'
import { IPC_CHANNELS, type LogLevel } from '../shared/ipc-channels'
import type { CleanerConfig } from '../main/types/config.schema'
import type { DownloadReleaseRequest, UpdateStatus } from '../main/types/update.types'
import type { UpdateDialogCatalog } from '../main/types/update.types'
type ErpSettingsPayload = {
erp?: {
@@ -218,6 +220,25 @@ const api = {
listByUser: (username: string): Promise<IpcResult> =>
invokeIpc(IPC_CHANNELS.REPORT_LIST_BY_USER, username),
download: (key: string): Promise<IpcResult> => invokeIpc(IPC_CHANNELS.REPORT_DOWNLOAD, key)
},
update: {
getStatus: (): Promise<IpcResult<UpdateStatus>> => invokeIpc(IPC_CHANNELS.UPDATE_GET_STATUS),
checkNow: (): Promise<IpcResult<UpdateStatus>> => invokeIpc(IPC_CHANNELS.UPDATE_CHECK_NOW),
getCatalog: (): Promise<IpcResult<UpdateDialogCatalog>> =>
invokeIpc(IPC_CHANNELS.UPDATE_GET_CATALOG),
getChangelog: (release: DownloadReleaseRequest): Promise<IpcResult<string>> =>
invokeIpc(IPC_CHANNELS.UPDATE_GET_CHANGELOG, release),
downloadRelease: (release: DownloadReleaseRequest): Promise<IpcResult<UpdateStatus>> =>
invokeIpc(IPC_CHANNELS.UPDATE_DOWNLOAD_RELEASE, release),
installDownloaded: (): Promise<IpcResult<void>> =>
invokeIpc(IPC_CHANNELS.UPDATE_INSTALL_DOWNLOADED),
onStatusChanged: (callback: (data: UpdateStatus) => void) => {
const subscription = (_event: Electron.IpcRendererEvent, data: UpdateStatus) =>
callback(data)
ipcRenderer.on(IPC_CHANNELS.UPDATE_STATUS_CHANGED, subscription)
return () => ipcRenderer.removeListener(IPC_CHANNELS.UPDATE_STATUS_CHANGED, subscription)
}
}
} as const