2017-10-06 65 views
1

我对电子很陌生,但喜欢它。但是,我坚持一件事,所以如果可能的话,在一些指导后。改变电子的窗口大小

我有一个小测试应用程序,我将用于用户登录到一个页面。

在我main.js文件I设置主窗口的属性如下:

function createWindow() { 

    mainWindow = new BrowserWindow({frame:false, 
    width: 1024, 
    height: 565, 
    minWidth: 1024, 
    minHeight: 565, 
    frame: false, 
    resizable: false, 
    show: false, 
    center: true, 
    backgroundColor: '#312450', 
    icon: path.join(__dirname, 'assets/icons/png/64x64.png') 
    }) 

    mainWindow.loadURL(`file://${__dirname}/login.html`) 

    mainWindow.once('ready-to-show',() => { 
     mainWindow.show() 
    }) 

    //mainWindow.webContents.openDevTools({detach: true}) 

    mainWindow.on('closed', function() { 
     mainWindow = null 
    }) 
    } 

然后在app.on事件启动此。

到目前为止,这一切都很好。

我也是在login.html的页面添加事件监听到一个按钮,如下所示:

btnSignIn.addEventListener('click', function(){ 

const email = txtEmail.value; 
const pass = txtPassword.value; 

firebase.auth().signInWithEmailAndPassword(email, pass).then(function(){ 
    document.location.href = 'loggedin.html'; 
}).catch(function(error){ 
    if(error != null){ 
     alert(error.message); 
     return; 
    } 
}) 

},false); 

这是所有工作得很好。我唯一的问题是,我想第二页(loggedin.html)是不同的大小。

我想我必须改变以前指定的主窗口选项,但我无法达到它。

任何指针非常感谢。

问候

Ĵ

回答

1

在您的渲染过程(从login.html加载JS脚本),你应该能够加载电子和节点模块。

const {ipcRenderer} = require('electron'); 

// Right after the line where you changed the document.location 
ipcRenderer.send('resize-me-please') 

main.js

const {ipcMain} = require('electron') 
ipcMain.on('resize-me-please', (event, arg) => { 
    mainWindow.setSize(width,height) 
}) 
+0

完美工作 - 感谢莱昂纳多,ilearn的东西,每天新!!。 – user1176737

+0

嗨,莱昂纳多,如果我可以的话,只需再提一个问题。在main.js中,我将mainWindow的选项中心设置为true,这很好。但是,当我启动调整大小的第二个窗口 - 它是偏旁(我认为这是主窗口居中。是否有一个简单的方法让它centerreed屏幕不是主窗口?Jason – user1176737

+1

大家好,不用担心,找到了window.center()。谢谢大家 – user1176737