|
@@ -1,3 +1,33 @@
|
|
|
|
|
+function isElectron(): boolean {
|
|
|
|
|
+ // 方法1: 检查window.electronPrint API
|
|
|
|
|
+ if (typeof window !== 'undefined' && window.electronPrint) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 方法2: 检查process.versions.electron
|
|
|
|
|
+ if (
|
|
|
|
|
+ typeof process !== 'undefined' &&
|
|
|
|
|
+ process.versions &&
|
|
|
|
|
+ process.versions.electron
|
|
|
|
|
+ ) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 方法3: 检查navigator.userAgent
|
|
|
|
|
+ if (
|
|
|
|
|
+ typeof navigator !== 'undefined' &&
|
|
|
|
|
+ navigator.userAgent.toLowerCase().indexOf('electron') > -1
|
|
|
|
|
+ ) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
export function getHostConfig() {
|
|
export function getHostConfig() {
|
|
|
|
|
+ if (isElectron()) {
|
|
|
|
|
+ // Electron 环境(包括开发和生产打包后)
|
|
|
|
|
+ // 强制走本地 loopback,最可靠
|
|
|
|
|
+ return 'ws://127.0.0.1:8083/mqtt'
|
|
|
|
|
+ }
|
|
|
return `ws://${window.location.host}:8083/mqtt`
|
|
return `ws://${window.location.host}:8083/mqtt`
|
|
|
}
|
|
}
|