@yiarce/dsh-chat 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -3
- package/appearance.js +158 -0
- package/chat.html +42 -0
- package/client.js +130 -0
- package/context-menu.js +142 -0
- package/cordis.patch.yml +4 -0
- package/history-client.js +106 -0
- package/history-host.js +86 -0
- package/history-model.js +20 -0
- package/history-store.js +188 -0
- package/host.js +67 -0
- package/login.js +250 -0
- package/media-client.js +46 -0
- package/media.js +197 -0
- package/package.json +52 -6
- package/page.css +1423 -0
- package/page.js +1726 -0
- package/standalone.js +11 -0
- package/window-client.js +31 -0
package/standalone.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { mountChat } from "./page.js"
|
|
2
|
+
import { bindNativeWindow } from "./window-client.js"
|
|
3
|
+
import { receiveAppearance } from "./appearance.js"
|
|
4
|
+
|
|
5
|
+
const root = document.getElementById("chat-root")
|
|
6
|
+
document.body.classList.add("yc-standalone")
|
|
7
|
+
root.dataset.theme = matchMedia("(prefers-color-scheme: light)").matches ? "light" : "dark"
|
|
8
|
+
const disposeAppearance = receiveAppearance(root)
|
|
9
|
+
const disposeWindow = new URL(location.href).searchParams.get("window") === "desktop" ? bindNativeWindow(root) : () => {}
|
|
10
|
+
const disposeChat = mountChat(root, { baseURL: new URL("./page", location.href).href })
|
|
11
|
+
window.addEventListener("pagehide", () => { disposeChat(); disposeWindow(); disposeAppearance() }, { once: true })
|
package/window-client.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Optional native window integration. Chat APIs never pass through this bridge.
|
|
2
|
+
export function openNativeChat(signal) {
|
|
3
|
+
return new Promise((resolve, reject) => {
|
|
4
|
+
const id = crypto.randomUUID()
|
|
5
|
+
let timer
|
|
6
|
+
const cleanup = () => { clearTimeout(timer); window.removeEventListener("yiarce-chat-window-result", receive); signal?.removeEventListener("abort", abort) }
|
|
7
|
+
const finish = error => { cleanup(); error ? reject(error) : resolve() }
|
|
8
|
+
const abort = () => finish(new Error("开窗已取消"))
|
|
9
|
+
const receive = event => { if (event.detail?.id === id) finish(event.detail.ok ? null : new Error(event.detail.error || "独立窗口打开失败")) }
|
|
10
|
+
window.addEventListener("yiarce-chat-window-result", receive)
|
|
11
|
+
signal?.addEventListener("abort", abort, { once: true })
|
|
12
|
+
if (signal?.aborted) { abort(); return }
|
|
13
|
+
timer = setTimeout(() => finish(new Error("独立窗口未响应")), 8000)
|
|
14
|
+
void fetch("http://wails.localhost/wails/runtime", { method: "POST", mode: "no-cors", headers: { "Content-Type": "text/plain" }, body: JSON.stringify({ object: 3, method: 0, args: { name: "chat:open-window", data: { id } } }) }).catch(error => finish(error))
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
export function bindNativeWindow(root) {
|
|
18
|
+
const life = new AbortController()
|
|
19
|
+
const emit = name => window._wails?.invoke?.("wails:event:emit:chat:window:" + name)
|
|
20
|
+
const initialize = () => {
|
|
21
|
+
if (!(window._wails || window.__wailsRuntimeInjected)) return
|
|
22
|
+
root.classList.add("yc-native")
|
|
23
|
+
root.querySelector("#window-controls").hidden = false
|
|
24
|
+
}
|
|
25
|
+
root.querySelector("#window-minimize").addEventListener("click", () => emit("minimize"), { signal: life.signal })
|
|
26
|
+
root.querySelector("#window-close").addEventListener("click", () => emit("close"), { signal: life.signal })
|
|
27
|
+
root.querySelector("#window-bar").addEventListener("dblclick", event => { if (!event.target.closest("button")) emit("maximize") }, { signal: life.signal })
|
|
28
|
+
window.addEventListener("yiarce-chat-native-ready", initialize, { signal: life.signal })
|
|
29
|
+
initialize()
|
|
30
|
+
return () => life.abort()
|
|
31
|
+
}
|