Skip to content

Commit e6bf38b

Browse files
mengfei1026meta-codesync[bot]
authored andcommitted
Suppress console window pop-ups on Windows for scribe_cat and commit cloud subscriber
Summary: On Windows, background source-control telemetry and the commit cloud subscriber daemon were spawning child processes without the `CREATE_NO_WINDOW` creation flag, so a console window flashed on the user's desktop on every spawn — when running source control, and even while the machine was otherwise idle (the commit cloud subscriber fires `hg cloud sync` on notifications). Two crates were affected: `scribe_cat` only applied `CREATE_NO_WINDOW` on the rarely-used orphaned path. The default (non-orphaned) `offer`, `blocking_put`, and the pooled `ScribeCatPool::spawn_process` all spawned `scribe_cat.exe` with no creation flags, flashing a window for ordinary telemetry. This adds a shared `apply_creation_flags` helper that always sets `CREATE_NO_WINDOW` on Windows, plus `CREATE_NEW_PROCESS_GROUP` only when orphaning, and routes every spawn path through it. `commitcloudsubscriber` spawned `hg cloud sync` (`action.rs`) and `clicat`/`corp_clicat` (`util.rs`) with no creation flags. This adds a shared `hide_console_window` helper that sets `CREATE_NO_WINDOW` on Windows and routes both spawns through it. All changes are no-ops on non-Windows platforms. Reviewed By: metacpp Differential Revision: D109767752 fbshipit-source-id: 9013efe976a12a7dc597c057f904d75b111fbfa9
1 parent 0abea02 commit e6bf38b

2 files changed

Lines changed: 36 additions & 16 deletions

File tree

eden/scm/lib/commitcloudsubscriber/src/action.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ impl CloudSyncTrigger {
3636
}
3737
for i in 0..retries {
3838
let now = Instant::now();
39-
let child = Command::new("hg")
39+
let mut command = Command::new("hg");
40+
command
4041
.current_dir(&path)
4142
.env(identity::default().env_name("PLAIN").as_ref(), "hint")
4243
.env("EDENSCM_LOG", "clienttelemetry=info")
@@ -48,8 +49,9 @@ impl CloudSyncTrigger {
4849
.args(&workspace_args)
4950
.args(vec!["--reason", &reason])
5051
.stdout(Stdio::piped())
51-
.stderr(Stdio::piped())
52-
.spawn()?; // do not retry if failed to start
52+
.stderr(Stdio::piped());
53+
crate::util::hide_console_window(&mut command);
54+
let child = command.spawn()?; // do not retry if failed to start
5355

5456
info!(
5557
"{} Fire `hg cloud sync` attempt {}, spawned process id '{}'",

eden/scm/lib/commitcloudsubscriber/src/util.rs

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,23 @@ static SEC_IN_WEEK: u64 = 604800;
3434
/// https://developers.facebook.com/apps/184975892288525/dashboard/
3535
pub static COMMIT_CLOUD_APP_ID: u64 = 184975892288525u64;
3636

37+
/// Configures `command` so spawning it does not flash a console window on
38+
/// Windows. The commit cloud subscriber runs as a background daemon, so without
39+
/// `CREATE_NO_WINDOW` every `hg cloud sync` and `clicat` invocation pops up a
40+
/// console window on the user's desktop, even while the machine is otherwise
41+
/// idle. No-op on other platforms.
42+
pub(crate) fn hide_console_window(command: &mut Command) {
43+
#[cfg(windows)]
44+
{
45+
use std::os::windows::process::CommandExt;
46+
// CREATE_NO_WINDOW: no console window is popped up for the child.
47+
const CREATE_NO_WINDOW: u32 = 0x08000000;
48+
command.creation_flags(CREATE_NO_WINDOW);
49+
}
50+
#[cfg(not(windows))]
51+
let _ = command;
52+
}
53+
3754
/// Map from a subscription to list of repo roots
3855
pub fn read_subscriptions(joined_pool_path: &Path) -> Result<HashMap<Subscription, Vec<PathBuf>>> {
3956
let mut joined_pool_path = joined_pool_path.to_path_buf();
@@ -211,19 +228,20 @@ pub fn read_or_generate_access_token(user_token_path: &Option<PathBuf>) -> Resul
211228
let token_timeout_seconds = 1200;
212229
let payload = base64::engine::general_purpose::STANDARD
213230
.encode(json!({"app":COMMIT_CLOUD_APP_ID, "x2p": !from_prod}).to_string());
214-
let output = Command::new(clicat_tool)
215-
.args(vec![
216-
"create",
217-
"--verifier_type",
218-
"SERVICE_IDENTITY",
219-
"--verifier_id",
220-
"interngraph",
221-
"--token_timeout_seconds",
222-
&token_timeout_seconds.to_string(),
223-
"--payload",
224-
&payload,
225-
])
226-
.output();
231+
let mut command = Command::new(clicat_tool);
232+
command.args(vec![
233+
"create",
234+
"--verifier_type",
235+
"SERVICE_IDENTITY",
236+
"--verifier_id",
237+
"interngraph",
238+
"--token_timeout_seconds",
239+
&token_timeout_seconds.to_string(),
240+
"--payload",
241+
&payload,
242+
]);
243+
hide_console_window(&mut command);
244+
let output = command.output();
227245

228246
match output {
229247
Err(e) => {

0 commit comments

Comments
 (0)