diff --git a/.eslintignore b/.eslintignore
new file mode 100644
index 0000000..c795b05
--- /dev/null
+++ b/.eslintignore
@@ -0,0 +1 @@
+build
\ No newline at end of file
diff --git a/.eslintrc b/.eslintrc
new file mode 100644
index 0000000..d83e491
--- /dev/null
+++ b/.eslintrc
@@ -0,0 +1,45 @@
+{
+ 'extends': [
+ 'xo',
+ 'plugin:react/recommended'
+ ],
+ "rules": {
+ "array-bracket-spacing": [
+ "error",
+ "always"
+ ],
+ "padded-blocks": [
+ "error",
+ {
+ "blocks": "always",
+ "switches": "always",
+ "classes": "always"
+ }
+ ],
+ "padding-line-between-statements": [
+ "error",
+ {
+ "blankLine": "always",
+ "prev": "multiline-block-like",
+ "next": "*"
+ },
+ {
+ "blankLine": "always",
+ "prev": "*",
+ "next": "return"
+ }
+ ],
+ "object-curly-spacing": [
+ "error",
+ "always"
+ ],
+ "semi": [
+ 2,
+ "never"
+ ],
+ "space-in-parens": [
+ "error",
+ "always"
+ ]
+ }
+}
diff --git a/README.md b/README.md
index 264397e..fd383a6 100644
--- a/README.md
+++ b/README.md
@@ -3,9 +3,9 @@
- [Electron Preferences](#electron-preferences)
- [Introduction](#introduction)
- [Getting Started](#getting-started)
- - [Initializing the Preferences Service](#initializing-the-preferences-service)
- - [Interacting with the Preferences Service from the Main Process](#interacting-with-the-preferences-service-from-the-main-process)
- - [Interacting with the Preferences Service from the Renderer Process](#interacting-with-the-preferences-service-from-the-renderer-process)
+ - [Initializing the Preferences Service](#initializing-the-preferences-service)
+ - [Interacting with the Preferences Service from the Main Process](#interacting-with-the-preferences-service-from-the-main-process)
+ - [Interacting with the Preferences Service from the Renderer Process](#interacting-with-the-preferences-service-from-the-renderer-process)
- [Field Types](#field-types)
- [Icons](#icons)
@@ -24,11 +24,13 @@ Using the API, developers can:
To see the library in action, clone this repository and see the demo application that is included within the `example` folder:
- $ git clone https://github.com/tkambler/electron-preferences.git
- $ cd electron-preferences
- $ npm i
- $ npm run build
- $ npm run example
+ $ git clone https://github.com/tkambler/electron-preferences.git
+ $ cd electron-preferences
+ $ npm i
+ $ npm run build
+ $ npm run example
+ $ npm run lint
+
@@ -47,200 +49,200 @@ const os = require('os');
const ElectronPreferences = require('electron-preferences');
const preferences = new ElectronPreferences({
- /**
- * Where should preferences be saved?
- */
- 'dataStore': path.resolve(app.getPath('userData'), 'preferences.json'),
- /**
- * Default values.
- */
- 'defaults': {
- 'notes': {
- 'folder': path.resolve(os.homedir(), 'Notes')
- },
- 'markdown': {
- 'auto_format_links': true,
- 'show_gutter': false
- },
- 'preview': {
- 'show': true
- },
- 'drawer': {
- 'show': true
- }
- },
- /**
- * The preferences window is divided into sections. Each section has a label, an icon, and one or
- * more fields associated with it. Each section should also be given a unique ID.
- */
- 'sections': [
- {
- 'id': 'about',
- 'label': 'About You',
- /**
- * See the list of available icons below.
- */
- 'icon': 'single-01',
- 'form': {
- 'groups': [
- {
- /**
- * Group heading is optional.
- */
- 'label': 'About You',
- 'fields': [
- {
- 'label': 'First Name',
- 'key': 'first_name',
- 'type': 'text',
- /**
- * Optional text to be displayed beneath the field.
- */
- 'help': 'What is your first name?'
- },
- {
- 'label': 'Last Name',
- 'key': 'last_name',
- 'type': 'text',
- 'help': 'What is your last name?'
- },
- {
- 'label': 'Gender',
- 'key': 'gender',
- 'type': 'dropdown',
- 'options': [
- {'label': 'Male', 'value': 'male'},
- {'label': 'Female', 'value': 'female'},
- {'label': 'Unspecified', 'value': 'unspecified'},
- ],
- 'help': 'What is your gender?'
- },
- {
- 'label': 'Which of the following foods do you like?',
- 'key': 'foods',
- 'type': 'checkbox',
- 'options': [
- { 'label': 'Ice Cream', 'value': 'ice_cream' },
- { 'label': 'Carrots', 'value': 'carrots' },
- { 'label': 'Cake', 'value': 'cake' },
- { 'label': 'Spinach', 'value': 'spinach' }
- ],
- 'help': 'Select one or more foods that you like.'
- },
- {
- 'label': 'Coolness',
- 'key': 'coolness',
- 'type': 'slider',
- 'min': 0,
- 'max': 9001
- },
- {
- 'label': 'Eye Color',
- 'key': 'eye_color',
- 'type': 'color',
- 'format': 'hex', // can be hex, hsl or rgb
- 'help': 'Your eye color'
- },
- {
- 'label': 'Hair Color',
- 'key': 'hair_color',
- 'type': 'color',
- 'format': 'rgb',
- 'help': 'Your hair color'
- }
- ]
- }
- ]
- }
- },
- {
- 'id': 'notes',
- 'label': 'Notes',
- 'icon': 'folder-15',
- 'form': {
- 'groups': [
- {
- 'label': 'Stuff',
- 'fields': [
- {
- 'label': 'Read notes from folder',
- 'key': 'folder',
- 'type': 'directory',
- 'help': 'The location where your notes will be stored.'
- },
- {
- 'heading': 'Important Message',
- 'content': '
The quick brown fox jumps over the long white fence. The quick brown fox jumps over the long white fence. The quick brown fox jumps over the long white fence. The quick brown fox jumps over the long white fence.
', - 'type': 'message', - } - ] - } - ] - } - }, - { - 'id': 'space', - 'label': 'Other Settings', - 'icon': 'spaceship', - 'form': { - 'groups': [ - { - 'label': 'Other Settings', - 'fields': [ - { - 'label': 'Phone Number', - 'key': 'phone_number', - 'type': 'text', - 'help': 'What is your phone number?' - }, - { - 'label': "Foo or Bar?", - 'key': 'foobar', - 'type': 'radio', - 'options': [ - {'label': 'Foo', 'value': 'foo'}, - {'label': 'Bar', 'value': 'bar'}, - {'label': 'FooBar', 'value': 'foobar'}, - ], - 'help': 'Foo? Bar?' - } - ] - } - ] - } - } - ], - /** - * These parameters on the preference window settings can be overwrinten - */ - browserWindowOpts: { - 'title': 'My custom preferences title', - 'width': 900, - 'maxWidth': 1000, - 'height': 700, - 'maxHeight': 1000, - 'resizable': true, - 'maximizable': false, - //... - }, - /** - * These parameters create an optional menu bar - */ - menu: Menu.buildFromTemplate( - [ - { - label: 'Window', - role: 'window', - submenu: [ - { - label: 'Close', - accelerator: 'CmdOrCtrl+W', - role: 'close' - } - ] - } - ] - ) + /** + * Where should preferences be saved? + */ + 'dataStore': path.resolve(app.getPath('userData'), 'preferences.json'), + /** + * Default values. + */ + 'defaults': { + 'notes': { + 'folder': path.resolve(os.homedir(), 'Notes') + }, + 'markdown': { + 'auto_format_links': true, + 'show_gutter': false + }, + 'preview': { + 'show': true + }, + 'drawer': { + 'show': true + } + }, + /** + * The preferences window is divided into sections. Each section has a label, an icon, and one or + * more fields associated with it. Each section should also be given a unique ID. + */ + 'sections': [ + { + 'id': 'about', + 'label': 'About You', + /** + * See the list of available icons below. + */ + 'icon': 'single-01', + 'form': { + 'groups': [ + { + /** + * Group heading is optional. + */ + 'label': 'About You', + 'fields': [ + { + 'label': 'First Name', + 'key': 'first_name', + 'type': 'text', + /** + * Optional text to be displayed beneath the field. + */ + 'help': 'What is your first name?' + }, + { + 'label': 'Last Name', + 'key': 'last_name', + 'type': 'text', + 'help': 'What is your last name?' + }, + { + 'label': 'Gender', + 'key': 'gender', + 'type': 'dropdown', + 'options': [ + {'label': 'Male', 'value': 'male'}, + {'label': 'Female', 'value': 'female'}, + {'label': 'Unspecified', 'value': 'unspecified'}, + ], + 'help': 'What is your gender?' + }, + { + 'label': 'Which of the following foods do you like?', + 'key': 'foods', + 'type': 'checkbox', + 'options': [ + { 'label': 'Ice Cream', 'value': 'ice_cream' }, + { 'label': 'Carrots', 'value': 'carrots' }, + { 'label': 'Cake', 'value': 'cake' }, + { 'label': 'Spinach', 'value': 'spinach' } + ], + 'help': 'Select one or more foods that you like.' + }, + { + 'label': 'Coolness', + 'key': 'coolness', + 'type': 'slider', + 'min': 0, + 'max': 9001 + }, + { + 'label': 'Eye Color', + 'key': 'eye_color', + 'type': 'color', + 'format': 'hex', // can be hex, hsl or rgb + 'help': 'Your eye color' + }, + { + 'label': 'Hair Color', + 'key': 'hair_color', + 'type': 'color', + 'format': 'rgb', + 'help': 'Your hair color' + } + ] + } + ] + } + }, + { + 'id': 'notes', + 'label': 'Notes', + 'icon': 'folder-15', + 'form': { + 'groups': [ + { + 'label': 'Stuff', + 'fields': [ + { + 'label': 'Read notes from folder', + 'key': 'folder', + 'type': 'directory', + 'help': 'The location where your notes will be stored.' + }, + { + 'heading': 'Important Message', + 'content': 'The quick brown fox jumps over the long white fence. The quick brown fox jumps over the long white fence. The quick brown fox jumps over the long white fence. The quick brown fox jumps over the long white fence.
', + 'type': 'message', + } + ] + } + ] + } + }, + { + 'id': 'space', + 'label': 'Other Settings', + 'icon': 'spaceship', + 'form': { + 'groups': [ + { + 'label': 'Other Settings', + 'fields': [ + { + 'label': 'Phone Number', + 'key': 'phone_number', + 'type': 'text', + 'help': 'What is your phone number?' + }, + { + 'label': "Foo or Bar?", + 'key': 'foobar', + 'type': 'radio', + 'options': [ + {'label': 'Foo', 'value': 'foo'}, + {'label': 'Bar', 'value': 'bar'}, + {'label': 'FooBar', 'value': 'foobar'}, + ], + 'help': 'Foo? Bar?' + } + ] + } + ] + } + } + ], + /** + * These parameters on the preference window settings can be overwrinten + */ + browserWindowOpts: { + 'title': 'My custom preferences title', + 'width': 900, + 'maxWidth': 1000, + 'height': 700, + 'maxHeight': 1000, + 'resizable': true, + 'maximizable': false, + //... + }, + /** + * These parameters create an optional menu bar + */ + menu: Menu.buildFromTemplate( + [ + { + label: 'Window', + role: 'window', + submenu: [ + { + label: 'Close', + accelerator: 'CmdOrCtrl+W', + role: 'close' + } + ] + } + ] + ) }); ```` @@ -258,7 +260,7 @@ preferences.value('some.nested.key', 'my-value'); // Subscribing to preference changes. preferences.on('save', (preferences) => { - console.log(`Preferences were saved.`, JSON.stringify(preferences, null, 4)); + console.log(`Preferences were saved.`, JSON.stringify(preferences, null, 4)); }); ``` @@ -275,7 +277,7 @@ ipcRenderer.send('showPreferences'); // Listen to the `preferencesUpdated` event to be notified when preferences are changed. ipcRenderer.on('preferencesUpdated', (e, preferences) => { - console.log('Preferences were updated', preferences); + console.log('Preferences were updated', preferences); }); // Instruct the preferences service to update the preferences object from within the renderer. @@ -311,255 +313,255 @@ The following icons come packaged with the library and can be specified when youName | -Icon | -
---|---|
Name | +Icon | +
archive-2 | -|
archive-paper | -|
award-48 | -|
badge-13 | -|
bag-09 | -|
barcode-qr | -|
bear-2 | -|
bell-53 | -|
bookmark-2 | -|
brightness-6 | -|
briefcase-24 | -|
calendar-60 | -|
camera-20 | -|
cart-simple | -|
chat-46 | -|
check-circle-07 | -|
cloud-26 | -|
compass-05 | -|
dashboard-level | -|
diamond | -|
edit-78 | -|
email-84 | -|
eye-19 | -|
favourite-31 | -|
flag-points-32 | -|
flash-21 | -|
folder-15 | -|
gift-2 | -|
grid-45 | -|
handout | -|
heart-2 | -|
home-52 | -|
image | -|
key-25 | -|
layers-3 | -|
like-2 | -|
link-72 | -|
lock-open | -|
lock | -|
multiple-11 | -|
notes | -|
pencil | -|
phone-2 | -|
preferences | -|
send-2 | -|
settings-gear-63 | -|
single-01 | -|
single-folded-content | -|
skull-2 | -|
spaceship | -|
square-download | -|
square-upload | -|
support-16 | -|
trash-simple | -|
turtle | -|
vector | -|
video-66 | -|
wallet-43 | -|
widget | -|
world | -|
zoom-2 | -|
archive-2 | +|
archive-paper | +|
award-48 | +|
badge-13 | +|
bag-09 | +|
barcode-qr | +|
bear-2 | +|
bell-53 | +|
bookmark-2 | +|
brightness-6 | +|
briefcase-24 | +|
calendar-60 | +|
camera-20 | +|
cart-simple | +|
chat-46 | +|
check-circle-07 | +|
cloud-26 | +|
compass-05 | +|
dashboard-level | +|
diamond | +|
edit-78 | +|
email-84 | +|
eye-19 | +|
favourite-31 | +|
flag-points-32 | +|
flash-21 | +|
folder-15 | +|
gift-2 | +|
grid-45 | +|
handout | +|
heart-2 | +|
home-52 | +|
image | +|
key-25 | +|
layers-3 | +|
like-2 | +|
link-72 | +|
lock-open | +|
lock | +|
multiple-11 | +|
notes | +|
pencil | +|
phone-2 | +|
preferences | +|
send-2 | +|
settings-gear-63 | +|
single-01 | +|
single-folded-content | +|
skull-2 | +|
spaceship | +|
square-download | +|
square-upload | +|
support-16 | +|
trash-simple | +|
turtle | +|
vector | +|
video-66 | +|
wallet-43 | +|
widget | +|
world | +|
zoom-2 | +