简体   繁体   English

电子从菜单栏打开新的全屏窗口

[英]Electron open new full-screen window from menubar

I have an electron app that runs in the menubar. 我有一个在菜单栏中运行的电子应用程序。

Code is currently heavily based on an existing pomodoro app ( https://github.com/G07cha/pomodoro ) 当前代码主要基于现有的pomodoro应用( https://github.com/G07cha/pomodoro

When the timer hits a certain point, it opens up a message box: 当计时器达到某个点时,它将打开一个消息框:

ipc.on('end-timer', function() {
    $('.timer').circleProgress('value', 1);

    var isRelaxTime = remote.getGlobal('isRelaxTime');

    dialog.showMessageBox({
        type: 'info',
        title: 'Pomodoro',
        message: (isRelaxTime) ? 'Timer ended it\'s time to relax' : 'Back to work',
        buttons: ['OK'],
        noLink: true
    }, function() {
        if(isRelaxTime) {
            $('.timer').circleProgress({fill: { gradient: ["blue", "skyblue"]}});
        } else {
            $('#counter').text(remote.getGlobal('pomodoroCount'));
            $('.timer').circleProgress({fill: { gradient: ["orange", "yellow"]}});
        }

        ipc.send('start-timer');
    });
});

Is it possible to open a new window instead of the message box, and make it full screen? 是否可以打开新窗口而不是消息框,并使其全屏显示?

Basically, making sure the user sees it and it fills the screen when the timer is up and allowing customization of the page that comes up with css and such. 基本上,确保用户看到它并在计时器启动时将其填满屏幕,并允许自定义css等附带的页面。

It depends if you want to fire a new renderer from an existing renderer or if you want to spin it up from the Main Process. 这取决于您是要从现有渲染器中启动新渲染器,还是要从“主进程”中启动它。

Either way its as easy as creating a new BrowserWindow instance and loading a URL to an HTMl file you want to load. 无论哪种方式,它都像创建一个新的BrowserWindow实例并将URL加载到要加载的HTMl文件一样容易。

If you want to spin up a renderer from an existing renderer you will need to require the remote module first. 如果要从现有渲染器启动渲染器,则需要首先需要remote模块。 Here is an example: 这是一个例子:

const remote = require('remote');

// create a new BrowserWindow and pass it an object of options
var msgWindow = new remote.BrowserWindow({
  // full width & height of monitor without going into kiosk mode
  width: remote.screen.getPrimaryDisplay().size.width, 
  height: remote.screen.getPrimaryDisplay().size.height
  //, other options
});

// load your message file into new browserwindow
msgWindow.loadURL('file://' + __dirname + '/index.html');

// set variable to null when window is closed to clean it up
msgWindow.on('close', () => {
  msgWindow = null;
});

If you did this from the the Main Process, then replace const remote = require('remote'); 如果您是从Main Process上完成的,则替换const remote = require('remote'); with: 与:

const electron = require('electron');
const BrowserWindow = electron.BrowserWindow;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM