@@ -7,7 +7,7 @@ const registerAppMenu = require('./menu');
77const registerAnalysis = require ( './analysis' ) ;
88const i18n = require ( './i18n' ) ;
99const store = require ( './store' ) ;
10- const { loadMainResource } = require ( './utils' ) ;
10+ const { loadMainResource, isMac } = require ( './utils' ) ;
1111
1212let mainWindow = null ;
1313
@@ -46,12 +46,6 @@ function createWindow() {
4646 // 加载应用-----
4747 loadMainResource ( mainWindow ) ;
4848
49- // 关闭window时触发下列事件.
50- mainWindow . on ( 'closed' , function ( event ) {
51- event . preventDefault ( ) ;
52- app . hide ( ) ;
53- } ) ;
54-
5549 mainWindow . webContents . setWindowOpenHandler ( ( { url } ) => {
5650 shell . openExternal ( url ) ;
5751 return { action : 'deny' } ;
@@ -75,19 +69,37 @@ app.on('ready', () => {
7569 createWindow ( ) ;
7670 registerAppMenu ( mainWindow ) ;
7771 registerAnalysis ( ) ;
78-
79- app . on ( 'activate' , ( ) => {
80- app . show ( ) ;
81- } ) ;
8272} ) ;
8373
84- app . on ( 'window-all-closed' , ( event ) => {
85- event . preventDefault ( ) ;
86- if ( process . platform !== 'darwin' ) {
87- app . quit ( ) ;
74+ app . on ( 'activate' , ( ) => {
75+ if ( ! ! mainWindow ) {
76+ createWindow ( ) ;
77+ } else {
78+ if ( mainWindow . isMinimized ( ) ) {
79+ mainWindow . restore ( ) ;
80+ }
81+ if ( mainWindow . isVisible ( ) ) {
82+ mainWindow . focus ( ) ;
83+ } else {
84+ mainWindow . show ( ) ;
85+ }
8886 }
8987} ) ;
9088
89+ // app.on('window-all-closed', (event) => {
90+ // event.preventDefault();
91+ // console.log('window-all-closed', process);
92+ // if (process.platform !== 'darwin') {
93+ // app.quit();
94+ // }
95+ // });
96+
97+ app . on ( 'window-all-closed' , ( e ) => {
98+ // 禁止默认行为
99+ if ( isMac ) return ;
100+ app . quit ( ) ;
101+ } ) ;
102+
91103app . on ( 'before-quit' , ( ) => {
92104 if ( baseUrl ) {
93105 try {
0 commit comments