refactor: updater now use i18n message

This commit is contained in:
林一二 2021-12-18 19:29:03 +08:00
parent 02cbc58370
commit 55506c32e5
2 changed files with 1 additions and 25 deletions

View file

@ -1,4 +1,5 @@
/**
* Used to be in updater to show download progress.
* https://stackoverflow.com/a/18650828
*/
export default function formatBytes(bytes: number, decimals = 2): string {

View file

@ -1,7 +1,6 @@
import { useState } from 'react';
import { useObservable } from 'beautiful-react-hooks';
import formatBytes from '@services/libs/formatBytes';
import { IUpdaterMetaData } from './interface';
export function useUpdaterObservable(): IUpdaterMetaData | undefined {
@ -9,27 +8,3 @@ export function useUpdaterObservable(): IUpdaterMetaData | undefined {
useObservable(window.observables.updater.updaterMetaData$, updaterMetaDataSetter as any);
return updaterMetaData;
}
export function getUpdaterDesc(status: IUpdaterMetaData['status'], info: IUpdaterMetaData['info']): string {
if (info instanceof Error) {
return info.message;
}
if (status === 'download-progress') {
if (info !== undefined && 'transferred' in info) {
const { transferred, total, bytesPerSecond } = info;
return `Downloading updates (${formatBytes(transferred)}/${formatBytes(total)} at ${formatBytes(bytesPerSecond)}/s)...`;
}
return 'Downloading updates...';
}
if (status === 'checking-for-update') {
return 'Checking for updates...';
}
if (status === 'update-available') {
return 'Downloading updates...';
}
if (status === 'update-downloaded') {
if (info !== undefined && 'version' in info) return `A new version (${info.version}) has been downloaded.`;
return 'A new version has been downloaded.';
}
return '';
}