chore: cleanup
This commit is contained in:
		
							parent
							
								
									2c52f297cb
								
							
						
					
					
						commit
						be9d1bc874
					
				| 
						 | 
					@ -9,9 +9,7 @@ export function update(win: Electron.BrowserWindow) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // When set to false, the update download will be triggered through the API
 | 
					  // When set to false, the update download will be triggered through the API
 | 
				
			||||||
  autoUpdater.autoDownload = false
 | 
					  autoUpdater.autoDownload = false
 | 
				
			||||||
 | 
					 | 
				
			||||||
  autoUpdater.disableWebInstaller = false
 | 
					  autoUpdater.disableWebInstaller = false
 | 
				
			||||||
 | 
					 | 
				
			||||||
  autoUpdater.allowDowngrade = false
 | 
					  autoUpdater.allowDowngrade = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // start check
 | 
					  // start check
 | 
				
			||||||
| 
						 | 
					@ -27,6 +25,11 @@ export function update(win: Electron.BrowserWindow) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Checking for updates
 | 
					  // Checking for updates
 | 
				
			||||||
  ipcMain.handle('check-update', async () => {
 | 
					  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 {
 | 
					    try {
 | 
				
			||||||
      return await autoUpdater.checkForUpdatesAndNotify()
 | 
					      return await autoUpdater.checkForUpdatesAndNotify()
 | 
				
			||||||
    } catch (error) {
 | 
					    } catch (error) {
 | 
				
			||||||
| 
						 | 
					@ -52,6 +55,7 @@ export function update(win: Electron.BrowserWindow) {
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Install now
 | 
					  // Install now
 | 
				
			||||||
  ipcMain.handle('quit-and-install', () => {
 | 
					  ipcMain.handle('quit-and-install', () => {
 | 
				
			||||||
    autoUpdater.quitAndInstall(false, true)
 | 
					    autoUpdater.quitAndInstall(false, true)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,7 +10,7 @@ const Update = () => {
 | 
				
			||||||
  const [updateAvailable, setUpdateAvailable] = useState(false)
 | 
					  const [updateAvailable, setUpdateAvailable] = useState(false)
 | 
				
			||||||
  const [versionInfo, setVersionInfo] = useState<VersionInfo>()
 | 
					  const [versionInfo, setVersionInfo] = useState<VersionInfo>()
 | 
				
			||||||
  const [updateError, setUpdateError] = useState<ErrorType>()
 | 
					  const [updateError, setUpdateError] = useState<ErrorType>()
 | 
				
			||||||
  const [progressInfo, setProgressInfo] = useState<ProgressInfo>()
 | 
					  const [progressInfo, setProgressInfo] = useState<Partial<ProgressInfo>>()
 | 
				
			||||||
  const [modalOpen, setModalOpen] = useState<boolean>(false)
 | 
					  const [modalOpen, setModalOpen] = useState<boolean>(false)
 | 
				
			||||||
  const [modalBtn, setModalBtn] = useState<{
 | 
					  const [modalBtn, setModalBtn] = useState<{
 | 
				
			||||||
    cancelText?: string
 | 
					    cancelText?: string
 | 
				
			||||||
| 
						 | 
					@ -45,7 +45,6 @@ const Update = () => {
 | 
				
			||||||
        ...state,
 | 
					        ...state,
 | 
				
			||||||
        cancelText: 'Cancel',
 | 
					        cancelText: 'Cancel',
 | 
				
			||||||
        okText: 'Update',
 | 
					        okText: 'Update',
 | 
				
			||||||
        onCancel: () => setModalOpen(false),
 | 
					 | 
				
			||||||
        onOk: () => ipcRenderer.invoke('start-download'),
 | 
					        onOk: () => ipcRenderer.invoke('start-download'),
 | 
				
			||||||
      }))
 | 
					      }))
 | 
				
			||||||
      setUpdateAvailable(true)
 | 
					      setUpdateAvailable(true)
 | 
				
			||||||
| 
						 | 
					@ -56,13 +55,11 @@ const Update = () => {
 | 
				
			||||||
  }, [])
 | 
					  }, [])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const onUpdateError = useCallback((_event: Electron.IpcRendererEvent, arg1: ErrorType) => {
 | 
					  const onUpdateError = useCallback((_event: Electron.IpcRendererEvent, arg1: ErrorType) => {
 | 
				
			||||||
    console.error('arg1.error',arg1.error)
 | 
					 | 
				
			||||||
    setUpdateAvailable(false)
 | 
					    setUpdateAvailable(false)
 | 
				
			||||||
    setUpdateError(arg1)
 | 
					    setUpdateError(arg1)
 | 
				
			||||||
  }, [])
 | 
					  }, [])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const onDownloadProgress = useCallback((_event: Electron.IpcRendererEvent, arg1: ProgressInfo) => {
 | 
					  const onDownloadProgress = useCallback((_event: Electron.IpcRendererEvent, arg1: ProgressInfo) => {
 | 
				
			||||||
    console.log(arg1)
 | 
					 | 
				
			||||||
    setUpdateAvailable(true)
 | 
					    setUpdateAvailable(true)
 | 
				
			||||||
    setProgressInfo(arg1)
 | 
					    setProgressInfo(arg1)
 | 
				
			||||||
  }, [])
 | 
					  }, [])
 | 
				
			||||||
| 
						 | 
					@ -105,8 +102,13 @@ const Update = () => {
 | 
				
			||||||
        footer={isUpdate ? /* hide footer */null : undefined}
 | 
					        footer={isUpdate ? /* hide footer */null : undefined}
 | 
				
			||||||
      >
 | 
					      >
 | 
				
			||||||
        <div className={styles.modalslot}>
 | 
					        <div className={styles.modalslot}>
 | 
				
			||||||
          {
 | 
					          {updateError
 | 
				
			||||||
            isUpdate
 | 
					            ? (
 | 
				
			||||||
 | 
					              <div className='update-error'>
 | 
				
			||||||
 | 
					                <p>Error downloading the latest version.</p>
 | 
				
			||||||
 | 
					                <p>{updateError.message}</p>
 | 
				
			||||||
 | 
					              </div>
 | 
				
			||||||
 | 
					            ) : isUpdate
 | 
				
			||||||
              ? (
 | 
					              ? (
 | 
				
			||||||
                <div>
 | 
					                <div>
 | 
				
			||||||
                  <div>The last version is: v{versionInfo.newVersion}</div>
 | 
					                  <div>The last version is: v{versionInfo.newVersion}</div>
 | 
				
			||||||
| 
						 | 
					@ -119,18 +121,7 @@ const Update = () => {
 | 
				
			||||||
                  </div>
 | 
					                  </div>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
              )
 | 
					              )
 | 
				
			||||||
              : updateError
 | 
					              : <div>Checking...</div>}
 | 
				
			||||||
                ? (
 | 
					 | 
				
			||||||
                  <div className='update-error'>
 | 
					 | 
				
			||||||
                    <p>Error downloading the latest version.</p>
 | 
					 | 
				
			||||||
                    <p>{updateError.message}</p>
 | 
					 | 
				
			||||||
                  </div>
 | 
					 | 
				
			||||||
                ) : (
 | 
					 | 
				
			||||||
                  <div>
 | 
					 | 
				
			||||||
                    <div>The last version is: v{versionInfo?.version}</div>
 | 
					 | 
				
			||||||
                  </div>
 | 
					 | 
				
			||||||
                )
 | 
					 | 
				
			||||||
          }
 | 
					 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
      </Modal>
 | 
					      </Modal>
 | 
				
			||||||
      <button disabled={checking} onClick={checkUpdate}>
 | 
					      <button disabled={checking} onClick={checkUpdate}>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue