-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
windows: Implement dock menus #17352
base: main
Are you sure you want to change the base?
Changes from all commits
edf8581
a833f95
4a1f92b
a73182c
162fc99
d7a37cd
d395211
a427b90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use std::sync::OnceLock; | ||
|
||
use windows::Win32::Foundation::MAX_PATH; | ||
|
||
static APP_IDENTIFIER: OnceLock<String> = OnceLock::new(); | ||
static APP_MUTEX_IDENTIFIER: OnceLock<String> = OnceLock::new(); | ||
static APP_EVENT_IDENTIFIER: OnceLock<String> = OnceLock::new(); | ||
static APP_SHARED_MEMORY_IDENTIFIER: OnceLock<String> = OnceLock::new(); | ||
|
||
/// TODO: | ||
pub const APP_SHARED_MEMORY_MAX_SIZE: usize = 1024; | ||
|
||
/// TODO: | ||
pub fn register_app_identifier(app_identifier: &str) { | ||
APP_IDENTIFIER.get_or_init(|| app_identifier.to_string()); | ||
} | ||
|
||
fn get_app_identifier() -> &'static str { | ||
APP_IDENTIFIER.get_or_init(|| { | ||
let rand_number = rand::random::<u32>(); | ||
let random_identifier = format!("Gpui-App-Identifier-{}", rand_number); | ||
log::error!( | ||
"No app identifier is set, call register_app_identifier first. Using {} instead.", | ||
random_identifier | ||
); | ||
random_identifier | ||
}) | ||
} | ||
|
||
/// TODO: | ||
pub fn get_app_instance_mutex_identifier() -> &'static str { | ||
APP_MUTEX_IDENTIFIER.get_or_init(|| { | ||
let identifier = format!("Local\\{}-Instance-Mutex", get_app_identifier()); | ||
if identifier.len() as u32 > MAX_PATH { | ||
panic!("The length of app instance mutex identifier `{identifier}` is limited to {MAX_PATH} characters."); | ||
} | ||
identifier | ||
}) | ||
} | ||
|
||
/// TODO: | ||
pub fn get_app_instance_event_identifier() -> &'static str { | ||
APP_EVENT_IDENTIFIER.get_or_init(|| { | ||
let identifier = format!("Local\\{}-Instance-Event", get_app_identifier()); | ||
if identifier.len() as u32 > MAX_PATH { | ||
panic!("The length of app instance event identifier `{identifier}` is limited to {MAX_PATH} characters."); | ||
} | ||
identifier | ||
}) | ||
} | ||
|
||
/// TODO: | ||
pub fn get_app_shared_memory_identifier() -> &'static str { | ||
APP_SHARED_MEMORY_IDENTIFIER.get_or_init(|| { | ||
let identifier = format!("Local\\{}-Shared-Memory", get_app_identifier()); | ||
if identifier.len() as u32 > MAX_PATH { | ||
panic!("The length of app shared memory identifier `{identifier}` is limited to {MAX_PATH} characters."); | ||
} | ||
identifier | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -319,6 +319,13 @@ fn init_ui( | |
|
||
fn main() { | ||
let start_time = std::time::Instant::now(); | ||
|
||
#[cfg(target_os = "windows")] | ||
{ | ||
use zed::windows_only_instance::*; | ||
register_zed_identifier(); | ||
} | ||
|
||
menu::init(); | ||
zed_actions::init(); | ||
|
||
|
@@ -361,11 +368,15 @@ fn main() { | |
} | ||
} | ||
|
||
let args = Args::parse(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we want this behavior, the sqlite database we use can't support more than one instance. If we remove this, I'd be happy to merge this feature :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry, but I didn't quite understand your point. Could you please explain how There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry, I misclicked the line. I meant to select the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. Sorry for the confusion here! The Handling the When the new instance starts, the previously merged single instance feature detects an already running instance through the if !check_single_instance() {
if let Some(dock_menu_args) = args.new_instance {
send_to_existing_instance(dock_menu_args);
}
println!("Already running!");
return;
} Then, the existing instance, after receiving the Since English isn't my first language, I often struggle with naming things, so I simply used |
||
#[cfg(target_os = "windows")] | ||
{ | ||
use zed::windows_only_instance::*; | ||
if !check_single_instance() { | ||
println!("zed is already running"); | ||
if let Some(ref argument) = args.new_instance { | ||
send_instance_message(argument); | ||
} | ||
return; | ||
} | ||
} | ||
|
@@ -500,7 +511,6 @@ fn main() { | |
reliability::init(client.http_client(), installation_id, cx); | ||
let prompt_builder = init_common(app_state.clone(), cx); | ||
|
||
let args = Args::parse(); | ||
let urls: Vec<_> = args | ||
.paths_or_urls | ||
.iter() | ||
|
@@ -1065,6 +1075,10 @@ struct Args { | |
/// URLs can either be `file://` or `zed://` scheme, or relative to <https://zed.dev>. | ||
paths_or_urls: Vec<String>, | ||
|
||
/// TODO: | ||
#[arg(long)] | ||
new_instance: Option<String>, | ||
|
||
/// Instructs zed to run as a dev server on this machine. (not implemented) | ||
#[arg(long)] | ||
dev_server_token: Option<String>, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible that we check single instance at the very beginning?