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

Add autoUpdateIndexFiles option in settings #178

Merged
merged 5 commits into from
Mar 22, 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
8 changes: 4 additions & 4 deletions html/app/actions/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ function postHTTP(url, postData) {
return window.fetch(request);
}

export function getBoardPackages() {
return window.fetch("/api/boardpackages").then((response) => response.json());
export function getBoardPackages(update) {
return window.fetch(`/api/boardpackages?update=${update}`).then((response) => response.json());
}

export function installBoard(packageName, arch, version) {
Expand All @@ -39,8 +39,8 @@ export function openLink(link) {
}).then((response) => response.json());
}

export function getLibraries() {
return window.fetch("/api/libraries").then((response) => response.json());
export function getLibraries(update) {
return window.fetch(`/api/libraries?update=${update}`).then((response) => response.json());
}

export function installLibrary(libraryName, version) {
Expand Down
8 changes: 4 additions & 4 deletions html/app/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ export function uninstallLibraryFailure(libraryName, errorMessage) {
};
}

export function getBoardPackages(dispatch) {
export function getBoardPackages(dispatch, update: boolean) {
dispatch(boardPackagesRequest());
API.getBoardPackages().then((response) => {
API.getBoardPackages(update).then((response) => {
const { platforms } = <any>response;
dispatch(boardPackagesSuccess(JSONHelper.retrocycle(platforms)));
}).catch((error) => {
Expand Down Expand Up @@ -183,9 +183,9 @@ export function uninstallBoard(dispatch, boardName, packagePath, callback?: Func
});
}

export function getLibraries(dispatch, callback?: Function) {
export function getLibraries(dispatch, update: boolean, callback?: Function) {
dispatch(librariesRequest());
API.getLibraries().then((response) => {
API.getLibraries(update).then((response) => {
const { libraries } = <any>response;
dispatch(librariesSuccess(libraries));
if (callback) {
Expand Down
6 changes: 3 additions & 3 deletions html/app/components/BoardManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ const mapStateToProps = (state) => {

const mapDispatchToProps = (dispatch) => {
return {
loadBoardPackages: () => actions.getBoardPackages(dispatch),
loadBoardPackages: () => actions.getBoardPackages(dispatch, true),
installBoard: (boardName, packageName, arch, version) => actions.installBoard(dispatch, boardName, packageName, arch, version, () => {
actions.getBoardPackages(dispatch);
actions.getBoardPackages(dispatch, false);
}),
uninstallBoard: (boardName, packagePath) => actions.uninstallBoard(dispatch, boardName, packagePath, () => {
actions.getBoardPackages(dispatch);
actions.getBoardPackages(dispatch, false);
}),
};
};
Expand Down
6 changes: 3 additions & 3 deletions html/app/components/LibraryManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ const mapStateToProps = (store) => {

const mapDispatchToProps = (dispatch) => {
return {
loadLibraries: () => actions.getLibraries(dispatch),
loadLibraries: () => actions.getLibraries(dispatch, true),
installLibrary: (libraryName, version, callback) => actions.installLibrary(dispatch, libraryName, version, (error) => {
if (!error) {
// Refresh library manager view
actions.getLibraries(dispatch, callback);
actions.getLibraries(dispatch, false, callback);
} else {
callback();
}
}),
uninstallLibrary: (libraryName, libraryPath, callback) => actions.uninstallLibrary(dispatch, libraryName, libraryPath, (error) => {
if (!error) {
// Refresh library manager view
actions.getLibraries(dispatch, callback);
actions.getLibraries(dispatch, false, callback);
} else {
callback();
}
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@
"info",
"verbose"
]
},
"arduino.autoUpdateIndexFiles": {
"type": "boolean",
"default": false,
"description": "Controls auto update of package_index.json and library_index.json index files. If enabled, each time when you open Boards Manager/Libraries Manager, download latest index files first. Otherwise, using index files cached on local disk for Boards Manager/Libraries Manager."
}
}
},
Expand Down
61 changes: 49 additions & 12 deletions src/arduino/arduino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,21 @@ export class ArduinoApp {
if (force || !util.fileExistsSync(path.join(this._settings.packagePath, "package_index.json"))) {
try {
// Use the dummy package to initialize the Arduino IDE
await this.installBoard("dummy", "dummy", "", false);
await this.installBoard("dummy", "", "", true);
} catch (ex) {
}
}
}

/**
* Initialize the arduino library.
* @param {boolean} force - Whether force refresh library index file
*/
public async initializeLibrary() {
if (!util.fileExistsSync(path.join(this._settings.packagePath, "library_index.json"))) {
public async initializeLibrary(force: boolean = false) {
if (force || !util.fileExistsSync(path.join(this._settings.packagePath, "library_index.json"))) {
try {
// Use the dummy library to initialize the Arduino IDE
await this.installLibrary("dummy", "", false);
await this.installLibrary("dummy", "", true);
} catch (ex) {
}
}
Expand Down Expand Up @@ -177,17 +178,35 @@ export class ArduinoApp {
/**
* Install arduino board package based on package name and platform hardware architecture.
*/
public async installBoard(packageName: string, arch: string, version: string = "", showOutput: boolean = true) {
public async installBoard(packageName: string, arch: string = "", version: string = "", showOutput: boolean = true) {
arduinoChannel.show();
arduinoChannel.start(`Install package - ${packageName}...`);
const updatingIndex = packageName === "dummy" && !arch && !version;
if (updatingIndex) {
arduinoChannel.start(`Update package index files...`);
} else {
arduinoChannel.start(`Install package - ${packageName}...`);
}
try {
await util.spawn(this._settings.commandPath,
showOutput ? arduinoChannel.channel : null,
["--install-boards", `${packageName}:${arch}${version && ":" + version}`]);
["--install-boards", `${packageName}${arch && ":" + arch}${version && ":" + version}`]);

arduinoChannel.end(`Installed board package - ${packageName}${os.EOL}`);
if (updatingIndex) {
arduinoChannel.end("Updated package index files.");
} else {
arduinoChannel.end(`Installed board package - ${packageName}${os.EOL}`);
}
} catch (error) {
arduinoChannel.error(`Exit with code=${error.code}${os.EOL}`);
// If a platform with the same version is already installed, nothing is installed and program exits with exit code 1
if (error.code === 1) {
if (updatingIndex) {
arduinoChannel.end("Updated package index files.");
} else {
arduinoChannel.end(`Installed board package - ${packageName}${os.EOL}`);
}
} else {
arduinoChannel.error(`Exit with code=${error.code}${os.EOL}`);
}
}
}

Expand All @@ -199,15 +218,33 @@ export class ArduinoApp {

public async installLibrary(libName: string, version: string = "", showOutput: boolean = true) {
arduinoChannel.show();
arduinoChannel.start(`Install library - ${libName}`);
const updatingIndex = (libName === "dummy" && !version);
if (updatingIndex) {
arduinoChannel.start("Update library index files...");
} else {
arduinoChannel.start(`Install library - ${libName}`);
}
try {
await util.spawn(this._settings.commandPath,
showOutput ? arduinoChannel.channel : null,
["--install-library", `${libName}${version && ":" + version}`]);

arduinoChannel.end(`Installed library - ${libName}${os.EOL}`);
if (updatingIndex) {
arduinoChannel.end("Updated library index files.");
} else {
arduinoChannel.end(`Installed library - ${libName}${os.EOL}`);
}
} catch (error) {
arduinoChannel.error(`Exit with code=${error.code}${os.EOL}`);
// If a library with the same version is already installed, nothing is installed and program exits with exit code 1
if (error.code === 1) {
if (updatingIndex) {
arduinoChannel.end("Updated library index files.");
} else {
arduinoChannel.end(`Installed library - ${libName}${os.EOL}`);
}
} else {
arduinoChannel.error(`Exit with code=${error.code}${os.EOL}`);
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/arduino/arduinoContentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import { ArduinoApp } from "./arduino";
import { BoardManager } from "./boardManager";
import { LibraryManager } from "./libraryManager";
import LocalWebServer from "./localWebServer";
import { IArduinoSettings } from "./settings";

export class ArduinoContentProvider implements vscode.TextDocumentContentProvider {
private _webserver: LocalWebServer;
private _onDidChange = new vscode.EventEmitter<vscode.Uri>();

constructor(
private _settings: IArduinoSettings,
private _arduinoApp: ArduinoApp,
private _boardManager: BoardManager,
private _libraryManager: LibraryManager,
Expand Down Expand Up @@ -86,7 +88,8 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
}

public async getBoardPackages(req, res) {
await this._boardManager.loadPackages();
const update = (this._settings.autoUpdateIndexFiles && req.query.update === "true");
await this._boardManager.loadPackages(update);
return res.json({
platforms: JSONHelper.decycle(this._boardManager.platforms, undefined),
});
Expand Down Expand Up @@ -142,7 +145,8 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
}

public async getLibraries(req, res) {
await this._libraryManager.loadLibraries();
const update = (this._settings.autoUpdateIndexFiles && req.query.update === "true");
await this._libraryManager.loadLibraries(update);
return res.json({
libraries: this._libraryManager.libraries,
});
Expand Down
Loading