常识 共享 合作 bodog官网

    bodog官网专心于网页资料下载,供给博狗博彩、网页规划、ps资料、图片资料等,服务于【个人站长】【网页规划师】和【web开发从业者】的代码资料与规划资料网站。

    bodog官网供给网页资料下载、博狗博彩
    常识 共享 合作!

    electron程序显现在右下角托盘

    作者:佳明妈 来历:云核算 2017-10-28 人气:
    electron程序显现在右下角托盘的办法,运用electron完成将使用程序参加体系托盘demo,完好demo演示

    electron程序显现在右下角托盘的办法,运用electron完成将使用程序参加体系托盘demo

    一、将使用程序参加体系托盘

    回到正文, 微信发动时,体系托盘中会自动增加一个微信发动程序图标运用electron怎么完成这种效果昵?

    以下是运用electron完成将使用程序参加体系托盘demo

    //electron
    const electron = require('electron');
    const app = electron.app;
    
    const path = require('path');
    
    //用一个 Tray 来表明一个图标,这个图标处于正在运转的体系的告诉区 ,通常被增加到一个 context menu 上.
    const Menu = electron.Menu;
    const Tray = electron.Tray;
    
    //托盘目标
    var appTray = null;
    
    function createWindow() {
        // Create the browser window.
        mainWindow = new BrowserWindow({
            width: 1000,
            height: 600,
            resizable: true,
            title: '将使用程序增加至体系托盘',
            skipTaskbar:false
        })
        //体系托盘右键菜单
        var trayMenuTemplate = [
            {
                label: '设置',
                click: function () {} //翻开相应页面
            },
             {
                label: '定见反应',
                click: function () {}
            },
            {
                label: '协助',
                click: function () {}
            },
            {
                label: '关于微信',
                click: function () {}
            },
            {
                label: '退出微信',
                click: function () {
                    //ipc.send('close-main-window');
                     app.quit();
                }
            }
        ];
    
        //体系托盘图标目录
        trayIcon = path.join(__dirname, 'tray');
    
        appTray = new Tray(path.join(trayIcon, 'app.ico'));
    
        //图标的上下文菜单
        const contextMenu = Menu.buildFromTemplate(trayMenuTemplate);
    
        //设置此托盘图标的悬停提示内容
        appTray.setToolTip('This is my application.');
    
        //设置此图标的上下文菜单
        appTray.setContextMenu(contextMenu);
    }
    
    // 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.on('ready', createWindow);
    
    
    // Quit when all windows are closed.
    app.on('window-all-closed', function() {
        // On OS X 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()
        }
    })
    

    二、体系托盘程序右键菜单

    便是过程一声明 trayMenuTemplate 目标,参加托盘上下文菜单 //设置此图标的上下文菜单 appTray.setContextMenu(contextMenu); 即可,

    而进入右键菜单相应页面就要触及主线程与烘托线程交互.对线程不了解的可参阅之前写的博客主线程与烘托线程之间通讯

    三、托盘来电音讯的闪耀

    像微信相同,推送一条未读新音讯闪耀,其原理不同时间图标切换,一张通明与不通明图标切换。

    //体系托盘图标闪耀
    var count = 0,timer = null;
        timer=setInterval(function() {
            count++;
            if (count%2 == 0) {
                tray.setImage(path.join(trayIcon, 'app.ico'))
            } else {
                tray.setImage(path.join(trayIcon, 'appa.ico'))
            }
        }, 600);
    
        //单点击 1.主窗口显现躲藏切换 2.铲除闪耀
        tray.on("click", function(){
            if(!!timer){
                tray.setImage(path.join(appTray, 'app.ico'))
                //主窗口显现躲藏切换
                mainWindow.isVisible() ? mainWindow.hide() : mainWindow.show();
            }
    })
    

    四、参加未读的音频

    若对方发送一条未读音讯,提示用户滴滴滴声响

    //playAudio
    function playAudio(){
        var audio = new Audio(__dirname + '/tray/app.wav');
        audio.play();
        setTimeout(function(){
            console.log("暂停播映....");
            audio.pause();// 暂停
        }, 800)
    }
    playAudio();
    

    完好代码demo

    //electron
    const electron = require('electron');
    const app = electron.app;
    
    const path = require('path');
    
    //用一个 Tray 来表明一个图标,这个图标处于正在运转的体系的告诉区 ,通常被增加到一个 context menu 上.
    const Menu = electron.Menu;
    const Tray = electron.Tray;
    
    //托盘目标
    var appTray = null;
    
    //createWindow
    function createWindow() {
        // Create the browser window.
        mainWindow = new BrowserWindow({
            width: 1000,
            height: 600,
            resizable: true,
            title: '将使用程序增加至体系托盘',
            skipTaskbar:false
        })
        //体系托盘右键菜单
        var trayMenuTemplate = [
            {
                label: '设置',
                click: function () {} //翻开相应页面
            },
             {
                label: '定见反应',
                click: function () {}
            },
            {
                label: '协助',
                click: function () {}
            },
            {
                label: '关于微信',
                click: function () {}
            },
            {
                label: '退出微信',
                click: function () {
                    //ipc.send('close-main-window');
                     app.quit();
                }
            }
        ];
    
        //体系托盘图标目录
        trayIcon = path.join(__dirname, 'tray');
        appTray = new Tray(path.join(trayIcon, 'app.ico'));
        //图标的上下文菜单
        const contextMenu = Menu.buildFromTemplate(trayMenuTemplate);
        //设置此托盘图标的悬停提示内容
        appTray.setToolTip('This is my application.');
        //设置此图标的上下文菜单
        appTray.setContextMenu(contextMenu);
    
    
    
        //体系托盘图标闪耀
        var count = 0,timer = null;
        timer=setInterval(function() {
            count++;
            if (count%2 == 0) {
                tray.setImage(path.join(trayIcon, 'app.ico'))
            } else {
                tray.setImage(path.join(trayIcon, 'appa.ico'))
            }
        }, 600);
    
        //单点击 1.主窗口显现躲藏切换 2.铲除闪耀
        tray.on("click", function(){
            if(!!timer){
                tray.setImage(path.join(appTray, 'app.ico'))
                //主窗口显现躲藏切换
                mainWindow.isVisible() ? mainWindow.hide() : mainWindow.show();
            }
        })
    }
    // 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.on('ready', createWindow);
    
    // Quit when all windows are closed.
    app.on('window-all-closed', function() {
        // On OS X 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()
        }
    })
    

    转载:http://www.cnblogs.com/zjf-1992/p/7534944.html?utm_medium=referral&utm_source=debugrun
    QQ登录框的比如:http://www.cnblogs.com/Starts_2000/p/electron-qqlogin-demo.html

    ↓ 检查全文

    electron程序显现在右下角托盘由bodog官网收集整理,您能够自在传达,请自动带上本文链接

    bodog官网便是免费共享,觉得有用就多来支撑一下,没有能帮到您,懒人也只能表明遗憾,期望有一天能帮到您。

    electron程序显现在右下角托盘-最新谈论