├── .editorconfig ├── .gitignore ├── .npmignore ├── .travis.yml ├── LICENSE ├── README.md ├── index.js └── package.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [{package.json,*.yml}] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .editorconfig 2 | .gitignore 3 | .npmignore 4 | .travis.yml 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 'node' 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Daniel Pham 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # electron-osx-appearance 2 | 3 | > APIs for accessing the OS X Appearance Settings. 4 | 5 | Requires: 6 | * **Electron >=0.37.8** 7 | 8 | ## Why? 9 | 10 | * Simple function calls instead of having to remember the name and types of each setting you need to access. 11 | 12 | ## Install 13 | 14 | ``` 15 | $ npm install --save electron-osx-appearance 16 | ``` 17 | 18 | ## Usage 19 | 20 | ```js 21 | const osxPrefs = require('electron-osx-appearance'); 22 | 23 | 24 | if (process.platform === 'darwin') { 25 | osxPrefs.isDarkMode(); 26 | 27 | osxPrefs.onDarkModeChanged(() => { 28 | // Handle the event 29 | }); 30 | } 31 | 32 | // ... 33 | ``` 34 | 35 | **Note**: This module is a wrapper around **OS X specific** methods from Electron's `systemPreferences` module. 36 | 37 | ## Methods 38 | 39 | ### `unsubscribe(id)` 40 | 41 | * `id` Integer 42 | 43 | Remove subscriber with `id`. 44 | 45 | ### `isDarkMode()` 46 | 47 | Returns `true` if the system is in Dark Mode, and `false` otherwise. 48 | 49 | ### `onDarkModeChanged(callback)` 50 | 51 | * `callback` Function 52 | 53 | Subscribe to the Dark Mode changed event. Runs `callback` when event is fired. 54 | 55 | Returns the `id` with which you can then unsubscribe. 56 | 57 | ### `isTintBlue()` 58 | 59 | This method return `true` if the system is using the blue tint, `false` otherwise. 60 | 61 | ### `getTint()` 62 | 63 | Return a `String` with the system's current Tint. 64 | 65 | Possible values are `'blue'` or `'graphite'`. 66 | 67 | ### `onTintChanged(callback)` 68 | 69 | * `callback` Function 70 | 71 | Subscribe to the Tint changed event. Runs `callback` when event is fired. 72 | 73 | Returns the `id` with which you can then unsubscribe with. 74 | 75 | ### `getHighlightColour()` 76 | 77 | Returns an RGB `array` of the system's current Highlight Colour. 78 | 79 | If none is found, returns `[9, 92, 220]` as default. 80 | 81 | ### `onHighlightColourChanged(callback)` 82 | 83 | * `callback` Function 84 | 85 | Subscribe to the Highlight Colour changed event. Runs `callback` when event is fired. 86 | 87 | Returns the `id` with which you can then unsubscribe with. 88 | 89 | ### `getSidebarIconSize()` 90 | 91 | Returns `String` with the system's current Sidebar Icon Size. 92 | 93 | Possible values are `small`, `medium` or `large`. 94 | 95 | ### `onSidebarIconSizeChanged(callback)` 96 | 97 | * `callback` Function 98 | 99 | Subscribe to the Sidebar Icon Size changed event. Runs `callback` when event is fired. 100 | 101 | Returns the `id` with which you can then unsubscribe with. 102 | 103 | ### `getScrollbarVisibility()` 104 | 105 | Returns a `String` with the system's current Scrollbar Visibility. 106 | 107 | Possible values are `automatic`, `whenscrolling` or `always`. 108 | 109 | ### `onScrollbarVisibilityChanged(callback)` 110 | 111 | * `callback` Function 112 | 113 | Subscribe to the Scrollbar Visibility changed event. Runs `callback` when event is fired. 114 | 115 | Returns the `id` with which you can then unsubscribe with. 116 | 117 | ### `isScrollbarPaging()` 118 | 119 | Returns `true` if the system is using Scrollbar Paging, `false` otherwise. 120 | 121 | ### `onScrollbarPagingChanged(callback)` 122 | 123 | * `callback` Function 124 | 125 | Subscribe to the Scrollbar Paging changed event. Runs `callback` when event is fired. 126 | 127 | Returns the `id` with which you can then unsubscribe with. 128 | 129 | ## License 130 | 131 | MIT © Daniel Pham 132 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const electron = require('electron'); 3 | 4 | const prefs = electron.systemPreferences || electron.remote.systemPreferences; 5 | 6 | exports.unsubscribe = id => { 7 | prefs.unsubscribeNotification(id); 8 | }; 9 | 10 | /* DARK MODE */ 11 | exports.isDarkMode = () => { 12 | return prefs.isDarkMode(); 13 | }; 14 | 15 | exports.onDarkModeChanged = callback => { 16 | return prefs.subscribeNotification('AppleInterfaceThemeChangedNotification', callback); 17 | }; 18 | 19 | /* TINT */ 20 | exports.isTintBlue = () => { 21 | return prefs.getUserDefault('AppleAquaColorVariant', 'string') === '1'; 22 | }; 23 | 24 | exports.getTint = () => { 25 | return prefs.getUserDefault('AppleAquaColorVariant', 'string') === '1' ? 'blue' : 'graphite'; 26 | }; 27 | 28 | exports.onTintChanged = callback => { 29 | return prefs.subscribeNotification('AppleAquaColorVariantChanged', callback); 30 | }; 31 | 32 | /* HIGHLIGHT COLOUR */ 33 | exports.getHighlightColour = () => { 34 | const colour = prefs.getUserDefault('AppleHighlightColor', 'string'); 35 | let rgb = [9, 92, 220]; 36 | if (colour) { 37 | rgb = colour.split(' ').map(i => Math.round(Number(i) * 255)); 38 | } 39 | return rgb; 40 | }; 41 | 42 | exports.onHighlightColourChanged = callback => { 43 | return prefs.subscribeNotification('AppleColorPreferencesChangedNotification', callback); 44 | }; 45 | 46 | /* SIDEBAR ICON SIZE */ 47 | exports.getSidebarIconSize = () => { 48 | const iconSize = prefs.getUserDefault('NSTableViewDefaultSizeMode', 'string'); 49 | 50 | switch (iconSize) { 51 | case '1': return 'small'; 52 | case '3': return 'large'; 53 | default: return 'medium'; 54 | } 55 | }; 56 | 57 | exports.onIconSizeChanged = callback => { 58 | return prefs.subscribeNotification('AppleSideBarDefaultIconSizeChanged', callback); 59 | }; 60 | 61 | /* SCROLLBAR VISIBILITY */ 62 | exports.getScrollbarVisibility = () => { 63 | return prefs.getUserDefault('AppleShowScrollBars', 'string').trim().toLowerCase(); 64 | }; 65 | 66 | exports.onScrollbarVisibilityChanged = callback => { 67 | return prefs.subscribeNotification('AppleShowScrollBarsSettingChanged', callback); 68 | }; 69 | 70 | /* SCROLLBAR PAGING */ 71 | exports.isScrollbarPaging = () => { 72 | return prefs.getUserDefault('AppleScrollerPagingBehavior', 'boolean'); 73 | }; 74 | 75 | exports.onScrollbarPagingChanged = callback => { 76 | return prefs.subscribeNotification('AppleNoRedisplayAppearancePreferenceChanged', callback); 77 | }; 78 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "electron-osx-appearance", 3 | "version": "0.1.1", 4 | "description": "APIs to access the OS X Appearance Settings.", 5 | "license": "MIT", 6 | "repository": "danhp/electron-osx-appearance", 7 | "author": { 8 | "name": "Daniel Pham", 9 | "email": "pham.dany@gmail.com", 10 | "url": "github.com/danhp" 11 | }, 12 | "scripts": { 13 | "test": "xo" 14 | }, 15 | "files": [ 16 | "index.js" 17 | ], 18 | "keywords": [ 19 | "electron", 20 | "appearance", 21 | "settings", 22 | "osx" 23 | ], 24 | "devDependencies": { 25 | "electron": "1.4.0", 26 | "xo": "*" 27 | }, 28 | "xo": { 29 | "esnext": true, 30 | "envs": [ 31 | "node", 32 | "browser" 33 | ] 34 | } 35 | } 36 | --------------------------------------------------------------------------------