1
是否可以在指定的ui-router
狀態下創建新的BrowserWindow
?這裏是我的main.js
:在指定的UI路由器狀態下啓動的新電子BrowserWindow
const {app, BrowserWindow, Menu} = require('electron')
let win
function createWindow() {
win = new BrowserWindow({ width: 950, height: 660 })
win.loadURL(`file://${__dirname}/index.html`)
// Emitted when the window is closed.
win.on('closed',() => { win = null })
app.dock.setMenu(Menu.buildFromTemplate([
{ label: 'Open at page', click:() => { goToState('page') } }
]))
}
let goToState = (state) => {
if (!win) {
createWindow()
// when win is ready, call win.webContents.send('sref', state)
} else {
win.webContents.send('sref', state)
}
}
app.on('ready', createWindow)
app.on('activate',() => {
if (win === null) {
createWindow()
}
})
的'sref'
事件執行在渲染過程中$state.go(state)
。
我已經嘗試過:
傳遞函數爲回調
createWindow()
function createWindow (callback) { ... if (callback) callback() } let goToState = (state) => { if (!win) { createWindow(() => { win.webContents.send('sref', state) }) } else { win.webContents.send('sref', state) } }
使用
app.on('web-contents-created')
let goToState = (state) => { if (!win) { createWindow() app.on('web-content-created',() => { win.webContents.send('sref', state) }) } else { win.webContents.send('sref', state) } }
感謝您的閱讀。
謝謝你,因爲國家名稱等於他們的url,這個解決方案對我的應用來說已經足夠了。我在'createWindow()'中添加了'stateUrl'作爲參數。 – xAlien95