• electron 的窗口设置最大化 最小化


    /**
     * Created by Administrator on 2016/11/23.
     * 页面对窗口的一些操作封装,用于渲染进程
     */
    "use strict";
    
    const Common = require('../../window/common.js');
    const { ipcRenderer, remote } = require('electron');
    const WinReg = require('winreg');
    const RUN_LOCATION = '\Software\Microsoft\Windows\CurrentVersion\Run';
    const file = process.execPath;
    
    let flashTrayTimer = null;
    
    class WindowUtil{
        // 窗口最小化
        static minWindow() {
            remote.getCurrentWindow().minimize();
        }
        // 窗口最大化
        static maxWindow(isMaxed) {
            const browserWindow = remote.getCurrentWindow();
            if(!isMaxed) {
                browserWindow.unmaximize();
            } else {
                browserWindow.maximize();
            }
        }
        // 设置窗口是否能改变大小,参数true/false
        static setResizable(resizable) {
            remote.getCurrentWindow().setResizable(resizable);
        }
        // 下载文件
        static download(url){
            remote.getCurrentWebContents().downloadURL(url);
        }
    
        // 隐藏窗口
        static hide(){
            const browserWindow = remote.getCurrentWindow();
            browserWindow.hide();
        }
    
        // 显示窗口
        static show(){
            const browserWindow = remote.getCurrentWindow();
            browserWindow.show();
        }
        // 窗口闪烁
        static flashFrame(){
            const browserWindow = remote.getCurrentWindow();
         //   if(browserWindow.isFocused() || browserWindow.isVisible())
            if(!browserWindow.isFocused()) {
                browserWindow.showInactive();
                browserWindow.flashFrame(true);
            }
        }
        // 设置窗口最前端显示
        static setAlwaysOnTop(top){
            const browserWindow = remote.getCurrentWindow();
            browserWindow.setAlwaysOnTop(top);
        }
    
        // 设置开机启动
        static enableAutoStart(callback) {
            let key = new WinReg({hive: WinReg.HKCU, key: RUN_LOCATION});
            key.set('EUC', WinReg.REG_SZ, file, (err)=> {
                console.log('设置自动启动'+err);
                callback(err);
            });
        }
        // 取消开机启动
        static disableAutoStart(callback) {
            let key = new WinReg({hive: WinReg.HKCU, key: RUN_LOCATION});
            key.remove('EUC',  (err)=>{
                console.log('取消自动启动'+err);
                callback(err);
            });
        }
        // 获取是否开机启动
        static getAutoStartValue(callback) {
            let key = new WinReg({hive: WinReg.HKCU, key: RUN_LOCATION});
            key.get('EUC', function (error, result) {
                console.log("查询自动启动:"+JSON.stringify(result));
                console.log("file:"+file);
                if (result) {
                    callback(true);
                }
                else {
                    callback(false);
                }
            });
        }
    
        /**
         * 托盘图标闪烁
         * @param flash true:闪烁;false:停止
         */
        static flashTray(flash) {
            let hasIcon = false;
            const tayIcon = './imgs/logo.ico';
            const tayIcon1 = './imgs/empty.png';
            if (flash) {
                if (flashTrayTimer) {
                    return;
                }
                flashTrayTimer = window.setInterval(() => {
                    ipcRenderer.send('ChangeTrayIcon', hasIcon ? tayIcon : tayIcon1);
                    hasIcon = !hasIcon;
                }, 500);
            } else {
                if(flashTrayTimer) {
                    window.clearInterval(flashTrayTimer);
                    flashTrayTimer = null;
                }
                ipcRenderer.send('ChangeTrayIcon', tayIcon);
            }
        }
    
    
    }
    module.exports = WindowUtil;
  • 相关阅读:
    C++顺序性容器、关联性容器与容器适配器
    Groovy与Java集成常见的坑--转
    selenium打开chrome浏览器代码
    分组密码的工作模式--wiki
    linux下C语言多线程编程实例
    C语言多线程pthread库相关函数说明
    C语言使用pthread多线程编程(windows系统)二
    C语言使用pthread多线程编程(windows系统)一
    使用_beginThreadex创建多线程(C语言版多线程)
    浅谈C语言中的联合体
  • 原文地址:https://www.cnblogs.com/sxz2008/p/6767746.html
Copyright © 2020-2023  润新知