Skip to content

Commit

Permalink
chore!: rename ErrorInfo to ErrorCode, UnavailableInfo to `Unav…
Browse files Browse the repository at this point in the history
…ailableCode`
  • Loading branch information
subframe7536 committed Aug 15, 2024
1 parent 6d0ad15 commit b26bf1f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export default startupWithUpdater((updater) => {
}
await updater.downloadUpdate()
})
updater.on('update-not-available', (reason, info) => console.log(reason, info))
updater.on('update-not-available', (code, reason, info) => console.log(code, reason, info))
updater.on('download-progress', (data) => {
console.log(data)
main.send(BrowserWindow.getAllWindows()[0], 'msg', data)
Expand Down
12 changes: 6 additions & 6 deletions src/entry/types.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import type { IProvider } from '../provider'
import type { UpdateInfo } from '../utils/version'

export type ErrorInfo =
export type ErrorCode =
| 'ERR_DOWNLOAD'
| 'ERR_VALIDATE'
| 'ERR_PARAM'
| 'ERR_NETWORK'

export type UnavailableInfo =
export type UnavailableCode =
| 'UNAVAILABLE_ERROR'
| 'UNAVAILABLE_DEV'
| 'UNAVAILABLE_VERSION'

export class UpdaterError extends Error {
public code: ErrorInfo
constructor(msg: ErrorInfo, info: string) {
super(`[${msg}] ${info}`)
this.code = msg
public code: ErrorCode
constructor(code: ErrorCode, info: string) {
super(`[${code}] ${info}`)
this.code = code
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/entry/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { app } from 'electron'
import { type UpdateInfo, type UpdateJSON, isUpdateJSON } from '../utils/version'
import type { DownloadingInfo, IProvider, UpdateJSONWithURL } from '../provider'
import { getAppVersion, getEntryVersion, getPathFromAppNameAsar, isDev, restartApp } from '../utils/electron'
import type { ErrorInfo, Logger, UnavailableInfo, UpdateInfoWithExtraVersion, UpdateInfoWithURL, UpdaterOption } from './types'
import type { ErrorCode, Logger, UnavailableCode, UpdateInfoWithExtraVersion, UpdateInfoWithURL, UpdaterOption } from './types'
import { UpdaterError } from './types'

/**
Expand All @@ -19,7 +19,7 @@ declare const __EIU_VERSION_PATH__: string
export class Updater extends EventEmitter<{
'checking': any
'update-available': [data: UpdateInfoWithExtraVersion]
'update-not-available': [code: UnavailableInfo, msg: string, info?: UpdateInfoWithExtraVersion]
'update-not-available': [code: UnavailableCode, msg: string, info?: UpdateInfoWithExtraVersion]
'error': [error: UpdaterError]
'download-progress': [info: DownloadingInfo]
'update-downloaded': any
Expand Down Expand Up @@ -112,7 +112,7 @@ export class Updater extends EventEmitter<{
/**
* Handle error message and emit error event
*/
private err(msg: string, code: ErrorInfo, errorInfo: string): void {
private err(msg: string, code: ErrorCode, errorInfo: string): void {
const err = new UpdaterError(code, errorInfo)
this.logger?.error(`[${code}] ${msg}`, err)
this.emit('error', err)
Expand All @@ -128,7 +128,7 @@ export class Updater extends EventEmitter<{
*/
public async checkForUpdates(data: UpdateJSON | UpdateJSONWithURL): Promise<boolean>
public async checkForUpdates(data?: UpdateJSON | UpdateJSONWithURL): Promise<boolean> {
const emitUnavailable = (msg: string, code: UnavailableInfo, info?: UpdateInfoWithExtraVersion): false => {
const emitUnavailable = (msg: string, code: UnavailableCode, info?: UpdateInfoWithExtraVersion): false => {
this.logger?.info(`[${code}] ${msg}`)
this.emit('update-not-available', code, msg, info)
return false
Expand Down

0 comments on commit b26bf1f

Please sign in to comment.