Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: prompt user to download an update manually #2261

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion electron/handlers/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 3,8 @@ import { WindowManager } from './../managers/window'
import { autoUpdater } from 'electron-updater'
import { AppEvent } from '@janhq/core'

export let waitingToInstallVersion: string | undefined = undefined

export function handleAppUpdates() {
/* Should not check for update during development */
if (!app.isPackaged) {
Expand All @@ -29,6 31,7 @@ export function handleAppUpdates() {
buttons: ['Restart', 'Later'],
})
if (action.response === 0) {
waitingToInstallVersion = _info?.version
autoUpdater.quitAndInstall()
}
})
Expand All @@ -37,7 40,7 @@ export function handleAppUpdates() {
autoUpdater.on('error', (info: any) => {
WindowManager.instance.currentWindow?.webContents.send(
AppEvent.onAppUpdateDownloadError,
info
{ failedToInstallVersion: waitingToInstallVersion, info }
)
})

Expand Down
69 changes: 69 additions & 0 deletions web/containers/Layout/BottomBar/UpdateFailedModal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 1,69 @@
import React from 'react'

import {
Modal,
ModalPortal,
ModalContent,
ModalHeader,
ModalTitle,
ModalFooter,
ModalClose,
Button,
} from '@janhq/uikit'
import { Share2Icon } from '@radix-ui/react-icons'
import { useAtom } from 'jotai'

import { updateVersionError } from '@/containers/Providers/Jotai'

const UpdatedFailedModal = () => {
const [error, setError] = useAtom(updateVersionError)

return (
<Modal open={!!error} onOpenChange={() => setError(undefined)}>
<ModalPortal />
<ModalContent>
<ModalHeader>
<ModalTitle>Unable to Install Update</ModalTitle>
</ModalHeader>
<p className="text-muted-foreground">
An error occurred while installing Jan{' '}
<span className="font-medium text-foreground">{error}</span>. We
appreciate your help with{' '}
<a
href="https://github.com/janhq/jan#download"
target="_blank"
className="font-medium text-foreground"
>
manual downloading and installation.
</a>
</p>
<ModalFooter>
<div className="flex gap-x-2">
<ModalClose asChild onClick={() => setError(undefined)}>
<Button themes="outline">Remind me later</Button>
</ModalClose>
<ModalClose
asChild
onClick={() => {
window.open('https://github.com/janhq/jan#download', '_blank')
setError(undefined)
}}
>
<Button themes="primary" autoFocus>
Download now{' '}
<Share2Icon
width={16}
height={16}
className="ml-2"
color="white"
/>
</Button>
</ModalClose>
</div>
</ModalFooter>
</ModalContent>
</Modal>
)
}

export default UpdatedFailedModal
2 changes: 2 additions & 0 deletions web/containers/Layout/BottomBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 17,7 @@ import { appDownloadProgress } from '@/containers/Providers/Jotai'

import ImportingModelState from './ImportingModelState'
import SystemMonitor from './SystemMonitor'
import UpdatedFailedModal from './UpdateFailedModal'

const menuLinks = [
{
Expand Down Expand Up @@ -44,6 45,7 @@ const BottomBar = () => {
</div>
<ImportingModelState />
<DownloadingState />
<UpdatedFailedModal />
</div>
<div className="flex items-center gap-x-3">
<SystemMonitor />
Expand Down
11 changes: 8 additions & 3 deletions web/containers/Providers/AppUpdateListener.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 3,11 @@

import { useSetAtom } from 'jotai'

import { appDownloadProgress } from './Jotai'
import { appDownloadProgress, updateVersionError } from './Jotai'

const AppUpdateListener = ({ children }: PropsWithChildren) => {
const setProgress = useSetAtom(appDownloadProgress)
const setUpdateVersionError = useSetAtom(updateVersionError)

useEffect(() => {
if (window && window.electronAPI) {
Expand All @@ -18,9 19,13 @@
)

window.electronAPI.onAppUpdateDownloadError(
(_event: string, callback: any) => {
console.error('Download error', callback)
(_event: string, error: any) => {
console.error('Download error: ', error)
setProgress(-1)

// Can not install update
// Prompt user to download the update manually
setUpdateVersionError(error.failedToInstallVersion)
}
)

Expand All @@ -29,7 34,7 @@
})
}
return () => {}
}, [setProgress])

Check warning on line 37 in web/containers/Providers/AppUpdateListener.tsx

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

React Hook useEffect has a missing dependency: 'setUpdateVersionError'. Either include it or remove the dependency array

Check warning on line 37 in web/containers/Providers/AppUpdateListener.tsx

View workflow job for this annotation

GitHub Actions / test-on-macos

React Hook useEffect has a missing dependency: 'setUpdateVersionError'. Either include it or remove the dependency array

Check warning on line 37 in web/containers/Providers/AppUpdateListener.tsx

View workflow job for this annotation

GitHub Actions / test-on-windows (mcafee)

React Hook useEffect has a missing dependency: 'setUpdateVersionError'. Either include it or remove the dependency array

Check warning on line 37 in web/containers/Providers/AppUpdateListener.tsx

View workflow job for this annotation

GitHub Actions / test-on-windows (default-windows-security)

React Hook useEffect has a missing dependency: 'setUpdateVersionError'. Either include it or remove the dependency array

Check warning on line 37 in web/containers/Providers/AppUpdateListener.tsx

View workflow job for this annotation

GitHub Actions / test-on-windows (bit-defender)

React Hook useEffect has a missing dependency: 'setUpdateVersionError'. Either include it or remove the dependency array

return <Fragment>{children}</Fragment>
}
Expand Down
1 change: 1 addition & 0 deletions web/containers/Providers/Jotai.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 12,7 @@ export const editPromptAtom = atom<string>('')
export const currentPromptAtom = atom<string>('')
export const fileUploadAtom = atom<FileInfo[]>([])
export const appDownloadProgress = atom<number>(-1)
export const updateVersionError = atom<string | undefined>(undefined)
export const searchAtom = atom<string>('')

export default function JotaiWrapper({ children }: Props) {
Expand Down
Loading