Skip to content

Added overwrite confirmation to ZIP lib install #212

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

Merged
merged 1 commit into from
Mar 15, 2021
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
2 changes: 1 addition & 1 deletion arduino-ide-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
],
"arduino": {
"cli": {
"version": "0.16.1"
"version": "20210315"
}
}
}
56 changes: 48 additions & 8 deletions arduino-ide-extension/src/browser/contributions/add-zip-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
import URI from '@theia/core/lib/common/uri';
import { InstallationProgressDialog } from '../widgets/progress-dialog';
import { LibraryService } from '../../common/protocol';
import { ConfirmDialog } from '@theia/core/lib/browser';

@injectable()
export class AddZipLibrary extends SketchContribution {
Expand Down Expand Up @@ -49,21 +50,60 @@ export class AddZipLibrary extends SketchContribution {
});
if (!canceled && filePaths.length) {
const zipUri = await this.fileSystemExt.getUri(filePaths[0]);
const dialog = new InstallationProgressDialog('Installing library', 'zip');
try {
this.outputChannelManager.getChannel('Arduino').clear();
dialog.open();
await this.libraryService.installZip({ zipUri });
} catch (e) {
this.messageService.error(e.toString());
} finally {
dialog.close();
await this.doInstall(zipUri);
} catch (error) {
if (error instanceof AlreadyInstalledError) {
const result = await new ConfirmDialog({
msg: error.message,
title: 'Do you want to overwrite the existing library?',
ok: 'Yes',
cancel: 'No'
}).open();
if (result) {
await this.doInstall(zipUri, true);
}
}
}
}
}

private async doInstall(zipUri: string, overwrite?: boolean): Promise<void> {
const dialog = new InstallationProgressDialog('Installing library', 'zip');
try {
this.outputChannelManager.getChannel('Arduino').clear();
dialog.open();
await this.libraryService.installZip({ zipUri, overwrite });
} catch (error) {
if (error instanceof Error) {
const match = error.message.match(/library (.*?) already installed/);
if (match && match.length >= 2) {
const name = match[1].trim();
if (name) {
throw new AlreadyInstalledError(`A library folder named ${name} already exists. Do you want to overwrite it?`, name);
} else {
throw new AlreadyInstalledError(`A library already exists. Do you want to overwrite it?`);
}
}
}
this.messageService.error(error.toString());
throw error;
} finally {
dialog.close();
}
}

}

class AlreadyInstalledError extends Error {

constructor(message: string, readonly libraryName?: string) {
super(message);
Object.setPrototypeOf(this, AlreadyInstalledError.prototype);
}

}

export namespace AddZipLibrary {
export namespace Commands {
export const ADD_ZIP_LIBRARY: Command = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface LibraryService extends Installable<LibraryPackage>, Searchable<
* When `installDependencies` is not set, it is `true` by default. If you want to skip the installation of required dependencies, set it to `false`.
*/
install(options: { item: LibraryPackage, version?: Installable.Version, installDependencies?: boolean }): Promise<void>;
installZip(options: { zipUri: string }): Promise<void>;
installZip(options: { zipUri: string, overwrite?: boolean }): Promise<void>;
/**
* Set `filterSelf` to `true` if you want to avoid having `item` in the result set.
* Note: as of today (22.02.2021), the CLI works like this: `./arduino-cli lib deps Adaino@0.1.0 ✕ Adaino 0.1.0 must be installed.`.
Expand Down
3 changes: 2 additions & 1 deletion arduino-ide-extension/src/node/boards-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import {
} from '../common/protocol';
import {
PlatformSearchReq, PlatformSearchResp, PlatformInstallReq, PlatformInstallResp, PlatformListReq,
PlatformListResp, Platform, PlatformUninstallResp, PlatformUninstallReq
PlatformListResp, PlatformUninstallResp, PlatformUninstallReq
} from './cli-protocol/commands/core_pb';
import { BoardDiscovery } from './board-discovery';
import { CoreClientAware } from './core-client-provider';
import { BoardDetailsReq, BoardDetailsResp } from './cli-protocol/commands/board_pb';
import { ListProgrammersAvailableForUploadReq, ListProgrammersAvailableForUploadResp } from './cli-protocol/commands/upload_pb';
import { Platform } from './cli-protocol/commands/common_pb';

@injectable()
export class BoardsServiceImpl extends CoreClientAware implements BoardsService {
Expand Down
70 changes: 70 additions & 0 deletions arduino-ide-extension/src/node/cli-protocol/commands/board_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ export class BoardDetailsResp extends jspb.Message {
getDebuggingSupported(): boolean;
setDebuggingSupported(value: boolean): BoardDetailsResp;

getSerialnumber(): string;
setSerialnumber(value: string): BoardDetailsResp;


serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): BoardDetailsResp.AsObject;
Expand Down Expand Up @@ -119,6 +122,7 @@ export namespace BoardDetailsResp {
identificationPrefList: Array<IdentificationPref.AsObject>,
programmersList: Array<commands_common_pb.Programmer.AsObject>,
debuggingSupported: boolean,
serialnumber: string,
}
}

Expand Down Expand Up @@ -535,6 +539,9 @@ export class DetectedPort extends jspb.Message {
setBoardsList(value: Array<BoardListItem>): DetectedPort;
addBoards(value?: BoardListItem, index?: number): BoardListItem;

getSerialNumber(): string;
setSerialNumber(value: string): DetectedPort;


serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): DetectedPort.AsObject;
Expand All @@ -552,6 +559,7 @@ export namespace DetectedPort {
protocol: string,
protocolLabel: string,
boardsList: Array<BoardListItem.AsObject>,
serialNumber: string,
}
}

Expand Down Expand Up @@ -689,6 +697,12 @@ export class BoardListItem extends jspb.Message {
setPid(value: string): BoardListItem;


hasPlatform(): boolean;
clearPlatform(): void;
getPlatform(): commands_common_pb.Platform | undefined;
setPlatform(value?: commands_common_pb.Platform): BoardListItem;


serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): BoardListItem.AsObject;
static toObject(includeInstance: boolean, msg: BoardListItem): BoardListItem.AsObject;
Expand All @@ -706,5 +720,61 @@ export namespace BoardListItem {
isHidden: boolean,
vid: string,
pid: string,
platform?: commands_common_pb.Platform.AsObject,
}
}

export class BoardSearchReq extends jspb.Message {

hasInstance(): boolean;
clearInstance(): void;
getInstance(): commands_common_pb.Instance | undefined;
setInstance(value?: commands_common_pb.Instance): BoardSearchReq;

getSearchArgs(): string;
setSearchArgs(value: string): BoardSearchReq;

getIncludeHiddenBoards(): boolean;
setIncludeHiddenBoards(value: boolean): BoardSearchReq;


serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): BoardSearchReq.AsObject;
static toObject(includeInstance: boolean, msg: BoardSearchReq): BoardSearchReq.AsObject;
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
static serializeBinaryToWriter(message: BoardSearchReq, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): BoardSearchReq;
static deserializeBinaryFromReader(message: BoardSearchReq, reader: jspb.BinaryReader): BoardSearchReq;
}

export namespace BoardSearchReq {
export type AsObject = {
instance?: commands_common_pb.Instance.AsObject,
searchArgs: string,
includeHiddenBoards: boolean,
}
}

export class BoardSearchResp extends jspb.Message {
clearBoardsList(): void;
getBoardsList(): Array<BoardListItem>;
setBoardsList(value: Array<BoardListItem>): BoardSearchResp;
addBoards(value?: BoardListItem, index?: number): BoardListItem;


serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): BoardSearchResp.AsObject;
static toObject(includeInstance: boolean, msg: BoardSearchResp): BoardSearchResp.AsObject;
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
static serializeBinaryToWriter(message: BoardSearchResp, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): BoardSearchResp;
static deserializeBinaryFromReader(message: BoardSearchResp, reader: jspb.BinaryReader): BoardSearchResp;
}

export namespace BoardSearchResp {
export type AsObject = {
boardsList: Array<BoardListItem.AsObject>,
}
}
Loading