From 0625006a9e7225d995cf392c51de9f938a999b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=B0=8F=E7=99=BD?= <364772080@qq.com> Date: Thu, 27 Feb 2025 16:00:42 +0800 Subject: [PATCH] windows: Missing commit of #25412 (#25732) Closes #ISSUE Release Notes: - N/A *or* Added/Fixed/Improved ... Co-authored-by: Mikayla Maki --- crates/cli/src/main.rs | 6 +++--- crates/release_channel/src/lib.rs | 14 ++++++++------ crates/zed/src/zed/windows_only_instance.rs | 8 ++++---- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 1210dbb49853f45a7981dced769df9a2351ee01b..b74a72b63cb75acf1802ad4e6ea64e7f49b1bf14 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -524,7 +524,7 @@ mod flatpak { #[cfg(target_os = "windows")] mod windows { use anyhow::Context; - use release_channel::APP_IDENTIFIER; + use release_channel::app_identifier; use windows::{ core::HSTRING, Win32::{ @@ -546,7 +546,7 @@ mod windows { CreateMutexW( None, false, - &HSTRING::from(format!("{}-Instance-Mutex", *APP_IDENTIFIER)), + &HSTRING::from(format!("{}-Instance-Mutex", app_identifier())), ) .expect("Unable to create instance sync event") }; @@ -583,7 +583,7 @@ mod windows { } else { unsafe { let pipe = CreateFileW( - &HSTRING::from(format!("\\\\.\\pipe\\{}-Named-Pipe", *APP_IDENTIFIER)), + &HSTRING::from(format!("\\\\.\\pipe\\{}-Named-Pipe", app_identifier())), GENERIC_WRITE.0, FILE_SHARE_MODE::default(), None, diff --git a/crates/release_channel/src/lib.rs b/crates/release_channel/src/lib.rs index 26be9ea697c5485e2213f5b8a2b411404f60da0f..5ee840f8f1d974d08b4656ad0c66b8ffb963c412 100644 --- a/crates/release_channel/src/lib.rs +++ b/crates/release_channel/src/lib.rs @@ -25,12 +25,14 @@ pub static RELEASE_CHANNEL: LazyLock = /// The app identifier for the current release channel, Windows only. #[cfg(target_os = "windows")] -pub static APP_IDENTIFIER: LazyLock<&str> = LazyLock::new(|| match *RELEASE_CHANNEL { - ReleaseChannel::Dev => "Zed-Editor-Dev", - ReleaseChannel::Nightly => "Zed-Editor-Nightly", - ReleaseChannel::Preview => "Zed-Editor-Preview", - ReleaseChannel::Stable => "Zed-Editor-Stable", -}); +pub fn app_identifier() -> &'static str { + match *RELEASE_CHANNEL { + ReleaseChannel::Dev => "Zed-Editor-Dev", + ReleaseChannel::Nightly => "Zed-Editor-Nightly", + ReleaseChannel::Preview => "Zed-Editor-Preview", + ReleaseChannel::Stable => "Zed-Editor-Stable", + } +} /// The Git commit SHA that Zed was built at. #[derive(Clone)] diff --git a/crates/zed/src/zed/windows_only_instance.rs b/crates/zed/src/zed/windows_only_instance.rs index 79c6254f65e5d4b0123e16d266e3208b244a015f..058507823fdc1c296cbc975ed9be82099f3919be 100644 --- a/crates/zed/src/zed/windows_only_instance.rs +++ b/crates/zed/src/zed/windows_only_instance.rs @@ -4,7 +4,7 @@ use anyhow::Context; use clap::Parser; use cli::{ipc::IpcOneShotServer, CliRequest, CliResponse, IpcHandshake}; use parking_lot::Mutex; -use release_channel::APP_IDENTIFIER; +use release_channel::app_identifier; use util::ResultExt; use windows::{ core::HSTRING, @@ -31,7 +31,7 @@ pub fn check_single_instance(opener: OpenListener, run_foreground: bool) -> bool CreateMutexW( None, false, - &HSTRING::from(format!("{}-Instance-Mutex", *APP_IDENTIFIER)), + &HSTRING::from(format!("{}-Instance-Mutex", app_identifier())), ) .expect("Unable to create instance sync event") }; @@ -51,7 +51,7 @@ pub fn check_single_instance(opener: OpenListener, run_foreground: bool) -> bool fn with_pipe(f: impl Fn(String)) { let pipe = unsafe { CreateNamedPipeW( - &HSTRING::from(format!("\\\\.\\pipe\\{}-Named-Pipe", *APP_IDENTIFIER)), + &HSTRING::from(format!("\\\\.\\pipe\\{}-Named-Pipe", app_identifier())), PIPE_ACCESS_INBOUND, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 1, @@ -152,7 +152,7 @@ fn send_args_to_instance() -> anyhow::Result<()> { unsafe { let pipe = CreateFileW( - &HSTRING::from(format!("\\\\.\\pipe\\{}-Named-Pipe", *APP_IDENTIFIER)), + &HSTRING::from(format!("\\\\.\\pipe\\{}-Named-Pipe", app_identifier())), GENERIC_WRITE.0, FILE_SHARE_MODE::default(), None,