Skip to content

Commit 5c8669d

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
Added overwrite confirmation to ZIP lib install
Signed-off-by: Akos Kitta <[email protected]>
1 parent 9cd9146 commit 5c8669d

17 files changed

+1488
-742
lines changed

Diff for: arduino-ide-extension/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
],
125125
"arduino": {
126126
"cli": {
127-
"version": "0.16.1"
127+
"version": "20210315"
128128
}
129129
}
130130
}

Diff for: arduino-ide-extension/src/browser/contributions/add-zip-library.ts

+48-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
66
import URI from '@theia/core/lib/common/uri';
77
import { InstallationProgressDialog } from '../widgets/progress-dialog';
88
import { LibraryService } from '../../common/protocol';
9+
import { ConfirmDialog } from '@theia/core/lib/browser';
910

1011
@injectable()
1112
export class AddZipLibrary extends SketchContribution {
@@ -49,21 +50,60 @@ export class AddZipLibrary extends SketchContribution {
4950
});
5051
if (!canceled && filePaths.length) {
5152
const zipUri = await this.fileSystemExt.getUri(filePaths[0]);
52-
const dialog = new InstallationProgressDialog('Installing library', 'zip');
5353
try {
54-
this.outputChannelManager.getChannel('Arduino').clear();
55-
dialog.open();
56-
await this.libraryService.installZip({ zipUri });
57-
} catch (e) {
58-
this.messageService.error(e.toString());
59-
} finally {
60-
dialog.close();
54+
await this.doInstall(zipUri);
55+
} catch (error) {
56+
if (error instanceof AlreadyInstalledError) {
57+
const result = await new ConfirmDialog({
58+
msg: error.message,
59+
title: 'Do you want to overwrite the existing library?',
60+
ok: 'Yes',
61+
cancel: 'No'
62+
}).open();
63+
if (result) {
64+
await this.doInstall(zipUri, true);
65+
}
66+
}
67+
}
68+
}
69+
}
70+
71+
private async doInstall(zipUri: string, overwrite?: boolean): Promise<void> {
72+
const dialog = new InstallationProgressDialog('Installing library', 'zip');
73+
try {
74+
this.outputChannelManager.getChannel('Arduino').clear();
75+
dialog.open();
76+
await this.libraryService.installZip({ zipUri, overwrite });
77+
} catch (error) {
78+
if (error instanceof Error) {
79+
const match = error.message.match(/library (.*?) already installed/);
80+
if (match && match.length >= 2) {
81+
const name = match[1].trim();
82+
if (name) {
83+
throw new AlreadyInstalledError(`A library folder named ${name} already exists. Do you want to overwrite it?`, name);
84+
} else {
85+
throw new AlreadyInstalledError(`A library already exists. Do you want to overwrite it?`);
86+
}
87+
}
6188
}
89+
this.messageService.error(error.toString());
90+
throw error;
91+
} finally {
92+
dialog.close();
6293
}
6394
}
6495

6596
}
6697

98+
class AlreadyInstalledError extends Error {
99+
100+
constructor(message: string, readonly libraryName?: string) {
101+
super(message);
102+
Object.setPrototypeOf(this, AlreadyInstalledError.prototype);
103+
}
104+
105+
}
106+
67107
export namespace AddZipLibrary {
68108
export namespace Commands {
69109
export const ADD_ZIP_LIBRARY: Command = {

Diff for: arduino-ide-extension/src/common/protocol/library-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface LibraryService extends Installable<LibraryPackage>, Searchable<
1010
* When `installDependencies` is not set, it is `true` by default. If you want to skip the installation of required dependencies, set it to `false`.
1111
*/
1212
install(options: { item: LibraryPackage, version?: Installable.Version, installDependencies?: boolean }): Promise<void>;
13-
installZip(options: { zipUri: string }): Promise<void>;
13+
installZip(options: { zipUri: string, overwrite?: boolean }): Promise<void>;
1414
/**
1515
* Set `filterSelf` to `true` if you want to avoid having `item` in the result set.
1616
* Note: as of today (22.02.2021), the CLI works like this: `./arduino-cli lib deps [email protected] ✕ Adaino 0.1.0 must be installed.`.

Diff for: arduino-ide-extension/src/node/boards-service-impl.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import {
88
} from '../common/protocol';
99
import {
1010
PlatformSearchReq, PlatformSearchResp, PlatformInstallReq, PlatformInstallResp, PlatformListReq,
11-
PlatformListResp, Platform, PlatformUninstallResp, PlatformUninstallReq
11+
PlatformListResp, PlatformUninstallResp, PlatformUninstallReq
1212
} from './cli-protocol/commands/core_pb';
1313
import { BoardDiscovery } from './board-discovery';
1414
import { CoreClientAware } from './core-client-provider';
1515
import { BoardDetailsReq, BoardDetailsResp } from './cli-protocol/commands/board_pb';
1616
import { ListProgrammersAvailableForUploadReq, ListProgrammersAvailableForUploadResp } from './cli-protocol/commands/upload_pb';
17+
import { Platform } from './cli-protocol/commands/common_pb';
1718

1819
@injectable()
1920
export class BoardsServiceImpl extends CoreClientAware implements BoardsService {

Diff for: arduino-ide-extension/src/node/cli-protocol/commands/board_pb.d.ts

+70
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ export class BoardDetailsResp extends jspb.Message {
9292
getDebuggingSupported(): boolean;
9393
setDebuggingSupported(value: boolean): BoardDetailsResp;
9494

95+
getSerialnumber(): string;
96+
setSerialnumber(value: string): BoardDetailsResp;
97+
9598

9699
serializeBinary(): Uint8Array;
97100
toObject(includeInstance?: boolean): BoardDetailsResp.AsObject;
@@ -119,6 +122,7 @@ export namespace BoardDetailsResp {
119122
identificationPrefList: Array<IdentificationPref.AsObject>,
120123
programmersList: Array<commands_common_pb.Programmer.AsObject>,
121124
debuggingSupported: boolean,
125+
serialnumber: string,
122126
}
123127
}
124128

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

542+
getSerialNumber(): string;
543+
setSerialNumber(value: string): DetectedPort;
544+
538545

539546
serializeBinary(): Uint8Array;
540547
toObject(includeInstance?: boolean): DetectedPort.AsObject;
@@ -552,6 +559,7 @@ export namespace DetectedPort {
552559
protocol: string,
553560
protocolLabel: string,
554561
boardsList: Array<BoardListItem.AsObject>,
562+
serialNumber: string,
555563
}
556564
}
557565

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

691699

700+
hasPlatform(): boolean;
701+
clearPlatform(): void;
702+
getPlatform(): commands_common_pb.Platform | undefined;
703+
setPlatform(value?: commands_common_pb.Platform): BoardListItem;
704+
705+
692706
serializeBinary(): Uint8Array;
693707
toObject(includeInstance?: boolean): BoardListItem.AsObject;
694708
static toObject(includeInstance: boolean, msg: BoardListItem): BoardListItem.AsObject;
@@ -706,5 +720,61 @@ export namespace BoardListItem {
706720
isHidden: boolean,
707721
vid: string,
708722
pid: string,
723+
platform?: commands_common_pb.Platform.AsObject,
724+
}
725+
}
726+
727+
export class BoardSearchReq extends jspb.Message {
728+
729+
hasInstance(): boolean;
730+
clearInstance(): void;
731+
getInstance(): commands_common_pb.Instance | undefined;
732+
setInstance(value?: commands_common_pb.Instance): BoardSearchReq;
733+
734+
getSearchArgs(): string;
735+
setSearchArgs(value: string): BoardSearchReq;
736+
737+
getIncludeHiddenBoards(): boolean;
738+
setIncludeHiddenBoards(value: boolean): BoardSearchReq;
739+
740+
741+
serializeBinary(): Uint8Array;
742+
toObject(includeInstance?: boolean): BoardSearchReq.AsObject;
743+
static toObject(includeInstance: boolean, msg: BoardSearchReq): BoardSearchReq.AsObject;
744+
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
745+
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
746+
static serializeBinaryToWriter(message: BoardSearchReq, writer: jspb.BinaryWriter): void;
747+
static deserializeBinary(bytes: Uint8Array): BoardSearchReq;
748+
static deserializeBinaryFromReader(message: BoardSearchReq, reader: jspb.BinaryReader): BoardSearchReq;
749+
}
750+
751+
export namespace BoardSearchReq {
752+
export type AsObject = {
753+
instance?: commands_common_pb.Instance.AsObject,
754+
searchArgs: string,
755+
includeHiddenBoards: boolean,
756+
}
757+
}
758+
759+
export class BoardSearchResp extends jspb.Message {
760+
clearBoardsList(): void;
761+
getBoardsList(): Array<BoardListItem>;
762+
setBoardsList(value: Array<BoardListItem>): BoardSearchResp;
763+
addBoards(value?: BoardListItem, index?: number): BoardListItem;
764+
765+
766+
serializeBinary(): Uint8Array;
767+
toObject(includeInstance?: boolean): BoardSearchResp.AsObject;
768+
static toObject(includeInstance: boolean, msg: BoardSearchResp): BoardSearchResp.AsObject;
769+
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
770+
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
771+
static serializeBinaryToWriter(message: BoardSearchResp, writer: jspb.BinaryWriter): void;
772+
static deserializeBinary(bytes: Uint8Array): BoardSearchResp;
773+
static deserializeBinaryFromReader(message: BoardSearchResp, reader: jspb.BinaryReader): BoardSearchResp;
774+
}
775+
776+
export namespace BoardSearchResp {
777+
export type AsObject = {
778+
boardsList: Array<BoardListItem.AsObject>,
709779
}
710780
}

0 commit comments

Comments
 (0)