Match the startup behavior of the CLI to the main app (#12044)

Currently the main binary will open an empty file if no previous
workspaces exist or, if it is the first startup, show the welcome page.
When starting via the CLI it will simply drop you in an empty workspace:
no empty file and no welcome page.

This changes the CLI startup to match the behavior of the non-CLI
startup, so they will both create an empty file or show the welcome page
if no path was given and no workspaces were opened in the past.

Release Notes:

- Matched startup behavior of the CLI to the behavior of the main app.
This commit is contained in:
Owen Law 2024-05-20 21:33:19 -04:00 committed by GitHub
parent 1e18bcb949
commit 315e45f543
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,6 +3,7 @@ use cli::{ipc, IpcHandshake};
use cli::{ipc::IpcSender, CliRequest, CliResponse};
use client::parse_zed_link;
use collections::HashMap;
use db::kvp::KEY_VALUE_STORE;
use editor::scroll::Autoscroll;
use editor::Editor;
use futures::channel::mpsc::{UnboundedReceiver, UnboundedSender};
@ -17,6 +18,7 @@ use std::time::Duration;
use std::{process, thread};
use util::paths::PathLikeWithPosition;
use util::ResultExt;
use welcome::{show_welcome_view, FIRST_OPEN};
use workspace::item::ItemHandle;
use workspace::{AppState, Workspace};
@ -313,6 +315,7 @@ pub async fn handle_cli_connection(
let mut errored = false;
if !paths.is_empty() {
match open_paths_with_positions(
&paths,
app_state,
@ -346,7 +349,10 @@ pub async fn handle_cli_connection(
Some(Err(err)) => {
responses
.send(CliResponse::Stderr {
message: format!("error opening {:?}: {}", path, err),
message: format!(
"error opening {:?}: {}",
path, err
),
})
.log_err();
errored = true;
@ -367,8 +373,8 @@ pub async fn handle_cli_connection(
});
let _ = done_rx.await;
} else {
let _ =
futures::future::try_join_all(item_release_futures).await;
let _ = futures::future::try_join_all(item_release_futures)
.await;
};
}
.fuse();
@ -398,6 +404,17 @@ pub async fn handle_cli_connection(
.log_err();
}
}
} else if matches!(KEY_VALUE_STORE.read_kvp(FIRST_OPEN), Ok(None)) {
cx.update(|cx| show_welcome_view(app_state, cx)).log_err();
} else {
cx.update(|cx| {
workspace::open_new(app_state, cx, |workspace, cx| {
Editor::new_file(workspace, &Default::default(), cx)
})
.detach();
})
.log_err();
}
responses
.send(CliResponse::Exit {