Skip to content

Commit

Permalink
feat: add support for custom app_id for window managers
Browse files Browse the repository at this point in the history
Added an `app_id` field to `App`, allowing users to specify a custom app_id
via the new `--app_id` command-line argument. The `build_window_options`
function now uses `cx.app_id`, defaulting to the release channel app ID
if none is provided. The app ID is initialized in `main.rs`

Signed-off-by: Marko Kungla <[email protected]>
  • Loading branch information
mkungla committed Feb 21, 2025
1 parent c31c638 commit b2dbe2b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions crates/gpui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ pub struct App {
pub(crate) tracked_entities: FxHashMap<WindowId, FxHashSet<EntityId>>,
#[cfg(any(test, feature = "test-support", debug_assertions))]
pub(crate) name: Option<&'static str>,
/// Represents the application identifier, which can be set via a command-line argument.
pub app_id: Option<String>,
}

impl App {
Expand Down Expand Up @@ -334,6 +336,7 @@ impl App {

#[cfg(any(test, feature = "test-support", debug_assertions))]
name: None,
app_id: None,
}),
});

Expand Down
6 changes: 6 additions & 0 deletions crates/zed/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,8 @@ fn main() {
open_listener.open_urls(urls)
}

cx.app_id = args.app_id; // None, by default

match open_rx
.try_next()
.ok()
Expand Down Expand Up @@ -1005,6 +1007,10 @@ struct Args {
/// Instructs zed to run as a dev server on this machine. (not implemented)
#[arg(long)]
dev_server_token: Option<String>,

/// Instructs zed to use custom app_id for window managers.
#[arg(long)]
app_id: Option<String>,
}

#[derive(Clone, Debug)]
Expand Down
8 changes: 6 additions & 2 deletions crates/zed/src/zed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ pub fn build_window_options(display_uuid: Option<Uuid>, cx: &mut App) -> WindowO
.into_iter()
.find(|display| display.uuid().ok() == Some(uuid))
});
let app_id = ReleaseChannel::global(cx).app_id();
if cx.app_id.is_none() {
let default_app_id = ReleaseChannel::global(cx).app_id().to_string();
cx.app_id = Some(default_app_id);
}

let window_decorations = match std::env::var("ZED_WINDOW_DECORATIONS") {
Ok(val) if val == "server" => gpui::WindowDecorations::Server,
Ok(val) if val == "client" => gpui::WindowDecorations::Client,
Expand All @@ -143,7 +147,7 @@ pub fn build_window_options(display_uuid: Option<Uuid>, cx: &mut App) -> WindowO
is_movable: true,
display_id: display.map(|display| display.id()),
window_background: cx.theme().window_background_appearance(),
app_id: Some(app_id.to_owned()),
app_id: cx.app_id.to_owned(),
window_decorations: Some(window_decorations),
window_min_size: Some(gpui::Size {
width: px(360.0),
Expand Down

0 comments on commit b2dbe2b

Please sign in to comment.