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

This commit is contained in:
Liang Ding 2022-11-24 11:25:00 +08:00
parent de529c2edd
commit eb3098bfe9
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
9 changed files with 31 additions and 22 deletions

View file

@ -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>",

View file

@ -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>",

View file

@ -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>",

View file

@ -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>",

View file

@ -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>",

View file

@ -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()
});
});
}

View file

@ -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
};

View file

@ -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) {

View file

@ -84,6 +84,8 @@ func SetNetworkProxy(proxyURL string) {
if "" != proxyURL {
logging.LogInfof("use network proxy [%s]", proxyURL)
} else {
logging.LogInfof("use network proxy [system]")
}
}