Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: 设置代理切换时不再需要重启 Fix https://github.com/siyuan-note/siyuan/issues/6680

Liang Dingeb3098bfe97d
diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json
index b834c3993b..3a800d9219 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 <code class='fn__code'>Direct connection</code>. The application will be closed automatically after modification, please restart manually",
+ "about17": "Do not enable proxy when set to <code class='fn__code'>Direct connection</code>",
"checkUpdate": "Check update",
"currentVer": "Current version",
"visitAnnouncements": "<a href=\"https://github.com/siyuan-note/siyuan/releases\" target=\"_blank\">View system announcements</a>",
diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json
index d3a3b25308..d4410c2917 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 <code class='fn__code'>Conexión directa</code>. 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 <code class='fn__code'>Conexión directa</code>",
"checkUpdate": "Comprobar actualización",
"currentVer": "Versión actual",
"visitAnnouncements": "<a href=\"https://github.com/siyuan-note/siyuan/releases\" target=\"_blank\">Ver los anuncios del sistema</a>",
diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json
index 65666e91c1..70050d492e 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 <code class='fn__code'>Connexion directe</code>. 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 <code class='fn__code'>Connexion directe</code>.",
"checkUpdate": "Vérifier la mise à jour",
"currentVer": "Version actuelle",
"visitAnnouncements": "<a href=\"https://github.com/siyuan-note/siyuan/releases\" target=\"_blank\">Voir les annonces du système</a>",
diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json
index 6240855a26..76eed1250d 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": "設置為 <code class='fn__code'>直接連接</code> 時不啟用代理。修改後會自動關閉應用,請手動重啟",
+ "about17": "設置為 <code class='fn__code'>直接連接</code> 時不啟用代理",
"checkUpdate": "檢查更新",
"currentVer": "當前版本",
"visitAnnouncements": "<a href=\"https://ld246.com/tag/siyuan-announcement\" target=\"_blank\">瀏覽系統公告</a>",
diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json
index 291868bb76..e157d7ac29 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": "设置为 <code class='fn__code'>直接连接</code> 时不启用代理。修改后会自动关闭应用,请手动重启",
+ "about17": "设置为 <code class='fn__code'>直接连接</code> 时不启用代理",
"checkUpdate": "检查更新",
"currentVer": "当前版本",
"visitAnnouncements": "<a href=\"https://ld246.com/tag/siyuan-announcement\" target=\"_blank\">浏览系统公告</a>",
diff --git a/app/src/config/about.ts b/app/src/config/about.ts
index 7f1371c8b1..557b281fda 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 = {
<span class="fn__space"></span>
<input id="aboutPort" placeholder="Port" class="b3-text-field fn__flex-1 fn__block" value="${window.siyuan.config.system.networkProxy.port}" type="number"/>
<span class="fn__space"></span>
- <button id="aboutConfim" class="b3-button b3-button--outline">${window.siyuan.languages.confirm}</button>
+ <button id="aboutConfirm" class="b3-button b3-button--outline">${window.siyuan.languages.confirm}</button>
</div>
</div>
<div class="b3-label">
@@ -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 037b91e9a0..ba9ae138ee 100644
--- a/app/src/util/onGetConfig.ts
+++ b/app/src/util/onGetConfig.ts
@@ -90,12 +90,18 @@ const hasKeymap = (keymap: Record<string, IKeymapItem>, 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 1c9c59ce93..a6ca40167a 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 412bc0ff63..eb007b607c 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]")
}
}