mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-09 02:18:32 +00:00
Implemented the Network tab.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
@@ -8,11 +8,79 @@ export interface ConfigService {
|
||||
isInSketchDir(uri: string): Promise<boolean>;
|
||||
}
|
||||
|
||||
export interface ProxySettings {
|
||||
protocol: string;
|
||||
hostname: string;
|
||||
port: string;
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
export type Network = 'none' | ProxySettings;
|
||||
export namespace Network {
|
||||
|
||||
export function Default(): Network {
|
||||
return {
|
||||
protocol: 'http',
|
||||
hostname: '',
|
||||
port: '',
|
||||
username: '',
|
||||
password: ''
|
||||
}
|
||||
}
|
||||
|
||||
export function parse(raw: string | undefined): Network {
|
||||
if (!raw) {
|
||||
return 'none';
|
||||
}
|
||||
try {
|
||||
// Patter: PROTOCOL://USER:PASS@HOSTNAME:PORT/
|
||||
const { protocol, hostname, password, username, port } = new URL(raw);
|
||||
return {
|
||||
protocol,
|
||||
hostname,
|
||||
password,
|
||||
username,
|
||||
port
|
||||
};
|
||||
} catch {
|
||||
return 'none';
|
||||
}
|
||||
};
|
||||
|
||||
export function stringify(network: Network): string | undefined {
|
||||
if (network === 'none') {
|
||||
return undefined;
|
||||
}
|
||||
const { protocol, hostname, password, username, port } = network;
|
||||
try {
|
||||
const defaultUrl = new URL(`${protocol ? protocol : 'http'}://${hostname ? hostname : '_'}`);
|
||||
return Object.assign(defaultUrl, { protocol, hostname, password, username, port }).toString();
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export function sameAs(left: Network, right: Network): boolean {
|
||||
if (left === 'none') {
|
||||
return right === 'none';
|
||||
}
|
||||
if (right === 'none') {
|
||||
return false;
|
||||
}
|
||||
return left.hostname === right.hostname
|
||||
&& left.password === right.password
|
||||
&& left.protocol === right.protocol
|
||||
&& left.username === right.username;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
export interface Config {
|
||||
readonly sketchDirUri: string;
|
||||
readonly dataDirUri: string;
|
||||
readonly downloadsDirUri: string;
|
||||
readonly additionalUrls: string[];
|
||||
readonly network: Network;
|
||||
}
|
||||
export namespace Config {
|
||||
export function sameAs(left: Config, right: Config): boolean {
|
||||
@@ -28,6 +96,7 @@ export namespace Config {
|
||||
}
|
||||
return left.dataDirUri === right.dataDirUri
|
||||
&& left.downloadsDirUri === right.downloadsDirUri
|
||||
&& left.sketchDirUri === right.sketchDirUri;
|
||||
&& left.sketchDirUri === right.sketchDirUri
|
||||
&& Network.sameAs(left.network, right.network);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user