36 lines
1.3 KiB
JavaScript
36 lines
1.3 KiB
JavaScript
// Load announcement content from the application info when the page loads
|
|
async function loadAnnouncement() {
|
|
try {
|
|
const announcementText = await window.electronAPI.readApplicationInfo('announcement');
|
|
const announcementContent = document.getElementById('announcement-content');
|
|
if (announcementContent && announcementText) {
|
|
|
|
console.log('Announcement:', announcementText);
|
|
announcementContent.innerHTML = formatTextForHtml(announcementText);
|
|
}
|
|
} catch (error) {
|
|
console.error('Failed to load announcement:', error);
|
|
document.getElementById('announcement-content').textContent = 'Failed to load announcement.';
|
|
}
|
|
}
|
|
|
|
function formatTextForHtml(text) {
|
|
// Replace newlines with <br> tags
|
|
let formattedText = text.replace(/\n/g, '<br>');
|
|
|
|
// Replace tabs with a few non-breaking spaces for indentation
|
|
formattedText = formattedText.replace(/\t/g, ' ');
|
|
|
|
// Replace other special characters as needed
|
|
// Example: Handle double spaces by converting to
|
|
formattedText = formattedText.replace(/ /g, ' ');
|
|
|
|
return formattedText;
|
|
}
|
|
|
|
// Close the window when the close button is clicked
|
|
function closeWindow() {
|
|
window.electronAPI.writeApplicationInfo('announcement', '');
|
|
window.electronAPI.closeAnnouncementWindow();
|
|
}
|