mirror of
https://github.com/W1NDes/M-AzurLaneAutoScript.git
synced 2026-05-14 04:08:09 +08:00
Fix(webapp): 修复electron http url和证书问题
- 修复electron对于http的固定url问题 - 增加对于证书的容忍性(介于本地客户端的情况)
This commit is contained in:
parent
c57dfb675a
commit
6d091aeb4d
@ -9,9 +9,12 @@ const file = fs.readFileSync(path.join(alasPath, './config/deploy.yaml'), 'utf8'
|
||||
const config = yaml.parse(file);
|
||||
const PythonExecutable = config.Deploy.Python.PythonExecutable;
|
||||
const WebuiPort = config.Deploy.Webui.WebuiPort.toString();
|
||||
const WebuiSSLKey = config.Deploy.Webui.WebuiSSLKey;
|
||||
const WebuiSSLCert = config.Deploy.Webui.WebuiSSLCert;
|
||||
const sslEnabled = WebuiSSLKey && WebuiSSLCert;
|
||||
|
||||
export const pythonPath = (path.isAbsolute(PythonExecutable) ? PythonExecutable : path.join(alasPath, PythonExecutable));
|
||||
export const webuiUrl = `http://127.0.0.1:${WebuiPort}`;
|
||||
export const webuiUrl = `${sslEnabled ? 'https' : 'http'}://127.0.0.1:${WebuiPort}`;
|
||||
export const webuiPath = 'gui.py';
|
||||
export const webuiArgs = ['--port', WebuiPort, '--electron'];
|
||||
export const dpiScaling = Boolean(config.Deploy.Webui.DpiScaling) || (config.Deploy.Webui.DpiScaling === undefined) ;
|
||||
|
||||
@ -5,6 +5,17 @@ import {webuiArgs, webuiPath, dpiScaling} from '/@/config';
|
||||
|
||||
const path = require('path');
|
||||
|
||||
// Allow self-signed certificates for local HTTPS connections
|
||||
app.on('certificate-error', (event, _webContents, url, _error, _certificate, callback) => {
|
||||
// Only allow for local connections
|
||||
if (url.startsWith('https://127.0.0.1') || url.startsWith('https://localhost')) {
|
||||
event.preventDefault();
|
||||
callback(true);
|
||||
} else {
|
||||
callback(false);
|
||||
}
|
||||
});
|
||||
|
||||
const isSingleInstance = app.requestSingleInstanceLock();
|
||||
|
||||
if (!isSingleInstance) {
|
||||
@ -52,6 +63,16 @@ const createWindow = async () => {
|
||||
},
|
||||
});
|
||||
|
||||
// Ignore certificate errors for local connections (domain mismatch)
|
||||
mainWindow.webContents.session.setCertificateVerifyProc((request, callback) => {
|
||||
const {hostname} = new URL(request.hostname.includes('://') ? request.hostname : `https://${request.hostname}`);
|
||||
if (hostname === '127.0.0.1' || hostname === 'localhost') {
|
||||
callback(0); // 0 = success, ignore certificate errors for local
|
||||
} else {
|
||||
callback(-3); // -3 = use default verification
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* If you install `show: true` then it can cause issues when trying to close the window.
|
||||
* Use `show: false` and listener events `ready-to-show` to fix these issues.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user