From be9d1bc87421c0004bb067623e4fdf794f4d3fc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7?= <308487730@qq.com> Date: Thu, 9 Mar 2023 22:59:24 +0800 Subject: [PATCH] chore: cleanup --- electron/main/update.ts | 8 ++++++-- src/components/update/index.tsx | 27 +++++++++------------------ 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/electron/main/update.ts b/electron/main/update.ts index e2386dd..473671c 100644 --- a/electron/main/update.ts +++ b/electron/main/update.ts @@ -9,9 +9,7 @@ export function update(win: Electron.BrowserWindow) { // When set to false, the update download will be triggered through the API autoUpdater.autoDownload = false - autoUpdater.disableWebInstaller = false - autoUpdater.allowDowngrade = false // start check @@ -27,6 +25,11 @@ export function update(win: Electron.BrowserWindow) { // Checking for updates ipcMain.handle('check-update', async () => { + if (!app.isPackaged) { + const error = new Error('The update feature is only available after the package.') + return { message: error.message, error } + } + try { return await autoUpdater.checkForUpdatesAndNotify() } catch (error) { @@ -52,6 +55,7 @@ export function update(win: Electron.BrowserWindow) { } ) }) + // Install now ipcMain.handle('quit-and-install', () => { autoUpdater.quitAndInstall(false, true) diff --git a/src/components/update/index.tsx b/src/components/update/index.tsx index b4448cd..083037c 100644 --- a/src/components/update/index.tsx +++ b/src/components/update/index.tsx @@ -10,7 +10,7 @@ const Update = () => { const [updateAvailable, setUpdateAvailable] = useState(false) const [versionInfo, setVersionInfo] = useState() const [updateError, setUpdateError] = useState() - const [progressInfo, setProgressInfo] = useState() + const [progressInfo, setProgressInfo] = useState>() const [modalOpen, setModalOpen] = useState(false) const [modalBtn, setModalBtn] = useState<{ cancelText?: string @@ -45,7 +45,6 @@ const Update = () => { ...state, cancelText: 'Cancel', okText: 'Update', - onCancel: () => setModalOpen(false), onOk: () => ipcRenderer.invoke('start-download'), })) setUpdateAvailable(true) @@ -56,13 +55,11 @@ const Update = () => { }, []) const onUpdateError = useCallback((_event: Electron.IpcRendererEvent, arg1: ErrorType) => { - console.error('arg1.error',arg1.error) setUpdateAvailable(false) setUpdateError(arg1) }, []) const onDownloadProgress = useCallback((_event: Electron.IpcRendererEvent, arg1: ProgressInfo) => { - console.log(arg1) setUpdateAvailable(true) setProgressInfo(arg1) }, []) @@ -105,8 +102,13 @@ const Update = () => { footer={isUpdate ? /* hide footer */null : undefined} >
- { - isUpdate + {updateError + ? ( +
+

Error downloading the latest version.

+

{updateError.message}

+
+ ) : isUpdate ? (
The last version is: v{versionInfo.newVersion}
@@ -119,18 +121,7 @@ const Update = () => {
) - : updateError - ? ( -
-

Error downloading the latest version.

-

{updateError.message}

-
- ) : ( -
-
The last version is: v{versionInfo?.version}
-
- ) - } + :
Checking...
}