Skip to content

Commit

Permalink
feat: install go+ env check
Browse files Browse the repository at this point in the history
Signed-off-by: uiuing <uiuing@foxmail.com>
  • Loading branch information
uiuing committed Aug 29, 2022
1 parent 10784d7 commit 891613f
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 44 deletions.
5 changes: 4 additions & 1 deletion ingop/main/ipc/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ export async function existsAllEnv(
if (i) {
r.gop.exist = i
i = await existsEnv.gop.isNew(p.gopNewVersion)
if (i) r.gop.isNew = true
if (i) {
r.gop.isIngop = await existsEnv.env.go.isIngop()
r.gop.isNew = true
}
}
}
}
Expand Down
72 changes: 41 additions & 31 deletions ingop/renderer/hooks/useInstallGo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,61 @@ import { useRecoilValue, useSetRecoilState } from 'recoil'
import { autoSaveFile, envManage } from '../apis/ipc'
import { FileDataParams } from '../apis/ipc/types'
import { getReleases, getRemoteFile } from '../apis/releases'
import { ExistsAllEnvStore, IsNetErrorStore } from '../store'
import { ExistsAllEnvStore, GopReleasesStore, IsNetErrorStore } from '../store'
import { useControlRouter } from '../utils/router'

type RunState = 'download' | 'compile' | 'success'

export default function useInstallGo() {
const setIsNetError = useSetRecoilState(IsNetErrorStore)
const gopReleases = useRecoilValue(GopReleasesStore)
const { toErrorNetwork } = useControlRouter()
const existsAllEnv = useRecoilValue(ExistsAllEnvStore)
const [percent, setPercent] = useState(0)
const [runState, setRunState] = useState<RunState>('download')
useEffect(() => {
getReleases.env.go((errorInfo, releasesData) => {
if (errorInfo === null && releasesData === null) {
setIsNetError(errorInfo)
toErrorNetwork()
} else {
getRemoteFile(
releasesData?.[existsAllEnv.system.platform][
existsAllEnv.system.arch
],
(isError, errorInfo, downloadOk, progress, base64Data, fileName) => {
setPercent(progress)
if (isError) {
setIsNetError(errorInfo)
toErrorNetwork()
} else if (downloadOk) {
setTimeout(() => {
setRunState('compile')
autoSaveFile.env
.go({ fileName, base64Data } as FileDataParams)
.then(() => {
envManage.env.initGo()
setTimeout(() => {
if (gopReleases === null) {
toErrorNetwork()
} else {
getReleases.env.go((errorInfo, releasesData) => {
if (errorInfo === null && releasesData === null) {
setIsNetError(errorInfo)
toErrorNetwork()
} else {
getRemoteFile(
releasesData?.[existsAllEnv.system.platform][
existsAllEnv.system.arch
],
(
isError,
errorInfo,
downloadOk,
progress,
base64Data,
fileName
) => {
setPercent(progress)
if (isError) {
setIsNetError(errorInfo)
toErrorNetwork()
} else if (downloadOk) {
setTimeout(() => {
setRunState('compile')
autoSaveFile.env
.go({ fileName, base64Data } as FileDataParams)
.then(() => {
envManage.env.initGo()
setTimeout(() => {
setRunState('success')
}, 500)
}, 500)
})
}, 500)
}, 300)
})
}, 300)
}
}
}
)
}
})
)
}
})
}
}, [])
return { percent, runState }
}
52 changes: 52 additions & 0 deletions ingop/renderer/hooks/useInstallGop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* eslint-disable react-hooks/exhaustive-deps */

import { useEffect, useState } from 'react'
import { useRecoilValue, useSetRecoilState } from 'recoil'

import { autoSaveFile, compile, envManage } from '../apis/ipc'
import { FileDataParams } from '../apis/ipc/types'
import { getReleases, getRemoteFile } from '../apis/releases'
import { ExistsAllEnvStore, GopReleasesStore, IsNetErrorStore } from '../store'
import { useControlRouter } from '../utils/router'

type RunState = 'download' | 'compile' | 'success'

export default function useInstallGop() {
const setIsNetError = useSetRecoilState(IsNetErrorStore)
const gopReleases = useRecoilValue(GopReleasesStore)
const { toErrorNetwork } = useControlRouter()
const existsAllEnv = useRecoilValue(ExistsAllEnvStore)
const [percent, setPercent] = useState(0)
const [runState, setRunState] = useState<RunState>('download')
useEffect(() => {
if (gopReleases === null) {
toErrorNetwork()
} else {
getRemoteFile(
gopReleases.tarball_url,
(isError, errorInfo, downloadOk, progress, base64Data, fileName) => {
setPercent(progress)
if (isError) {
setIsNetError(errorInfo)
toErrorNetwork()
} else if (downloadOk) {
setTimeout(() => {
setRunState('compile')
autoSaveFile
.gop({ fileName, base64Data } as FileDataParams)
.then(() => {
compile.gop().then(() => {
envManage.initGop()
setTimeout(() => {
setRunState('success')
}, 2000)
})
})
}, 2000)
}
}
)
}
}, [])
return { percent, runState }
}
9 changes: 6 additions & 3 deletions ingop/renderer/locales/data/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
"desc": "Go+ programming language For engineering, STEM education, and data science",
"button": "Start Installation",
"download": {
"go": "Downloading packets now, re: Golang ..."
"go": "Downloading packets now, re: Golang ...",
"gop": "Downloading packets now, re: Go+ ..."
},
"compile": {
"title": "In execution ...",
"go": "Golang being compiled and configured ..."
"go": "Golang being compiled and configured ...",
"gop": "Go+ being compiled and configured ..."
},
"success": {
"go": "Golang has been installed successfully !"
"go": "Environment required for Go+ has been installed successfully !",
"gop": "Go+ has been installed successfully !"
}
},
"error": {
Expand Down
9 changes: 6 additions & 3 deletions ingop/renderer/locales/data/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
"desc": "Go+ 编程语言用于工程、STEM教育和数据科学",
"button": "开始安装",
"download": {
"go": "正在下载数据包,关于:GoLang ..."
"go": "正在下载数据包,关于:GoLang ...",
"gop": "正在下载数据包,关于:Go+ ..."
},
"compile": {
"title": "正在执行 ...",
"go": "正在编译并配置 Golang ..."
"go": "正在编译并配置 Golang ...",
"gop": "正在编译并配置 Go+ ..."
},
"success": {
"go": "Golang 已成功安装 !"
"go": "Go+ 所需环境已成功安装 !",
"gop": "Go+ 已成功安装 !"
}
},
"error": {
Expand Down
1 change: 0 additions & 1 deletion ingop/renderer/pages/error/network.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
IllustrationNoResultDark
} from '@douyinfe/semi-illustrations'
import { Button, Empty, Typography } from '@douyinfe/semi-ui'
import { changeLanguage } from 'i18next'
import { useTranslation } from 'react-i18next'
import { useRecoilValue } from 'recoil'

Expand Down
2 changes: 1 addition & 1 deletion ingop/renderer/pages/install/go.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function Go() {
return <EffectBinary title={t('install.compile.title')} />
}
if (runState === 'success') {
setTimeout(() => toInstallGop(), 1300)
setTimeout(() => toInstallGop(), 2000)
return <EffectLogo />
}
}
Expand Down
60 changes: 57 additions & 3 deletions ingop/renderer/pages/install/gop.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,61 @@
/* eslint-disable react-hooks/rules-of-hooks */

import { Typography } from '@douyinfe/semi-ui'
import { useTranslation } from 'react-i18next'
import { useRecoilValue } from 'recoil'

import EffectBinary from '../../components/Effect/Binary'
import EffectLogo from '../../components/Effect/Logo'
import StateDownload from '../../components/State/Download'
import useInstallGop from '../../hooks/useInstallGop'
import { ExistsAllEnvStore } from '../../store'
import { useControlRouter } from '../../utils/router'

export default function Gop() {
const existsAllEnv = useRecoilValue(ExistsAllEnvStore)
const { toManage, toErrorVersion, toTipsReboot, toTipsIngopGo } =
useControlRouter()
if (!existsAllEnv.env.go.isNew) {
toErrorVersion()
return <></>
}
if (!existsAllEnv.env.go.isIngop) {
if (typeof global !== 'undefined') {
const s = global.sessionStorage.getItem('ingop-tips-isIngop-go')
if (s !== 'true') {
toTipsIngopGo()
global.sessionStorage.setItem('ingop-tips-isIngop-go', 'true')
}
}
return <></>
}
const { percent, runState } = useInstallGop()
const { Title } = Typography
const { t } = useTranslation()
function activeLoadEffect() {
if (runState === 'download') {
return <StateDownload percent={percent} />
}
if (runState === 'compile') {
return <EffectBinary title={t('install.compile.title')} />
}
if (runState === 'success') {
setTimeout(() => {
if (existsAllEnv.system.platform === 'win32') {
toTipsReboot()
} else {
toManage()
}
}, 2000)
return <EffectLogo />
}
}
return (
<div>
<h1>Gop</h1>
</div>
<>
<Title heading={3} style={{ margin: '10% 0 10% 0' }}>
{t(`install.${runState}.gop`)}
</Title>
{activeLoadEffect()}
</>
)
}
20 changes: 19 additions & 1 deletion ingop/renderer/utils/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,23 @@ export const useControlRouter = () => {
router.push('/error/network')
setRouterModule('errorNet')
}
return { toInstall, toInstallGo, toInstallGop, toManage, toErrorNetwork }
const toErrorVersion = () => {
router.push('/error/version')
}
const toTipsReboot = () => {
router.push('/tips/reboot')
}
const toTipsIngopGo = () => {
router.push('/tips/ingop-go')
}
return {
toInstall,
toInstallGo,
toInstallGop,
toManage,
toErrorNetwork,
toErrorVersion,
toTipsReboot,
toTipsIngopGo
}
}

0 comments on commit 891613f

Please sign in to comment.