1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2025-02-10 00:30:39 +01:00

Merge pull request #446 from h3poteto/iss-377

closes #377 Hide and show application in mac
This commit is contained in:
AkiraFukushima 2018-07-21 14:36:08 +09:00 committed by GitHub
commit 9f5db01ca8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -76,23 +76,62 @@ async function listAccounts () {
} }
} }
function createWindow () { async function changeAccount (account, index) {
// In MacOS, user can hide the window.
// In this time, mainWindow in not exist, so we have to create window.
if (mainWindow === null) {
await createWindow()
// We have to wait the web contents is loaded.
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.webContents.send('change-account', Object.assign(account, { index: index }))
})
} else {
mainWindow.webContents.send('change-account', Object.assign(account, { index: index }))
}
}
async function createWindow () {
/** /**
* List accounts * List accounts
*/ */
listAccounts() const accounts = await listAccounts()
.then((accounts) => {
const accountsChange = accounts.map((a, index) => { const accountsChange = accounts.map((a, index) => {
return { return {
label: a.domain, label: a.domain,
accelerator: `CmdOrCtrl+${index + 1}`, accelerator: `CmdOrCtrl+${index + 1}`,
click: () => { click: () => changeAccount(a, index)
mainWindow.webContents.send('change-account', Object.assign(a, { index: index }))
}
} }
}) })
/** /**
* Set menu * For mac menu
*/
const macGeneralMenu = process.platform !== 'darwin' ? [] : [
{
type: 'separator'
},
{
label: 'Services',
role: 'services',
submenu: []
},
{
type: 'separator'
},
{
label: 'Hide Whalebird',
role: 'hide'
},
{
label: 'Hide Othres',
role: 'hideothers'
},
{
label: 'Show All',
role: 'unhide'
}
]
/**
* Set application menu
*/ */
const template = [ const template = [
{ {
@ -120,6 +159,7 @@ function createWindow () {
mainWindow.webContents.send('open-preferences') mainWindow.webContents.send('open-preferences')
} }
}, },
...macGeneralMenu,
{ {
type: 'separator' type: 'separator'
}, },
@ -180,6 +220,15 @@ function createWindow () {
} }
] ]
}, },
{
label: 'View',
submenu: [
{
label: 'Toggle Full Screen',
role: 'togglefullscreen'
}
]
},
{ {
label: 'Window', label: 'Window',
submenu: [ submenu: [
@ -213,6 +262,14 @@ function createWindow () {
const menu = Menu.buildFromTemplate(template) const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu) Menu.setApplicationMenu(menu)
/**
* Set dock menu for mac
*/
if (process.platform === 'darwin') {
const dockMenu = Menu.buildFromTemplate(accountsChange)
app.dock.setMenu(dockMenu)
}
/** /**
* Initial window options * Initial window options
*/ */
@ -238,7 +295,6 @@ function createWindow () {
mainWindow.on('closed', () => { mainWindow.on('closed', () => {
mainWindow = null mainWindow = null
}) })
})
} }
// Do not lower the rendering priority of Chromium when background // Do not lower the rendering priority of Chromium when background
@ -247,12 +303,11 @@ app.commandLine.appendSwitch('disable-renderer-backgrounding')
app.on('ready', createWindow) app.on('ready', createWindow)
app.on('window-all-closed', () => { app.on('window-all-closed', () => {
// this action is called when user click the close button.
// In macOS, close button does not shutdown application. It is hide application window.
if (process.platform !== 'darwin') {
app.quit() app.quit()
// This is a single-window application. }
// So quit application when main window is closed.
// if (process.platform !== 'darwin') {
// app.quit()
// }
}) })
app.on('activate', () => { app.on('activate', () => {