FIX: share link from neutralino's app

This commit is contained in:
Julien Maille 2026-02-15 21:07:43 +01:00
parent 094ae91af9
commit 8eaafd7e18
4 changed files with 16 additions and 8 deletions

View file

@ -15,7 +15,7 @@ import { LyricsManager, openLyricsPanel, clearLyricsPanelSync } from './lyrics.j
import { createRouter, updateTabTitle, navigate } from './router.js'; import { createRouter, updateTabTitle, navigate } from './router.js';
import { initializePlayerEvents, initializeTrackInteractions, handleTrackAction } from './events.js'; import { initializePlayerEvents, initializeTrackInteractions, handleTrackAction } from './events.js';
import { initializeUIInteractions } from './ui-interactions.js'; import { initializeUIInteractions } from './ui-interactions.js';
import { debounce, SVG_PLAY } from './utils.js'; import { debounce, SVG_PLAY, getShareUrl } from './utils.js';
import { sidePanelManager } from './side-panel.js'; import { sidePanelManager } from './side-panel.js';
import { db } from './db.js'; import { db } from './db.js';
import { syncManager } from './accounts/pocketbase.js'; import { syncManager } from './accounts/pocketbase.js';
@ -1050,7 +1050,7 @@ document.addEventListener('DOMContentLoaded', async () => {
if (shareBtn) { if (shareBtn) {
shareBtn.style.display = playlist.isPublic ? 'flex' : 'none'; shareBtn.style.display = playlist.isPublic ? 'flex' : 'none';
shareBtn.onclick = () => { shareBtn.onclick = () => {
const url = `${window.location.origin}/userplaylist/${playlist.id}`; const url = getShareUrl(`/userplaylist/${playlist.id}`);
navigator.clipboard.writeText(url).then(() => alert('Link copied to clipboard!')); navigator.clipboard.writeText(url).then(() => alert('Link copied to clipboard!'));
}; };
} }
@ -1091,7 +1091,7 @@ document.addEventListener('DOMContentLoaded', async () => {
if (shareBtn) { if (shareBtn) {
shareBtn.style.display = playlist.isPublic ? 'flex' : 'none'; shareBtn.style.display = playlist.isPublic ? 'flex' : 'none';
shareBtn.onclick = () => { shareBtn.onclick = () => {
const url = `${window.location.origin}/userplaylist/${playlist.id}`; const url = getShareUrl(`/userplaylist/${playlist.id}`);
navigator.clipboard.writeText(url).then(() => alert('Link copied to clipboard!')); navigator.clipboard.writeText(url).then(() => alert('Link copied to clipboard!'));
}; };
} }

View file

@ -10,6 +10,7 @@ import {
SVG_BIN, SVG_BIN,
getTrackArtists, getTrackArtists,
positionMenu, positionMenu,
getShareUrl,
} from './utils.js'; } from './utils.js';
import { lastFMStorage, libreFmSettings, waveformSettings } from './storage.js'; import { lastFMStorage, libreFmSettings, waveformSettings } from './storage.js';
import { showNotification, downloadTrackWithMetadata, downloadAlbumAsZip, downloadPlaylistAsZip } from './downloads.js'; import { showNotification, downloadTrackWithMetadata, downloadAlbumAsZip, downloadPlaylistAsZip } from './downloads.js';
@ -1159,9 +1160,9 @@ export async function handleTrackAction(
// Use stored href from card if available, otherwise construct URL // Use stored href from card if available, otherwise construct URL
const contextMenu = document.getElementById('context-menu'); const contextMenu = document.getElementById('context-menu');
const storedHref = contextMenu?._contextHref; const storedHref = contextMenu?._contextHref;
const url = storedHref const url = getShareUrl(
? `${window.location.origin}${storedHref}` storedHref ? storedHref : `/track/${item.id || item.uuid}`
: `${window.location.origin}/track/${item.id || item.uuid}`; );
trackCopyLink(type, item.id || item.uuid); trackCopyLink(type, item.id || item.uuid);
navigator.clipboard.writeText(url).then(() => { navigator.clipboard.writeText(url).then(() => {

View file

@ -18,6 +18,7 @@ import {
calculateTotalDuration, calculateTotalDuration,
formatDuration, formatDuration,
escapeHtml, escapeHtml,
getShareUrl,
} from './utils.js'; } from './utils.js';
import { openLyricsPanel } from './lyrics.js'; import { openLyricsPanel } from './lyrics.js';
import { import {
@ -3324,7 +3325,7 @@ export class UIRenderer {
'<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8"/><polyline points="16 6 12 2 8 6"/><line x1="12" y1="2" x2="12" y2="15"/></svg><span>Share</span>'; '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8"/><polyline points="16 6 12 2 8 6"/><line x1="12" y1="2" x2="12" y2="15"/></svg><span>Share</span>';
shareBtn.onclick = () => { shareBtn.onclick = () => {
const url = `${window.location.origin}/userplaylist/${playlist.id || playlist.uuid}`; const url = getShareUrl(`/userplaylist/${playlist.id || playlist.uuid}`);
navigator.clipboard.writeText(url).then(() => alert('Link copied to clipboard!')); navigator.clipboard.writeText(url).then(() => alert('Link copied to clipboard!'));
}; };
fragment.appendChild(shareBtn); fragment.appendChild(shareBtn);
@ -3660,7 +3661,7 @@ export class UIRenderer {
}; };
shareBtn.onclick = () => { shareBtn.onclick = () => {
const url = `${window.location.origin}/track/${track.id}`; const url = getShareUrl(`/track/${track.id}`);
navigator.clipboard.writeText(url).then(() => { navigator.clipboard.writeText(url).then(() => {
showNotification('Link copied to clipboard!'); showNotification('Link copied to clipboard!');
}); });

View file

@ -489,3 +489,9 @@ export function positionMenu(menu, x, y, anchorRect = null) {
menu.style.left = `${left}px`; menu.style.left = `${left}px`;
menu.style.visibility = 'visible'; menu.style.visibility = 'visible';
} }
export const getShareUrl = (path) => {
const baseUrl = window.NL_MODE ? 'https://monochrome.tf' : window.location.origin;
const safePath = path.startsWith('/') ? path : `/${path}`;
return `${baseUrl}${safePath}`;
};