Windowsで閉じるボタンを押した場合にはウィンドウを最小化し、終了したい場合はCtrl+Qを使用する
This commit is contained in:
31
main.js
31
main.js
@@ -3,10 +3,12 @@
|
|||||||
var app = require('app'); // Module to control application life.
|
var app = require('app'); // Module to control application life.
|
||||||
var BrowserWindow = require('browser-window'); // Module to create native browser window.
|
var BrowserWindow = require('browser-window'); // Module to create native browser window.
|
||||||
var ipc = require('ipc');
|
var ipc = require('ipc');
|
||||||
|
var Menu = require('menu');
|
||||||
|
|
||||||
// Keep a global reference of the window object, if you don't, the window will
|
// Keep a global reference of the window object, if you don't, the window will
|
||||||
// be closed automatically when the JavaScript object is garbage collected.
|
// be closed automatically when the JavaScript object is garbage collected.
|
||||||
var mainWindow = null;
|
var mainWindow = null;
|
||||||
|
var willAppQuit = false;
|
||||||
|
|
||||||
// Quit when all windows are closed.
|
// Quit when all windows are closed.
|
||||||
app.on('window-all-closed', function() {
|
app.on('window-all-closed', function() {
|
||||||
@@ -45,6 +47,35 @@ app.on('ready', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mainWindow.on('close', function(event){
|
||||||
|
// Minimize the window for close button.
|
||||||
|
if(process.platform==='win32'){
|
||||||
|
if(!willAppQuit){ // for Ctrl+Q
|
||||||
|
event.preventDefault();
|
||||||
|
mainWindow.minimize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if(process.platform==='win32'){
|
||||||
|
var menu = Menu.buildFromTemplate([
|
||||||
|
{
|
||||||
|
label: 'File',
|
||||||
|
submenu: [
|
||||||
|
{
|
||||||
|
label: 'Quit',
|
||||||
|
accelerator: 'Ctrl + Q',
|
||||||
|
click: function(item, focusedWindow){
|
||||||
|
willAppQuit = true;
|
||||||
|
app.quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
Menu.setApplicationMenu(menu);
|
||||||
|
}
|
||||||
|
|
||||||
// Emitted when the window is closed.
|
// Emitted when the window is closed.
|
||||||
mainWindow.on('closed', function() {
|
mainWindow.on('closed', function() {
|
||||||
// Dereference the window object, usually you would store windows
|
// Dereference the window object, usually you would store windows
|
||||||
|
Reference in New Issue
Block a user