/**
* 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;

electron 的窗口设置最大化 最小化的更多相关文章

  1. Qt 窗口操作函数(置顶、全屏,最大化最小化按钮设置等)

    一.窗口置顶 与 取消置顶 void MainWindow::on_windowTopButton_clicked() { if (m_flags == NULL) { m_flags = windo ...

  2. Electron 无边框窗口最大化最小化关闭功能

    Electron 无边框窗口最大化最小化关闭功能 目的 实现无边框窗口,并添加最大化最小化和关闭功能 前提 了解Electron 主进程和渲染进程的通讯 了解 BrowserWindow相关功能 操作 ...

  3. Q窗口操作函数(窗口最大化,全屏,隐藏最大化最小化按钮)

    //Qt主窗口没有最小化,最大化按钮且最大化显示  int main(int argc, char *argv[]) { QApplication a(argc, argv); TestQtForWi ...

  4. C#winform如何主窗口最大化最小化默认大小

    this.WindowState = FormWindowState.Minimized; bool b = true; private void button2_Click(object sende ...

  5. PyQt:无边框自定义标题栏及最大化最小化窗体大小调整

    环境 Python3.5.2 PyQt5 陈述 隐藏掉系统的控制栏,实现了自定义的标题控制栏,以及关闭/最大化/最小化的功能,自由调整窗体大小的功能(跟随一个大佬学的),代码内有详细注释 只要把Mai ...

  6. delphi ,1)控件根据窗口大小,一直居中显示 2)显示最大化最小化按钮控件

    一.控件根据窗口大小,一直居中显示 1)onResize:当窗体尺寸改变时发生 例子:如何使控件随窗口的放大和缩小动态改变自己的大小,使控件“保存.返回”在窗口变大变小中随着变. 在Panel调用 p ...

  7. c# 窗体相关操作(最大化/最小化/关闭/标题栏)

    /// <summary> /// 窗体跟随鼠标移动的标记 /// </summary> private bool normalmoving = false; /// < ...

  8. 【转】ubuntu 12.04 LTS将关闭最大化最小化移动到右上角

    原文网址:http://www.4byte.cn/learning/114801.html ubuntu 12.04 LTS将关闭最大化最小化移动到右上角   还是按下“ALT +F2”组合键,输入g ...

  9. C# 设置程序最小化到任务栏右下角,鼠标左键单击还原,右键提示关闭程序

    首先设置程序最小化到任务栏右下角 先给窗口添加一个notifyIcon控件 为notifyIcon控件设置ICO图标(不设置图标将无法在任务栏显示) 给notifyIcon控件添加点击事件 然后是最小 ...

随机推荐

  1. JAVA 爬虫Gecco

    主要代码: Gecco(matchUrl="https://github.com/{user}/{project}", pipelines="consolePipelin ...

  2. uniq命令 (转)

    uniq命令可以去除排序过的文件中的重复行,因此uniq经常和sort合用.也就是说,为了使uniq起作用,所有的重复行必须是相邻的. uniq语法 [root@www ~]# uniq [-icu] ...

  3. 【转】Html.RenderPartial与 Html.RenderAction的区别

    Html.RenderPartial与Html.RenderAction 这个两个方法都是用于把MVC用户控件嵌入到View中. Html.RenderPartial是直接将MVC用户控件嵌入到界面上 ...

  4. Best Time to Buy and Sell Stock I &amp;&amp; II &amp;&amp; III

    题目1:Best Time to Buy and Sell Stock Say you have an array for which the ith element is the price of ...

  5. Python之reduce

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #Python之reduce #http://python.jobbole.com/82597/ #1)red ...

  6. Windows下如何配置tomcat环境变量

    Apache Tomcat 是一款 Java Servlet 和 JavaServer Pages 技术的开源软件实现,可以作为测试 Servlet 的独立服务器,而且可以集成到 Apache Web ...

  7. VMware Player 12.5.0 中文免费版

    VMWare Player优点:– 免费的 VMWare Player 体积仅90多MB,相比7百多MB且还要付费的 VMware Workstation 无疑更适合个人用户使用– 主界面清爽简洁,几 ...

  8. 社区类 App 如何引导用户发帖和产生内容?

    作者:Pmer在路上链接:http://www.zhihu.com/question/25502904/answer/31342246来源:知乎著作权归作者所有,转载请联系作者获得授权. ugc的产出 ...

  9. 解决windows下MySQL表名大写自动变小写的问题

    解决windows下MySQL表名大写自动变小写的问题   有些人可能会遇到在windows下,表名不能用大写字母, 即使使用了大写字母的建表语句,还是会被自动转成小写.   解决方法:  打开 My ...

  10. 一个PHP操作大变量的例子

    By C extensions we can directly manipulate the large PHP variables, such as:GET,POST,SERVER You can ...