• 【electron系列之一】创建右下角通知栏小图标


    electron 用Tray对象来实现右下角通知栏小图标

    一、先引入app, BrowserWindow来实现浏览器功能,接着引入Tray, Menu来实现右下角

    二、

    new Tray('./page/images/icon.ico')
    const {app, BrowserWindow, Tray, Menu} = require('electron')
    
    app.on('ready', () => {
    
    	application.createWindow()
    	// 拖盘图标
    	application.initTrayIcon()
    	
    
    }
    
    application = {
    	
        createWindow() {
    
    		uiWin = new BrowserWindow({
    			 1230,
    			height: 830,
    			autoHideMenuBar: true,  // 自动隐藏菜单栏, 除非按了Alt键
    			// skipTaskbar: true    // 不显示在任务栏
    		})
    		uiWin.once('focus', () => uiWin.flashFrame(false))
    		uiWin.loadURL(path.join(__dirname, 'page/login.html'))
    		uiWin.webContents.openDevTools()
    		uiWin.on('closed', () => {
    			uiWin = null
    		})
    		
    	},
    
        initTrayIcon() {
            
            const tray = new Tray('./page/images/icon.ico');
            const trayContextMenu = Menu.buildFromTemplate([
                {
                    label: '打开',
                    click: () => {
                        this.showAndFocusWindow();
                    }
                }, {
                    label: '退出',
                    click: () => {
                        uiWin.webContents.send(remote.app.quit, 'quit');
                    }
                }
            ]);
            tray.setToolTip('IM云通信');
    
            tray.on('click', () => {
                this.showAndFocusWindow();
            });
            tray.on('right-click', () => {
                tray.popUpContextMenu(trayContextMenu);
            });
    
        },
    

      

    Tray资料:https://github.com/electron/electron/blob/master/docs/api/tray.md

  • 相关阅读:
    搜索专题
    KMP专题
    CSU 1326: The contest(分组背包)
    强连通专题
    MST:Bad Cowtractors(POJ 2377)
    MST:Agri-Net(POJ 1258)
    ShortestPath:Layout(POJ 3169)(差分约束的应用)
    MST:Conscription(POJ 3723)
    MST:Roadblocks(POJ 3255)
    DP:Space Elevator(POJ 2392)
  • 原文地址:https://www.cnblogs.com/iloveyou-sky/p/8110061.html
Copyright © 2020-2023  润新知