Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed: Item Arrays now work #7

Merged
merged 5 commits into from
Sep 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
.jshintrc
npm-debug.log
node_modules
22 changes: 0 additions & 22 deletions .jshintrc

This file was deleted.

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Touch Bar Utility

<div class="alert alert-warning" role="alert">
<strong>Beware</strong> This package only works with Atom Beta v1.19
<strong>Beware</strong> This package only works with Atom >=v1.19
</div>
<br>
An Atom package that allows you to assign custom actions to Touch Bar components.
Expand All @@ -10,7 +10,7 @@ An Atom package that allows you to assign custom actions to Touch Bar components
1. Go to File → Settings → Packages
2. Find touch-bar-utility and click on the card **but not on the name of the package**
3. Go to Settings and edit the Buttons entry with a JSON array of Touch Bar components
* A component has the following format: {type: <typeOfElement>\[, ...\]}
* A component has the following format: {"type": "&lt;typeOfElement&gt;"\[, ...\]}

## Touch Bar Components

Expand All @@ -22,7 +22,7 @@ An Atom package that allows you to assign custom actions to Touch Bar components
pathOfIcon | **String** | _Yes_ | Path to button icon.
iconPosition | **String** | _No_ | Can be left, right or overlay.
click | **Function** | _Yes_ | Function to call when the button is clicked.
clickDispatchAction | **String** | _Yes_ | Event from another package that you want to execute when button is clicked. It will override the click property. It must be in the following format: "<package-name>:<event-name>" without quotation marks.
clickDispatchAction | **String** | _Yes_ | Event from another package that you want to execute when button is clicked. It will override the click property. It must be in the following format: "&lt;package-name&gt;:&lt;event-name&gt;" without quotation marks.
dispatchActionTarget | **String** | _Yes_ | Can have a value of 'workspace' or 'editor'. It defaults to 'workspace'.

### TouchBarColorPicker (type: "color-picker")
Expand All @@ -46,8 +46,8 @@ An Atom package that allows you to assign custom actions to Touch Bar components
Name of variable | Type of variable | Optional | Description
-----------------|---------------------------|----------|--------------------------------------------------------------------------------------------------
label | **String** | _Yes_ | Popover button text.
<!-- pathOfIcon | **String** | _Yes_ | Popover button icon. -->
<!-- items | **Array of elements** | _Yes_ | Items to display in the popover. -->
pathOfIcon | **String** | _Yes_ | Popover button icon.
items | **Array of elements** | _Yes_ | Items to display in the popover.
showCloseButton | **Boolean** | _Yes_ | true to display a close button on the left of the popover, false to not show it. Default is true.

### TouchBarSlider (type: "slider")
Expand Down
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
## TODO
* Add Touch Bar screenshot with sample configuration
* Add TouchBarScrubber and TouchBarSegmentedControl to the list of supported Touch Bar elements
6 changes: 3 additions & 3 deletions lib/touch-bar-utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function configureButtons(configString, callback) {
} = TouchBar

try {
let itemsConfig = JSON.parse(configString);
let itemsConfig = (typeof configString==='string')?JSON.parse(configString):configString;
let items = [];

itemsConfig.forEach(function(element) {
Expand Down Expand Up @@ -190,7 +190,7 @@ function configureButtons(configString, callback) {
break;

case 'group':
if (!element.items || typeof element.items !== 'object' || element.items.name != 'TouchBar')
if (!element.items || typeof element.items !== 'object' || !Array.isArray(element.items))
return callback(new Error("The touch-bar-group's items must be an array of elements"));

configureButtons(element.items, function(err, items) {
Expand Down Expand Up @@ -223,7 +223,7 @@ function configureButtons(configString, callback) {
return callback(new Error("The popover's label must be a string"));
if (element.pathOfIcon && typeof element.pathOfIcon !== 'string')
return callback(new Error("The popover's pathOfIcon must be a a string path pointing to PNG or JPEG file"));
if (element.items && (typeof element.items !== 'object' || element.items.name != 'TouchBar'))
if (element.items && (typeof element.items !== 'object' || !Array.isArray(element.items)))
return callback(new Error("The popover's items must be an array of elements"));
if (element.showCloseButton && typeof element.showCloseButton !== 'boolean')
return callback(new Error("The popover's showCloseButton must be a boolean"));
Expand Down