Skip to content

Commit

Permalink
Relaunch the app when the icon is clicked on Mac
Browse files Browse the repository at this point in the history
On macOS, if an app is not fully closed, it is expected to open again
when the icon is clicked.
  • Loading branch information
hackjutsu committed Jan 19, 2017
1 parent e179d01 commit 66cd01f
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,40 @@ initGlobalLogger()

let mainWindow = null

app.on('ready', () => {
function createWindow () {
mainWindow = new BrowserWindow({
width: 1000,
height: 700,
minWidth: 1000,
minHeight: 700,
titleBarStyle: 'hidden'
width: 1000,
height: 700,
minWidth: 1000,
minHeight: 700,
titleBarStyle: 'hidden'
})
mainWindow.loadURL(`file://${__dirname}/index.html`)
setUpApplicationMenu()
// mainWindow.webContents.openDevTools()
}

app.on('ready', createWindow)

app.on('window-all-closed', function() {
logger.info('The app window is closed')
if (process.platform !== 'darwin') app.quit()
mainWindow = null
})

app.on('before-quit', function() {

})

app.on('activate', () => {
// On macOS, if an app is not fully closed, it is expected to open again
// when the icon is clicked.
if (process.platform === 'darwin' && mainWindow === null) {
createWindow()
}
})

function setUpApplicationMenu () {
// Create the Application's main menu
let template = [{
label: "Application",
Expand All @@ -46,24 +69,7 @@ app.on('ready', () => {
]}
]
Menu.setApplicationMenu(Menu.buildFromTemplate(template))
})

app.on('window-all-closed', function() {
logger.info('The app window is closed')
// mainWindow.webContents.session.clearStorageData([
// 'appcache',
// 'cookies',
// 'indexdb',
// 'shadercache',
// 'websql',
// 'serviceworkers',
// ], () => {})
if (process.platform !== 'darwin') app.quit()
})

app.on('before-quit', function() {

})
}

function initGlobalLogger () {
logger.level = 'debug'
Expand Down

0 comments on commit 66cd01f

Please sign in to comment.