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

Upgrades snoretoast to 0.6.0 #288

Merged
merged 2 commits into from
Aug 23, 2019
Merged
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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ notifier.notify(
message: void 0, // String. Required if remove is not defined
icon: void 0, // String. Absolute path to Icon
sound: false, // Bool | String (as defined by http://msdn.microsoft.com/en-us/library/windows/apps/hh761492.aspx)
wait: false, // Bool. Wait for User Action against Notification or times out
id: void 0, // Number. ID to use for closing notification.
appID: void 0, // String. App.ID and app Name. Defaults to no value, causing SnoreToast text to be visible.
remove: void 0, // Number. Refer to previously created notification to close.
Expand Down
13 changes: 5 additions & 8 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,19 +318,21 @@ function removeNewLines(str) {
---- Options ----
[-t] <title string> | Displayed on the first line of the toast.
[-m] <message string> | Displayed on the remaining lines, wrapped.
[-b] <button1;button2 string>| Displayed on the bottom line, can list multiple buttons separated by ;
[-tb] | Displayed a textbox on the bottom line, only if buttons are not presented.
[-p] <image URI> | Display toast with an image, local files only.
[-w] | Wait for toast to expire or activate.
[-id] <id> | sets the id for a notification to be able to close it later.
[-s] <sound URI> | Sets the sound of the notifications, for possible values see http://msdn.microsoft.com/en-us/library/windows/apps/hh761492.aspx.
[-silent] | Don't play a sound file when showing the notifications.
[-appID] <App.ID> | Don't create a shortcut but use the provided app id.
-close <id> | Closes a currently displayed notification, in order to be able to close a notification the parameter -w must be used to create the notification.
[-pipeName] <\.\pipe\pipeName\> | Provide a name pipe which is used for callbacks.
[-application] <C:\foo.exe> | Provide a application that might be started if the pipe does not exist.
-close <id> | Closes a currently displayed notification.
*/
var allowedToasterFlags = [
't',
'm',
'p',
'w',
'id',
's',
'silent',
Expand Down Expand Up @@ -405,11 +407,6 @@ module.exports.mapToWin8 = function(options) {
options.s = toasterDefaultSound;
}

if (options.wait) {
options.w = options.wait;
delete options.wait;
}

for (var key in options) {
// Check if is allowed. If not, delete!
if (
Expand Down
8 changes: 6 additions & 2 deletions notifiers/toaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
* Wrapper for the toaster (https://github.com/nels-o/toaster)
*/
var path = require('path');
var notifier = path.resolve(__dirname, '../vendor/snoreToast/SnoreToast.exe');
var notifier = path.resolve(__dirname, '../vendor/snoreToast/snoretoast');
var utils = require('../lib/utils');
var Balloon = require('./balloon');
var os = require('os');

var EventEmitter = require('events').EventEmitter;
var util = require('util');
Expand Down Expand Up @@ -37,6 +38,7 @@ function hasText(str, txt) {
WindowsToaster.prototype.notify = function(options, callback) {
options = utils.clone(options || {});
callback = callback || noop;
var is64Bit = os.arch() === 'x64';

if (typeof options === 'string') {
options = { title: 'node-notifier', message: options };
Expand Down Expand Up @@ -91,8 +93,10 @@ WindowsToaster.prototype.notify = function(options, callback) {
keepNewlines: true,
noEscape: true
});

var notifierWithArch = notifier + '-x' + (is64Bit ? '64' : '86') + '.exe';
utils.fileCommand(
this.options.customPath || notifier,
this.options.customPath || notifierWithArch,
argsList,
actionJackedCallback
);
Expand Down
32 changes: 26 additions & 6 deletions test/toaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ describe('WindowsToaster', function() {
utils.fileCommand = function(notifier, argsList, callback) {
expect(testUtils.argsListHas(argsList, '-t')).toBeTruthy();
expect(testUtils.argsListHas(argsList, '-m')).toBeTruthy();
expect(testUtils.argsListHas(argsList, '-w')).toBeTruthy();
expect(testUtils.argsListHas(argsList, '-p')).toBeTruthy();
expect(testUtils.argsListHas(argsList, '-id')).toBeTruthy();
expect(testUtils.argsListHas(argsList, '-appID')).toBeTruthy();
Expand All @@ -56,14 +55,12 @@ describe('WindowsToaster', function() {
appID: 123,
icon: 'file:///C:/node-notifier/test/fixture/coulson.jpg',
id: 1337,
sound: 'Notification.IM',
wait: true
sound: 'Notification.IM'
});
});

it('should pass wait and silent without parameters', function(done) {
it('should pass silent without parameters', function(done) {
utils.fileCommand = function(notifier, argsList, callback) {
expect(testUtils.getOptionValue(argsList, '-w')).not.toBe('true');
expect(testUtils.getOptionValue(argsList, '-silent')).not.toBe('true');
done();
};
Expand All @@ -72,7 +69,6 @@ describe('WindowsToaster', function() {
notifier.notify({
title: 'Heya',
message: 'foo bar',
wait: true,
silent: true
});
});
Expand Down Expand Up @@ -186,6 +182,30 @@ describe('WindowsToaster', function() {
notifier.notify({ title: 'Heya', message: 'foo bar', sound: 'Frog' });
});

it('should use 32 bit snoreToaster if 32 arch', function(done) {
os.arch = function() {
return 'ia32';
};
var expected = 'snoretoast-x86.exe';
utils.fileCommand = function(notifier, argsList, callback) {
expect(notifier).toEndWith(expected);
done();
};
new Notify().notify({ title: 'title', message: 'body' });
});

it('should default to x64 version', function(done) {
os.arch = function() {
return 'x64';
};
var expected = 'snoretoast-x64.exe';
utils.fileCommand = function(notifier, argsList, callback) {
expect(notifier).toEndWith(expected);
done();
};
new Notify().notify({ title: 'title', message: 'body' });
});

it('sound as true should select default value', function(done) {
utils.fileCommand = function(notifier, argsList, callback) {
expect(testUtils.getOptionValue(argsList, '-s')).toBe(
Expand Down
Binary file removed vendor/snoreToast/SnoreToast.exe
Binary file not shown.
Binary file added vendor/snoreToast/snoretoast-x64.exe
Binary file not shown.
Binary file added vendor/snoreToast/snoretoast-x86.exe
Binary file not shown.