mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-03 09:52:50 +08:00
Implement Nachrichten options panel: named away-message presets + disconnect message
Wires up the previously placeholder-only "Nachrichten" options section: users can now save/delete named away-message templates and set a default leave message that's sent to the server (via DisconnectOptions) when disconnecting. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
234feb4d55
commit
8fb6d72957
5 files changed
+182
-21
No files matched your search
@@ -16,7 +16,7 @@ use tsclientlib::messages::c2s::{OutClientPokeRequestPart, OutSendTextMessagePar
|
|||||||
use tsclientlib::prelude::*;
|
use tsclientlib::prelude::*;
|
||||||
use tsclientlib::{
|
use tsclientlib::{
|
||||||
data, ChannelId, ClientId, Connection, DisconnectOptions, MaxClients, MessageHandle,
|
data, ChannelId, ClientId, Connection, DisconnectOptions, MaxClients, MessageHandle,
|
||||||
MessageTarget, StreamItem, TextMessageTargetMode,
|
MessageTarget, Reason, StreamItem, TextMessageTargetMode,
|
||||||
};
|
};
|
||||||
use tsproto_packets::packets::{AudioData, CodecType, OutAudio};
|
use tsproto_packets::packets::{AudioData, CodecType, OutAudio};
|
||||||
|
|
||||||
@@ -321,8 +321,14 @@ async fn run(args: Args) -> Result<()> {
|
|||||||
LoopOutcome::StdinLine(line) => match line {
|
LoopOutcome::StdinLine(line) => match line {
|
||||||
Ok(Some(l)) => {
|
Ok(Some(l)) => {
|
||||||
let l = l.trim();
|
let l = l.trim();
|
||||||
if l == "disconnect" {
|
if l == "disconnect" || l.starts_with("disconnect ") {
|
||||||
con.disconnect(DisconnectOptions::new())?;
|
let message = l.strip_prefix("disconnect").unwrap_or("").trim();
|
||||||
|
let options = if message.is_empty() {
|
||||||
|
DisconnectOptions::new()
|
||||||
|
} else {
|
||||||
|
DisconnectOptions::new().reason(Reason::Clientdisconnect).message(message)
|
||||||
|
};
|
||||||
|
con.disconnect(options)?;
|
||||||
con.events().for_each(|_| future::ready(())).await;
|
con.events().for_each(|_| future::ready(())).await;
|
||||||
emit(&Event::Disconnected { reason: "client requested".into() });
|
emit(&Event::Disconnected { reason: "client requested".into() });
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -113,6 +113,10 @@ wss.on("connection", (socket: WebSocket) => {
|
|||||||
await connection?.setOutputMuted(msg.muted);
|
await connection?.setOutputMuted(msg.muted);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "disconnect": {
|
||||||
|
await connection?.disconnect(msg.message ?? "");
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
socket.send(
|
socket.send(
|
||||||
JSON.stringify({ type: "error", message: `Unknown message type: ${msg.type}` })
|
JSON.stringify({ type: "error", message: `Unknown message type: ${msg.type}` })
|
||||||
|
|||||||
@@ -245,9 +245,10 @@ export class Ts3Connection {
|
|||||||
this.child?.stdin.write(`muteoutput ${muted ? "1" : "0"}\n`);
|
this.child?.stdin.write(`muteoutput ${muted ? "1" : "0"}\n`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async disconnect(): Promise<void> {
|
async disconnect(message = ""): Promise<void> {
|
||||||
if (this.child && !this.child.killed) {
|
if (this.child && !this.child.killed) {
|
||||||
this.child.stdin.write("disconnect\n");
|
const sanitized = message.replace(/[\r\n]+/g, " ").trim();
|
||||||
|
this.child.stdin.write(`disconnect ${sanitized}\n`);
|
||||||
this.child.stdin.end();
|
this.child.stdin.end();
|
||||||
}
|
}
|
||||||
this.listeners.clear();
|
this.listeners.clear();
|
||||||
|
|||||||
+140
-14
@@ -87,16 +87,38 @@ function loadFavorites(): Favorite[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const AWAY_PRESETS_KEY = "webspeak3:away-presets";
|
const AWAY_PRESETS_KEY = "webspeak3:away-presets";
|
||||||
|
const DISCONNECT_MESSAGE_KEY = "webspeak3:disconnect-message";
|
||||||
|
|
||||||
function loadAwayPresets(): string[] {
|
interface MessagePreset {
|
||||||
|
name: string;
|
||||||
|
message: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadAwayPresets(): MessagePreset[] {
|
||||||
try {
|
try {
|
||||||
const raw = localStorage.getItem(AWAY_PRESETS_KEY);
|
const raw = localStorage.getItem(AWAY_PRESETS_KEY);
|
||||||
return raw ? (JSON.parse(raw) as string[]) : [];
|
if (!raw) return [];
|
||||||
|
const parsed = JSON.parse(raw) as unknown;
|
||||||
|
if (!Array.isArray(parsed)) return [];
|
||||||
|
// Older versions stored presets as plain strings (name == message) - migrate on read.
|
||||||
|
return parsed.map((p) => (typeof p === "string" ? { name: p, message: p } : (p as MessagePreset)));
|
||||||
} catch {
|
} catch {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function saveAwayPresets(presets: MessagePreset[]): void {
|
||||||
|
localStorage.setItem(AWAY_PRESETS_KEY, JSON.stringify(presets));
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadDisconnectMessage(): string {
|
||||||
|
return localStorage.getItem(DISCONNECT_MESSAGE_KEY) ?? "";
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveDisconnectMessage(message: string): void {
|
||||||
|
localStorage.setItem(DISCONNECT_MESSAGE_KEY, message);
|
||||||
|
}
|
||||||
|
|
||||||
type LogEntry = { text: string; kind: "info" | "error" };
|
type LogEntry = { text: string; kind: "info" | "error" };
|
||||||
|
|
||||||
interface ChannelInfo {
|
interface ChannelInfo {
|
||||||
@@ -730,7 +752,7 @@ function AwayDialog({
|
|||||||
onCancel,
|
onCancel,
|
||||||
}: {
|
}: {
|
||||||
message: string;
|
message: string;
|
||||||
presets: string[];
|
presets: MessagePreset[];
|
||||||
onMessageChange: (v: string) => void;
|
onMessageChange: (v: string) => void;
|
||||||
onOk: () => void;
|
onOk: () => void;
|
||||||
onSaveTemplate: () => void;
|
onSaveTemplate: () => void;
|
||||||
@@ -759,8 +781,8 @@ function AwayDialog({
|
|||||||
>
|
>
|
||||||
<option value="">{t("away.dialog.none")}</option>
|
<option value="">{t("away.dialog.none")}</option>
|
||||||
{presets.map((p) => (
|
{presets.map((p) => (
|
||||||
<option key={p} value={p}>
|
<option key={p.name} value={p.message}>
|
||||||
{p}
|
{p.name}
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
@@ -1172,6 +1194,97 @@ function SoundsPanel() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function NachrichtenPanel() {
|
||||||
|
const t = useT();
|
||||||
|
const [presets, setPresets] = useState<MessagePreset[]>(() => loadAwayPresets());
|
||||||
|
const [disconnectMessage, setDisconnectMessageState] = useState(() => loadDisconnectMessage());
|
||||||
|
const [newName, setNewName] = useState("");
|
||||||
|
const [newMessage, setNewMessage] = useState("");
|
||||||
|
|
||||||
|
const handleDisconnectMessageChange = (v: string) => {
|
||||||
|
setDisconnectMessageState(v);
|
||||||
|
saveDisconnectMessage(v);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAdd = () => {
|
||||||
|
const name = newName.trim();
|
||||||
|
const message = newMessage.trim();
|
||||||
|
if (!name || !message) return;
|
||||||
|
const next = [...presets, { name, message }];
|
||||||
|
setPresets(next);
|
||||||
|
saveAwayPresets(next);
|
||||||
|
setNewName("");
|
||||||
|
setNewMessage("");
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDelete = (index: number) => {
|
||||||
|
const next = presets.filter((_, i) => i !== index);
|
||||||
|
setPresets(next);
|
||||||
|
saveAwayPresets(next);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<h3>{t("nachrichten.title")}</h3>
|
||||||
|
<p className="ts-options-subtitle">{t("nachrichten.subtitle")}</p>
|
||||||
|
<label className="ts-dialog-field">
|
||||||
|
{t("nachrichten.disconnectMessage")}
|
||||||
|
<input
|
||||||
|
value={disconnectMessage}
|
||||||
|
onChange={(e) => handleDisconnectMessageChange(e.target.value)}
|
||||||
|
placeholder={t("nachrichten.disconnectMessagePlaceholder")}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<h4>{t("nachrichten.presetsTitle")}</h4>
|
||||||
|
<table className="ts-options-sounds-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>{t("nachrichten.type")}</th>
|
||||||
|
<th>{t("nachrichten.templateName")}</th>
|
||||||
|
<th>{t("nachrichten.message")}</th>
|
||||||
|
<th />
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{presets.map((preset, index) => (
|
||||||
|
<tr key={`${preset.name}-${index}`}>
|
||||||
|
<td>{t("nachrichten.type.away")}</td>
|
||||||
|
<td>{preset.name}</td>
|
||||||
|
<td>{preset.message}</td>
|
||||||
|
<td>
|
||||||
|
<button onClick={() => handleDelete(index)}>{t("nachrichten.delete")}</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
<tr>
|
||||||
|
<td>{t("nachrichten.type.away")}</td>
|
||||||
|
<td>
|
||||||
|
<input
|
||||||
|
value={newName}
|
||||||
|
onChange={(e) => setNewName(e.target.value)}
|
||||||
|
placeholder={t("nachrichten.templateName")}
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input
|
||||||
|
value={newMessage}
|
||||||
|
onChange={(e) => setNewMessage(e.target.value)}
|
||||||
|
placeholder={t("nachrichten.message")}
|
||||||
|
onKeyDown={(e) => e.key === "Enter" && handleAdd()}
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<button onClick={handleAdd} disabled={!newName.trim() || !newMessage.trim()}>
|
||||||
|
{t("nachrichten.add")}
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function OptionsDialog({
|
function OptionsDialog({
|
||||||
section,
|
section,
|
||||||
onSectionChange,
|
onSectionChange,
|
||||||
@@ -1216,6 +1329,8 @@ function OptionsDialog({
|
|||||||
<AufnahmePanel audio={audio} />
|
<AufnahmePanel audio={audio} />
|
||||||
) : active.id === "sounds" ? (
|
) : active.id === "sounds" ? (
|
||||||
<SoundsPanel />
|
<SoundsPanel />
|
||||||
|
) : active.id === "nachrichten" ? (
|
||||||
|
<NachrichtenPanel />
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<h3>{t(`options.section.${active.id}`)}</h3>
|
<h3>{t(`options.section.${active.id}`)}</h3>
|
||||||
@@ -1295,7 +1410,7 @@ function AppInner() {
|
|||||||
const [awayMenuOpen, setAwayMenuOpen] = useState(false);
|
const [awayMenuOpen, setAwayMenuOpen] = useState(false);
|
||||||
const [awayDialogOpen, setAwayDialogOpen] = useState(false);
|
const [awayDialogOpen, setAwayDialogOpen] = useState(false);
|
||||||
const [awayDialogMessage, setAwayDialogMessage] = useState("");
|
const [awayDialogMessage, setAwayDialogMessage] = useState("");
|
||||||
const [awayPresets, setAwayPresets] = useState<string[]>(() => loadAwayPresets());
|
const [awayPresets, setAwayPresets] = useState<MessagePreset[]>(() => loadAwayPresets());
|
||||||
const [extrasMenuOpen, setExtrasMenuOpen] = useState(false);
|
const [extrasMenuOpen, setExtrasMenuOpen] = useState(false);
|
||||||
const [optionsDialogOpen, setOptionsDialogOpen] = useState(false);
|
const [optionsDialogOpen, setOptionsDialogOpen] = useState(false);
|
||||||
const [optionsSection, setOptionsSection] = useState<string>(OPTIONS_SECTIONS[0].id);
|
const [optionsSection, setOptionsSection] = useState<string>(OPTIONS_SECTIONS[0].id);
|
||||||
@@ -1641,7 +1756,15 @@ function AppInner() {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDisconnect = () => socketRef.current?.close();
|
const handleDisconnect = () => {
|
||||||
|
const socket = socketRef.current;
|
||||||
|
if (!socket) return;
|
||||||
|
const message = loadDisconnectMessage();
|
||||||
|
if (message && socket.readyState === WebSocket.OPEN) {
|
||||||
|
socket.send(JSON.stringify({ type: "disconnect", message }));
|
||||||
|
}
|
||||||
|
socket.close();
|
||||||
|
};
|
||||||
|
|
||||||
const connectToFavorite = (f: Favorite) => {
|
const connectToFavorite = (f: Favorite) => {
|
||||||
setHost(f.host);
|
setHost(f.host);
|
||||||
@@ -1690,9 +1813,9 @@ function AppInner() {
|
|||||||
const trimmed = awayDialogMessage.trim();
|
const trimmed = awayDialogMessage.trim();
|
||||||
if (!trimmed) return;
|
if (!trimmed) return;
|
||||||
setAwayPresets((prev) => {
|
setAwayPresets((prev) => {
|
||||||
if (prev.includes(trimmed)) return prev;
|
if (prev.some((p) => p.message === trimmed)) return prev;
|
||||||
const next = [...prev, trimmed];
|
const next = [...prev, { name: trimmed, message: trimmed }];
|
||||||
localStorage.setItem(AWAY_PRESETS_KEY, JSON.stringify(next));
|
saveAwayPresets(next);
|
||||||
return next;
|
return next;
|
||||||
});
|
});
|
||||||
setAwayDialogOpen(false);
|
setAwayDialogOpen(false);
|
||||||
@@ -2140,7 +2263,10 @@ function AppInner() {
|
|||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className="ts-icon-caret"
|
className="ts-icon-caret"
|
||||||
onClick={() => setAwayMenuOpen((v) => !v)}
|
onClick={() => {
|
||||||
|
setAwayPresets(loadAwayPresets());
|
||||||
|
setAwayMenuOpen((v) => !v);
|
||||||
|
}}
|
||||||
disabled={!connected}
|
disabled={!connected}
|
||||||
title={t("toolbar.awayOptions")}
|
title={t("toolbar.awayOptions")}
|
||||||
>
|
>
|
||||||
@@ -2172,14 +2298,14 @@ function AppInner() {
|
|||||||
{awayPresets.length > 0 && <div className="ts-menu-separator" />}
|
{awayPresets.length > 0 && <div className="ts-menu-separator" />}
|
||||||
{awayPresets.map((preset) => (
|
{awayPresets.map((preset) => (
|
||||||
<button
|
<button
|
||||||
key={preset}
|
key={preset.name}
|
||||||
className="ts-menu-item"
|
className="ts-menu-item"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
sendAway(true, preset);
|
sendAway(true, preset.message);
|
||||||
setAwayMenuOpen(false);
|
setAwayMenuOpen(false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span className="ts-menu-item-label">{preset}</span>
|
<span className="ts-menu-item-label">{preset.name}</span>
|
||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+26
-2
@@ -215,6 +215,18 @@ const translations: Record<Lang, Record<string, string>> = {
|
|||||||
"sounds.test": "▶ Testen",
|
"sounds.test": "▶ Testen",
|
||||||
"sounds.upload": "Hochladen",
|
"sounds.upload": "Hochladen",
|
||||||
"sounds.reset": "Zurücksetzen",
|
"sounds.reset": "Zurücksetzen",
|
||||||
|
|
||||||
|
"nachrichten.title": "Nachrichten",
|
||||||
|
"nachrichten.subtitle": "Nachrichten anpassen",
|
||||||
|
"nachrichten.disconnectMessage": "Verbindung trennen:",
|
||||||
|
"nachrichten.disconnectMessagePlaceholder": "verlassen",
|
||||||
|
"nachrichten.presetsTitle": "Voreingestellte Nachrichten",
|
||||||
|
"nachrichten.type": "Typ",
|
||||||
|
"nachrichten.type.away": "Abwesend",
|
||||||
|
"nachrichten.templateName": "Vorlagenname",
|
||||||
|
"nachrichten.message": "Nachricht",
|
||||||
|
"nachrichten.add": "Hinzufügen",
|
||||||
|
"nachrichten.delete": "Löschen",
|
||||||
},
|
},
|
||||||
en: {
|
en: {
|
||||||
"menu.connections": "Connections",
|
"menu.connections": "Connections",
|
||||||
@@ -322,8 +334,8 @@ const translations: Record<Lang, Record<string, string>> = {
|
|||||||
"options.section.downloads": "Downloads",
|
"options.section.downloads": "Downloads",
|
||||||
"options.section.chat": "Chat",
|
"options.section.chat": "Chat",
|
||||||
"options.section.sicherheit": "Security",
|
"options.section.sicherheit": "Security",
|
||||||
"options.section.nachrichten": "Notifications",
|
"options.section.nachrichten": "Messages",
|
||||||
"options.section.meldungen": "Messages",
|
"options.section.meldungen": "Notifications",
|
||||||
"options.section.sounds": "Sounds",
|
"options.section.sounds": "Sounds",
|
||||||
|
|
||||||
"app.title": "Application",
|
"app.title": "Application",
|
||||||
@@ -421,6 +433,18 @@ const translations: Record<Lang, Record<string, string>> = {
|
|||||||
"sounds.test": "▶ Test",
|
"sounds.test": "▶ Test",
|
||||||
"sounds.upload": "Upload",
|
"sounds.upload": "Upload",
|
||||||
"sounds.reset": "Reset",
|
"sounds.reset": "Reset",
|
||||||
|
|
||||||
|
"nachrichten.title": "Messages",
|
||||||
|
"nachrichten.subtitle": "Customize messages",
|
||||||
|
"nachrichten.disconnectMessage": "Disconnect:",
|
||||||
|
"nachrichten.disconnectMessagePlaceholder": "leaving",
|
||||||
|
"nachrichten.presetsTitle": "Preset messages",
|
||||||
|
"nachrichten.type": "Type",
|
||||||
|
"nachrichten.type.away": "Away",
|
||||||
|
"nachrichten.templateName": "Template name",
|
||||||
|
"nachrichten.message": "Message",
|
||||||
|
"nachrichten.add": "Add",
|
||||||
|
"nachrichten.delete": "Delete",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user