fix(web-client): use default_layout if configured (#4278)

* fix(web-client): use default_layout if configured

* docs(changelog): add PR
This commit is contained in:
Aram Drevekenin 2025-07-09 16:39:52 +02:00 committed by GitHub
parent da9cf4ffeb
commit f8b8d61552
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 54 additions and 10 deletions

View file

@ -7,7 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
## [Unreleased] ## [Unreleased]
* feat: multiple select and bulk pane actions (https://github.com/zellij-org/zellij/pull/4169 and https://github.com/zellij-org/zellij/pull/4171 and https://github.com/zellij-org/zellij/pull/4221) * feat: multiple select and bulk pane actions (https://github.com/zellij-org/zellij/pull/4169 and https://github.com/zellij-org/zellij/pull/4171 and https://github.com/zellij-org/zellij/pull/4221)
* feat: add an optional key tooltip to show the current keybindings for the compact bar (https://github.com/zellij-org/zellij/pull/4225) * feat: add an optional key tooltip to show the current keybindings for the compact bar (https://github.com/zellij-org/zellij/pull/4225)
* feat: web-client, allowing users to share sessions in the browser (https://github.com/zellij-org/zellij/pull/4242 and https://github.com/zellij-org/zellij/pull/4257) * feat: web-client, allowing users to share sessions in the browser (https://github.com/zellij-org/zellij/pull/4242, https://github.com/zellij-org/zellij/pull/4257 and https://github.com/zellij-org/zellij/pull/4278)
* performance: consolidate renders (https://github.com/zellij-org/zellij/pull/4245) * performance: consolidate renders (https://github.com/zellij-org/zellij/pull/4245)
* feat: add plugin API to replace a pane with another existing pane (https://github.com/zellij-org/zellij/pull/4246) * feat: add plugin API to replace a pane with another existing pane (https://github.com/zellij-org/zellij/pull/4246)
* feat: add "stack" keybinding and CLI action to add a stacked pane to the current pane (https://github.com/zellij-org/zellij/pull/4255) * feat: add "stack" keybinding and CLI action to add a stacked pane to the current pane (https://github.com/zellij-org/zellij/pull/4255)

View file

@ -34,7 +34,8 @@ pub fn zellij_server_listener(
move || { move || {
let mut client_connection_bus = let mut client_connection_bus =
ClientConnectionBus::new(&web_client_id, &connection_table); ClientConnectionBus::new(&web_client_id, &connection_table);
let mut reconnect_to_session = match build_initial_connection(session_name) { let mut reconnect_to_session = match build_initial_connection(session_name, &config)
{
Ok(initial_session_connection) => initial_session_connection, Ok(initial_session_connection) => initial_session_connection,
Err(e) => { Err(e) => {
log::error!("{}", e); log::error!("{}", e);

View file

@ -18,8 +18,11 @@ use zellij_utils::{
pub fn build_initial_connection( pub fn build_initial_connection(
session_name: Option<String>, session_name: Option<String>,
config: &Config,
) -> Result<Option<ConnectToSession>, &'static str> { ) -> Result<Option<ConnectToSession>, &'static str> {
let should_start_with_welcome_screen = session_name.is_none(); let should_start_with_welcome_screen = session_name.is_none();
let default_layout_from_config =
LayoutInfo::from_config(&config.options.layout_dir, &config.options.default_layout);
if should_start_with_welcome_screen { if should_start_with_welcome_screen {
let Some(initial_session_name) = session_name.clone().or_else(generate_unique_session_name) let Some(initial_session_name) = session_name.clone().or_else(generate_unique_session_name)
else { else {
@ -33,6 +36,12 @@ pub fn build_initial_connection(
} else if let Some(session_name) = session_name { } else if let Some(session_name) = session_name {
Ok(Some(ConnectToSession { Ok(Some(ConnectToSession {
name: Some(session_name.clone()), name: Some(session_name.clone()),
layout: default_layout_from_config,
..Default::default()
}))
} else if default_layout_from_config.is_some() {
Ok(Some(ConnectToSession {
layout: default_layout_from_config,
..Default::default() ..Default::default()
})) }))
} else { } else {

View file

@ -1,3 +1,4 @@
use crate::home::default_layout_dir;
use crate::input::actions::Action; use crate::input::actions::Action;
use crate::input::config::ConversionError; use crate::input::config::ConversionError;
use crate::input::keybinds::Keybinds; use crate::input::keybinds::Keybinds;
@ -1672,6 +1673,34 @@ impl LayoutInfo {
LayoutInfo::Stringified(_stringified) => false, LayoutInfo::Stringified(_stringified) => false,
} }
} }
pub fn from_config(
layout_dir: &Option<PathBuf>,
default_layout: &Option<PathBuf>,
) -> Option<Self> {
match default_layout {
Some(default_layout) => {
if default_layout.extension().is_some() || default_layout.components().count() > 1 {
let Some(layout_dir) = layout_dir
.as_ref()
.map(|l| l.clone())
.or_else(default_layout_dir)
else {
return None;
};
Some(LayoutInfo::File(
layout_dir.join(default_layout).display().to_string(),
))
} else if default_layout.starts_with("http://")
|| default_layout.starts_with("https://")
{
Some(LayoutInfo::Url(default_layout.display().to_string()))
} else {
Some(LayoutInfo::BuiltIn(default_layout.display().to_string()))
}
},
None => None,
}
}
} }
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};

View file

@ -1163,15 +1163,20 @@ impl Layout {
let mut available_layouts = vec![]; let mut available_layouts = vec![];
for file in layout_files { for file in layout_files {
if let Ok(file) = file { if let Ok(file) = file {
if Layout::from_path_or_default_without_config( if file.path().extension().map(|e| e.to_ascii_lowercase())
Some(&file.path()), == Some(std::ffi::OsString::from("kdl"))
layout_dir.clone(),
)
.is_ok()
{ {
if let Some(file_name) = file.path().file_stem() { if Layout::from_path_or_default_without_config(
available_layouts Some(&file.path()),
.push(LayoutInfo::File(file_name.to_string_lossy().to_string())) layout_dir.clone(),
)
.is_ok()
{
if let Some(file_name) = file.path().file_stem() {
available_layouts.push(LayoutInfo::File(
file_name.to_string_lossy().to_string(),
))
}
} }
} }
} }