This is my DynamicIsland app for windows so index.js code is "// index.js (Main Process)…
- User
This is my DynamicIsland app for windows so index.js code is "// index.js (Main Process) const { app, BrowserWindow, ipcMain } = require('electron'); const path = require('path'); const os = require('os-utils');
let mainWindow;
function createWindow() { mainWindow = new BrowserWindow({ width: 400, height: 200, frame: false, transparent: true, webPreferences: { nodeIntegration: true, contextIsolation: false }, alwaysOnTop: true, skipTaskbar: true });
mainWindow.loadFile('index.html'); // Position window at the top center of the screen const screenBounds = require('electron').screen.getPrimaryDisplay().workAreaSize; mainWindow.setPosition( Math.floor(screenBounds.width / 2 - 200), 10 );}
app.whenReady().then(createWindow);
app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); } });
app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow(); } });
// Send system stats to renderer function sendSystemStats() { os.cpuUsage((cpuUsage) => { const stats = { cpu: (cpuUsage * 100).toFixed(1), memory: ((os.totalmem() - os.freemem()) / os.totalmem() * 100).toFixed(1), temp: Math.random() * 20 + 40, // Simulated temperature (you can use actual temp monitoring library) uptime: os.sysUptime() }; mainWindow.webContents.send('system-stats', stats); }); }
// Update stats every 2 seconds setInterval(sendSystemStats, 2000);" my index.html code is "
body { display: flex; justify-content: center; height: 100vh; overflow: hidden; } .dynamic-island { background: #000; width: 95px; height: 35px; border-radius: 30px; position: relative; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3); -webkit-app-region: drag; } .dynamic-island.expanded { width: 380px; height: 180px; border-radius: 30px; } .island-content { color: white; opacity: 0; width: 100%; height: 100%; padding: 20px; transition: opacity 0.3s ease-in-out; pointer-events: none; } .expanded .island-content { opacity: 1; pointer-events: auto; } .activity-container { display: flex; flex-direction: column; height: 100%; } .activity-header { display: flex; align-items: center; margin-bottom: 15px; } .activity-icon { width: 32px; height: 32px; background: #2c2c2c; border-radius: 8px; margin-right: 12px; display: flex; align-items: center; justify-content: center; position: relative; } .activity-details { flex-grow: 1; } .activity-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; } .activity-subtitle { font-size: 13px; color: #aaa; } .activity-stats { display: flex; justify-content: space-between; margin-top: 20px; background: #1a1a1a; padding: 15px; border-radius: 15px; } .stat-item { text-align: center; flex: 1; } .stat-value { font-size: 22px; font-weight: 600; margin-bottom: 4px; } .stat-label { font-size: 12px; color: #aaa; text-transform: uppercase; letter-spacing: 0.5px; } .minimized-content { display: flex; align-items: center; justify-content: center; gap: 8px; height: 100%; } .minimized-content .dot { width: 4px; height: 4px; background: #fff; border-radius: 50%; animation: pulse 2s infinite; } @keyframes pulse { 0% { opacity: 0.3; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1); } 100% { opacity: 0.3; transform: scale(0.8); } } .island-camera { width: 8px; height: 8px; background: #1a1a1a; border-radius: 50%; position: absolute; right: 25px; display: flex; align-items: center; justify-content: center; } .island-camera::after { content: ''; width: 4px; height: 4px; background: #2a2a2a; border-radius: 50%; } .close-button { position: absolute; top: 10px; right: 10px; width: 20px; height: 20px; border-radius: 50%; background: #ff3b30; opacity: 0; transition: opacity 0.3s ease; -webkit-app-region: no-drag; cursor: pointer; display: flex; align-items: center; justify-content: center; color: #000; font-size: 14px; font-weight: bold; } .expanded .close-button { opacity: 1; } .close-button:hover { background: #ff1f1f; } .color-ring { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border-radius: 30px; border: 2px solid transparent; background: conic-gradient( #FF6B6B, #FFC93C, #6BCB77, #4D96FF, #9B59B6, #E056FD, #FF6B6B ); animation: rotate 10s linear infinite; z-index: -1; } @keyframes rotate { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } .time-display { position: absolute; top: 50%; left: 15px; transform: translateY(-50%); font-size: 14px; color: #aaa; } .music-info { position: absolute; top: 50%; left: 50px; transform: translateY(-50%); display: flex; align-items: center; } .music-cover { width: 32px; height: 32px; border-radius: 4px; margin-right: 12px; } .music-title { font-size: 14px; font-weight: 600; margin-bottom: 2px; } .music-artist { font-size: 12px; color: #aaa; } </style><script> const { ipcRenderer } = require('electron'); const dynamicIsland = document.querySelector('.dynamic-island'); const minimizedContent = document.querySelector('.minimized-content'); const closeButton = document.querySelector('.close-button'); const progressRing = document.querySelector('.progress-ring-circle'); const timeDisplay = document.querySelector('.time-display'); const musicCover = document.querySelector('.music-cover'); const musicTitle = document.querySelector('.music-title'); const musicArtist = document.querySelector('.music-artist'); let isExpanded = false; // Update progress ring function updateProgressRing(percentage) { const radius = progressRing.r.baseVal.value; const circumference = radius * 2 * Math.PI; const offset = circumference - (percentage / 100 * circumference); progressRing.style.strokeDasharray = `${circumference} ${circumference}`; progressRing.style.strokeDashoffset = offset; } // Receive system stats from main process ipcRenderer.on('system-stats', (event, stats) => { document.getElementById('cpuUsage').textContent = `${stats.cpu}%`; document.getElementById('memoryUsage').textContent = `${stats.memory}%`; document.getElementById('temperature').textContent = `${Math.round(stats.temp)}°C`; if (isExpanded) { updateProgressRing(stats.cpu); } }); // Receive music info from main process ipcRenderer.on('music-info', (event, info) => { musicCover.src = info.cover; musicTitle.textContent = info.title; musicArtist.textContent = info.artist; }); // Toggle expansion dynamicIsland.addEventListener('click', (e) => { if (e.target !== closeButton) { isExpanded = !isExpanded; dynamicIsland.classList.toggle('expanded'); minimizedContent.style.display = isExpanded ? 'none' : 'flex'; } }); // Close application closeButton.addEventListener('click', () => { window.close(); }); // Hover effect dynamicIsland.addEventListener('mouseenter', () => { dynamicIsland.style.width = '105px'; dynamicIsland.style.height = '40px'; }); dynamicIsland.addEventListener('mouseleave', () => { if (!isExpanded) { dynamicIsland.style.width = '95px'; dynamicIsland.style.height = '35px'; } }); // Simulate notifications function simulateNotification() { if (!isExpanded) { dynamicIsland.style.width = '120px'; setTimeout(() => { if (!isExpanded) { dynamicIsland.style.width = '95px'; } }, 1500); } } setInterval(simulateNotification, 5000); // Update time display function updateTimeDisplay() { const currentTime = new Date(); const hours = currentTime.getHours(); const minutes = currentTime.getMinutes(); const ampm = hours >= 12 ? 'PM' : 'AM'; timeDisplay.textContent = `${hours % 12 || 12}:${minutes.toString().padStart(2, '0')} ${ampm}`; } setInterval(updateTimeDisplay, 1000); </script> - Assistant
To address your issues:
-
Colorful Border Not Displaying Correctly: The colorful border is not appearing as expected because of the
z-indexand the layering of elements. Also, thez-index: -1places the.color-ringbehind everything, including the window background. We need to adjust the HTML structure and CSS to make the colorful border appear correctly around the dynamic island. -
Automatic Hover Effect: The
simulateNotificationfunction is causing the dynamic island to expand automatically every 5 seconds. We need to remove this function to stop the automatic expansion. Additionally, we need to adjust the hover behavior so that the dynamic island expands fully when hovered over, and when clicked, it remains expanded showing the full content.
1. Fixing the Colorful Border
Adjust the HTML Structure:
Wrap the existing content inside a new div
.dynamic-island-contentand move.color-ringinside.dynamic-islandbut before.dynamic-island-content:<div class="dynamic-island"> <div class="color-ring"></div> <div class="dynamic-island-content"> <!-- All existing content including minimizedContent, island-camera, island-content, and close-button --> <div class="minimized-content"> <!-- ... --> </div> <div class="island-camera"></div> <div class="island-content"> <!-- ... --> </div> <div class="close-button">×</div> </div> </div>Update the CSS:
.dynamic-island { position: relative; width: 95px; height: 35px; border-radius: 30px; cursor: pointer; overflow: hidden; z-index: 1; -webkit-app-region: drag; } .dynamic-island-content { background: #000; width: 100%; height: 100%; border-radius: inherit; position: relative; z-index: 2; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3); transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); } .color-ring { position: absolute; top: -4px; left: -4px; width: calc(100% + 8px); height: calc(100% + 8px); border-radius: inherit; background: conic-gradient(#FF6B6B, #FFC93C, #6BCB77, #4D96FF, #9B59B6, #E056FD, #FF6B6B); animation: rotate 10s linear infinite; z-index: 1; } @keyframes rotate { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }This changes ensure that:
- The
.color-ringacts as a border behind the dynamic island content. - We use
position: relativeon.dynamic-islandto correctly position child elements. - The
z-indexis set so that.color-ringis behind.dynamic-island-contentbut above the window background. overflow: hiddenon.dynamic-islandensures that the border doesn't overflow its rounded corners.
2. Adjusting Hover and Click Behavior
Remove Automatic Expansion:
In your script, remove or comment out the
simulateNotificationfunction and thesetIntervalcall:// Remove this function // function simulateNotification() { // if (!isExpanded) { // dynamicIsland.style.width = '120px'; // setTimeout(() => { // if (!isExpanded) { // dynamicIsland.style.width = '95px'; // } // }, 1500); // } // } // Remove this interval // setInterval(simulateNotification, 5000);Adjust Hover Behavior:
Modify the hover event listeners to expand the dynamic island fully on hover:
dynamicIsland.addEventListener('mouseenter', () => { if (!isExpanded) { dynamicIsland.classList.add('hovered'); minimizedContent.style.display = 'none'; } }); dynamicIsland.addEventListener('mouseleave', () => { if (!isExpanded) { dynamicIsland.classList.remove('hovered'); minimizedContent.style.display = 'flex'; } });Update CSS for Hover State:
Add styles for the
hoveredstate:.dynamic-island.hovered .dynamic-island-content { width: 380px; height: 180px; border-radius: 30px; } .dynamic-island.hovered { width: 380px; height: 180px; } .dynamic-island-content { transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); } .minimized-content { transition: opacity 0.3s ease-in-out; }Adjust Click Behavior:
Ensure that when the dynamic island is clicked, it remains expanded:
dynamicIsland.addEventListener('click', (e) => { if (e.target !== closeButton) { isExpanded = !isExpanded; if (isExpanded) { dynamicIsland.classList.add('expanded'); } else { dynamicIsland.classList.remove('expanded'); // Reset to hover state if still hovered if (dynamicIsland.matches(':hover')) { dynamicIsland.classList.add('hovered'); } } } });Update CSS for Expanded State:
.dynamic-island.expanded .dynamic-island-content { width: 380px; height: 180px; border-radius: 15px; /* More rectangular with rounded corners */ } .dynamic-island.expanded { width: 380px; height: 180px; } .dynamic-island-content { /* Ensure smooth transition */ transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); }Remove Unwanted Hover Effects:
Since the original hover effect caused slight changes, remove or adjust this part in your CSS:
/* Remove these if not needed */ dynamicIsland.addEventListener('mouseenter', () => { dynamicIsland.style.width = '105px'; dynamicIsland.style.height = '40px'; }); dynamicIsland.addEventListener('mouseleave', () => { if (!isExpanded) { dynamicIsland.style.width = '95px'; dynamicIsland.style.height = '35px'; } });
Final Adjustments
With these changes:
- The dynamic island will not automatically expand every few seconds.
- It will expand fully when you hover over it.
- When you click on it, it will remain expanded, showing the full content inside a rectangular box with rounded corners.
- The colorful border will display correctly around the dynamic island, with the colors constantly changing due to the rotating conic gradient.
Important Note: Ensure that you have the
position,z-index, andoverflowproperties set correctly in your CSS, as they are crucial for the layering and visibility of elements.
Updated Code Snippets
index.html (Adjusted Parts Only):
<div class="dynamic-island"> <div class="color-ring"></div> <div class="dynamic-island-content"> <div class="minimized-content"> <!-- ... --> </div> <div class="island-camera"></div> <div class="island-content"> <!-- ... --> </div> <div class="close-button">×</div> </div> </div> <script> const { ipcRenderer } = require('electron'); const dynamicIsland = document.querySelector('.dynamic-island'); const dynamicIslandContent = document.querySelector('.dynamic-island-content'); const minimizedContent = document.querySelector('.minimized-content'); const closeButton = document.querySelector('.close-button'); // ... rest of your script // Remove simulateNotification function and its setInterval call // Adjust hover and click event listeners as shown above // Remove or adjust hover effect code that causes automatic expansion </script>style.css (Adjusted Parts Only):
.dynamic-island { position: relative; width: 95px; height: 35px; border-radius: 30px; cursor: pointer; overflow: hidden; z-index: 1; -webkit-app-region: drag; } .dynamic-island-content { background: #000; width: 100%; height: 100%; border-radius: inherit; position: relative; z-index: 2; display: flex; align-items: center; justify-content: center; /* Removed box-shadow if not needed */ transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); } /* Styles for hovered and expanded states */ .dynamic-island.hovered, .dynamic-island.expanded { width: 380px; height: 180px; } .dynamic-island.hovered .dynamic-island-content, .dynamic-island.expanded .dynamic-island-content { width: 380px; height: 180px; border-radius: 30px; } .dynamic-island.expanded .dynamic-island-content { border-radius: 15px; /* More rectangular */ } .color-ring { position: absolute; top: -4px; left: -4px; width: calc(100% + 8px); height: calc(100% + 8px); border-radius: inherit; background: conic-gradient(#FF6B6B, #FFC93C, #6BCB77, #4D96FF, #9B59B6, #E056FD, #FF6B6B); animation: rotate 10s linear infinite; z-index: 1; }
By making these changes, your dynamic island should now:
- Display the colorful border correctly, with seven colors that constantly change.
- Only expand when you hover over it.
- Remain expanded when clicked, showing all the content inside a rectangular box with rounded corners.
- Not expand or hover automatically without user interaction.
Let me know if you need further assistance or if you encounter any other issues!
-