Skip to content

Commit

Permalink
style: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Aetherinox committed Jul 12, 2024
1 parent ce09799 commit b4dcd5d
Show file tree
Hide file tree
Showing 21 changed files with 1,259 additions and 562 deletions.
27 changes: 25 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
{
"extends": "semistandard",
"plugins": ["prettier"],
"extends": [
"semistandard"
],
"env": {
"node": true,
"jest": true
},
"rules": {
"space-before-function-paren": 0,
"no-control-regex": 0,
"no-console": 1,
"no-var": 2,
"prefer-const": 1,
"no-prototype-builtins": 0,
"no-useless-escape": 1,
"comma-dangle": 0,
"indent": "off"
"keyword-spacing": ["error", { "before": true, "after": true }],
"comma-spacing": ["error", { "before": false, "after": true }],
"indent": 0,
"prefer-spread": 1,
"no-mixed-operators": 1,
"prettier/prettier": 1,
"camelcase": ["error", {
"allow": ["^UNSAFE_"],
"properties": "never",
"ignoreGlobals": true
}],
"quotes": [
"error", "single", {
"avoidEscape": true,
"allowTemplateLiterals": true
}
],
}
}
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ toasted.notify(
<br />

There is a default timeout set of `10` to ensure that the application closes properly. To remove the timeout and have a notification instantly close _(does not support actions)_, set `timeout: false`. If you are using an `action:`; it is recommended to set timeout to a high value to ensure the user has time to respond to the notification.
Default timeout is `10` to ensure that the application closes properly. To remove the timeout and have notifications instantly close _(does not support actions)_, set `timeout: false`. If you are using an `action:` declaration; it is recommended to set the timeout to a high value to ensure the user has time to respond to the notification.

> [!NOTE]
> **Exception**: If `reply: true` is defined, set timeout to a high value, or to nothing at all.
Expand Down Expand Up @@ -376,7 +376,7 @@ If you do not see notifications from Toasted-Notifier, click windows **Start** a

Locate `NtfyToast`, or your `customPath` / `appID` program in the list.

<sup>`Note`: <a href="https://github.com/Aetherinox/ntfy-toast">NtfyToast</a> is the library used in Toasted-Notifier for Windows notifications</sup>
<sup>`Note`: <a href="https://github.com/Aetherinox/ntfy-toast">NtfyToast</a> is the library used by Toasted-Notifier for Windows notifications</sup>

<div align="center">

Expand Down Expand Up @@ -709,7 +709,6 @@ For instructions on accomplishing this, read the section [appID support](#appid-
### Can't use Windows Toast notifications in WSL2
Ntfy makes use of a 3rd party package for Windows notifications to work. You must change the permissions on the Ntfy vendor .exe in order for it to work properly.


```shell
chmod +x node_modules/toasted-notifier/vendor/ntfyToast/ntfytoast.exe
```
Expand Down Expand Up @@ -812,8 +811,6 @@ When using toasted-notifier within a tmux session, it can cause the system to ab
set -g default-command "which reattach-to-user-namespace > /dev/null && reattach-to-user-namespace -l $SHELL || $SHELL -l"
```
<br />
---
Expand Down
13 changes: 7 additions & 6 deletions example/advanced.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
const notifier = require('../');
const nc = new notifier.NotificationCenter();
/* eslint-disable no-console */

const toasted = require('../');
const nc = new toasted.NotificationCenter();
const path = require('path');

nc.notify(
{
title: 'Phil Coulson',
subtitle: 'Agent of S.H.I.E.L.D.',
message: "If I come out, will you shoot me? 'Cause then I won't come out.",
title: 'Test Notification',
subtitle: 'This is a subtitle',
message: 'This is an advanced test message',
sound: 'Funk',
// case sensitive
wait: true,
icon: path.join(__dirname, 'example_1.png'),
contentImage: path.join(__dirname, 'example_1.png'),
Expand Down
3 changes: 3 additions & 0 deletions example/forceBallon.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/* eslint-disable no-console */
const toasted = require('../index');

const balloon = toasted.WindowsBalloon();
balloon
.notify({ message: 'Hello' }, function (err, data) {
console.log(err, data);
})

.on('click', function () {
console.log(arguments);
});
20 changes: 12 additions & 8 deletions example/macInput.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
/* eslint-disable no-console */

const notifier = require('../');
const nc = new notifier.NotificationCenter();

const trueAnswer = 'Most def.';
const trueAnswer = 'Yessir.';

/*
@note : closeLabel is case sensitive
*/

nc.notify(
{
title: 'Notifications',
message: 'Are they cool?',
message: 'Do you like them?',
sound: 'Funk',
// case sensitive
closeLabel: 'Absolutely not',
closeLabel: 'Nope',
actions: trueAnswer
},
function (err, response, metadata) {
if (err) throw err;
console.log(metadata);

if (metadata.activationValue !== trueAnswer) {
return; // No need to continue
return; // Do not continue
}

nc.notify(
{
title: 'Notifications',
message: 'Do you want to reply to them?',
message: 'Do you wish to reply to them?',
sound: 'Funk',
// case sensitive
reply: true
},
function (err, response, metadata) {
Expand All @@ -37,5 +41,5 @@ nc.notify(
);

nc.on('replied', function (obj, options, metadata) {
console.log('User replied', metadata);
console.log('User has replied', metadata);
});
4 changes: 3 additions & 1 deletion example/message.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* eslint-disable no-console */

const toasted = require('../index');

toasted
.notify({ message: 'Hello', wait: true }, function (err, data) {
// Will also wait until notification is closed.
// wait until notification is closed.
console.log('Waited');
console.log(err, data);
})
Expand Down
4 changes: 3 additions & 1 deletion example/toaster-custom-path.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-console */

const path = require('path');

/*
Expand All @@ -17,7 +19,7 @@ const { WindowsToaster } = require('../');
const customPath = path.join('vendor', 'ntfyToast', 'ntfytoast.exe');
const toasted = new WindowsToaster({
withFallback: false,
customPath: customPath
customPath
});

/*
Expand Down
1 change: 1 addition & 0 deletions example/toaster-persistent.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
const path = require('path');
const toasted = require('../index');

Expand Down
1 change: 1 addition & 0 deletions example/toaster-with-actions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
const path = require('path');
const toasted = require('../index');

Expand Down
2 changes: 2 additions & 0 deletions example/toaster.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-console */

const path = require('path');
const toasted = require('../index');

Expand Down
31 changes: 16 additions & 15 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
const shellwords = require('shellwords');
const cp = require('child_process');
const semver = require('semver');
Expand Down Expand Up @@ -54,10 +55,10 @@ const notifySendFlags = {

module.exports.command = function (notifier, options, cb) {
notifier = shellwords.escape(notifier);
if (process.env.DEBUG && process.env.DEBUG.indexOf('notifier') !== -1) {
console.info('node-notifier debug info (command):');
console.info('[notifier path]', notifier);
console.info('[notifier options]', options.join(' '));
if (process.env.DEBUG && process.env.DEBUG.indexOf('toasted') !== -1) {
console.info('toasted-notifier debug info (command):');
console.info('[toast path]', notifier);
console.info('[toast options]', options.join(' '));
}

return cp.exec(notifier + ' ' + options.join(' '), function (error, stdout, stderr) {
Expand All @@ -67,10 +68,10 @@ module.exports.command = function (notifier, options, cb) {
};

module.exports.fileCommand = function (notifier, options, cb) {
if (process.env.DEBUG && process.env.DEBUG.indexOf('notifier') !== -1) {
console.info('node-notifier debug info (fileCommand):');
console.info('[notifier path]', notifier);
console.info('[notifier options]', options.join(' '));
if (process.env.DEBUG && process.env.DEBUG.indexOf('toasted') !== -1) {
console.info('toasted-notifier debug info (fileCommand):');
console.info('[toast path]', notifier);
console.info('[toast options]', options.join(' '));
}

return cp.execFile(notifier, options, function (error, stdout, stderr) {
Expand All @@ -80,10 +81,10 @@ module.exports.fileCommand = function (notifier, options, cb) {
};

module.exports.fileCommandJson = function (notifier, options, cb) {
if (process.env.DEBUG && process.env.DEBUG.indexOf('notifier') !== -1) {
console.info('node-notifier debug info (fileCommandJson):');
console.info('[notifier path]', notifier);
console.info('[notifier options]', options.join(' '));
if (process.env.DEBUG && process.env.DEBUG.indexOf('toasted') !== -1) {
console.info('toasted-notifier debug info (fileCommandJson):');
console.info('[toast path]', notifier);
console.info('[toast options]', options.join(' '));
}

return cp.execFile(notifier, options, function (error, stdout, stderr) {
Expand All @@ -100,9 +101,9 @@ module.exports.fileCommandJson = function (notifier, options, cb) {
};

module.exports.immediateFileCommand = function (notifier, options, cb) {
if (process.env.DEBUG && process.env.DEBUG.indexOf('notifier') !== -1) {
console.info('node-notifier debug info (notifier):');
console.info('[notifier path]', notifier);
if (process.env.DEBUG && process.env.DEBUG.indexOf('toasted') !== -1) {
console.info('toasted-notifier debug info (Toast):');
console.info('[toast path]', notifier);
}

notifierExists(notifier, function (_, exists) {
Expand Down
4 changes: 2 additions & 2 deletions notifiers/balloon.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function notifyRaw(options, callback) {
callback = callback || noop;

if (typeof options === 'string') {
options = { title: 'node-notifier', message: options };
options = { title: 'toasted-notifier', message: options };
}

const actionJackedCallback = utils.actionJackerDecorator(this, options, callback, function (data) {
Expand Down Expand Up @@ -128,7 +128,7 @@ function doNotification(options, notifierOptions, callback) {
wrapper: '',
noEscape: true,
explicitTrue: true,
allowedArguments: allowedArguments
allowedArguments
});

if (options.wait) {
Expand Down
2 changes: 1 addition & 1 deletion notifiers/growl.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function notifyRaw(options, callback) {
options = utils.clone(options || {});

if (typeof options === 'string') {
options = { title: 'node-notifier', message: options };
options = { title: 'toasted-notifier', message: options };
}

callback = utils.actionJackerDecorator(this, options, callback, function (data) {
Expand Down
2 changes: 1 addition & 1 deletion notifiers/notificationcenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function notifyRaw(options, callback) {
activeId = id;

if (typeof options === 'string') {
options = { title: 'node-notifier', message: options };
options = { title: 'toasted-notifier', message: options };
}
callback = callback || noop;

Expand Down
6 changes: 3 additions & 3 deletions notifiers/notifysend.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function notifyRaw(options, callback) {
}

if (typeof options === 'string') {
options = { title: 'node-notifier', message: options };
options = { title: 'toasted-notifier', message: options };
}

if (!options.message) {
Expand Down Expand Up @@ -87,9 +87,9 @@ function doNotification(options, callback) {
delete options.message;

const argsList = utils.constructArgumentList(options, {
initial: initial,
initial,
keyExtra: '-',
allowedArguments: allowedArguments
allowedArguments
});

utils.command(notifier, argsList, callback);
Expand Down
3 changes: 1 addition & 2 deletions notifiers/toaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function notifyRaw(options, callback) {
};

if (typeof options === 'string') {
options = { title: 'node-notifier', message: options };
options = { title: 'toasted-notifier', message: options };
}

if (typeof callback !== 'function') {
Expand Down Expand Up @@ -102,7 +102,6 @@ function notifyRaw(options, callback) {
callback(null, result);

/*
@ref : https://github.com/mikaelbr/node-notifier/issues/334
Due to an issue with ntfytoast not using stdio and pipe
when notifications are disabled, make sure named pipe server
is closed before exiting.
Expand Down
Loading

0 comments on commit b4dcd5d

Please sign in to comment.