Implemented library search and installation

This commit is contained in:
Christian Weichel 2019-05-07 17:04:37 +02:00
parent 50c1c7dcb2
commit 2f7d26ded9
13 changed files with 738 additions and 94 deletions

View File

@ -7,7 +7,7 @@ export class ComponentList extends React.Component<ComponentList.Props> {
render(): React.ReactNode {
return <div>
{this.props.items.map(item => <ComponentListItem key={item.name} item={item} windowService={this.props.windowService} install={this.props.install} />)}
{this.props.items.map((item, idx) => <ComponentListItem key={idx} item={item} windowService={this.props.windowService} install={this.props.install} />)}
</div>;
}

View File

@ -39,7 +39,15 @@ export class FilterableListContainer extends React.Component<FilterableListConta
const { items } = result;
this.setState({
filterText,
items
items: items.sort((a, b) => {
if (a.name < b.name) {
return -1;
} else if (a.name === b.name) {
return 0;
} else {
return 1;
}
})
});
});
}

View File

@ -4,7 +4,7 @@ export const LibraryServicePath = '/services/library-service';
export const LibraryService = Symbol('LibraryService');
export interface LibraryService {
search(options: { query?: string }): Promise<{ items: Library[] }>;
install(board: Library): Promise<void>;
install(library: Library): Promise<void>;
}
export interface Library extends ArduinoComponent {

View File

@ -80,14 +80,6 @@ export class BoardsServiceImpl implements BoardsService {
installedVersion,
}
return result;
}).sort((a, b) => {
if (a.name < b.name) {
return -1;
} else if (a.name === b.name) {
return 0;
} else {
return 1;
}
});
return { items };

View File

@ -32,6 +32,7 @@ interface IArduinoCoreService extends grpc.ServiceDefinition<grpc.UntypedService
libraryUninstall: IArduinoCoreService_ILibraryUninstall;
libraryUpgradeAll: IArduinoCoreService_ILibraryUpgradeAll;
librarySearch: IArduinoCoreService_ILibrarySearch;
libraryList: IArduinoCoreService_ILibraryList;
}
interface IArduinoCoreService_IInit extends grpc.MethodDefinition<commands_pb.InitReq, commands_pb.InitResp> {
@ -205,6 +206,15 @@ interface IArduinoCoreService_ILibrarySearch extends grpc.MethodDefinition<lib_p
responseSerialize: grpc.serialize<lib_pb.LibrarySearchResp>;
responseDeserialize: grpc.deserialize<lib_pb.LibrarySearchResp>;
}
interface IArduinoCoreService_ILibraryList extends grpc.MethodDefinition<lib_pb.LibraryListReq, lib_pb.LibraryListResp> {
path: string; // "/arduino.ArduinoCore/LibraryList"
requestStream: boolean; // false
responseStream: boolean; // false
requestSerialize: grpc.serialize<lib_pb.LibraryListReq>;
requestDeserialize: grpc.deserialize<lib_pb.LibraryListReq>;
responseSerialize: grpc.serialize<lib_pb.LibraryListResp>;
responseDeserialize: grpc.deserialize<lib_pb.LibraryListResp>;
}
export const ArduinoCoreService: IArduinoCoreService;
@ -228,6 +238,7 @@ export interface IArduinoCoreServer {
libraryUninstall: grpc.handleServerStreamingCall<lib_pb.LibraryUninstallReq, lib_pb.LibraryUninstallResp>;
libraryUpgradeAll: grpc.handleServerStreamingCall<lib_pb.LibraryUpgradeAllReq, lib_pb.LibraryUpgradeAllResp>;
librarySearch: grpc.handleUnaryCall<lib_pb.LibrarySearchReq, lib_pb.LibrarySearchResp>;
libraryList: grpc.handleUnaryCall<lib_pb.LibraryListReq, lib_pb.LibraryListResp>;
}
export interface IArduinoCoreClient {
@ -277,6 +288,9 @@ export interface IArduinoCoreClient {
librarySearch(request: lib_pb.LibrarySearchReq, callback: (error: grpc.ServiceError | null, response: lib_pb.LibrarySearchResp) => void): grpc.ClientUnaryCall;
librarySearch(request: lib_pb.LibrarySearchReq, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: lib_pb.LibrarySearchResp) => void): grpc.ClientUnaryCall;
librarySearch(request: lib_pb.LibrarySearchReq, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: lib_pb.LibrarySearchResp) => void): grpc.ClientUnaryCall;
libraryList(request: lib_pb.LibraryListReq, callback: (error: grpc.ServiceError | null, response: lib_pb.LibraryListResp) => void): grpc.ClientUnaryCall;
libraryList(request: lib_pb.LibraryListReq, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: lib_pb.LibraryListResp) => void): grpc.ClientUnaryCall;
libraryList(request: lib_pb.LibraryListReq, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: lib_pb.LibraryListResp) => void): grpc.ClientUnaryCall;
}
export class ArduinoCoreClient extends grpc.Client implements IArduinoCoreClient {
@ -327,4 +341,7 @@ export class ArduinoCoreClient extends grpc.Client implements IArduinoCoreClient
public librarySearch(request: lib_pb.LibrarySearchReq, callback: (error: grpc.ServiceError | null, response: lib_pb.LibrarySearchResp) => void): grpc.ClientUnaryCall;
public librarySearch(request: lib_pb.LibrarySearchReq, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: lib_pb.LibrarySearchResp) => void): grpc.ClientUnaryCall;
public librarySearch(request: lib_pb.LibrarySearchReq, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: lib_pb.LibrarySearchResp) => void): grpc.ClientUnaryCall;
public libraryList(request: lib_pb.LibraryListReq, callback: (error: grpc.ServiceError | null, response: lib_pb.LibraryListResp) => void): grpc.ClientUnaryCall;
public libraryList(request: lib_pb.LibraryListReq, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: lib_pb.LibraryListResp) => void): grpc.ClientUnaryCall;
public libraryList(request: lib_pb.LibraryListReq, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: lib_pb.LibraryListResp) => void): grpc.ClientUnaryCall;
}

View File

@ -182,6 +182,28 @@ function deserialize_arduino_LibraryInstallResp(buffer_arg) {
return lib_pb.LibraryInstallResp.deserializeBinary(new Uint8Array(buffer_arg));
}
function serialize_arduino_LibraryListReq(arg) {
if (!(arg instanceof lib_pb.LibraryListReq)) {
throw new Error('Expected argument of type arduino.LibraryListReq');
}
return Buffer.from(arg.serializeBinary());
}
function deserialize_arduino_LibraryListReq(buffer_arg) {
return lib_pb.LibraryListReq.deserializeBinary(new Uint8Array(buffer_arg));
}
function serialize_arduino_LibraryListResp(arg) {
if (!(arg instanceof lib_pb.LibraryListResp)) {
throw new Error('Expected argument of type arduino.LibraryListResp');
}
return Buffer.from(arg.serializeBinary());
}
function deserialize_arduino_LibraryListResp(buffer_arg) {
return lib_pb.LibraryListResp.deserializeBinary(new Uint8Array(buffer_arg));
}
function serialize_arduino_LibrarySearchReq(arg) {
if (!(arg instanceof lib_pb.LibrarySearchReq)) {
throw new Error('Expected argument of type arduino.LibrarySearchReq');
@ -666,6 +688,17 @@ var ArduinoCoreService = exports.ArduinoCoreService = {
responseSerialize: serialize_arduino_LibrarySearchResp,
responseDeserialize: deserialize_arduino_LibrarySearchResp,
},
libraryList: {
path: '/arduino.ArduinoCore/LibraryList',
requestStream: false,
responseStream: false,
requestType: lib_pb.LibraryListReq,
responseType: lib_pb.LibraryListResp,
requestSerialize: serialize_arduino_LibraryListReq,
requestDeserialize: deserialize_arduino_LibraryListReq,
responseSerialize: serialize_arduino_LibraryListResp,
responseDeserialize: deserialize_arduino_LibraryListResp,
},
};
exports.ArduinoCoreClient = grpc.makeGenericClientConstructor(ArduinoCoreService);

View File

@ -325,6 +325,81 @@ export namespace SearchLibraryOutput {
}
}
export class LibraryListReq extends jspb.Message {
hasInstance(): boolean;
clearInstance(): void;
getInstance(): common_pb.Instance | undefined;
setInstance(value?: common_pb.Instance): void;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): LibraryListReq.AsObject;
static toObject(includeInstance: boolean, msg: LibraryListReq): LibraryListReq.AsObject;
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
static serializeBinaryToWriter(message: LibraryListReq, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): LibraryListReq;
static deserializeBinaryFromReader(message: LibraryListReq, reader: jspb.BinaryReader): LibraryListReq;
}
export namespace LibraryListReq {
export type AsObject = {
instance?: common_pb.Instance.AsObject,
}
}
export class LibraryListResp extends jspb.Message {
clearLibrariesList(): void;
getLibrariesList(): Array<InstalledLibrary>;
setLibrariesList(value: Array<InstalledLibrary>): void;
addLibraries(value?: InstalledLibrary, index?: number): InstalledLibrary;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): LibraryListResp.AsObject;
static toObject(includeInstance: boolean, msg: LibraryListResp): LibraryListResp.AsObject;
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
static serializeBinaryToWriter(message: LibraryListResp, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): LibraryListResp;
static deserializeBinaryFromReader(message: LibraryListResp, reader: jspb.BinaryReader): LibraryListResp;
}
export namespace LibraryListResp {
export type AsObject = {
librariesList: Array<InstalledLibrary.AsObject>,
}
}
export class InstalledLibrary extends jspb.Message {
getName(): string;
setName(value: string): void;
hasInstalled(): boolean;
clearInstalled(): void;
getInstalled(): LibraryRelease | undefined;
setInstalled(value?: LibraryRelease): void;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): InstalledLibrary.AsObject;
static toObject(includeInstance: boolean, msg: InstalledLibrary): InstalledLibrary.AsObject;
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
static serializeBinaryToWriter(message: InstalledLibrary, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): InstalledLibrary;
static deserializeBinaryFromReader(message: InstalledLibrary, reader: jspb.BinaryReader): InstalledLibrary;
}
export namespace InstalledLibrary {
export type AsObject = {
name: string,
installed?: LibraryRelease.AsObject,
}
}
export class LibraryRelease extends jspb.Message {
getAuthor(): string;
setAuthor(value: string): void;

View File

@ -14,10 +14,13 @@ var global = Function('return this')();
var common_pb = require('./common_pb.js');
goog.object.extend(proto, common_pb);
goog.exportSymbol('proto.arduino.DownloadResource', null, global);
goog.exportSymbol('proto.arduino.InstalledLibrary', null, global);
goog.exportSymbol('proto.arduino.LibraryDownloadReq', null, global);
goog.exportSymbol('proto.arduino.LibraryDownloadResp', null, global);
goog.exportSymbol('proto.arduino.LibraryInstallReq', null, global);
goog.exportSymbol('proto.arduino.LibraryInstallResp', null, global);
goog.exportSymbol('proto.arduino.LibraryListReq', null, global);
goog.exportSymbol('proto.arduino.LibraryListResp', null, global);
goog.exportSymbol('proto.arduino.LibraryRelease', null, global);
goog.exportSymbol('proto.arduino.LibrarySearchReq', null, global);
goog.exportSymbol('proto.arduino.LibrarySearchResp', null, global);
@ -2147,6 +2150,519 @@ proto.arduino.SearchLibraryOutput.prototype.hasLatest = function() {
/**
* Generated by JsPbCodeGenerator.
* @param {Array=} opt_data Optional initial data array, typically from a
* server response, or constructed directly in Javascript. The array is used
* in place and becomes part of the constructed object. It is not cloned.
* If no data is provided, the constructed object will be empty, but still
* valid.
* @extends {jspb.Message}
* @constructor
*/
proto.arduino.LibraryListReq = function(opt_data) {
jspb.Message.initialize(this, opt_data, 0, -1, null, null);
};
goog.inherits(proto.arduino.LibraryListReq, jspb.Message);
if (goog.DEBUG && !COMPILED) {
proto.arduino.LibraryListReq.displayName = 'proto.arduino.LibraryListReq';
}
if (jspb.Message.GENERATE_TO_OBJECT) {
/**
* Creates an object representation of this proto suitable for use in Soy templates.
* Field names that are reserved in JavaScript and will be renamed to pb_name.
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
* For the list of reserved names please see:
* com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.
* @param {boolean=} opt_includeInstance Whether to include the JSPB instance
* for transitional soy proto support: http://goto/soy-param-migration
* @return {!Object}
*/
proto.arduino.LibraryListReq.prototype.toObject = function(opt_includeInstance) {
return proto.arduino.LibraryListReq.toObject(opt_includeInstance, this);
};
/**
* Static version of the {@see toObject} method.
* @param {boolean|undefined} includeInstance Whether to include the JSPB
* instance for transitional soy proto support:
* http://goto/soy-param-migration
* @param {!proto.arduino.LibraryListReq} msg The msg instance to transform.
* @return {!Object}
* @suppress {unusedLocalVariables} f is only used for nested messages
*/
proto.arduino.LibraryListReq.toObject = function(includeInstance, msg) {
var f, obj = {
instance: (f = msg.getInstance()) && common_pb.Instance.toObject(includeInstance, f)
};
if (includeInstance) {
obj.$jspbMessageInstance = msg;
}
return obj;
};
}
/**
* Deserializes binary data (in protobuf wire format).
* @param {jspb.ByteSource} bytes The bytes to deserialize.
* @return {!proto.arduino.LibraryListReq}
*/
proto.arduino.LibraryListReq.deserializeBinary = function(bytes) {
var reader = new jspb.BinaryReader(bytes);
var msg = new proto.arduino.LibraryListReq;
return proto.arduino.LibraryListReq.deserializeBinaryFromReader(msg, reader);
};
/**
* Deserializes binary data (in protobuf wire format) from the
* given reader into the given message object.
* @param {!proto.arduino.LibraryListReq} msg The message object to deserialize into.
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
* @return {!proto.arduino.LibraryListReq}
*/
proto.arduino.LibraryListReq.deserializeBinaryFromReader = function(msg, reader) {
while (reader.nextField()) {
if (reader.isEndGroup()) {
break;
}
var field = reader.getFieldNumber();
switch (field) {
case 1:
var value = new common_pb.Instance;
reader.readMessage(value,common_pb.Instance.deserializeBinaryFromReader);
msg.setInstance(value);
break;
default:
reader.skipField();
break;
}
}
return msg;
};
/**
* Serializes the message to binary data (in protobuf wire format).
* @return {!Uint8Array}
*/
proto.arduino.LibraryListReq.prototype.serializeBinary = function() {
var writer = new jspb.BinaryWriter();
proto.arduino.LibraryListReq.serializeBinaryToWriter(this, writer);
return writer.getResultBuffer();
};
/**
* Serializes the given message to binary data (in protobuf wire
* format), writing to the given BinaryWriter.
* @param {!proto.arduino.LibraryListReq} message
* @param {!jspb.BinaryWriter} writer
* @suppress {unusedLocalVariables} f is only used for nested messages
*/
proto.arduino.LibraryListReq.serializeBinaryToWriter = function(message, writer) {
var f = undefined;
f = message.getInstance();
if (f != null) {
writer.writeMessage(
1,
f,
common_pb.Instance.serializeBinaryToWriter
);
}
};
/**
* optional Instance instance = 1;
* @return {?proto.arduino.Instance}
*/
proto.arduino.LibraryListReq.prototype.getInstance = function() {
return /** @type{?proto.arduino.Instance} */ (
jspb.Message.getWrapperField(this, common_pb.Instance, 1));
};
/** @param {?proto.arduino.Instance|undefined} value */
proto.arduino.LibraryListReq.prototype.setInstance = function(value) {
jspb.Message.setWrapperField(this, 1, value);
};
proto.arduino.LibraryListReq.prototype.clearInstance = function() {
this.setInstance(undefined);
};
/**
* Returns whether this field is set.
* @return {boolean}
*/
proto.arduino.LibraryListReq.prototype.hasInstance = function() {
return jspb.Message.getField(this, 1) != null;
};
/**
* Generated by JsPbCodeGenerator.
* @param {Array=} opt_data Optional initial data array, typically from a
* server response, or constructed directly in Javascript. The array is used
* in place and becomes part of the constructed object. It is not cloned.
* If no data is provided, the constructed object will be empty, but still
* valid.
* @extends {jspb.Message}
* @constructor
*/
proto.arduino.LibraryListResp = function(opt_data) {
jspb.Message.initialize(this, opt_data, 0, -1, proto.arduino.LibraryListResp.repeatedFields_, null);
};
goog.inherits(proto.arduino.LibraryListResp, jspb.Message);
if (goog.DEBUG && !COMPILED) {
proto.arduino.LibraryListResp.displayName = 'proto.arduino.LibraryListResp';
}
/**
* List of repeated fields within this message type.
* @private {!Array<number>}
* @const
*/
proto.arduino.LibraryListResp.repeatedFields_ = [1];
if (jspb.Message.GENERATE_TO_OBJECT) {
/**
* Creates an object representation of this proto suitable for use in Soy templates.
* Field names that are reserved in JavaScript and will be renamed to pb_name.
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
* For the list of reserved names please see:
* com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.
* @param {boolean=} opt_includeInstance Whether to include the JSPB instance
* for transitional soy proto support: http://goto/soy-param-migration
* @return {!Object}
*/
proto.arduino.LibraryListResp.prototype.toObject = function(opt_includeInstance) {
return proto.arduino.LibraryListResp.toObject(opt_includeInstance, this);
};
/**
* Static version of the {@see toObject} method.
* @param {boolean|undefined} includeInstance Whether to include the JSPB
* instance for transitional soy proto support:
* http://goto/soy-param-migration
* @param {!proto.arduino.LibraryListResp} msg The msg instance to transform.
* @return {!Object}
* @suppress {unusedLocalVariables} f is only used for nested messages
*/
proto.arduino.LibraryListResp.toObject = function(includeInstance, msg) {
var f, obj = {
librariesList: jspb.Message.toObjectList(msg.getLibrariesList(),
proto.arduino.InstalledLibrary.toObject, includeInstance)
};
if (includeInstance) {
obj.$jspbMessageInstance = msg;
}
return obj;
};
}
/**
* Deserializes binary data (in protobuf wire format).
* @param {jspb.ByteSource} bytes The bytes to deserialize.
* @return {!proto.arduino.LibraryListResp}
*/
proto.arduino.LibraryListResp.deserializeBinary = function(bytes) {
var reader = new jspb.BinaryReader(bytes);
var msg = new proto.arduino.LibraryListResp;
return proto.arduino.LibraryListResp.deserializeBinaryFromReader(msg, reader);
};
/**
* Deserializes binary data (in protobuf wire format) from the
* given reader into the given message object.
* @param {!proto.arduino.LibraryListResp} msg The message object to deserialize into.
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
* @return {!proto.arduino.LibraryListResp}
*/
proto.arduino.LibraryListResp.deserializeBinaryFromReader = function(msg, reader) {
while (reader.nextField()) {
if (reader.isEndGroup()) {
break;
}
var field = reader.getFieldNumber();
switch (field) {
case 1:
var value = new proto.arduino.InstalledLibrary;
reader.readMessage(value,proto.arduino.InstalledLibrary.deserializeBinaryFromReader);
msg.addLibraries(value);
break;
default:
reader.skipField();
break;
}
}
return msg;
};
/**
* Serializes the message to binary data (in protobuf wire format).
* @return {!Uint8Array}
*/
proto.arduino.LibraryListResp.prototype.serializeBinary = function() {
var writer = new jspb.BinaryWriter();
proto.arduino.LibraryListResp.serializeBinaryToWriter(this, writer);
return writer.getResultBuffer();
};
/**
* Serializes the given message to binary data (in protobuf wire
* format), writing to the given BinaryWriter.
* @param {!proto.arduino.LibraryListResp} message
* @param {!jspb.BinaryWriter} writer
* @suppress {unusedLocalVariables} f is only used for nested messages
*/
proto.arduino.LibraryListResp.serializeBinaryToWriter = function(message, writer) {
var f = undefined;
f = message.getLibrariesList();
if (f.length > 0) {
writer.writeRepeatedMessage(
1,
f,
proto.arduino.InstalledLibrary.serializeBinaryToWriter
);
}
};
/**
* repeated InstalledLibrary libraries = 1;
* @return {!Array<!proto.arduino.InstalledLibrary>}
*/
proto.arduino.LibraryListResp.prototype.getLibrariesList = function() {
return /** @type{!Array<!proto.arduino.InstalledLibrary>} */ (
jspb.Message.getRepeatedWrapperField(this, proto.arduino.InstalledLibrary, 1));
};
/** @param {!Array<!proto.arduino.InstalledLibrary>} value */
proto.arduino.LibraryListResp.prototype.setLibrariesList = function(value) {
jspb.Message.setRepeatedWrapperField(this, 1, value);
};
/**
* @param {!proto.arduino.InstalledLibrary=} opt_value
* @param {number=} opt_index
* @return {!proto.arduino.InstalledLibrary}
*/
proto.arduino.LibraryListResp.prototype.addLibraries = function(opt_value, opt_index) {
return jspb.Message.addToRepeatedWrapperField(this, 1, opt_value, proto.arduino.InstalledLibrary, opt_index);
};
proto.arduino.LibraryListResp.prototype.clearLibrariesList = function() {
this.setLibrariesList([]);
};
/**
* Generated by JsPbCodeGenerator.
* @param {Array=} opt_data Optional initial data array, typically from a
* server response, or constructed directly in Javascript. The array is used
* in place and becomes part of the constructed object. It is not cloned.
* If no data is provided, the constructed object will be empty, but still
* valid.
* @extends {jspb.Message}
* @constructor
*/
proto.arduino.InstalledLibrary = function(opt_data) {
jspb.Message.initialize(this, opt_data, 0, -1, null, null);
};
goog.inherits(proto.arduino.InstalledLibrary, jspb.Message);
if (goog.DEBUG && !COMPILED) {
proto.arduino.InstalledLibrary.displayName = 'proto.arduino.InstalledLibrary';
}
if (jspb.Message.GENERATE_TO_OBJECT) {
/**
* Creates an object representation of this proto suitable for use in Soy templates.
* Field names that are reserved in JavaScript and will be renamed to pb_name.
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
* For the list of reserved names please see:
* com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.
* @param {boolean=} opt_includeInstance Whether to include the JSPB instance
* for transitional soy proto support: http://goto/soy-param-migration
* @return {!Object}
*/
proto.arduino.InstalledLibrary.prototype.toObject = function(opt_includeInstance) {
return proto.arduino.InstalledLibrary.toObject(opt_includeInstance, this);
};
/**
* Static version of the {@see toObject} method.
* @param {boolean|undefined} includeInstance Whether to include the JSPB
* instance for transitional soy proto support:
* http://goto/soy-param-migration
* @param {!proto.arduino.InstalledLibrary} msg The msg instance to transform.
* @return {!Object}
* @suppress {unusedLocalVariables} f is only used for nested messages
*/
proto.arduino.InstalledLibrary.toObject = function(includeInstance, msg) {
var f, obj = {
name: jspb.Message.getFieldWithDefault(msg, 1, ""),
installed: (f = msg.getInstalled()) && proto.arduino.LibraryRelease.toObject(includeInstance, f)
};
if (includeInstance) {
obj.$jspbMessageInstance = msg;
}
return obj;
};
}
/**
* Deserializes binary data (in protobuf wire format).
* @param {jspb.ByteSource} bytes The bytes to deserialize.
* @return {!proto.arduino.InstalledLibrary}
*/
proto.arduino.InstalledLibrary.deserializeBinary = function(bytes) {
var reader = new jspb.BinaryReader(bytes);
var msg = new proto.arduino.InstalledLibrary;
return proto.arduino.InstalledLibrary.deserializeBinaryFromReader(msg, reader);
};
/**
* Deserializes binary data (in protobuf wire format) from the
* given reader into the given message object.
* @param {!proto.arduino.InstalledLibrary} msg The message object to deserialize into.
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
* @return {!proto.arduino.InstalledLibrary}
*/
proto.arduino.InstalledLibrary.deserializeBinaryFromReader = function(msg, reader) {
while (reader.nextField()) {
if (reader.isEndGroup()) {
break;
}
var field = reader.getFieldNumber();
switch (field) {
case 1:
var value = /** @type {string} */ (reader.readString());
msg.setName(value);
break;
case 2:
var value = new proto.arduino.LibraryRelease;
reader.readMessage(value,proto.arduino.LibraryRelease.deserializeBinaryFromReader);
msg.setInstalled(value);
break;
default:
reader.skipField();
break;
}
}
return msg;
};
/**
* Serializes the message to binary data (in protobuf wire format).
* @return {!Uint8Array}
*/
proto.arduino.InstalledLibrary.prototype.serializeBinary = function() {
var writer = new jspb.BinaryWriter();
proto.arduino.InstalledLibrary.serializeBinaryToWriter(this, writer);
return writer.getResultBuffer();
};
/**
* Serializes the given message to binary data (in protobuf wire
* format), writing to the given BinaryWriter.
* @param {!proto.arduino.InstalledLibrary} message
* @param {!jspb.BinaryWriter} writer
* @suppress {unusedLocalVariables} f is only used for nested messages
*/
proto.arduino.InstalledLibrary.serializeBinaryToWriter = function(message, writer) {
var f = undefined;
f = message.getName();
if (f.length > 0) {
writer.writeString(
1,
f
);
}
f = message.getInstalled();
if (f != null) {
writer.writeMessage(
2,
f,
proto.arduino.LibraryRelease.serializeBinaryToWriter
);
}
};
/**
* optional string name = 1;
* @return {string}
*/
proto.arduino.InstalledLibrary.prototype.getName = function() {
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, ""));
};
/** @param {string} value */
proto.arduino.InstalledLibrary.prototype.setName = function(value) {
jspb.Message.setProto3StringField(this, 1, value);
};
/**
* optional LibraryRelease installed = 2;
* @return {?proto.arduino.LibraryRelease}
*/
proto.arduino.InstalledLibrary.prototype.getInstalled = function() {
return /** @type{?proto.arduino.LibraryRelease} */ (
jspb.Message.getWrapperField(this, proto.arduino.LibraryRelease, 2));
};
/** @param {?proto.arduino.LibraryRelease|undefined} value */
proto.arduino.InstalledLibrary.prototype.setInstalled = function(value) {
jspb.Message.setWrapperField(this, 2, value);
};
proto.arduino.InstalledLibrary.prototype.clearInstalled = function() {
this.setInstalled(undefined);
};
/**
* Returns whether this field is set.
* @return {boolean}
*/
proto.arduino.InstalledLibrary.prototype.hasInstalled = function() {
return jspb.Message.getField(this, 2) != null;
};
/**
* Generated by JsPbCodeGenerator.
* @param {Array=} opt_data Optional initial data array, typically from a

View File

@ -6,8 +6,6 @@ import { WorkspaceServiceExt } from '../browser/workspace-service-ext';
import { FileSystem } from '@theia/filesystem/lib/common';
import URI from '@theia/core/lib/common/uri';
import { CoreClientProvider, Client } from './core-client-provider';
import * as fs from 'fs';
import * as path from 'path';
import * as PQueue from 'p-queue';
@injectable()
@ -72,49 +70,23 @@ export class CoreClientProviderImpl implements CoreClientProvider {
}
// workaround to speed up startup on existing workspaces
if (!fs.existsSync(path.join(config.getDatadir(), "package_index.json"))) {
const updateReq = new UpdateIndexReq();
updateReq.setInstance(instance);
const updateResp = client.updateIndex(updateReq);
updateResp.on('data', (o: UpdateIndexResp) => {
const progress = o.getDownloadProgress();
if (progress) {
if (progress.getCompleted()) {
console.log(`Download${progress.getFile() ? ` of ${progress.getFile()}` : ''} completed.`);
} else {
console.log(`Downloading${progress.getFile() ? ` ${progress.getFile()}:` : ''} ${progress.getDownloaded()}.`);
}
const updateReq = new UpdateIndexReq();
updateReq.setInstance(instance);
const updateResp = client.updateIndex(updateReq);
updateResp.on('data', (o: UpdateIndexResp) => {
const progress = o.getDownloadProgress();
if (progress) {
if (progress.getCompleted()) {
console.log(`Download${progress.getFile() ? ` of ${progress.getFile()}` : ''} completed.`);
} else {
console.log(`Downloading${progress.getFile() ? ` ${progress.getFile()}:` : ''} ${progress.getDownloaded()}.`);
}
});
await new Promise<void>((resolve, reject) => {
updateResp.on('error', reject);
updateResp.on('end', resolve);
});
}
// {
// const installBuiltinPkgReq = new PlatformInstallReq();
// installBuiltinPkgReq.setInstance(instance);
// installBuiltinPkgReq.setPlatformPackage("builtin");
// const resp = client.platformInstall(installBuiltinPkgReq);
// resp.on('data', (r: PlatformInstallResp) => {
// const prog = r.getProgress();
// if (prog) {
// console.info(`downloading ${prog.getFile()}: ${prog.getCompleted()}%`)
// }
// });
// await new Promise<void>((resolve, reject) => {
// resp.on('end', resolve);
// resp.on('error', reject);
// });
// }
// TODO: revisit this!!!
// `updateResp.on('data'` is called only when running, for instance, `compile`. It does not run eagerly.
// await new Promise<void>((resolve, reject) => {
// updateResp.on('close', resolve);
// updateResp.on('error', reject);
// });
}
});
await new Promise<void>((resolve, reject) => {
updateResp.on('error', reject);
updateResp.on('end', resolve);
});
const result = {
client,

View File

@ -1,7 +1,9 @@
import { injectable, inject } from 'inversify';
import { Library, LibraryService } from '../common/protocol/library-service';
import { CoreClientProvider } from './core-client-provider';
import { LibrarySearchReq, LibrarySearchResp } from './cli-protocol/lib_pb';
import { LibrarySearchReq, LibrarySearchResp, LibraryListReq, LibraryListResp, LibraryRelease,
InstalledLibrary, LibraryInstallReq, LibraryInstallResp } from './cli-protocol/lib_pb';
import { ToolOutputServiceServer } from '../common/protocol/tool-output-service';
@injectable()
export class LibraryServiceImpl implements LibraryService {
@ -9,55 +11,84 @@ export class LibraryServiceImpl implements LibraryService {
@inject(CoreClientProvider)
protected readonly coreClientProvider: CoreClientProvider;
@inject(ToolOutputServiceServer)
protected readonly toolOutputService: ToolOutputServiceServer;
async search(options: { query?: string; }): Promise<{ items: Library[] }> {
const { client, instance } = await this.coreClientProvider.getClient();
const listReq = new LibraryListReq();
listReq.setInstance(instance);
const installedLibsResp = await new Promise<LibraryListResp>((resolve, reject) => client.libraryList(listReq, (err, resp) => !!err ? reject(err) : resolve(resp)));
const installedLibs = installedLibsResp.getLibrariesList();
const installedLibsIdx = new Map<string, InstalledLibrary>();
installedLibs.forEach(l => installedLibsIdx.set(l.getName(), l));
if (!options.query || options.query.length < 2) {
const items: Library[] = Array.from(installedLibsIdx.values()).map(lib => toLibrary({
name: lib.getName(),
installable: false,
installedVersion: lib.getInstalled()!.getVersion(),
}, lib.getInstalled()!));
return { items };
}
const req = new LibrarySearchReq();
req.setQuery(options.query || '');
req.setInstance(instance);
const resp = await new Promise<LibrarySearchResp>((resolve, reject) => client.librarySearch(req, (err, resp) => !!err ? reject(err) : resolve(resp)));
console.log(resp.getSearchOutputList());
const items = resp.getSearchOutputList()
.filter(item => !!item.getLatest())
.slice(0, 50)
.map(item => {
let installedVersion: string | undefined;
const installed = installedLibsIdx.get(item.getName());
if (installed) {
installedVersion = installed.getInstalled()!.getVersion();
}
return toLibrary({
name: item.getName(),
installable: true,
installedVersion
}, item.getLatest()!)
})
const { query } = options;
const allItems: Library[] = [
<Library>{
name: 'Keyboard',
availableVersions: ['1.0.0', '1.0.1', '1.02'],
author: 'Arduino',
summary: 'Allows an Arduino/Genuino board with USB capabilities to act as a Keyboard',
description: 'This library plugs on the HID library. It can be used with or without other HIG-based libraries (Mouse, Gamepad etc)',
installedVersion: '1.0.1',
moreInfoLink: 'https://www.arduino.cc/reference/en/language/functions/usb/keyboard/',
builtIn: true
},
<Library>{
name: 'Mouse',
availableVersions: ['1.0.0', '1.0.1'],
author: 'Arduino',
summary: 'Allows an Arduino board with USB capabilities to act as a Mouse. For Leonardo/Micro only',
description: 'This library plugs on the HID library. Can be used with ot without other HID-based libraries (Keyboard, Gamepad etc)',
installedVersion: '1.0.1',
moreInfoLink: 'https://www.arduino.cc/reference/en/language/functions/usb/mouse/',
builtIn: true
},
<Library>{
name: 'USBHost',
availableVersions: ['1.0.0', '1.0.1', '1.02', '1.0.3', '1.0.3', '1.0.4', '1.0.5'],
author: 'Arduino',
summary: 'Allows communication with USB peripherals like mice, keyboard, and thumbdrives.',
// tslint:disable-next-line:max-line-length
description: 'This USBHost library allows an Arduino Due board to appear as a USB host, enabling it to communicate with peripherals like USB mice and keyboards. USBHost does not support devices that ace corrected through USB hubs. This includes some keyboards that have an internal hub.',
moreInfoLink: 'https://www.arduino.cc/en/Reference/USBHost',
installable: true
}
];
return {
items: allItems.filter(item => !query || item.name.toLocaleLowerCase().indexOf(query.toLocaleLowerCase()) !== -1)
};
return { items };
}
async install(board: Library): Promise<void> {
async install(library: Library): Promise<void> {
const { client, instance } = await this.coreClientProvider.getClient();
const req = new LibraryInstallReq();
req.setInstance(instance);
req.setName(library.name);
req.setVersion(library.availableVersions[0]);
const resp = client.libraryInstall(req);
resp.on('data', (r: LibraryInstallResp) => {
const prog = r.getProgress();
if (prog) {
this.toolOutputService.publishNewOutput("library download", `downloading ${prog.getFile()}: ${prog.getCompleted()}%\n`)
}
});
await new Promise<void>((resolve, reject) => {
resp.on('end', resolve);
resp.on('error', reject);
});
}
}
function toLibrary(tpl: Partial<Library>, release: LibraryRelease): Library {
return {
name: "",
installable: false,
...tpl,
author: release.getAuthor(),
availableVersions: [release.getVersion()],
description: release.getSentence(),
moreInfoLink: release.getWebsite(),
summary: release.getParagraph()
}
}