├── .gitignore ├── LICENSE ├── README.md ├── binding.gyp ├── index.d.ts ├── lib ├── index.js └── quiethours.cc ├── package-lock.json ├── package.json └── test ├── benchmark.js └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | *.pid.lock 11 | 12 | # Directory for instrumented libs generated by jscoverage/JSCover 13 | lib-cov 14 | 15 | # Coverage directory used by tools like istanbul 16 | coverage 17 | 18 | # nyc test coverage 19 | .nyc_output 20 | 21 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 22 | .grunt 23 | 24 | # node-waf configuration 25 | .lock-wscript 26 | 27 | # Compiled binary addons (http://nodejs.org/api/addons.html) 28 | build/Release 29 | 30 | # Dependency directories 31 | node_modules 32 | jspm_packages 33 | 34 | # Optional npm cache directory 35 | .npm 36 | 37 | # Optional eslint cache 38 | .eslintcache 39 | 40 | # Optional REPL history 41 | .node_repl_history 42 | 43 | build 44 | node_modules/ 45 | npm-debug.log 46 | 47 | .vscode -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 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: -------------------------------------------------------------------------------- 1 | ## windows-quiet hours 2 | Easily check if Windows 10 "Quiet Hours" are active - natively, without shelling out, and without any dependencies. 3 | 4 | ``` 5 | npm install windows-quiet-hours 6 | ``` 7 | 8 | ``` 9 | const { getIsQuietHours } = require('windows-quiet-hours`) 10 | const isQuietHours = getIsQuietHours() 11 | ``` 12 | 13 | #### License 14 | MIT, please see LICENSE for details. Copyright (c) 2016 Felix Rieseberg. -------------------------------------------------------------------------------- /binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "targets": [ 3 | { 4 | "target_name": "quiethours", 5 | "sources": [ ], 6 | "cflags!": [ "-fno-exceptions" ], 7 | "cflags_cc!": [ "-fno-exceptions" ], 8 | "defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ], 9 | "include_dirs": [ 10 | " 2 | 3 | #ifdef _WIN32 4 | #include 5 | #include 6 | #include 7 | #else 8 | #include 9 | #endif 10 | 11 | #define PREFERENCE_KEY TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Notifications\\Settings") 12 | 13 | Napi::Boolean Method(const Napi::CallbackInfo& info) { 14 | Napi::Env env = info.Env(); 15 | bool isQuietHours = false; 16 | 17 | #ifdef _WIN32 18 | HKEY hKey; 19 | LPTSTR lpValueName = "NOC_GLOBAL_SETTING_TOASTS_ENABLED"; 20 | LONG lResult; 21 | DWORD dwValue = sizeof(true); 22 | DWORD dwType, dwSize = sizeof(dwValue); 23 | lResult = RegOpenKeyEx(HKEY_CURRENT_USER, PREFERENCE_KEY, 0, KEY_READ, &hKey); 24 | 25 | if (lResult == ERROR_SUCCESS) 26 | { 27 | lResult = RegQueryValueEx(hKey, lpValueName, 0, &dwType, (LPBYTE)&dwValue, &dwSize); 28 | RegCloseKey (hKey); 29 | } 30 | 31 | if (dwValue == 0x00000000) 32 | { 33 | isQuietHours = true; 34 | } 35 | #endif 36 | 37 | return Napi::Boolean::New(env, isQuietHours); 38 | } 39 | 40 | Napi::Object Init(Napi::Env env, Napi::Object exports) { 41 | exports.Set(Napi::String::New(env, "isQuietHours"), 42 | Napi::Function::New(env, Method)); 43 | return exports; 44 | } 45 | 46 | NODE_API_MODULE(quiethours, Init) 47 | 48 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "windows-quiet-hours", 3 | "version": "2.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "bindings": { 8 | "version": "1.5.0", 9 | "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", 10 | "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", 11 | "requires": { 12 | "file-uri-to-path": "1.0.0" 13 | } 14 | }, 15 | "file-uri-to-path": { 16 | "version": "1.0.0", 17 | "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", 18 | "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==" 19 | }, 20 | "node-addon-api": { 21 | "version": "1.7.1", 22 | "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-1.7.1.tgz", 23 | "integrity": "sha512-2+DuKodWvwRTrCfKOeR24KIc5unKjOh8mz17NCzVnHWfjAdDqbfbjqh7gUT+BkXBRQM52+xCHciKWonJ3CbJMQ==" 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "windows-quiet-hours", 3 | "version": "2.0.0", 4 | "description": "Checks if Windows 10 quiet hours are active", 5 | "main": "lib/index.js", 6 | "scripts": { 7 | "test": "standard && node ./test/test.js" 8 | }, 9 | "repository": "https://github.com/felixrieseberg/windows-quiet-hours", 10 | "license": "MIT", 11 | "licenses": [ 12 | { 13 | "type": "MIT", 14 | "url": "http://github.com/felixrieseberg/windows-quiet-hours/blob/master/LICENSE" 15 | } 16 | ], 17 | "dependencies": { 18 | "bindings": "^1.5.0", 19 | "node-addon-api": "*" 20 | }, 21 | "author": { 22 | "email": "felix@felixrieseberg.com", 23 | "name": "Felix Rieseberg", 24 | "url": "http://www.felixrieseberg.com" 25 | }, 26 | "keywords": [ 27 | "windows", 28 | "registry", 29 | "quiet hours" 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /test/benchmark.js: -------------------------------------------------------------------------------- 1 | const perfy = require('perfy') 2 | const isQuietHours = require('../lib/index').getIsQuietHours 3 | const {Key, windef} = require('windows-registry') 4 | 5 | const iterations = process.argv[2] || 100000 6 | 7 | // Surpress windows-registry's dumb logs 8 | const log = console.log 9 | console.log = function () {} 10 | 11 | function getIsQuietHoursThis () { 12 | isQuietHours() 13 | } 14 | 15 | function getIsQuietHoursWinReg () { 16 | const QUIET_HOURS_REGISTRY_KEY = 'NOC_GLOBAL_SETTING_TOASTS_ENABLED' 17 | 18 | try { 19 | let settingsKey = new Key( 20 | windef.HKEY.HKEY_CURRENT_USER, 21 | 'Software\\Microsoft\\Windows\\CurrentVersion\\Notifications\\Settings', 22 | windef.KEY_ACCESS.KEY_READ 23 | ) 24 | 25 | settingsKey.getValue(QUIET_HOURS_REGISTRY_KEY) 26 | } catch (error) { 27 | return false 28 | } 29 | } 30 | 31 | function measureThisTime () { 32 | perfy.start('this') 33 | for (let i = 0; i < iterations; i++) { 34 | getIsQuietHoursThis() 35 | } 36 | 37 | return perfy.end('this').time 38 | } 39 | 40 | function measureWinRegTime () { 41 | perfy.start('winreg') 42 | for (let i = 0; i < iterations; i++) { 43 | getIsQuietHoursWinReg() 44 | } 45 | 46 | return perfy.end('winreg').time 47 | } 48 | 49 | // Fight! 50 | log(`Reading the quiet hours setting ${iterations} times:`) 51 | 52 | const thisTime = measureThisTime() 53 | const wrTime = measureWinRegTime() 54 | 55 | log(`With this addon: ${thisTime}`) 56 | log(`With windows-registry: ${wrTime}`) 57 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert') 2 | const getIsQuietHours = require('../lib/index').getIsQuietHours 3 | const isQuietHours = getIsQuietHours() 4 | 5 | if (process.platform !== 'win32') { 6 | assert.strictEqual(isQuietHours, false) 7 | } else { 8 | const ok = isQuietHours === false || isQuietHours === true 9 | assert.ok(ok, true) 10 | } 11 | --------------------------------------------------------------------------------