Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow node-notifier to work on Apple Silicon Macs #441

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ notifier.notify({ sound: 'Morse' });

### `v3.1.0`

1. Adds Growl as fallback for Mac OS X pre 10.8.
1. Adds Growl as fallback for Mac OS X pre 10.13.

### `v3.0.6`

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ notifier.notify({

## Requirements

- **macOS**: >= 10.8 for native notifications, or Growl if earlier.
- **macOS**: >= 10.13 for native notifications, or Growl if earlier.
- **Linux**: `notify-osd` or `libnotify-bin` installed (Ubuntu should have this by default)
- **Windows**: >= 8, or task bar balloons for Windows < 8. Growl as fallback. Growl takes precedence over Windows balloons.
- **General Fallback**: Growl
Expand Down Expand Up @@ -134,7 +134,7 @@ new nn.Growl(options).notify(options);

Same usage and parameter setup as [**`terminal-notifier`**](https://github.com/julienXX/terminal-notifier).

Native Notification Center requires macOS version 10.8 or higher. If you have
Native Notification Center requires macOS version 10.13 or higher. If you have
an earlier version, Growl will be the fallback. If Growl isn't installed, an
error will be returned in the callback.

Expand All @@ -158,7 +158,7 @@ but they aren't documented.
const NotificationCenter = require('node-notifier').NotificationCenter;

var notifier = new NotificationCenter({
withFallback: false, // Use Growl Fallback if <= 10.8
withFallback: false, // Use Growl Fallback if <= 10.13
customPath: undefined // Relative/Absolute path to binary if you want to use your own fork of terminal-notifier
});

Expand Down
19 changes: 9 additions & 10 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ module.exports.command = function (notifier, options, cb) {
console.info('[notifier options]', options.join(' '));
}

return cp.exec(notifier + ' ' + options.join(' '), function (
error,
stdout,
stderr
) {
if (error) return cb(error);
cb(stderr, stdout);
});
return cp.exec(
notifier + ' ' + options.join(' '),
function (error, stdout, stderr) {
if (error) return cb(error);
cb(stderr, stdout);
}
);
};

module.exports.fileCommand = function (notifier, options, cb) {
Expand Down Expand Up @@ -507,10 +506,10 @@ module.exports.isMac = function () {
return os.type() === 'Darwin';
};

module.exports.isMountainLion = function () {
module.exports.isHighSierraOrLater = function () {
return (
os.type() === 'Darwin' &&
semver.satisfies(garanteeSemverFormat(os.release()), '>=12.0.0')
semver.satisfies(garanteeSemverFormat(os.release()), '>=17.0.0')
);
};

Expand Down
8 changes: 4 additions & 4 deletions notifiers/notificationcenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const EventEmitter = require('events').EventEmitter;
const util = require('util');

const errorMessageOsX =
'You need Mac OS X 10.8 or above to use NotificationCenter,' +
'You need Mac OS X 10.13 or above to use NotificationCenter,' +
' or use Growl fallback with constructor option {withFallback: true}.';

module.exports = NotificationCenter;
Expand Down Expand Up @@ -53,7 +53,7 @@ function notifyRaw(options, callback) {
this,
options,
callback,
function(data) {
function (data) {
if (activeId !== id) return false;

if (data === 'activate') {
Expand All @@ -77,7 +77,7 @@ function notifyRaw(options, callback) {
}

const argsList = utils.constructArgumentList(options);
if (utils.isMountainLion()) {
if (utils.isHighSierraOrLater()) {
utils.fileCommandJson(
this.options.customPath || notifier,
argsList,
Expand All @@ -96,7 +96,7 @@ function notifyRaw(options, callback) {
}

Object.defineProperty(NotificationCenter.prototype, 'notify', {
get: function() {
get: function () {
if (!this._notify) this._notify = notifyRaw.bind(this);
return this._notify;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"keywords": [
"notification center",
"mac os x 10.8",
"mac os x 10.13",
"notify",
"terminal-notifier",
"notify-send",
Expand Down
16 changes: 8 additions & 8 deletions test/terminal-notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ const testUtils = require('./_test-utils');

let notifier = null;
const originalUtils = utils.fileCommandJson;
const originalMacVersion = utils.isMountainLion;
const originalMacVersion = utils.isHighSierraOrLater;
const originalType = os.type;

describe('Mac fallback', function () {
const original = utils.isMountainLion;
const original = utils.isHighSierraOrLater;
const originalMac = utils.isMac;

afterEach(function () {
utils.isMountainLion = original;
utils.isHighSierraOrLater = original;
utils.isMac = originalMac;
});

it('should default to Growl notification if older Mac OSX than 10.8', function (done) {
utils.isMountainLion = function () {
it('should default to Growl notification if older Mac OSX than 10.13', function (done) {
utils.isHighSierraOrLater = function () {
return false;
};
utils.isMac = function () {
Expand All @@ -35,7 +35,7 @@ describe('Mac fallback', function () {
});

it('should not fallback to Growl notification if withFallback is false', function (done) {
utils.isMountainLion = function () {
utils.isHighSierraOrLater = function () {
return false;
};
utils.isMac = function () {
Expand All @@ -56,7 +56,7 @@ describe('terminal-notifier', function () {
return 'Darwin';
};

utils.isMountainLion = function () {
utils.isHighSierraOrLater = function () {
return true;
};
});
Expand All @@ -67,7 +67,7 @@ describe('terminal-notifier', function () {

afterEach(function () {
os.type = originalType;
utils.isMountainLion = originalMacVersion;
utils.isHighSierraOrLater = originalMacVersion;
});

// Simulate async operation, move to end of message queue.
Expand Down
Binary file not shown.
18 changes: 10 additions & 8 deletions vendor/mac.noindex/terminal-notifier.app/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>16E195</string>
<string>23E224</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand Down Expand Up @@ -31,19 +31,21 @@
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>8B62</string>
<string></string>
<key>DTPlatformName</key>
<string>macosx</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<string>14.4</string>
<key>DTSDKBuild</key>
<string>16B2649</string>
<string>23E208</string>
<key>DTSDKName</key>
<string>macosx10.12</string>
<string>macosx14.4</string>
<key>DTXcode</key>
<string>0810</string>
<string>1530</string>
<key>DTXcodeBuild</key>
<string>8B62</string>
<string>15E204a</string>
<key>LSMinimumSystemVersion</key>
<string>10.8</string>
<string>10.13</string>
<key>LSUIElement</key>
<true/>
<key>NSAppTransportSecurity</key>
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>files</key>
<dict>
<key>Resources/Terminal.icns</key>
<data>
Oq9GtJM1DqcGF1JCHiEgb0hoN6I=
</data>
<key>Resources/en.lproj/Credits.rtf</key>
<dict>
<key>hash</key>
<data>
YKJIFIsxneJuNkJNJQIcJIjiPOg=
</data>
<key>optional</key>
<true/>
</dict>
<key>Resources/en.lproj/InfoPlist.strings</key>
<dict>
<key>hash</key>
<data>
MiLKDDnrUKr4EmuvhS5VQwxHGK8=
</data>
<key>optional</key>
<true/>
</dict>
<key>Resources/en.lproj/MainMenu.nib</key>
<dict>
<key>hash</key>
<data>
ks63ht6nCtcvf9VjUbrnRAck+t8=
</data>
<key>optional</key>
<true/>
</dict>
</dict>
<key>files2</key>
<dict>
<key>Resources/Terminal.icns</key>
<dict>
<key>hash2</key>
<data>
zPwPRX277SsWSp9wjhoAAPrY+Jaw1TMrN24rdI8/9SU=
</data>
</dict>
<key>Resources/en.lproj/Credits.rtf</key>
<dict>
<key>hash2</key>
<data>
tDhv4c72XNkebI7MBl0RcIkIP5G3ytvww+Xq4g6LlkA=
</data>
<key>optional</key>
<true/>
</dict>
<key>Resources/en.lproj/InfoPlist.strings</key>
<dict>
<key>hash2</key>
<data>
Oc8u4Ht7Mz58F50L9NeYpbcq9qTlhPUeZCcDu/pPyCg=
</data>
<key>optional</key>
<true/>
</dict>
<key>Resources/en.lproj/MainMenu.nib</key>
<dict>
<key>hash2</key>
<data>
T28xZ3pEIF+z1AwdptRqPpSBbjWA+HVFDrMmTQ6sosQ=
</data>
<key>optional</key>
<true/>
</dict>
</dict>
<key>rules</key>
<dict>
<key>^Resources/</key>
<true/>
<key>^Resources/.*\.lproj/</key>
<dict>
<key>optional</key>
<true/>
<key>weight</key>
<real>1000</real>
</dict>
<key>^Resources/.*\.lproj/locversion.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>1100</real>
</dict>
<key>^Resources/Base\.lproj/</key>
<dict>
<key>weight</key>
<real>1010</real>
</dict>
<key>^version.plist$</key>
<true/>
</dict>
<key>rules2</key>
<dict>
<key>.*\.dSYM($|/)</key>
<dict>
<key>weight</key>
<real>11</real>
</dict>
<key>^(.*/)?\.DS_Store$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>2000</real>
</dict>
<key>^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/</key>
<dict>
<key>nested</key>
<true/>
<key>weight</key>
<real>10</real>
</dict>
<key>^.*</key>
<true/>
<key>^Info\.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>20</real>
</dict>
<key>^PkgInfo$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>20</real>
</dict>
<key>^Resources/</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
<key>^Resources/.*\.lproj/</key>
<dict>
<key>optional</key>
<true/>
<key>weight</key>
<real>1000</real>
</dict>
<key>^Resources/.*\.lproj/locversion.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>1100</real>
</dict>
<key>^Resources/Base\.lproj/</key>
<dict>
<key>weight</key>
<real>1010</real>
</dict>
<key>^[^/]+$</key>
<dict>
<key>nested</key>
<true/>
<key>weight</key>
<real>10</real>
</dict>
<key>^embedded\.provisionprofile$</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
<key>^version\.plist$</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
</dict>
</dict>
</plist>