-
+
+
+
+
+
{{ $t('tenant.api.desktopBindPublicDescription') }}
+
+
+
+
+
+
+
+
+
+
{{ $t('tenant.api.lanUrlDescription') }}
+
+
+
+
+
+
+
+
@@ -187,7 +228,11 @@ const showApiKey = ref(false)
/** WeKnora Lite (Wails): real API origin is loopback + dynamic port, not window.location.origin */
const wailsApiBaseURL = ref(null)
const showDesktopPortSetting = ref(false)
+const showDesktopBindPublicSetting = ref(false)
const desktopPortInput = ref(0)
+const desktopBindPublicInput = ref(false)
+const wailsApiLanBaseURL = ref(null)
+const desktopListenPublicActive = ref(false)
// Computed
const displayApiKey = computed(() => {
@@ -202,6 +247,13 @@ const displayApiKey = computed(() => {
return masked
})
+const showLanUrlUnavailableHint = computed(
+ () =>
+ showDesktopBindPublicSetting.value &&
+ desktopListenPublicActive.value &&
+ !wailsApiLanBaseURL.value
+)
+
const apiBaseUrlDisplay = computed(() => {
if (wailsApiBaseURL.value) {
return wailsApiBaseURL.value
@@ -217,12 +269,17 @@ const apiBaseUrlDisplay = computed(() => {
type WeKnoraDesktopWindow = Window & {
__WEKNORA_API_BASE__?: string
+ __WEKNORA_API_LAN_BASE__?: string
go?: {
main?: {
App?: {
GetAPIBaseURL?: () => Promise | string
+ GetAPILanBaseURL?: () => Promise | string
GetDesktopHTTPPortSetting?: () => Promise | number
+ GetDesktopHTTPBindPublicSetting?: () => Promise | boolean
+ GetDesktopListenPublicActive?: () => Promise | boolean
SetDesktopHTTPPortSetting?: (port: number) => Promise | void
+ SetDesktopHTTPBindPublicSetting?: (v: boolean) => Promise | void
}
}
}
@@ -234,6 +291,7 @@ async function tryLoadWailsApiBaseURL() {
const injected = win.__WEKNORA_API_BASE__
if (typeof injected === 'string' && injected.trim()) {
wailsApiBaseURL.value = injected.trim().replace(/\/$/, '')
+ await tryLoadWailsLanHints(win)
return
}
const fn = win.go?.main?.App?.GetAPIBaseURL
@@ -246,10 +304,38 @@ async function tryLoadWailsApiBaseURL() {
} catch {
/* binding error */
}
+ await tryLoadWailsLanHints(win)
return
}
await new Promise((r) => setTimeout(r, 50))
}
+ await tryLoadWailsLanHints(win)
+}
+
+async function tryLoadWailsLanHints(win: WeKnoraDesktopWindow) {
+ const injectedLan = win.__WEKNORA_API_LAN_BASE__
+ if (typeof injectedLan === 'string' && injectedLan.trim()) {
+ wailsApiLanBaseURL.value = injectedLan.trim().replace(/\/$/, '')
+ }
+ const fnLan = win.go?.main?.App?.GetAPILanBaseURL
+ if (typeof fnLan === 'function' && !wailsApiLanBaseURL.value) {
+ try {
+ const raw = await Promise.resolve(fnLan())
+ if (typeof raw === 'string' && raw.trim()) {
+ wailsApiLanBaseURL.value = raw.trim().replace(/\/$/, '')
+ }
+ } catch {
+ /* binding error */
+ }
+ }
+ const fnAct = win.go?.main?.App?.GetDesktopListenPublicActive
+ if (typeof fnAct === 'function') {
+ try {
+ desktopListenPublicActive.value = !!(await Promise.resolve(fnAct()))
+ } catch {
+ desktopListenPublicActive.value = false
+ }
+ }
}
function desktopPortBindingsAvailable(win: WeKnoraDesktopWindow) {
@@ -257,15 +343,47 @@ function desktopPortBindingsAvailable(win: WeKnoraDesktopWindow) {
return typeof app?.GetDesktopHTTPPortSetting === 'function' && typeof app?.SetDesktopHTTPPortSetting === 'function'
}
-async function loadDesktopPortPrefs() {
+function desktopBindPublicBindingsAvailable(win: WeKnoraDesktopWindow) {
+ const app = win.go?.main?.App
+ return (
+ typeof app?.GetDesktopHTTPBindPublicSetting === 'function' &&
+ typeof app?.SetDesktopHTTPBindPublicSetting === 'function'
+ )
+}
+
+async function loadDesktopApiPrefs() {
const win = window as WeKnoraDesktopWindow
- if (!desktopPortBindingsAvailable(win)) return
- showDesktopPortSetting.value = true
+ if (desktopPortBindingsAvailable(win)) {
+ showDesktopPortSetting.value = true
+ try {
+ const p = await Promise.resolve(win.go!.main!.App!.GetDesktopHTTPPortSetting!())
+ desktopPortInput.value = typeof p === 'number' ? p : 0
+ } catch {
+ desktopPortInput.value = 0
+ }
+ }
+ if (desktopBindPublicBindingsAvailable(win)) {
+ showDesktopBindPublicSetting.value = true
+ try {
+ const b = await Promise.resolve(win.go!.main!.App!.GetDesktopHTTPBindPublicSetting!())
+ desktopBindPublicInput.value = !!b
+ } catch {
+ desktopBindPublicInput.value = false
+ }
+ }
+}
+
+const onDesktopBindPublicChange = async (value: boolean) => {
+ const v = value === true
+ const win = window as WeKnoraDesktopWindow
+ const fn = win.go?.main?.App?.SetDesktopHTTPBindPublicSetting
+ if (typeof fn !== 'function') return
try {
- const p = await Promise.resolve(win.go!.main!.App!.GetDesktopHTTPPortSetting!())
- desktopPortInput.value = typeof p === 'number' ? p : 0
- } catch {
- desktopPortInput.value = 0
+ await Promise.resolve(fn(v))
+ MessagePlugin.success(t('tenant.api.desktopBindPublicSaved'))
+ } catch (err: unknown) {
+ MessagePlugin.error(err instanceof Error ? err.message : t('tenant.api.desktopBindPublicSaveFailed'))
+ desktopBindPublicInput.value = !v
}
}
@@ -342,6 +460,22 @@ const copyApiKey = async () => {
}
}
+const copyLanApiUrl = async () => {
+ const text = wailsApiLanBaseURL.value
+ if (!text) return
+ try {
+ if (navigator.clipboard && navigator.clipboard.writeText) {
+ await navigator.clipboard.writeText(text)
+ } else {
+ fallbackCopyText(text)
+ }
+ MessagePlugin.success(t('tenant.api.lanUrlCopySuccess'))
+ } catch {
+ fallbackCopyText(text)
+ MessagePlugin.success(t('tenant.api.lanUrlCopySuccess'))
+ }
+}
+
const copyApiUrl = async () => {
const text = apiBaseUrlDisplay.value
try {
@@ -378,7 +512,7 @@ const formatDate = (dateStr: string | undefined) => {
// Lifecycle
onMounted(async () => {
await tryLoadWailsApiBaseURL()
- await loadDesktopPortPrefs()
+ await loadDesktopApiPrefs()
loadInfo()
})
@@ -531,5 +665,18 @@ onMounted(async () => {
font-size: 12px;
}
}
+
+.desktop-bind-public-control {
+ padding-top: 4px;
+}
+
+.lan-url-hint-row {
+ padding-top: 0;
+ border-bottom: 1px solid var(--td-component-stroke);
+
+ :deep(.t-alert) {
+ width: 100%;
+ }
+}
diff --git a/frontend/src/wailsjs/go/main/App.d.ts b/frontend/src/wailsjs/go/main/App.d.ts
index cee879bb..24e23ed9 100755
--- a/frontend/src/wailsjs/go/main/App.d.ts
+++ b/frontend/src/wailsjs/go/main/App.d.ts
@@ -3,6 +3,14 @@
export function GetAPIBaseURL():Promise;
+export function GetAPILanBaseURL():Promise;
+
+export function GetDesktopHTTPBindPublicSetting():Promise;
+
export function GetDesktopHTTPPortSetting():Promise;
+export function GetDesktopListenPublicActive():Promise;
+
+export function SetDesktopHTTPBindPublicSetting(arg1:boolean):Promise;
+
export function SetDesktopHTTPPortSetting(arg1:number):Promise;
diff --git a/frontend/src/wailsjs/go/main/App.js b/frontend/src/wailsjs/go/main/App.js
index df8ecf64..29947483 100755
--- a/frontend/src/wailsjs/go/main/App.js
+++ b/frontend/src/wailsjs/go/main/App.js
@@ -6,10 +6,26 @@ export function GetAPIBaseURL() {
return window['go']['main']['App']['GetAPIBaseURL']();
}
+export function GetAPILanBaseURL() {
+ return window['go']['main']['App']['GetAPILanBaseURL']();
+}
+
+export function GetDesktopHTTPBindPublicSetting() {
+ return window['go']['main']['App']['GetDesktopHTTPBindPublicSetting']();
+}
+
export function GetDesktopHTTPPortSetting() {
return window['go']['main']['App']['GetDesktopHTTPPortSetting']();
}
+export function GetDesktopListenPublicActive() {
+ return window['go']['main']['App']['GetDesktopListenPublicActive']();
+}
+
+export function SetDesktopHTTPBindPublicSetting(arg1) {
+ return window['go']['main']['App']['SetDesktopHTTPBindPublicSetting'](arg1);
+}
+
export function SetDesktopHTTPPortSetting(arg1) {
return window['go']['main']['App']['SetDesktopHTTPPortSetting'](arg1);
}