-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from InfuseAI/feature/sc-23364/crane-new-versi…
…on-released-update-app-notify [Feature] sc-23364 Pop up modal when crane have new released version
- Loading branch information
Showing
5 changed files
with
787 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ import { | |
Switch, | ||
} from 'react-router-dom'; | ||
import './App.less'; | ||
import { Alert, Button, Space, Layout, Skeleton } from 'antd'; | ||
import { Alert, Button, Space, Layout, Skeleton, Modal, Divider } from 'antd'; | ||
import Sidebar from './Sidebar'; | ||
import BuildImage from './BuildImage'; | ||
import ListImage from './ListImage'; | ||
|
@@ -16,6 +16,10 @@ import { send } from './utils/ipcClient'; | |
import CreatePrimeHubImage from './CreatePrimeHubImage'; | ||
import * as Sentry from '@sentry/browser'; | ||
import { Integrations } from '@sentry/tracing'; | ||
import compareVersions from 'compare-versions'; | ||
import ReactMarkdown from 'react-markdown'; | ||
import rehypeRaw from 'rehype-raw'; | ||
import useLocalStorage from './hooks/useLocalStorage'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/6088888', | ||
|
@@ -29,6 +33,14 @@ const OK = 'ok'; | |
|
||
const Crane = () => { | ||
const [missingDocker, setMissingDocker] = useState(false); | ||
const [isNewVersionReleased, setIsNewVersionReleased] = useState(false); | ||
const [releasedData, setReleasedData] = useState({ | ||
name: '', | ||
version: '', | ||
url: '', | ||
changelog: '', | ||
}); | ||
const [skipVersion, setSkipVersion] = useLocalStorage('skip_version', ''); | ||
const siderWidth = { | ||
collapsed: 80, | ||
unCollapsed: 160, | ||
|
@@ -42,6 +54,17 @@ const Crane = () => { | |
if (pong !== OK) { | ||
setMissingDocker(true); | ||
} | ||
const crane = await send('get-crane-version'); | ||
if ( | ||
crane.latest && | ||
compareVersions(crane.latest.version, crane.version) > 0 && | ||
crane.latest.version !== skipVersion | ||
) { | ||
// Show New version released | ||
setIsNewVersionReleased(true); | ||
setReleasedData(crane.latest); | ||
console.log(crane.latest); | ||
} | ||
})(); | ||
}, []); | ||
|
||
|
@@ -76,6 +99,65 @@ const Crane = () => { | |
) : ( | ||
<></> | ||
)} | ||
<Modal | ||
title={`New Version Released: ${releasedData.name}`} | ||
width={'50%'} | ||
mask={true} | ||
className='modal-version-update' | ||
visible={isNewVersionReleased} | ||
onOk={() => { | ||
setIsNewVersionReleased(false); | ||
console.log('OK'); | ||
}} | ||
onCancel={() => { | ||
setIsNewVersionReleased(false); | ||
console.log('Cancel'); | ||
}} | ||
footer={[ | ||
<Button | ||
key='download' | ||
type='primary' | ||
href={releasedData.url} | ||
target='_blank' | ||
onClick={() => { | ||
setIsNewVersionReleased(false); | ||
console.log('Download'); | ||
}} | ||
> | ||
Download on GitHub | ||
</Button>, | ||
<Button | ||
key='skip' | ||
onClick={() => { | ||
setIsNewVersionReleased(false); | ||
setSkipVersion(releasedData.version); | ||
console.log('Skip'); | ||
}} | ||
> | ||
Skip this Version | ||
</Button>, | ||
]} | ||
> | ||
<div className='release-note'> | ||
<ReactMarkdown | ||
children={releasedData.changelog} | ||
rehypePlugins={[rehypeRaw]} | ||
components={{ | ||
img: ({ children, ...props }) => { | ||
console.log(props); | ||
return <img src={props.src} alt={props.alt} width='100%' />; | ||
}, | ||
}} | ||
/> | ||
<div className='read-more'> | ||
</div> | ||
</div> | ||
<Divider> | ||
<a href={releasedData.url} target='_blank' rel='noreferrer'> | ||
Read More | ||
</a> | ||
</Divider> | ||
</Modal> | ||
<Suspense | ||
fallback={ | ||
<div className='site-layout-background'> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import { createMarkdownArrayTableSync } from 'parse-markdown-table'; | |
import AwsAdapter from './AwsAdapter'; | ||
import DockerHubAdapter from './DockerHubAdapter'; | ||
import * as Sentry from '@sentry/electron'; | ||
import tag from 'antd/lib/tag'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/6088888', | ||
|
@@ -145,6 +146,24 @@ export async function getAwsCredential() { | |
return awsCredential; | ||
} | ||
|
||
export async function getCraneLatestVersion() { | ||
const githubApiUrl = | ||
'https://api.github.com/repos/infuseai/crane/releases/latest'; | ||
const response = await axios.get(githubApiUrl); | ||
|
||
const version: string = response.data['tag_name']; | ||
|
||
const release = { | ||
version: version.replace('v', ''), | ||
name: response.data['name'], | ||
url: response.data['html_url'], | ||
changelog: response.data['body'], | ||
// published_at: response.data['published_at'], | ||
}; | ||
|
||
return release; | ||
} | ||
|
||
const handlers = { | ||
build_events: [], | ||
build_status: '', | ||
|
@@ -156,6 +175,16 @@ const handlers = { | |
} | ||
return 'ok'; | ||
}, | ||
'get-crane-version': async () => { | ||
try { | ||
return { | ||
version: config.version, | ||
latest: await getCraneLatestVersion(), | ||
}; | ||
} catch (error) { | ||
return { version: config.version, error: error.message }; | ||
} | ||
}, | ||
'get-dockerhub-credential': async () => { | ||
return await getCredential(dockerHubCredentialKeyName); | ||
}, | ||
|
Oops, something went wrong.