macOS: Add --bounce option for dock counter (PR #570)

This commit is contained in:
Matt Rose 2018-04-14 17:17:25 -04:00 committed by Ronan Jouchet
parent cec29c88ed
commit 574205ab0d
6 changed files with 27 additions and 8 deletions

View File

@ -181,7 +181,7 @@ function createMainWindow(inpOptions, onAppQuit, setDockBadge) {
const itemCountRegex = /[([{](\d*?)\+?[}\])]/;
const match = itemCountRegex.exec(title);
if (match) {
setDockBadge(match[1]);
setDockBadge(match[1], options.bounce);
} else {
setDockBadge('');
}
@ -191,7 +191,7 @@ function createMainWindow(inpOptions, onAppQuit, setDockBadge) {
if (!isOSX() || mainWindow.isFocused()) {
return;
}
setDockBadge('•');
setDockBadge('•', options.bounce);
});
mainWindow.on('focus', () => {
setDockBadge('');

View File

@ -62,7 +62,13 @@ if (appArgs.basicAuthPassword) {
let setDockBadge = () => {};
if (isOSX()) {
setDockBadge = app.dock.setBadge;
let currentBadgeCount = 0;
setDockBadge = (count, bounce = false) => {
app.dock.setBadge(count);
if (bounce && count > currentBadgeCount) app.dock.bounce();
currentBadgeCount = count;
};
}
app.on('window-all-closed', () => {

View File

@ -15,6 +15,7 @@
- [[conceal]](#conceal)
- [[icon]](#icon)
- [[counter]](#counter)
- [[bounce]](#bounce)
- [[width]](#width)
- [[height]](#height)
- [[min-width]](#min-width)
@ -97,7 +98,7 @@ The name of the application, which will affect strings in titles and the icon.
```
Automatically determined based on the current OS. Can be overwritten by specifying either `linux`, `windows`, `osx` or `mas` for a Mac App Store specific build.
The alternative values `win32` (for Windows) or `darwin`, `mac` (for OSX) can also be used.
The alternative values `win32` (for Windows) or `darwin`, `mac` (for macOS) can also be used.
#### [arch]
@ -165,7 +166,7 @@ Specifies if the source code within the nativefied app should be packaged into a
The icon parameter should be a path to a `.png` file.
##### Packaging for OSX
##### Packaging for macOS
The icon parameter can either be a `.icns` or a `.png` file if the [optional dependencies](../README.md#optional-dependencies) are installed.
@ -185,6 +186,14 @@ To retrieve the `.icns` file from the downloaded file, extract it first and pres
Use a counter that persists even with window focus for the application badge for sites that use an "(X)" format counter in the page title (i.e. Gmail). Same limitations as the badge option (above).
#### [bounce]
```
--bounce
```
(macOS only) When the the counter increases, the dock icon will bounce for one second. This only works if the `--counter` option is active.
#### [width]
```
@ -263,7 +272,7 @@ Specifies if the menu bar should be shown.
-f, --fast-quit
```
(OSX Only) Specifies to quit the app after closing all windows, defaults to false.
(macOS only) Specifies to quit the app after closing all windows, defaults to false.
#### [user-agent]
@ -526,6 +535,7 @@ var options = {
asar: false, // see conceal
icon: '~/Desktop/icon.png',
counter: false,
bounce: false,
width: 1280,
height: 800,
showMenuBar: false,

View File

@ -15,6 +15,7 @@ function selectAppArgs(options) {
name: options.name,
targetUrl: options.targetUrl,
counter: options.counter,
bounce: options.bounce,
width: options.width,
height: options.height,
minWidth: options.minWidth,

View File

@ -52,7 +52,8 @@ if (require.main === module) {
.option('-e, --electron-version <value>', 'electron version to package, without the \'v\', see https://github.com/atom/electron/releases')
.option('--no-overwrite', 'do not override output directory if it already exists, defaults to false')
.option('-c, --conceal', 'packages the source code within your app into an archive, defaults to false, see http://electron.atom.io/docs/v0.36.0/tutorial/application-packaging/')
.option('--counter', 'if the target app should use a persistant counter badge in the dock (OSX only), defaults to false')
.option('--counter', 'if the target app should use a persistent counter badge in the dock (macOS only), defaults to false')
.option('--bounce', 'if the the dock icon should bounce when counter increases (macOS only), defaults to false')
.option('-i, --icon <value>', 'the icon file to use as the icon for the app (should be a .png)')
.option('--width <value>', 'set window default width, defaults to 1280px', parseInt)
.option('--height <value>', 'set window default height, defaults to 800px', parseInt)
@ -63,7 +64,7 @@ if (require.main === module) {
.option('--x <value>', 'set window x location', parseInt)
.option('--y <value>', 'set window y location', parseInt)
.option('-m, --show-menu-bar', 'set menu bar visible, defaults to false')
.option('-f, --fast-quit', 'quit app after window close (OSX only), defaults to false')
.option('-f, --fast-quit', 'quit app after window close (macOS only), defaults to false')
.option('-u, --user-agent <value>', 'set the user agent string for the app')
.option('--honest', 'prevent the nativefied app from changing the user agent string to masquerade as a regular chrome browser')
.option('--ignore-certificate', 'ignore certificate related errors')

View File

@ -27,6 +27,7 @@ export default function (inpOptions) {
asar: inpOptions.conceal || false,
icon: inpOptions.icon,
counter: inpOptions.counter || false,
bounce: inpOptions.bounce || false,
width: inpOptions.width || 1280,
height: inpOptions.height || 800,
minWidth: inpOptions.minWidth,