zoukankan      html  css  js  c++  java
  • 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;
  • 相关阅读:
    经济--股票--深圳指数基金
    经济--年终奖理财攻略
    经济--股票--基金经理打死不肯说的赚钱黑幕
    经济--股票--基金定投
    经济--股票--基金分类的三个角度
    经济学--股票--必胜法则
    经济--降息对股市是好消息还是坏消息?
    PHP数组的排序函数
    使用回调函数处理数组的函数
    统计数组元素的个数和唯一性的函数
  • 原文地址:https://www.cnblogs.com/sxz2008/p/6767746.html
Copyright © 2011-2022 走看看