【问题标题】:New electron BrowserWindow starting at specified ui-router state新的电子浏览器窗口从指定的 ui-router 状态开始
【发布时间】:2016-12-20 08:55:36
【问题描述】:

是否可以在指定的ui-router 状态下创建新的BrowserWindow?这是我的main.js

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

感谢阅读。

【问题讨论】:

    标签: javascript angularjs angular-ui-router electron


    【解决方案1】:

    您是否尝试仅使用哈希后的状态设置 url:

    win.loadURL(`file://${__dirname}/index.html#/page`)
    

    假设你有一个使用 url 配置的 ui-router 状态:

    "url":"/page"
    

    【讨论】:

    • 谢谢,因为州名等于他们的网址,这个解决方案对我的应用程序来说已经足够了。我在createWindow() 中添加了stateUrl 作为参数。
    猜你喜欢
    • 2011-05-03
    • 2011-02-18
    • 2020-05-11
    • 2018-05-20
    • 1970-01-01
    • 1970-01-01
    • 2021-03-24
    • 2018-07-28
    • 1970-01-01
    相关资源
    最近更新 更多