Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/cli/src/constants.rs
3309 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
use serde::Deserialize;
7
use std::{collections::HashMap, io::IsTerminal};
8
9
use const_format::concatcp;
10
use lazy_static::lazy_static;
11
12
use crate::options::Quality;
13
14
pub const CONTROL_PORT: u16 = 31545;
15
16
/// Protocol version sent to clients. This can be used to indicate new or
17
/// changed capabilities that clients may wish to leverage.
18
/// 1 - Initial protocol version
19
/// 2 - Addition of `serve.compressed` property to control whether servermsg's
20
/// are compressed bidirectionally.
21
/// 3 - The server's connection token is set to a SHA256 hash of the tunnel ID
22
/// 4 - The server's msgpack messages are no longer length-prefixed
23
pub const PROTOCOL_VERSION: u32 = 4;
24
25
/// Prefix for the tunnel tag that includes the version.
26
pub const PROTOCOL_VERSION_TAG_PREFIX: &str = "protocolv";
27
/// Tag for the current protocol version, which is included in dev tunnels.
28
pub const PROTOCOL_VERSION_TAG: &str = concatcp!("protocolv", PROTOCOL_VERSION);
29
30
pub const VSCODE_CLI_VERSION: Option<&'static str> = option_env!("VSCODE_CLI_VERSION");
31
pub const VSCODE_CLI_AI_KEY: Option<&'static str> = option_env!("VSCODE_CLI_AI_KEY");
32
pub const VSCODE_CLI_AI_ENDPOINT: Option<&'static str> = option_env!("VSCODE_CLI_AI_ENDPOINT");
33
pub const VSCODE_CLI_QUALITY: Option<&'static str> = option_env!("VSCODE_CLI_QUALITY");
34
pub const DOCUMENTATION_URL: Option<&'static str> = option_env!("VSCODE_CLI_DOCUMENTATION_URL");
35
pub const VSCODE_CLI_COMMIT: Option<&'static str> = option_env!("VSCODE_CLI_COMMIT");
36
pub const VSCODE_CLI_UPDATE_ENDPOINT: Option<&'static str> = option_env!("VSCODE_CLI_UPDATE_URL");
37
38
/// Windows lock name for the running tunnel service. Used by the setup script
39
/// to detect a tunnel process. See #179265.
40
pub const TUNNEL_SERVICE_LOCK_NAME: Option<&'static str> =
41
option_env!("VSCODE_CLI_WIN32_TUNNEL_SERVICE_MUTEX");
42
43
/// Windows lock name for the running tunnel without a service. Used by the setup
44
/// script to detect a tunnel process. See #179265.
45
pub const TUNNEL_CLI_LOCK_NAME: Option<&'static str> = option_env!("VSCODE_CLI_WIN32_TUNNEL_MUTEX");
46
47
pub const TUNNEL_SERVICE_USER_AGENT_ENV_VAR: &str = "TUNNEL_SERVICE_USER_AGENT";
48
49
/// Application name as it appears on the CLI.
50
pub const APPLICATION_NAME: &str = match option_env!("VSCODE_CLI_APPLICATION_NAME") {
51
Some(n) => n,
52
None => "code",
53
};
54
55
/// Full name of the product with its version.
56
pub const PRODUCT_NAME_LONG: &str = match option_env!("VSCODE_CLI_NAME_LONG") {
57
Some(n) => n,
58
None => "Code - OSS",
59
};
60
61
/// Name of the application without quality information.
62
pub const QUALITYLESS_PRODUCT_NAME: &str = match option_env!("VSCODE_CLI_QUALITYLESS_PRODUCT_NAME")
63
{
64
Some(n) => n,
65
None => "Code",
66
};
67
68
/// Name of the application without quality information.
69
pub const QUALITYLESS_SERVER_NAME: &str = concatcp!(QUALITYLESS_PRODUCT_NAME, " Server");
70
71
pub const QUALITY: &str = match VSCODE_CLI_QUALITY {
72
Some(q) => q,
73
_ => "oss",
74
};
75
76
/// Web URL the editor is hosted at. For VS Code, this is vscode.dev.
77
pub const EDITOR_WEB_URL: Option<&'static str> = option_env!("VSCODE_CLI_TUNNEL_EDITOR_WEB_URL");
78
79
/// Name shown in places where we need to tell a user what a process is, e.g. in sleep inhibition.
80
pub const TUNNEL_ACTIVITY_NAME: &str = concatcp!(PRODUCT_NAME_LONG, " Tunnel");
81
82
/// Download URL of the desktop product.
83
pub const PRODUCT_DOWNLOAD_URL: Option<&'static str> = option_env!("VSCODE_CLI_DOWNLOAD_URL");
84
85
const NONINTERACTIVE_VAR: &str = "VSCODE_CLI_NONINTERACTIVE";
86
87
/// Default data CLI data directory.
88
pub const DEFAULT_DATA_PARENT_DIR: &str = match option_env!("VSCODE_CLI_DATA_FOLDER_NAME") {
89
Some(n) => n,
90
None => ".vscode-oss",
91
};
92
93
pub fn get_default_user_agent() -> String {
94
format!(
95
"vscode-server-launcher/{}",
96
VSCODE_CLI_VERSION.unwrap_or("dev")
97
)
98
}
99
100
const NO_COLOR_ENV: &str = "NO_COLOR";
101
102
#[derive(Deserialize, Debug)]
103
#[serde(rename_all = "camelCase")]
104
pub struct ServerQualityInfo {
105
pub server_application_name: String,
106
}
107
108
lazy_static! {
109
pub static ref TUNNEL_SERVICE_USER_AGENT: String =
110
match std::env::var(TUNNEL_SERVICE_USER_AGENT_ENV_VAR) {
111
Ok(ua) if !ua.is_empty() => format!("{} {}", ua, get_default_user_agent()),
112
_ => get_default_user_agent(),
113
};
114
115
/// Map of qualities to the server name
116
pub static ref SERVER_NAME_MAP: Option<HashMap<Quality, ServerQualityInfo>> =
117
option_env!("VSCODE_CLI_TUNNEL_SERVER_QUALITIES").and_then(|s| serde_json::from_str(s).unwrap());
118
119
/// Whether i/o interactions are allowed in the current CLI.
120
pub static ref IS_A_TTY: bool = std::io::stdin().is_terminal();
121
122
/// Whether i/o interactions are allowed in the current CLI.
123
pub static ref COLORS_ENABLED: bool = *IS_A_TTY && std::env::var(NO_COLOR_ENV).is_err();
124
125
/// Whether i/o interactions are allowed in the current CLI.
126
pub static ref IS_INTERACTIVE_CLI: bool = *IS_A_TTY && std::env::var(NONINTERACTIVE_VAR).is_err();
127
128
/// Map of quality names to arrays of app IDs used for them, for example, `{"stable":["ABC123"]}`
129
pub static ref WIN32_APP_IDS: Option<Vec<String>> =
130
option_env!("VSCODE_CLI_WIN32_APP_IDS").map(|s| s.split(',').map(|s| s.to_string()).collect());
131
}
132
133