fix(web-client): theme not loading (#4265)

Fix theme not getting applied in web client.

- Ensure theme is properly read from config
- Update config in web server shared state when it gets updated (without this, clients connecting after a config change would still get the old settings)
This commit is contained in:
Thomas Linford 2025-07-28 11:28:04 +02:00 committed by GitHub
parent 090b1714b0
commit be20acaa3e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 28 additions and 28 deletions

View file

@ -91,7 +91,7 @@ impl From<&Config> for SetConfigPayload {
fn from(config: &Config) -> Self {
let font = config.web_client.font.clone();
let palette = config.theme_config(None);
let palette = config.theme_config(config.options.theme.as_ref());
let web_client_theme_from_config = config.web_client.theme.as_ref();
let mut theme = SetConfigPayloadTheme::default();

View file

@ -1,7 +1,7 @@
use crate::web_client::types::AppState;
use super::control_message::{SetConfigPayload, WebServerToWebClientControlMessage};
use super::types::ConnectionTable;
use axum_server::Handle;
use std::sync::{Arc, Mutex};
use tokio::io::AsyncReadExt;
use tokio::net::{UnixListener, UnixStream};
use zellij_utils::consts::WEBSERVER_SOCKET_PATH;
@ -33,11 +33,7 @@ pub async fn receive_webserver_instruction(
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))
}
pub async fn listen_to_web_server_instructions(
server_handle: Handle,
connection_table: Arc<Mutex<ConnectionTable>>,
id: &str,
) {
pub async fn listen_to_web_server_instructions(server_handle: Handle, state: AppState, id: &str) {
loop {
let receiver = create_webserver_receiver(id).await;
match receiver {
@ -51,8 +47,11 @@ pub async fn listen_to_web_server_instructions(
InstructionForWebServer::ConfigWrittenToDisk(new_config) => {
let set_config_payload = SetConfigPayload::from(&new_config);
let mut config = state.config.lock().unwrap();
*config = new_config.clone();
let client_ids: Vec<String> = {
let connection_table_lock = connection_table.lock().unwrap();
let connection_table_lock = state.connection_table.lock().unwrap();
connection_table_lock
.client_id_to_channels
.keys()
@ -71,7 +70,8 @@ pub async fn listen_to_web_server_instructions(
};
for client_id in client_ids {
if let Some(control_tx) = connection_table
if let Some(control_tx) = state
.connection_table
.lock()
.unwrap()
.get_client_control_tx(&client_id)
@ -88,7 +88,8 @@ pub async fn listen_to_web_server_instructions(
},
}
}
if let Some(os_input) = connection_table
if let Some(os_input) = state
.connection_table
.lock()
.unwrap()
.get_client_os_api(&client_id)

View file

@ -54,9 +54,7 @@ use uuid::Uuid;
use websocket_handlers::{ws_handler_control, ws_handler_terminal};
use zellij_utils::{
cli::CliArgs,
consts::WEBSERVER_SOCKET_PATH,
ipc::{ClientAttributes, ClientToServerMsg, ExitReason, ServerToClientMsg},
web_server_commands::{
create_webserver_sender, send_webserver_instruction, InstructionForWebServer,
},
@ -230,24 +228,23 @@ pub async fn serve_web_client(
}
});
tokio::spawn({
let server_handle = server_handle.clone();
let connection_table = connection_table.clone();
async move {
listen_to_web_server_instructions(server_handle, connection_table, &format!("{}", id))
.await;
}
});
let state = AppState {
connection_table,
config,
connection_table: connection_table.clone(),
config: Arc::new(Mutex::new(config)),
config_options,
config_file_path,
session_manager,
client_os_api_factory,
};
tokio::spawn({
let server_handle = server_handle.clone();
let state = state.clone();
async move {
listen_to_web_server_instructions(server_handle, state, &format!("{}", id)).await;
}
});
let app = Router::new()
.route("/ws/control", any(ws_handler_control))
.route("/ws/terminal", any(ws_handler_terminal))

View file

@ -169,7 +169,7 @@ impl ClientConnectionBus {
#[derive(Clone)]
pub struct AppState {
pub connection_table: Arc<Mutex<ConnectionTable>>,
pub config: Config,
pub config: Arc<Mutex<Config>>,
pub config_options: Options,
pub config_file_path: PathBuf,
pub session_manager: Arc<dyn SessionManager>,

View file

@ -37,8 +37,8 @@ pub async fn ws_handler_terminal(
}
async fn handle_ws_control(socket: WebSocket, state: AppState) {
let config = SetConfigPayload::from(&state.config);
let set_config_msg = WebServerToWebClientControlMessage::SetConfig(config);
let payload = SetConfigPayload::from(&*state.config.lock().unwrap());
let set_config_msg = WebServerToWebClientControlMessage::SetConfig(payload);
let (control_socket_tx, mut control_socket_rx) = socket.split();
@ -136,7 +136,7 @@ async fn handle_ws_terminal(
os_input.clone(),
state.connection_table.clone(),
session_name.map(|p| p.0),
state.config.clone(),
state.config.lock().unwrap().clone(),
state.config_options.clone(),
Some(state.config_file_path.clone()),
web_client_id.clone(),
@ -160,6 +160,8 @@ async fn handle_ws_terminal(
let explicitly_disable_kitty_keyboard_protocol = state
.config
.lock()
.unwrap()
.options
.support_kitty_keyboard_protocol
.map(|e| !e)