Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

Commit

Permalink
Enable creating new main windows
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Mar 29, 2018
1 parent 816f14a commit 87e7f74
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/controller/window-manager.js
Expand Up @@ -30,7 +30,7 @@ class WindowManager {
throw new Error('Can not add existing window')
this.windows.push(win)
if (process.platform !== 'darwin') {
const menubar = new AppMenu()
const menubar = new AppMenu(win)
this.menubars.push(menubar)
win.setMenuBar(menubar.menu)
}
Expand Down
6 changes: 1 addition & 5 deletions lib/main.js
Expand Up @@ -12,8 +12,4 @@ process.on('unhandledRejection', (error) => {
const configStore = require('./controller/config-store')

const MainWindow = require('./view/main-window')

const win = new MainWindow()
win.window.setContentSize({width: 850, height: 600})
win.window.center()
win.window.activate()
new MainWindow()
38 changes: 37 additions & 1 deletion lib/view/app-menu.js
Expand Up @@ -3,7 +3,7 @@ const gui = require('gui')
const accountManager = require('../controller/account-manager')

class AppMenu {
constructor() {
constructor(win) {
const menus = []

// The main menu.
Expand Down Expand Up @@ -52,6 +52,24 @@ class AppMenu {
onRemoveAccount: accountManager.onRemoveAccount.add(this.removeAccount.bind(this)),
}

// Windows menu.
menus.push({
label: 'Window',
role: 'window',
submenu: [
{
label: 'New Window',
accelerator: 'CmdOrCtrl+Shift+N',
onClick: this.newWindow.bind(this),
},
{
label: 'Close Window',
accelerator: 'CmdOrCtrl+W',
onClick: this.closeWindow.bind(this, win),
},
],
})

// Create the native menu.
this.menu = gui.MenuBar.create(menus)
}
Expand All @@ -70,6 +88,24 @@ class AppMenu {
const i = accountManager.accounts.indexOf(account)
this.accountsMenu.remove(this.accountsMenu.itemAt(i))
}

newWindow() {
const MainWindow = require('./main-window')
new MainWindow()
}

closeWindow(win) {
if (process.platform === 'darwin') {
for (const win of require('../controller/window-manager').windows) {
if (win.window.isActive()) {
win.window.close()
break
}
}
} else {
win.window.close()
}
}
}

module.exports = AppMenu
4 changes: 4 additions & 0 deletions lib/view/main-window.js
Expand Up @@ -29,6 +29,10 @@ class MainWindow {

initWithConfig(config) {
this.accountsPanel.initWithConfig(config)

this.window.setContentSize({width: 850, height: 600})
this.window.center()
this.window.activate()
}

getConfig() {
Expand Down
2 changes: 1 addition & 1 deletion scripts/start.js
Expand Up @@ -9,6 +9,6 @@ const yode = path.resolve(root, 'yode',
`yode-${version}-${process.platform}-${process.arch}`,
process.platform == 'win32' ? 'yode.exe' : 'yode')

const child = spawn(yode, [root])
const child = spawn(yode, ['--expose-gc', root])
child.stdout.pipe(process.stdout)
child.stderr.pipe(process.stderr)

0 comments on commit 87e7f74

Please sign in to comment.