File size: 1,655 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const { app, Menu } = require( 'electron' );
const appQuit = require( '../../../lib/app-quit' );
const log = require( '../../../lib/logger' )( 'platform:mac' );
const menuSetter = require( '../../../lib/menu-setter' );

let window;
let dockMenu;

function MacPlatform( appWindow ) {
	window = appWindow.window;
	dockMenu = Menu.buildFromTemplate( require( './dock-menu' )( app, appWindow ) );

	app.dock.setMenu( dockMenu );

	app.on( 'activate', function () {
		window.show();
		window.focus();
	} );

	app.on( 'window-all-closed', function () {
		log.info( 'All windows closed, shutting down' );
		app.quit();
	} );

	app.on( 'before-quit', function () {
		log.info( 'Application quit triggered' );

		appQuit.allowQuit();
	} );

	window.on( 'close', function ( ev ) {
		if ( appQuit.shouldQuitToBackground() ) {
			log.info( `User clicked 'close': hiding main window...` );
			ev.preventDefault();
			window.hide();
			appWindow.view.webContents.send( 'notifications-panel-show', false );
		}
	} );
}

MacPlatform.prototype.restore = function () {
	if ( window.isMinimized() ) {
		window.restore();
	}

	window.show();
};

MacPlatform.prototype.showNotificationsBadge = function ( count, bounce ) {
	const badgeCount = app.getBadgeCount();
	if ( count === badgeCount ) {
		return;
	}

	app.setBadgeCount( count );

	const shouldBounce = bounce && count > badgeCount;
	if ( shouldBounce ) {
		app.dock.bounce();
	}
};

MacPlatform.prototype.clearNotificationsBadge = function () {
	app.setBadgeCount( 0 );
};

MacPlatform.prototype.setDockMenu = function ( enabled ) {
	menuSetter.setRequiresUser( dockMenu, enabled );
};

module.exports = MacPlatform;