Use same logic for skipping single instance check on Linux as on Mac/Win (#19446)

Release Notes:

- Linux: Now skips check which exits with "zed is already running" when
in development mode or when run with `zed-local`, matching the behavior
on Mac and Windows

Co-authored-by: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Michael Sloan 2024-10-29 10:12:34 -06:00 committed by GitHub
parent 5893e85708
commit 3fed738d2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 36 deletions

View file

@ -32,7 +32,7 @@ use node_runtime::{NodeBinaryOptions, NodeRuntime};
use parking_lot::Mutex; use parking_lot::Mutex;
use project::project_settings::ProjectSettings; use project::project_settings::ProjectSettings;
use recent_projects::{open_ssh_project, SshSettings}; use recent_projects::{open_ssh_project, SshSettings};
use release_channel::{AppCommitSha, AppVersion}; use release_channel::{AppCommitSha, AppVersion, ReleaseChannel};
use session::{AppSession, Session}; use session::{AppSession, Session};
use settings::{ use settings::{
handle_settings_file_changes, watch_config_file, InvalidSettingsError, Settings, SettingsStore, handle_settings_file_changes, watch_config_file, InvalidSettingsError, Settings, SettingsStore,
@ -164,33 +164,30 @@ fn main() {
let (open_listener, mut open_rx) = OpenListener::new(); let (open_listener, mut open_rx) = OpenListener::new();
let failed_single_instance_check =
if *db::ZED_STATELESS || *release_channel::RELEASE_CHANNEL == ReleaseChannel::Dev {
false
} else {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
{ {
if env::var("ZED_STATELESS").is_err() { crate::zed::listen_for_cli_connections(open_listener.clone()).is_err()
if crate::zed::listen_for_cli_connections(open_listener.clone()).is_err() {
println!("zed is already running");
return;
}
}
} }
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
{ {
use zed::windows_only_instance::*; !crate::zed::windows_only_instance::check_single_instance()
if !check_single_instance() {
println!("zed is already running");
return;
}
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
{ {
use zed::mac_only_instance::*; use zed::mac_only_instance::*;
if ensure_only_instance() != IsOnlyInstance::Yes { ensure_only_instance() != IsOnlyInstance::Yes
}
};
if failed_single_instance_check {
println!("zed is already running"); println!("zed is already running");
return; return;
} }
}
let git_hosting_provider_registry = Arc::new(GitHostingProviderRegistry::new()); let git_hosting_provider_registry = Arc::new(GitHostingProviderRegistry::new());
let git_binary_path = let git_binary_path =

View file

@ -87,10 +87,6 @@ pub enum IsOnlyInstance {
} }
pub fn ensure_only_instance() -> IsOnlyInstance { pub fn ensure_only_instance() -> IsOnlyInstance {
if *db::ZED_STATELESS || *release_channel::RELEASE_CHANNEL == ReleaseChannel::Dev {
return IsOnlyInstance::Yes;
}
if check_got_handshake() { if check_got_handshake() {
return IsOnlyInstance::No; return IsOnlyInstance::No;
} }

View file

@ -17,14 +17,6 @@ fn retrieve_app_instance_event_identifier() -> &'static str {
} }
pub fn check_single_instance() -> bool { pub fn check_single_instance() -> bool {
if *db::ZED_STATELESS || *release_channel::RELEASE_CHANNEL == ReleaseChannel::Dev {
return true;
}
check_single_instance_event()
}
fn check_single_instance_event() -> bool {
unsafe { unsafe {
CreateEventW( CreateEventW(
None, None,