Skip to content

Commit

Permalink
feat: install go+
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 62902ab commit eeb1404
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 61 deletions.
10 changes: 8 additions & 2 deletions ingop/main/methods/check/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ async function isNewVersion(cmd: string, newVersion: string): AsyncBoolean {
export const existsEnv: ExistsEnv = {
gop: {
exist: async () => {
return (await checkVersionEnv('gop')) !== ''
const i = (await checkVersionEnv('gop')) !== ''
return i
? i
: (await checkVersionEnv(join(ingopPaths.gop_bin, 'gop'))) !== ''
},
isNew: async (newVersion: string) => {
return await isNewVersion('gop', newVersion)
Expand All @@ -55,7 +58,10 @@ export const existsEnv: ExistsEnv = {
env: {
go: {
exist: async () => {
return (await checkVersionEnv('go')) !== ''
const i = (await checkVersionEnv('go')) !== ''
return i
? i
: (await checkVersionEnv(join(ingopPaths.go_bin, 'go'))) !== ''
},
isNew: async (newVersion: string) => {
return await isNewVersion('go', newVersion)
Expand Down
28 changes: 28 additions & 0 deletions ingop/renderer/hooks/useIngopGo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useEffect, useState } from 'react'
import { useRecoilValue } from 'recoil'

import { ExistsAllEnvStore } from '../store'
import { useControlRouter } from '../utils/router'

export default function useIngopGo() {
const existsAllEnv = useRecoilValue(ExistsAllEnvStore)
const { toErrorVersion, toTipsIngopGo } = useControlRouter()
const [isLoad, setIsLoad] = useState(false)
useEffect(() => {
if (!existsAllEnv.env.go.isNew) {
toErrorVersion()
}
if (!existsAllEnv.env.go.isIngop) {
const s = global.sessionStorage.getItem('ingop-tips-isIngop-go')
if (s !== 'true') {
toTipsIngopGo()
global.sessionStorage.setItem('ingop-tips-isIngop-go', 'true')
} else {
setIsLoad(true)
}
} else {
setIsLoad(true)
}
}, [])
return { isLoad }
}
1 change: 1 addition & 0 deletions ingop/renderer/hooks/useInitConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default function useInitConfig(): InitConfigResult {
gopNewVersion,
env: { goNewVersion: '1.16' }
})
console.log(e)
setExistsAllEnvStore(e)
if (!e.env.go.exist || !e.gop.exist) {
await toInstall()
Expand Down
21 changes: 13 additions & 8 deletions ingop/renderer/hooks/useInstallGop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,30 @@ 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 { getRemoteFile } from '../apis/releases'
import { GopReleasesStore, IsNetErrorStore } from '../store'
import { useControlRouter } from '../utils/router'

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

export default function useInstallGop() {
export default function useInstallGop(isLoad: boolean) {
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 (!isLoad) return
if (gopReleases === null) {
toErrorNetwork()
} else {
setTimeout(() => {
run(gopReleases.tarball_url)
}, 1200)
}
function run(tarball_url: string) {
getRemoteFile(
gopReleases.tarball_url,
tarball_url,
(isError, errorInfo, downloadOk, progress, base64Data, fileName) => {
setPercent(progress)
if (isError) {
Expand All @@ -39,14 +44,14 @@ export default function useInstallGop() {
envManage.initGop()
setTimeout(() => {
setRunState('success')
}, 2000)
}, 3500)
})
})
}, 2000)
}, 1500)
}
}
)
}
}, [])
}, [isLoad])
return { percent, runState }
}
12 changes: 11 additions & 1 deletion ingop/renderer/locales/data/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"installGo": "Installing the required environment ...",
"installGop": "Installing Go+ ...",
"manage": "Environment Management",
"errorNet": "Network Anomalies"
"errorNet": "Network Anomalies",
"errorVersion": "Golang version too low",
"tipsReboot": "Make the installation effective",
"tipsIngopGo": "Recommended environment for InGop installations"
},
"install": {
"title": "Welcome to the Go+ installation with InGop",
Expand All @@ -29,5 +32,12 @@
"network": "Network error, please check your network connection and try again.",
"version": "Golang version must be greater than or equal to 1.16, Please uninstall your Golang yourself and click Retry afterwards, InGop will automatically install the appropriate environment for you.",
"again": "Try again"
},
"tips": {
"ingop": {
"go": "Detecting that your Golang is not installed on InGop, it is recommended that you uninstall Golang yourself and click Retry, leaving all environments for InGop to install (not required).",
"try": "Uninstalled, try again",
"cancel": "No problem, install Go+"
}
}
}
12 changes: 11 additions & 1 deletion ingop/renderer/locales/data/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"installGo": "正在安装所需的环境 ...",
"installGop": "正在安装 Go+ ...",
"manage": "环境管理",
"errorNet": "网络异常"
"errorNet": "网络异常",
"errorVersion": "Golang 版本过低",
"tipsReboot": "使安装生效",
"tipsIngopGo": "建议使用 InGop 来安装环境"
},
"install": {
"title": "欢迎使用 InGop 来安装 Go+",
Expand All @@ -28,5 +31,12 @@
"network": "网络错误,请检查您的网络连接并重试。",
"version": "Golang 版本必须大于或等于 1.16,请自行卸载你的 Golang,之后点击重试,InGop 会自动为你安装合适的环境。",
"again": "重试"
},
"tips": {
"ingop": {
"go": "检测到你的 Golang 没有安装在 InGop 上,建议您自行卸载 Golang,然后点击重试,留下所有环境让 InGop 安装(不是必须的)。",
"try": "已卸载,重试",
"cancel": "没关系,继续安装 Go+"
}
}
}
2 changes: 1 addition & 1 deletion ingop/renderer/pages/error/network.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useTranslation } from 'react-i18next'
import { useRecoilValue } from 'recoil'

import { IsNetErrorStore } from '../../store'
import styles from './style.module.scss'
import styles from '../../utils/content.module.scss'

export default function Network() {
const { t } = useTranslation()
Expand Down
17 changes: 2 additions & 15 deletions ingop/renderer/pages/error/version.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import {
IllustrationNoAccess,
IllustrationNoAccessDark
} from '@douyinfe/semi-illustrations'
import { Button, Empty, Typography } from '@douyinfe/semi-ui'
import { Button, Empty } from '@douyinfe/semi-ui'
import { useTranslation } from 'react-i18next'
import { useRecoilValue } from 'recoil'

import { IsNetErrorStore } from '../../store'
import styles from './style.module.scss'
import styles from '../../utils/content.module.scss'

export default function Version() {
const { t } = useTranslation()
Expand All @@ -27,7 +25,6 @@ export default function Version() {
}
description={t('error.version')}
/>
<div style={{ marginTop: '2vh' }}>{ErrorTips()}</div>
</div>
<Button theme="light" type="primary" onClick={again}>
{t('error.again')}
Expand All @@ -36,13 +33,3 @@ export default function Version() {
</>
)
}

function ErrorTips() {
const { Text } = Typography
const isNetError = useRecoilValue(IsNetErrorStore)
return isNetError !== null ? (
<Text type="tertiary">url - {isNetError.config.url}</Text>
) : (
<></>
)
}
12 changes: 11 additions & 1 deletion ingop/renderer/pages/install/go.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { Typography } from '@douyinfe/semi-ui'
import { useTranslation } from 'react-i18next'
import { useSetRecoilState } from 'recoil'

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

export default function Go() {
const setExistsAllEnvStore = useSetRecoilState(ExistsAllEnvStore)
const { percent, runState } = useInstallGo()
const { toInstallGop } = useControlRouter()
const { t } = useTranslation()
Expand All @@ -20,13 +24,19 @@ export default function Go() {
return <EffectBinary title={t('install.compile.title')} />
}
if (runState === 'success') {
existsAllEnv({
gopNewVersion: '0.0.0',
env: { goNewVersion: '1.16' }
}).then((e) => {
setExistsAllEnvStore(e)
})
setTimeout(() => toInstallGop(), 2000)
return <EffectLogo />
}
}
return (
<>
<Title heading={3} style={{ margin: '10% 0 10% 0' }}>
<Title heading={3} style={{ margin: '10% 0 4% 0' }}>
{t(`install.${runState}.go`)}
</Title>
{activeLoadEffect()}
Expand Down
24 changes: 6 additions & 18 deletions ingop/renderer/pages/install/gop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,16 @@ import { useRecoilValue } from 'recoil'
import EffectBinary from '../../components/Effect/Binary'
import EffectLogo from '../../components/Effect/Logo'
import StateDownload from '../../components/State/Download'
import useIngopGo from '../../hooks/useIngopGo'
import useInstallGop from '../../hooks/useInstallGop'
import { ExistsAllEnvStore } from '../../store'
import { useControlRouter } from '../../utils/router'

export default function Gop() {
const { isLoad } = useIngopGo()
const { percent, runState } = useInstallGop(isLoad)
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 { toManage, toTipsReboot } = useControlRouter()
const { Title } = Typography
const { t } = useTranslation()
function activeLoadEffect() {
Expand All @@ -39,6 +26,7 @@ export default function Gop() {
if (runState === 'compile') {
return <EffectBinary title={t('install.compile.title')} />
}
// TODO to manage
if (runState === 'success') {
setTimeout(() => {
if (existsAllEnv.system.platform === 'win32') {
Expand All @@ -52,7 +40,7 @@ export default function Gop() {
}
return (
<>
<Title heading={3} style={{ margin: '10% 0 10% 0' }}>
<Title heading={3} style={{ margin: '10% 0 4% 0' }}>
{t(`install.${runState}.gop`)}
</Title>
{activeLoadEffect()}
Expand Down
56 changes: 56 additions & 0 deletions ingop/renderer/pages/tips/ingop-go/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {
IllustrationNoAccess,
IllustrationNoAccessDark
} from '@douyinfe/semi-illustrations'
import { Button, Empty } from '@douyinfe/semi-ui'
import { useTranslation } from 'react-i18next'

import styles from '../../../utils/content.module.scss'
import { useControlRouter } from '../../../utils/router'

export default function Version() {
const { t } = useTranslation()
const { toInstallGop } = useControlRouter()
function again() {
if (typeof global !== 'undefined') {
global.sessionStorage.removeItem('ingop-tips-isIngop-go')
global.location.reload()
}
}
function install() {
toInstallGop()
}
return (
<>
<div className={styles.wrapper}>
<div className={styles.empty}>
<Empty
image={<IllustrationNoAccess style={{ width: '50vw' }} />}
darkModeImage={
<IllustrationNoAccessDark style={{ width: '50vw' }} />
}
description={t('tips.ingop.go')}
/>
</div>
<div>
<Button
theme="light"
type="primary"
style={{ marginRight: '1vw' }}
onClick={again}
>
{t('tips.ingop.try')}
</Button>
<Button
theme="light"
type="tertiary"
style={{ marginLeft: '1vw' }}
onClick={install}
>
{t('tips.ingop.cancel')}
</Button>
</div>
</div>
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
flex-direction: column;
align-items: center;
justify-content: space-evenly;
padding: 0 5vw;

.empty {
display: flex;
Expand Down
Loading

0 comments on commit eeb1404

Please sign in to comment.