parent
bcac7fc375
commit
0273eab753
8 changed files with 127 additions and 8 deletions
|
|
@ -71,6 +71,7 @@ const el = {
|
|||
addGuildBtn: document.getElementById("add-guild-btn"),
|
||||
guildTitle: document.getElementById("guild-title"),
|
||||
createInviteBtn: document.getElementById("create-invite-btn"),
|
||||
inviteCopiedBadge: document.getElementById("invite-copied-badge"),
|
||||
|
||||
// Channels
|
||||
channelList: document.getElementById("channel-list"),
|
||||
|
|
@ -536,11 +537,27 @@ async function createInviteLink() {
|
|||
method: "POST",
|
||||
body: JSON.stringify({ max_uses: 50, expires_in_hours: 24 }),
|
||||
});
|
||||
const link = `${location.origin}/?invite=${encodeURIComponent(invite.code)}`;
|
||||
// Use the backend URL if available, otherwise fallback to current origin
|
||||
const base = API_BASE_URL ? new URL(API_BASE_URL).origin : location.origin;
|
||||
const link = `${base}/?invite=${encodeURIComponent(invite.code)}`;
|
||||
|
||||
// Use Electron's native clipboard API if available (defined in preload.js)
|
||||
if (window.electronAPI && window.electronAPI.copyToClipboard) {
|
||||
try {
|
||||
await window.electronAPI.copyToClipboard(link);
|
||||
showCopiedBadge();
|
||||
return;
|
||||
} catch (e) {
|
||||
console.error("Electron clipboard write failed:", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to navigator.clipboard
|
||||
try {
|
||||
await navigator.clipboard.writeText(link);
|
||||
alert(`Invite link copied:\n${link}`);
|
||||
} catch {
|
||||
showCopiedBadge();
|
||||
} catch (err) {
|
||||
console.error("Navigator clipboard write failed:", err);
|
||||
prompt("Copy invite link:", link);
|
||||
}
|
||||
} catch (err) {
|
||||
|
|
@ -548,6 +565,13 @@ async function createInviteLink() {
|
|||
}
|
||||
}
|
||||
|
||||
function showCopiedBadge() {
|
||||
el.inviteCopiedBadge.classList.remove("hidden");
|
||||
setTimeout(() => {
|
||||
el.inviteCopiedBadge.classList.add("hidden");
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
// --- Logic ---
|
||||
|
||||
async function loadGuilds() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue