Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit 8aafc87

Browse files
Fix bug: Search path for Library Manager is incomplete (#166)
* Fix bug: Search path for Library Manager is incomplete * filter folders when parsing libraries * Refactor libraryManager & boardManager code
1 parent e36c976 commit 8aafc87

File tree

9 files changed

+166
-87
lines changed

9 files changed

+166
-87
lines changed

html/app/components/BoardItemView.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ export default class BoardView extends React.Component<IBoardProps, IBoardState>
5252
private buildBoardSectionHeader(p) {
5353
return (<div>
5454
<span className="listitem-header">{p.name}</span>
55+
{
56+
p.defaultPlatform && (<span> Built-In </span>)
57+
}
5558
<span className="listitem-author"> by <span className="listitem-header">{p.package.maintainer}</span></span>
5659
{
5760
p.installedVersion && (

html/app/components/LibraryItemView.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,13 @@ export default class LibraryItemView extends React.Component<ILibraryProps, ILib
127127
this.state.isUninstalling && (<div className="toolbar-mask theme-bgcolor">Removing</div>)
128128
}
129129
{
130-
lib.version && (
130+
lib.installed && (
131131
<div className="right-side">
132-
<Button className="operation-btn" onClick={() => this.addLibPath(lib.srcPath)}>Add to Include Path</Button>
132+
{
133+
lib.supported && (
134+
<Button className="operation-btn" onClick={() => this.addLibPath(lib.srcPath)}>Add to Include Path</Button>
135+
)
136+
}
133137
{
134138
lib.versions && lib.versions.length && util.versionCompare(lib.versions[0], lib.version) > 0 && (
135139
<Button className="operation-btn" onClick={() => this.installLibrary(lib.name, lib.versions[0])}>Update</Button>

html/app/components/LibraryManager.tsx

+15-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*-------------------------------------------------------------------------------------------*/
55

66
import * as React from "react";
7-
import { Button, DropdownButton, MenuItem } from "react-bootstrap";
7+
import { Button, Checkbox, DropdownButton, MenuItem } from "react-bootstrap";
88
import { connect } from "react-redux";
99
import SearchInput, { createFilter } from "react-search-input";
1010
import * as actions from "../actions";
@@ -28,6 +28,7 @@ interface ILibraryManagerState extends React.Props<any> {
2828
searchTerm: string;
2929
type: string;
3030
topic: string;
31+
checked: boolean;
3132
}
3233

3334
const mapStateToProps = (store) => {
@@ -72,10 +73,12 @@ class LibraryManager extends React.Component<ILibraryManagerProps, ILibraryManag
7273
searchTerm: "",
7374
type: "All",
7475
topic: "All",
76+
checked: false,
7577
};
7678
this.typeUpdate = this.typeUpdate.bind(this);
7779
this.topicUpdate = this.topicUpdate.bind(this);
7880
this.searchUpdate = this.searchUpdate.bind(this);
81+
this.handleCheck = this.handleCheck.bind(this);
7982
}
8083

8184
public componentWillMount() {
@@ -103,8 +106,8 @@ class LibraryManager extends React.Component<ILibraryManagerProps, ILibraryManag
103106
switch (topic) {
104107
case "All":
105108
return true;
106-
case "Uncatogorized":
107-
return !element.category;
109+
case "Uncategorized":
110+
return !element.category || element.category === topic;
108111
default:
109112
return element.category === topic;
110113
}
@@ -114,7 +117,8 @@ class LibraryManager extends React.Component<ILibraryManagerProps, ILibraryManag
114117
const filterSearch = createFilter(this.state.searchTerm, SEARCH_KEYS);
115118
let totalCount = 0;
116119
this.props.libraries.forEach((element) => {
117-
if (filterType(element, this.state.type) && filterTopic(element, this.state.topic) && filterSearch(element)) {
120+
const filterSupported = this.state.checked ? element.supported : true;
121+
if (filterSupported && filterType(element, this.state.type) && filterTopic(element, this.state.topic) && filterSearch(element)) {
118122
element.shouldBeDisplayed = true;
119123
totalCount++;
120124
} else {
@@ -154,6 +158,7 @@ class LibraryManager extends React.Component<ILibraryManagerProps, ILibraryManag
154158
})}
155159
</DropdownButton>
156160
<SearchInput className="search-input" placeholder="Filter your search..." onChange={this.searchUpdate} />
161+
<Checkbox className="supported-checkbox" onChange={this.handleCheck}>Only show libraries supported by current board</Checkbox>
157162
</div>
158163
<div className="arduinomanager-container">
159164
{
@@ -187,6 +192,12 @@ class LibraryManager extends React.Component<ILibraryManagerProps, ILibraryManag
187192
searchTerm: term,
188193
});
189194
}
195+
196+
private handleCheck() {
197+
this.setState({
198+
checked: !this.state.checked,
199+
});
200+
}
190201
}
191202

192203
export default connect(mapStateToProps, mapDispatchToProps)(LibraryManager);

html/app/reducers/libraryManagerReducer.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ export function libraryManagerReducer(state = initalState, action) {
3030
return item.category || "Uncategorized";
3131
});
3232
// Sorting versions in descending order.
33-
action.libraries.forEach((element) => {
33+
// for loop is faster than forEach iterator.
34+
for (let element of action.libraries) {
3435
element.versions = element.versions ? element.versions.sort(util.versionCompare).reverse() : element.versions;
35-
});
36+
}
3637
return {
3738
...state,
3839
libraries: action.libraries,

html/app/styles/board.scss

+15-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020

2121
.arduinomanager-toolbar {
22-
height: 60px;
22+
min-height: 60px;
2323
padding: 15px 10px;
2424
position: fixed;
2525
width: 100%;
@@ -162,6 +162,20 @@ a {
162162
}
163163

164164
.librarymanager {
165+
.arduinomanager-toolbar {
166+
min-height: 80px;
167+
}
168+
169+
.supported-checkbox {
170+
margin-top: -5px;
171+
margin-bottom: 0px;
172+
padding-left: 5px;
173+
}
174+
175+
.arduinomanager-container {
176+
padding-top: 80px;
177+
}
178+
165179
.search-input {
166180
margin-left: 380px;
167181
padding-top: 0px;

src/arduino/boardManager.ts

+7-15
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ export class BoardManager {
211211
this.parsePackageIndex(JSON.parse(packageContent));
212212
}
213213

214-
this.loadInstalledPlatforms();
215214
this.loadDefaultPlatforms();
215+
this.loadInstalledPlatforms();
216216

217217
this.loadInstalledBoards();
218218
this.updateStatusBar();
@@ -280,18 +280,10 @@ export class BoardManager {
280280

281281
private loadDefaultPlatforms() {
282282
// Default arduino package information:
283-
const arduinoPath = this._settings.arduinoPath;
284283
const packageName = "arduino";
285284
const archName = "avr";
286-
let defaultPlatformPath = path.join(arduinoPath, "hardware");
287-
const platform = os.platform();
288-
if (platform === "darwin") {
289-
defaultPlatformPath = path.join(arduinoPath, "Arduino.app/Contents/Java/hardware");
290-
} else if (platform === "linux") {
291-
// TODO Check default platform path at linux.
292-
}
293285
try {
294-
let packageBundled = fs.readFileSync(path.join(defaultPlatformPath, "package_index_bundled.json"), "utf8");
286+
let packageBundled = fs.readFileSync(path.join(this._settings.defaultPackagePath, "package_index_bundled.json"), "utf8");
295287
if (!packageBundled) {
296288
return;
297289
}
@@ -315,7 +307,7 @@ export class BoardManager {
315307
return;
316308
} else {
317309
filteredPlat.installedVersion = v;
318-
filteredPlat.rootBoardPath = path.join(defaultPlatformPath, "arduino/avr");
310+
filteredPlat.rootBoardPath = path.join(this._settings.defaultPackagePath, "arduino", "avr");
319311
this.installedPlatforms.push(filteredPlat);
320312
}
321313
}
@@ -351,11 +343,11 @@ export class BoardManager {
351343

352344
private loadInstalledPlatforms(): void {
353345
this._installedPlatforms = [];
354-
let rootPacakgesPath = path.join(path.join(this._settings.packagePath, "packages"));
355-
if (!util.directoryExistsSync(rootPacakgesPath)) {
346+
let rootPackagePath = path.join(path.join(this._settings.packagePath, "packages"));
347+
if (!util.directoryExistsSync(rootPackagePath)) {
356348
return;
357349
}
358-
const dirs = util.filterJunk(fs.readdirSync(rootPacakgesPath)); // in Mac, filter .DS_Store file.
350+
const dirs = util.filterJunk(util.readdirSync(rootPackagePath, true)); // in Mac, filter .DS_Store file.
359351
dirs.forEach((packageName) => {
360352
let archPath = path.join(this._settings.packagePath, "packages", packageName, "hardware");
361353
if (!util.directoryExistsSync(archPath)) {
@@ -369,6 +361,7 @@ export class BoardManager {
369361
let allVersion = util.filterJunk(fs.readdirSync(path.join(archPath, architecture)));
370362
let existingPlatform = this._platforms.find((_plat) => _plat.package.name === packageName && _plat.architecture === architecture);
371363
if (existingPlatform && allVersion && allVersion.length) {
364+
existingPlatform.defaultPlatform = false;
372365
existingPlatform.installedVersion = allVersion[0];
373366
existingPlatform.rootBoardPath = path.join(archPath, architecture, allVersion[0]);
374367
this._installedPlatforms.push(existingPlatform);
@@ -378,7 +371,6 @@ export class BoardManager {
378371
}
379372

380373
private loadInstalledBoards(): void {
381-
// let boards: Map<string, IBoard> = new Map<string, IBoard>();
382374
this._boards = new Map<string, IBoard>();
383375
this.installedPlatforms.forEach((plat) => {
384376
let dir = plat.rootBoardPath;

0 commit comments

Comments
 (0)