FIX: make notifications work when using in wsl

This commit is contained in:
Peter 2021-04-23 23:50:18 +08:00
parent 55d8b738a0
commit 8d32117d0e
2 changed files with 62 additions and 55 deletions

107
README.md
View File

@ -1,53 +1,54 @@
# SpaceX-cli
## View upcoming launches in the terminal
### Install with `npm install -g npc-strider/spacex-cli`
### ** I'm not including the proper `spacex.ico` in my releases to prevent trademark infringement :/ sorry. Add your own spacex logo in the npm directory: `npm\node_modules\spacex-cli` **
![Main view](./preview-images/main.png)
*You may notice that falcon heavy launch shows as falcon 9, but that appears to be due to the API. Doesn't appear like this now.
```
Usage:
spacex-cli
spacex-cli [-a <polling interval>] | [-h] | [-s <polling interval>] | [-d] | [-b] | [-v] | [-p <appdir>] | [-n <time remaining>] | [-g <time remaining>]
spacex-cli [--api_refresh=<polling interval>] | [--help] | [--screen_refresh=<polling interval>] | [--dump] | [--blink] | [--archive] | [--path=<appdir>] | [--notify_time=<time remaining>] | [--highlight_time=<time remaining>]
Options:
-h, --help Show this help information.
-s, --screen_refresh Screen refresh interval in milliseconds. How often time-based information updates [default: 1000]
-a, --api_refresh API refresh interval in milliseconds. How often we poll the api for new/updated information. Please don't use small values! [default: 600000]
-c, --color Print with color [default: true]
-d, --dump Non-interactive mode - dumps the main launches table [default: false]
-b, --blink Blink for close launches. This argument exists because I know some people hate blink [default: false]
-v, --archive Archive launch data when changed [default: false]
-p, --path Application directory [default: ~/.spacexcli]
-n, --notify_time At this amount of seconds remaining until launch, send a notification [default: 5400]
-g, --highlight_time At this amount of seconds remaining until launch, highlight the row in the table view [default: 86400]
```
This is an enhanced version of a basic CLI bash script I was using.
Because the bash script was based on the v3 [spacexdata](https://github.com/r-spacex/SpaceX-API) api, I was forced to upgrade it to use the new v4 api.
So I decided to not just upgrade the bash script to use the new api, but also add some new features and more interactibility.
The cli isn't pretty like some others, but I think it's quite dense in relevant information.
## More screenshots
---
View raw response\
![View raw JSON](./preview-images/raw-view.png)
View differences in data (You'll be notified as well when the data changes)\
You can also view the differences (which includes data not in the table) in JSON form.\
![Diff table](./preview-images/diff-table.png)
## Changelog
---
| Date | Version | Changes |
| --- | --- | --- |
| 2021-01-08 | 1.0.0 | Initial release. |
| 2021-02-07 | 1.0.1 | Fix bug with diff where undefined cells would cause an error. |
| 2021-02-16 | 1.0.2 | Added temp/placeholder icon to fix notifications. Remember to add your own icon (not including originals to prevent trademark infringement) |
# SpaceX-cli
## View upcoming launches in the terminal
### Install with `npm install -g npc-strider/spacex-cli`
### ** I'm not including the proper `spacex.ico` in my releases to prevent trademark infringement :/ sorry. Add your own spacex logo in the npm directory: `npm\node_modules\spacex-cli` **
![Main view](./preview-images/main.png)
*You may notice that falcon heavy launch shows as falcon 9, but that appears to be due to the API. Doesn't appear like this now.
```
Usage:
spacex-cli
spacex-cli [-a <polling interval>] | [-h] | [-s <polling interval>] | [-d] | [-b] | [-v] | [-p <appdir>] | [-n <time remaining>] | [-g <time remaining>]
spacex-cli [--api_refresh=<polling interval>] | [--help] | [--screen_refresh=<polling interval>] | [--dump] | [--blink] | [--archive] | [--path=<appdir>] | [--notify_time=<time remaining>] | [--highlight_time=<time remaining>]
Options:
-h, --help Show this help information.
-s, --screen_refresh Screen refresh interval in milliseconds. How often time-based information updates [default: 1000]
-a, --api_refresh API refresh interval in milliseconds. How often we poll the api for new/updated information. Please don't use small values! [default: 600000]
-c, --color Print with color [default: true]
-d, --dump Non-interactive mode - dumps the main launches table [default: false]
-b, --blink Blink for close launches. This argument exists because I know some people hate blink [default: false]
-v, --archive Archive launch data when changed [default: false]
-p, --path Application directory [default: ~/.spacexcli]
-n, --notify_time At this amount of seconds remaining until launch, send a notification [default: 5400]
-g, --highlight_time At this amount of seconds remaining until launch, highlight the row in the table view [default: 86400]
```
This is an enhanced version of a basic CLI bash script I was using.
Because the bash script was based on the v3 [spacexdata](https://github.com/r-spacex/SpaceX-API) api, I was forced to upgrade it to use the new v4 api.
So I decided to not just upgrade the bash script to use the new api, but also add some new features and more interactibility.
The cli isn't pretty like some others, but I think it's quite dense in relevant information.
## More screenshots
---
View raw response\
![View raw JSON](./preview-images/raw-view.png)
View differences in data (You'll be notified as well when the data changes)\
You can also view the differences (which includes data not in the table) in JSON form.\
![Diff table](./preview-images/diff-table.png)
## Changelog
---
| Date | Version | Changes |
| --- | --- | --- |
| 2021-01-08 | 1.0.0 | Initial release. |
| 2021-02-07 | 1.0.1 | Fix bug with diff where undefined cells would cause an error. |
| 2021-02-16 | 1.0.2 | Added temp/placeholder icon to fix notifications. Remember to add your own icon (not including originals to prevent trademark infringement) |
| 2021-04-23 | 1.0.3 | Fixed notifications on WSL due to unix-style paths not working as an argument on Windows with node-notifier |

View File

@ -3,6 +3,7 @@ const clc = require('cli-color');
const notifier = require('node-notifier');
const Diff = require('diff');
const path = require('path');
const isWsl = require('is-wsl');
const arguments = require('./tools/process-args').arguments;
const cli_elem = require('./tools/cli-elements'); //Idk js package structure/conventions...
@ -50,6 +51,11 @@ const ARCHIVE = arguments.archive;
var notified_1h = [];
var notifying_1h = [];
var ICON_PATH = path.join(__dirname, 'spacex.ico');
if (isWsl && ICON_PATH.startsWith("/mnt/",0)) {
ICON_PATH = ICON_PATH.substr(5).replace("/",":/");
}
function selectData(arr) {
const LUNCHPADS_RESP = arr[0];
const LUNCHES_RESP = arr[1];
@ -293,7 +299,7 @@ async function main() {
notifier.notify({
title: STRING.H_WARNING,
message: notifying_1h.join(' │ '),
icon: path.join(__dirname, 'spacex.ico'),
icon: ICON_PATH,
appID: STRING.APPID
});
notifying_1h = [];
@ -373,7 +379,7 @@ async function main() {
notifier.notify({
title: STRING.NEW_DATA,
message: 'Press d to see table diff. Press j to see JSON diff.',
icon: path.join(__dirname, 'spacex.ico'),
icon: ICON_PATH,
appID: STRING.APPID
});
net_tools.writeFile(path_prev_launches, JSON.stringify(curr_launches));