[英]How to flash messages (or pop-ups) on desktop screen at regular intervals
我正在嘗試制作一個應用程序,它通過每 15 秒在屏幕中間呈現一個小的閃爍動畫來提醒我眨眼,無論我打開什么(我有干眼症,並且在打開時眨眼不夠電腦)。 我已經在我的手機上安裝了一個類似的應用程序,但找不到桌面應用程序,所以我決定制作一個。 我正在使用 Windows 10。
我試過使用 Electron,但到目前為止只能找到 apis 來制作出現在右下角的常規 Windows 通知。
我下載了一個名為 EyeLeo 的應用程序,它的功能與我想要實現的功能類似,所以我知道這一定是可能的,盡管它每 5 分鍾只閃爍一次消息(下圖)
有人有任何想法嗎?
編輯:我無法使用警報框,因為它非常大且具有障礙性,並且據我所知不會自行消失就僅在屏幕上閃爍 html 元素(又名自定義警報)而言,我不是確定如何使它出現在我打開的任何東西上。 例如,如果我打開瀏覽器並將應用程序置於后台,如何使元素出現在我的瀏覽器窗口上? 這就是困難
您可以為此設置異步間隔:
// Define the notification function :
function blink() {
// Either add an html message in your page or just alert a message
// alert("Blink");
// Create a div for the blink-message (with absolute position at top)
var alertBox = document.createElement('div');
alertBox.innerText = "Reminder: Please Blink";
alertBox.style.zIndex = "99999";
alertBox.style.position = "fixed";
alertBox.style.width = "100%";
alertBox.style.top = "0px";
//alertBox.style.left = "1%";
alertBox.style.padding = "5px";
alertBox.style.background = "#242424";
alertBox.style.color = "white";
alertBox.style.border = "1px solid white";
alertBox.style.boxShadow = "5px 5px 5px 5px rgb(0,0,0,0.2)";
// Append this div to the document body
document.body.appendChild(alertBox);
// Remove the notification msg after 2 sec
setTimeout( function(){ document.body.removeChild(alertBox); }, 2000);
}
// Set an interval to alert every 10 seconds:
var blinkInterval = setInterval( blink, 10000);
// To unset the interval, use clearInterval :
clearInterval(blinkInterval);
您可以使用帶有超時和間隔的 Electronjs,就像這樣
const { app, BrowserWindow } = require('electron')
app.whenReady().then(() => {
const win = new BrowserWindow({
width: 300,
height: 220,
frame: false,
show: false
})
win.once('ready-to-show', () => {
setInterval(() => win.show(), 15000) // 15s for show
})
win.on('show', () => {
setTimeout(() => win.hide(), 3000) // 3s for hide
})
win.loadFile('index.html')
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.