From 825cbd15f8b6640311f6c8341dc687afc311b7a1 Mon Sep 17 00:00:00 2001 From: josc146 Date: Sun, 21 May 2023 10:49:45 +0800 Subject: [PATCH] add cnMirror --- backend-golang/rwkv.go | 14 +++++++++++--- frontend/src/_locales/zh-hans/main.json | 3 ++- frontend/src/components/RunButton.tsx | 2 +- frontend/src/pages/Settings.tsx | 12 ++++++++++++ frontend/src/stores/commonStore.ts | 3 ++- frontend/wailsjs/go/backend_golang/App.d.ts | 2 +- frontend/wailsjs/go/backend_golang/App.js | 4 ++-- 7 files changed, 31 insertions(+), 9 deletions(-) diff --git a/backend-golang/rwkv.go b/backend-golang/rwkv.go index ddc020e..756499c 100644 --- a/backend-golang/rwkv.go +++ b/backend-golang/rwkv.go @@ -34,12 +34,16 @@ func (a *App) DepCheck() error { return nil } -func (a *App) InstallPyDep() (string, error) { +func (a *App) InstallPyDep(cnMirror bool) (string, error) { python, err := GetPython() if err != nil { return "", err } - _, err = Cmd(python, "./backend-python/get-pip.py") + if cnMirror { + _, err = Cmd(python, "./backend-python/get-pip.py", "-i", "https://pypi.tuna.tsinghua.edu.cn/simple") + } else { + _, err = Cmd(python, "./backend-python/get-pip.py") + } if err != nil { return "", err } @@ -48,5 +52,9 @@ func (a *App) InstallPyDep() (string, error) { if err != nil { return "", err } - return Cmd(python, "-m", "pip", "install", "-r", "./backend-python/requirements_versions.txt") + if cnMirror { + return Cmd(python, "-m", "pip", "install", "-r", "./backend-python/requirements_versions.txt", "-i", "https://pypi.tuna.tsinghua.edu.cn/simple") + } else { + return Cmd(python, "-m", "pip", "install", "-r", "./backend-python/requirements_versions.txt") + } } diff --git a/frontend/src/_locales/zh-hans/main.json b/frontend/src/_locales/zh-hans/main.json index 1ad989f..04c75f8 100644 --- a/frontend/src/_locales/zh-hans/main.json +++ b/frontend/src/_locales/zh-hans/main.json @@ -94,5 +94,6 @@ "Python target not found, would you like to download it?": "没有找到目标Python, 是否下载?", "Python dependencies are incomplete, would you like to install them?": "Python依赖缺失, 是否安装?", "Install": "安装", - "This is the latest version": "已是最新版" + "This is the latest version": "已是最新版", + "Use Tsinghua Pip Mirrors": "使用清华大学Pip镜像源" } \ No newline at end of file diff --git a/frontend/src/components/RunButton.tsx b/frontend/src/components/RunButton.tsx index d8e6a70..88ebd75 100644 --- a/frontend/src/components/RunButton.tsx +++ b/frontend/src/components/RunButton.tsx @@ -52,7 +52,7 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean }); } else if (depErrorMsg.includes('DepCheck Error')) { toastWithButton(t('Python dependencies are incomplete, would you like to install them?'), t('Install'), () => { - InstallPyDep(); + InstallPyDep(commonStore.settings.cnMirror); }); } else { toast(depErrorMsg, {type: 'error'}); diff --git a/frontend/src/pages/Settings.tsx b/frontend/src/pages/Settings.tsx index 70a4c8a..17d8bba 100644 --- a/frontend/src/pages/Settings.tsx +++ b/frontend/src/pages/Settings.tsx @@ -18,6 +18,7 @@ export type SettingsType = { language: Language, darkMode: boolean autoUpdatesCheck: boolean + cnMirror: boolean } export const Settings: FC = observer(() => { @@ -63,6 +64,17 @@ export const Settings: FC = observer(() => { checkUpdate(true); }}/> }/> + { + commonStore.settings.language === 'zh' && + { + commonStore.setSettings({ + cnMirror: data.checked + }); + }}/> + }/> + } }/> ); diff --git a/frontend/src/stores/commonStore.ts b/frontend/src/stores/commonStore.ts index b97403a..b0eff2d 100644 --- a/frontend/src/stores/commonStore.ts +++ b/frontend/src/stores/commonStore.ts @@ -48,7 +48,8 @@ class CommonStore { settings: SettingsType = { language: getUserLanguage(), darkMode: !isSystemLightMode(), - autoUpdatesCheck: true + autoUpdatesCheck: true, + cnMirror: getUserLanguage() === 'zh' }; // about diff --git a/frontend/wailsjs/go/backend_golang/App.d.ts b/frontend/wailsjs/go/backend_golang/App.d.ts index 63a99ea..9cf3c8c 100644 --- a/frontend/wailsjs/go/backend_golang/App.d.ts +++ b/frontend/wailsjs/go/backend_golang/App.d.ts @@ -18,7 +18,7 @@ export function FileExists(arg1:string):Promise; export function GetPlatform():Promise; -export function InstallPyDep():Promise; +export function InstallPyDep(arg1:boolean):Promise; export function ListDirFiles(arg1:string):Promise>; diff --git a/frontend/wailsjs/go/backend_golang/App.js b/frontend/wailsjs/go/backend_golang/App.js index 93cac10..68518cd 100644 --- a/frontend/wailsjs/go/backend_golang/App.js +++ b/frontend/wailsjs/go/backend_golang/App.js @@ -34,8 +34,8 @@ export function GetPlatform() { return window['go']['backend_golang']['App']['GetPlatform'](); } -export function InstallPyDep() { - return window['go']['backend_golang']['App']['InstallPyDep'](); +export function InstallPyDep(arg1) { + return window['go']['backend_golang']['App']['InstallPyDep'](arg1); } export function ListDirFiles(arg1) {