From eb3098bfe97d89db2fbbcb52f72716f9b6b9c538 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 24 Nov 2022 11:25:00 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E8=AE=BE=E7=BD=AE=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E6=97=B6=E4=B8=8D=E5=86=8D=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E9=87=8D=E5=90=AF=20Fix=20https://github.com/siyuan-note/siyua?= =?UTF-8?q?n/issues/6680?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/appearance/langs/en_US.json | 2 +- app/appearance/langs/es_ES.json | 2 +- app/appearance/langs/fr_FR.json | 2 +- app/appearance/langs/zh_CHT.json | 2 +- app/appearance/langs/zh_CN.json | 2 +- app/src/config/about.ts | 21 +++++++++++---------- app/src/util/onGetConfig.ts | 16 +++++++++++----- kernel/api/system.go | 4 ++-- kernel/util/runtime.go | 2 ++ 9 files changed, 31 insertions(+), 22 deletions(-) diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json index b834c3993..3a800d921 100644 --- a/app/appearance/langs/en_US.json +++ b/app/appearance/langs/en_US.json @@ -723,7 +723,7 @@ "about12": "After enabling, other devices in the same LAN will be allowed to access. The application will be closed automatically after modification, please restart manually", "about13": "API token", "about14": "The token needs to be authenticated when calling the API", - "about17": "Do not enable proxy when set to Direct connection. The application will be closed automatically after modification, please restart manually", + "about17": "Do not enable proxy when set to Direct connection", "checkUpdate": "Check update", "currentVer": "Current version", "visitAnnouncements": "View system announcements", diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json index d3a3b2530..d4410c291 100644 --- a/app/appearance/langs/es_ES.json +++ b/app/appearance/langs/es_ES.json @@ -723,7 +723,7 @@ "about12": "Después de habilitarla, se permitirá el acceso a otros dispositivos de la misma LAN. La aplicación se cerrará automáticamente después de la modificación, por favor reinicie manualmente", "about13": "Token API", "about14": "El token debe ser autentificado al llamar a la API", - "about17": "No habilite el proxy cuando esté configurado como Conexión directa. La aplicación se cerrará automáticamente después de la modificación, por favor reinicie manualmente", + "about17": "No habilite el proxy cuando esté configurado como Conexión directa", "checkUpdate": "Comprobar actualización", "currentVer": "Versión actual", "visitAnnouncements": "Ver los anuncios del sistema", diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json index 65666e91c..70050d492 100644 --- a/app/appearance/langs/fr_FR.json +++ b/app/appearance/langs/fr_FR.json @@ -723,7 +723,7 @@ "about12": "Après l'activation, les autres appareils du même réseau local seront autorisés à accéder. L'application sera fermée automatiquement après modification, veuillez la redémarrer manuellement.", "about13": "API token", "about14": "Le token doit être authentifié lors de l'appel de l'API.", - "about17": "N'activez pas le proxy lorsqu'il est défini sur Connexion directe. L'application se fermera automatiquement après modification, merci de redémarrer manuellement", + "about17": "N'activez pas le proxy lorsqu'il est défini sur Connexion directe.", "checkUpdate": "Vérifier la mise à jour", "currentVer": "Version actuelle", "visitAnnouncements": "Voir les annonces du système", diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json index 6240855a2..76eed1250 100644 --- a/app/appearance/langs/zh_CHT.json +++ b/app/appearance/langs/zh_CHT.json @@ -723,7 +723,7 @@ "about12": "啟用後將允許同一區域網內的其他設備進行存取。修改後會自動關閉應用,請手動重啟", "about13": "API token", "about14": "調用 API 時需要通過該 token 進行鑒權", - "about17": "設置為 直接連接 時不啟用代理。修改後會自動關閉應用,請手動重啟", + "about17": "設置為 直接連接 時不啟用代理", "checkUpdate": "檢查更新", "currentVer": "當前版本", "visitAnnouncements": "瀏覽系統公告", diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json index 291868bb7..e157d7ac2 100644 --- a/app/appearance/langs/zh_CN.json +++ b/app/appearance/langs/zh_CN.json @@ -723,7 +723,7 @@ "about12": "启用后将允许同一局域网内的其他设备进行访问。修改后会自动关闭应用,请手动重启", "about13": "API token", "about14": "调用 API 时需要通过该 token 进行鉴权", - "about17": "设置为 直接连接 时不启用代理。修改后会自动关闭应用,请手动重启", + "about17": "设置为 直接连接 时不启用代理", "checkUpdate": "检查更新", "currentVer": "当前版本", "visitAnnouncements": "浏览系统公告", diff --git a/app/src/config/about.ts b/app/src/config/about.ts index 7f1371c8b..557b281fd 100644 --- a/app/src/config/about.ts +++ b/app/src/config/about.ts @@ -12,6 +12,7 @@ import {openByMobile, writeText} from "../protyle/util/compatibility"; import {showMessage} from "../dialog/message"; import {Dialog} from "../dialog"; import {confirmDialog} from "../dialog/confirmDialog"; +import {setProxy} from "../util/onGetConfig"; export const about = { element: undefined as Element, @@ -170,7 +171,7 @@ export const about = { - +
@@ -388,15 +389,15 @@ export const about = { window.siyuan.config.system.downloadInstallPkg = downloadInstallPkgElement.checked; }); }); - about.element.querySelector("#aboutConfim").addEventListener("click", () => { - fetchPost("/api/system/setNetworkProxy", { - scheme: (about.element.querySelector("#aboutScheme") as HTMLInputElement).value, - host: (about.element.querySelector("#aboutHost") as HTMLInputElement).value, - port: (about.element.querySelector("#aboutPort") as HTMLInputElement).value - }, () => { - exportLayout(false, () => { - exitSiYuan(); - }); + about.element.querySelector("#aboutConfirm").addEventListener("click", () => { + const scheme = (about.element.querySelector("#aboutScheme") as HTMLInputElement).value; + const host = (about.element.querySelector("#aboutHost") as HTMLInputElement).value + const port = (about.element.querySelector("#aboutPort") as HTMLInputElement).value; + fetchPost("/api/system/setNetworkProxy", {scheme, host, port}, () => { + window.siyuan.config.system.networkProxy.scheme = scheme + window.siyuan.config.system.networkProxy.host = host + window.siyuan.config.system.networkProxy.port = port + setProxy() }); }); } diff --git a/app/src/util/onGetConfig.ts b/app/src/util/onGetConfig.ts index 037b91e9a..ba9ae138e 100644 --- a/app/src/util/onGetConfig.ts +++ b/app/src/util/onGetConfig.ts @@ -90,12 +90,18 @@ const hasKeymap = (keymap: Record, key1: "general" | "edito export const setProxy = () => { /// #if !BROWSER - const session = getCurrentWindow().webContents.session; - if (window.siyuan.config.system.networkProxy.scheme) { - session.closeAllConnections().then(() => { - session.setProxy({proxyRules: `${window.siyuan.config.system.networkProxy.scheme}://${window.siyuan.config.system.networkProxy.host}:${window.siyuan.config.system.networkProxy.port}`}).then(); - }); + if ("" === window.siyuan.config.system.networkProxy.scheme) { + console.log("network proxy [system]"); + return } + + const session = getCurrentWindow().webContents.session; + session.closeAllConnections().then(() => { + const proxyURL = `${window.siyuan.config.system.networkProxy.scheme}://${window.siyuan.config.system.networkProxy.host}:${window.siyuan.config.system.networkProxy.port}` + session.setProxy({proxyRules: proxyURL}).then( + () => console.log("network proxy [" + proxyURL + "]"), + ); + }); /// #endif }; diff --git a/kernel/api/system.go b/kernel/api/system.go index 1c9c59ce9..a6ca40167 100644 --- a/kernel/api/system.go +++ b/kernel/api/system.go @@ -366,8 +366,8 @@ func setNetworkProxy(c *gin.Context) { } model.Conf.Save() - util.PushMsg(model.Conf.Language(42), 1000*15) - time.Sleep(time.Second * 3) + proxyURL := model.Conf.System.NetworkProxy.String() + util.SetNetworkProxy(proxyURL) } func addUIProcess(c *gin.Context) { diff --git a/kernel/util/runtime.go b/kernel/util/runtime.go index 412bc0ff6..eb007b607 100644 --- a/kernel/util/runtime.go +++ b/kernel/util/runtime.go @@ -84,6 +84,8 @@ func SetNetworkProxy(proxyURL string) { if "" != proxyURL { logging.LogInfof("use network proxy [%s]", proxyURL) + } else { + logging.LogInfof("use network proxy [system]") } }