I made dyamic island app which code is here : index.html "<!DOCTYPE html> <html…
- User
I made dyamic island app which code is here : index.html "
let mainWindow;
function createWindow() { const { width: screenWidth, height: screenHeight } = screen.getPrimaryDisplay().workAreaSize;
mainWindow = new BrowserWindow({ width: 350, height: 120, frame: false, transparent: true, alwaysOnTop: true, skipTaskbar: true, webPreferences: { nodeIntegration: true, contextIsolation: false, }, });
mainWindow.loadFile('index.html'); mainWindow.setPosition((screenWidth - 350) / 2, 0);
// Get initial volume operatingSystem.getVolume() .then(volume => { // Ensure the volume is between 0 and 100 if (volume < 0 || volume > 100) { volume = 50; // Default to 50 if the value is out of range } mainWindow.webContents.send('initial-volume', volume); }) .catch(err => console.error('Error fetching initial volume:', err)); }
app.on('ready', createWindow);
app.on('window-all-closed', () => { if (process.platform !== 'darwin') app.quit(); });
app.on('activate', () => { if (mainWindow === null) createWindow(); });
// Set system volume based on slider change ipcMain.on('set-volume', (event, volume) => { // Ensure volume is within 0 to 100 volume = Math.max(0, Math.min(100, volume)); operatingSystem.setVolume(volume) .then(vol => { console.log(
System volume set to ${vol}); }) .catch(err => { console.error('Error setting volume:', err); }); }); " and renderer.js "const { ipcRenderer } = require('electron');const dynamicIsland = document.getElementById('dynamic-island'); const timeElement = document.getElementById('time'); const volumeIcon = document.getElementById('volume-icon'); const volumeControl = document.getElementById('volume-control'); const volumeSlider = document.getElementById('volume-slider'); const volumeLabel = document.getElementById('volume-label');
let isExpanded = false; let isManuallyExpanded = false;
// Update the clock function updateTime() { const now = new Date(); timeElement.textContent = now.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); } setInterval(updateTime, 60000); updateTime();
// Expand and collapse the Dynamic Island function expandIsland() { dynamicIsland.classList.add('expanded'); volumeControl.style.display = 'flex'; isExpanded = true; } function collapseIsland() { if (!isManuallyExpanded) { dynamicIsland.classList.remove('expanded'); volumeControl.style.display = 'none'; isExpanded = false; } }
// Set volume from main process ipcRenderer.on('initial-volume', (event, volume) => { volumeSlider.value = volume; volumeLabel.textContent =
Volume: ${volume}%; });// Event listeners volumeIcon.addEventListener('click', () => { isManuallyExpanded = !isManuallyExpanded; if (isManuallyExpanded) expandIsland(); else collapseIsland(); });
volumeSlider.addEventListener('input', e => { const volume = e.target.value; volumeLabel.textContent = ; ipcRenderer.send('set-volume', parseInt(volume, 10)); // Send new volume to main process }); " but main problem with this code is that it ui is perfect working but when i move volume slider in dynamic island then it sets system real volume to zero and i already installed necessary dependencies so give me correct code which 100% work and don't change ui of this app
- Assistant