electron消息提醒图标闪烁效果实现

// Modules to control application life and create native browser window
const {
     app, BrowserWindow, globalShortcut, ipcMain, ipcRenderer, Menu, Tray} = require('electron')
const path = require('path')
let mainWindow = null;
let appIcon = null;
	function createWindow() {
     
		mainWindow = new BrowserWindow({
     
			minWidth: 1200,
			minHeight: 750,
			resizable: true,
			icon: 'favicon.ico',
			skipTaskbar: false
		});
		// 开始或停止显示窗口来获得用户的关注
		mainWindow.flashFrame(true);

		let appIcon = new Tray('favicon.ico');

		const contextMenu = Menu.buildFromTemplate([{
     
			label: '移除',
			click: function() {
     
				event.sender.send('tray-removed');
			}
		}, {
     
			type: 'separator'
		}, {
     
			label: 'Item1',
			type: 'radio'
		}, {
     
			type: 'separator'
		},{
     
			label: 'MenuItem2',
			type: 'checkbox',
			checked: true
		}]);

		// Make a change to the context menu
		contextMenu.items[2].checked = false;

		appIcon.setToolTip('在托盘中的 Electron 示例.');

		appIcon.setContextMenu(contextMenu);
		var count = 0;
		let interv = setInterval(function() {
     
			if (count++ % 2 == 0) {
     
				appIcon.setImage(path.join(__dirname, 'favicon.ico'));
			} else {
     
				appIcon.setImage(path.join(__dirname, 'logo_wikiwhite.png'));
			}
		}, 400);
		clearInterval(interv);
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.allowRendererProcessReuse = false;
app.disableHardwareAcceleration()
app.whenReady().then(createWindow)

// Quit when all windows are closed.
app.on('window-all-closed', function () {
     
	// On macOS it is common for applications and their menu bar
	// to stay active until the user quits explicitly with Cmd + Q
	if (process.platform !== 'darwin') app.quit()
})

app.on('activate', function () {
     
	// On macOS it's common to re-create a window in the app when the
	// dock icon is clicked and there are no other windows open.
	if (BrowserWindow.getAllWindows().length === 0) createWindow()
})

你可能感兴趣的:(js,electron,消息提醒,闪烁效果,javascript)