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

Improve additionalUrls settings UI #1419

Merged
merged 3 commits into from
Jan 14, 2022
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ This extension provides several commands in the Command Palette (<kbd>F1</kbd> o
| --- | --- |
| `arduino.path` | Path to Arduino, you can use a custom version of Arduino by modifying this setting to include the full path. Example: `C:\\Program Files\\Arduino` for Windows, `/Applications` for Mac, `/home/<username>/Downloads/arduino-1.8.1` for Linux. (Requires a restart after change). The default value is automatically detected from your Arduino IDE installation path. |
| `arduino.commandPath` | Path to an executable (or script) relative to `arduino.path`. The default value is `arduino_debug.exe` for Windows, `Contents/MacOS/Arduino` for Mac and `arduino` for Linux, You also can use a custom launch script to run Arduino by modifying this setting. (Requires a restart after change) Example: `run-arduino.bat` for Windows, `Contents/MacOS/run-arduino.sh` for Mac and `bin/run-arduino.sh` for Linux. |
| `arduino.additionalUrls` | Additional Boards Manager URLs for 3rd party packages. You can have multiple URLs in one string with a comma(`,`) as separator, or have a string array. The default value is empty. |
| `arduino.additionalUrls` | Additional Boards Manager URLs for 3rd party packages as a string array. The default value is empty. |
| `arduino.logLevel` | CLI output log level. Could be info or verbose. The default value is `"info"`. |
| `arduino.clearOutputOnBuild` | Clear the output logs before uploading or verifying. Default value is `false`. |
| `arduino.allowPDEFiletype` | Allow the VSCode Arduino extension to open .pde files from pre-1.0.0 versions of Arduino. Note that this will break Processing code. Default value is `false`. |
Expand Down
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,9 @@
"description": "Path to a script relative to 'arduino.path', you can use a custom launch script to run Arduino by modifying this setting. Example: 'run-arduino.bat' for Windows, 'Contents/MacOS/run-arduino.sh' for Mac, 'bin/run-arduino.sh' for Linux. (Requires a restart after change)"
},
"arduino.additionalUrls": {
"type": [
"string",
"array"
],
"description": "Additional URLs for 3-rd party packages. You can have multiple URLs in one string with comma(,) as separator, or have a string array."
"type": "array",
"items": { "type": "string" },
"description": "Additional URLs for 3rd party packages."
},
"arduino.logLevel": {
"type": "string",
Expand Down
18 changes: 13 additions & 5 deletions src/arduino/arduinoContentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,19 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
}
}

public openSettings(req, res) {
vscode.commands.executeCommand("workbench.action.openGlobalSettings");
return res.json({
status: "OK",
});
public async openSettings(req, res) {
if (!req.body.query) {
return res.status(400).send("BAD Request! Missing { query } parameter!");
} else {
try {
await vscode.commands.executeCommand("workbench.action.openGlobalSettings", { query: req.body.query });
return res.json({
status: "OK",
});
} catch (error) {
return res.status(500).send(`Cannot open the setting with error message "${error}"`);
}
}
}

public async getLibraries(req, res) {
Expand Down
18 changes: 2 additions & 16 deletions src/arduino/boardManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,26 +518,12 @@ export class BoardManager {
}

private getAdditionalUrls(): string[] {
function formatUrls(urls): string[] {
if (urls) {
let _urls: string[];

if (!Array.isArray(urls) && typeof urls === "string") {
_urls = (<string>urls).split(",");
} else {
_urls = <string[]>urls;
}

return util.trim(_urls);
}
return [];
}
// For better compatibility, merge urls both in user settings and arduino IDE preferences.
const settingsUrls = formatUrls(VscodeSettings.getInstance().additionalUrls);
const settingsUrls = VscodeSettings.getInstance().additionalUrls;
let preferencesUrls = [];
const preferences = this._settings.preferences;
if (preferences && preferences.has("boardsmanager.additional.urls")) {
preferencesUrls = formatUrls(preferences.get("boardsmanager.additional.urls"));
preferencesUrls = util.toStringArray(preferences.get("boardsmanager.additional.urls"));
}
return util.union(settingsUrls, preferencesUrls);
}
Expand Down
21 changes: 17 additions & 4 deletions src/arduino/vscodeSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

import * as vscode from "vscode";
import { toStringArray } from "../common/util";

const configKeys = {
ARDUINO_PATH: "arduino.path",
Expand All @@ -23,7 +24,7 @@ const configKeys = {
export interface IVscodeSettings {
arduinoPath: string;
commandPath: string;
additionalUrls: string | string[];
additionalUrls: string[];
logLevel: string;
clearOutputOnBuild: boolean;
allowPDEFiletype: boolean;
Expand All @@ -34,7 +35,7 @@ export interface IVscodeSettings {
defaultBaudRate: number;
useArduinoCli: boolean;
disableIntelliSenseAutoGen: boolean;
updateAdditionalUrls(urls: string | string[]): void;
updateAdditionalUrls(urls: string[]): void;
}

export class VscodeSettings implements IVscodeSettings {
Expand All @@ -57,8 +58,20 @@ export class VscodeSettings implements IVscodeSettings {
return this.getConfigValue<string>(configKeys.ARDUINO_COMMAND_PATH);
}

public get additionalUrls(): string | string[] {
return this.getConfigValue<string | string[]>(configKeys.ADDITIONAL_URLS);
public get additionalUrls(): string[] {
const value = this.getConfigValue<string | string[]>(configKeys.ADDITIONAL_URLS);

// Even though the schema says value must be a string array, version
// 0.4.9 and earlier also allowed a single comma delimeted string. We
// continue to unofficially support that format to avoid breaking
// existing settings, but we immediately write back the correctly
// formatted version.
const split = toStringArray(value);
if (typeof value === "string") {
this.updateAdditionalUrls(split);
}

return split;
}

public get logLevel(): string {
Expand Down
22 changes: 22 additions & 0 deletions src/common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,25 @@ export function resolveMacArduinoAppPath(arduinoPath: string, useArduinoCli = fa
return path.join(arduinoPath, "Arduino.app");
}
}

/**
* If given an string, splits the string on commas. If given an array, returns
* the array. All strings in the output are trimmed.
* @param value String or string array to convert.
* @returns Array of strings split from the input.
*/
export function toStringArray(value: string | string[]): string[] {
if (value) {
let result: string[];

if (typeof value === "string") {
result = value.split(",");
} else {
result = <string[]>value;
}

return trim(result);
}

return [];
}
6 changes: 4 additions & 2 deletions src/views/app/actions/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ export function openLink(link) {
}).then((response) => response.json());
}

export function openSettings() {
return postHTTP("/api/opensettings", {}).then((response) => response.json());
export function openSettings(query) {
return postHTTP("/api/opensettings", {
query,
}).then((response) => response.json());
}

export function getLibraries(update) {
Expand Down
2 changes: 1 addition & 1 deletion src/views/app/components/BoardManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class BoardManager extends React.Component<IBoardManagerProps, IBoardManagerStat
<div className="arduinomanager-footer theme-bgcolor">
<span>{totalCountTips}</span>
<a className="help-link right-side" title="Configure Additional Boards Manager URLs"
onClick={() => API.openSettings()}>Additional URLs</a>
onClick={() => API.openSettings("arduino.additionalUrls")}>Additional URLs</a>
</div>

</div>);
Expand Down