Skip to content

Commit 8a251af

Browse files
committedMar 23, 2017
🎉 A module is born
0 parents  commit 8a251af

File tree

8 files changed

+167
-0
lines changed

8 files changed

+167
-0
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lib
2+
node_modules

‎.npmignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
build
2+
lib
3+
node_modules
4+
.git
5+
.gitignore
6+
test
7+
src

‎.vscode/tasks.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "0.1.0",
5+
"command": "tsc",
6+
"isShellCommand": true,
7+
"args": ["-p", "."],
8+
"showOutput": "silent",
9+
"problemMatcher": "$tsc"
10+
}

‎LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Felix Rieseberg
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# electron-notification-state
2+
Should you display a notification to your user? This module allows you to check.
3+
4+
## Usage
5+
6+
### Do Not Disturb / Quiet Hours
7+
```js
8+
const { getDoNotDisturb } from 'electron-notification-state'
9+
// On Windows, logs `true` if "quiet hours" are enabled
10+
// On macOS, logs `true` if "do not disturb" is enabled
11+
console.log(getDoNotDisturb());
12+
```
13+
14+
### Session State
15+
On Windows, you likely want to check [SHQueryUserNotificationState](https://msdn.microsoft.com/en-us/library/windows/desktop/bb762242(v=vs.85).aspx), checking whether or not a screensaver is running, if the screen is locked, or if a presentation is running. On macOS, you likely want to check if the screen is locked and if the if the user has an active screen session.
16+
17+
The call below logs a different string, depending on the platform:
18+
#### macOS
19+
- `SESSION_SCREEN_IS_LOCKED` The screen is locked.
20+
- `SESSION_ON_CONSOLE_KEY` The user currently has console/graphical control.
21+
22+
#### Windows
23+
- `QUNS_NOT_PRESENT` A screen saver is displayed, the machine is locked, or a nonactive Fast User Switching session is in progress.
24+
- `QUNS_BUSY` A full-screen application is running or Presentation Settings are applied. Presentation Settings allow a user to put their machine into a state fit for an uninterrupted presentation, such as a set of PowerPoint slides, with a single click.
25+
- `QUNS_RUNNING_D3D_FULL_SCREEN` A full-screen (exclusive mode) Direct3D application is running.
26+
- `QUNS_PRESENTATION_MODE` The user has activated Windows presentation settings to block notifications and pop-up messages.
27+
- `QUNS_ACCEPTS_NOTIFICATIONS` None of the other states are found, notifications can be freely sent.
28+
- `QUNS_QUIET_TIME` Introduced in Windows 7. The current user is in "quiet time", which is the first hour after a new user logs into his or her account for the first time. During this time, most notifications should not be sent or shown. This lets a user become accustomed to a new computer system without those distractions. Quiet time also occurs for each user after an operating system upgrade or clean installation, according to Windows. This is _not_ the same as "quiet hours".
29+
Note that during quiet time, if the user is in one of the other blocked modes (QUNS_NOT_PRESENT, QUNS_BUSY, QUNS_PRESENTATION_MODE, or QUNS_RUNNING_D3D_FULL_SCREEN) SHQueryUserNotificationState returns only that value, and does not report QUNS_QUIET_TIME.
30+
- `QUNS_APP` Introduced in Windows 8. A Windows Store app is running.
31+
32+
```js
33+
const { getSessionState } from 'electron-notification-state'
34+
35+
console.log(getSessionState());
36+
```
37+
38+
## License
39+
MIT. Please see LICENSE for details.

‎package.json

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "electron-notification-state",
3+
"version": "1.0.0",
4+
"description": "Should you send a notification?",
5+
"main": "index.js",
6+
"typings": "./lib/index",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/felixrieseberg/electron-notification-state.git"
10+
},
11+
"author": {
12+
"email": "felix@felixrieseberg.com",
13+
"name": "Felix Rieseberg",
14+
"url": "http://www.felixrieseberg.com"
15+
},
16+
"scripts": {
17+
"build": "tsc -p .",
18+
"prepublish": "npm run build"
19+
},
20+
"license": "MIT",
21+
"keywords": [
22+
"macos",
23+
"darwin",
24+
"CGSSessionScreenIsLocked",
25+
"kCGSSessionOnConsoleKey",
26+
"doNotDisturb",
27+
"do not disturb",
28+
"windows",
29+
"SHQueryUserNotificationState",
30+
"notifications"
31+
],
32+
"bugs": {
33+
"url": "https://github.com/felixrieseberg/electron-notification-state/issues"
34+
},
35+
"homepage": "https://github.com/felixrieseberg/electron-notification-state#readme",
36+
"dependencies": {
37+
"macos-notification-state": "^1.1.0",
38+
"windows-notification-state": "^1.3.0",
39+
"windows-quiet-hours": "^1.2.2"
40+
},
41+
"devDependencies": {
42+
"@types/node": "^7.0.10"
43+
}
44+
}

‎src/index.ts

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { } from '@types/node';
2+
import { getNotificationState as getWindowsNotificationState, QUERY_USER_NOTIFICATION_STATE } from 'windows-notification-state';
3+
import { getIsQuietHours } from 'windows-quiet-hours';
4+
import { getSessionState as getDarwinSessionState, getDoNotDisturb as getDarwinDoNotDisturb, SessionState } from 'macos-notification-state';
5+
6+
export type NotificationState = QUERY_USER_NOTIFICATION_STATE | SessionState | 'UNKNOWN' | 'UNKNOWN_ERROR' | 'DO_NOT_DISTURB'
7+
8+
export function getSessionState(): NotificationState {
9+
if (process.platform === 'win32') {
10+
return getWindowsNotificationState();
11+
}
12+
13+
if (process.platform === 'darwin') {
14+
return getDarwinSessionState();
15+
}
16+
17+
return 'UNKNOWN_ERROR';
18+
}
19+
20+
export function getDoNotDisturb(): boolean {
21+
if (process.platform === 'win32') {
22+
return getIsQuietHours();
23+
}
24+
25+
if (process.platform === 'darwin') {
26+
return getDarwinDoNotDisturb();
27+
}
28+
29+
return false;
30+
}

‎tsconfig.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"noImplicitAny": true,
4+
"noImplicitReturns": true,
5+
"noUnusedLocals": true,
6+
"noUnusedParameters": true,
7+
"strictNullChecks": true,
8+
"declaration": true,
9+
"outDir": "lib"
10+
},
11+
"include": [
12+
"src/**/*"
13+
]
14+
}

0 commit comments

Comments
 (0)
Please sign in to comment.