2017-10-06 101 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