【问题标题】:Electron open new full-screen window from menubarElectron 从菜单栏打开新的全屏窗口
【发布时间】:2016-04-12 11:31:44
【问题描述】:

我有一个在菜单栏中运行的电子应用程序。

代码目前主要基于现有的番茄钟应用 (https://github.com/G07cha/pomodoro)

当计时器到达某个点时,它会打开一个消息框:

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');
    });
});

是否可以打开一个新窗口而不是消息框,并使其全屏显示?

基本上,确保用户看到它并在计时器到时填满屏幕,并允许自定义带有 css 等的页面。

【问题讨论】:

    标签: javascript node.js electron


    【解决方案1】:

    这取决于您是要从现有渲染器中触发新渲染器,还是要从主进程中启动它。

    无论哪种方式,它都像创建一个新的BrowserWindow 实例并将一个 URL 加载到您要加载的 HTMl 文件一样简单。

    如果您想从现有的渲染器中启动渲染器,您需要首先需要 remote 模块。这是一个例子:

    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;
    });
    

    如果您是从主进程执行此操作,则将 const remote = require('remote'); 替换为:

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

    【讨论】:

    • 这对我不起作用。我找不到任何示例,它在菜单栏应用程序未激活时打开一个新窗口,仅在应用程序处于活动状态时打开新窗口
    • 您需要运行某种进程才能使计时器运行。您可以在不打开窗口的情况下运行主进程,然后在计时器准备好时打开一个窗口。
    猜你喜欢
    • 2012-05-05
    • 2019-04-22
    • 2012-06-09
    • 2018-02-13
    • 2018-01-23
    • 2020-08-12
    • 1970-01-01
    • 2017-02-17
    • 1970-01-01
    相关资源
    最近更新 更多