Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions crates/conch_tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::theme;
/// Return general app config the frontend needs.
#[tauri::command]
pub(crate) fn get_app_config(state: tauri::State<'_, TauriState>) -> serde_json::Value {
let cfg = state.config.lock();
let cfg = state.config.read();
let dec = format!("{:?}", cfg.window.decorations).to_lowercase();
serde_json::json!({
"appearance_mode": format!("{:?}", cfg.colors.appearance_mode).to_lowercase(),
Expand Down Expand Up @@ -65,7 +65,7 @@ pub(crate) fn get_home_dir() -> String {

#[tauri::command]
pub(crate) fn get_theme_colors(state: tauri::State<'_, TauriState>) -> theme::ThemeColors {
let cfg = state.config.lock();
let cfg = state.config.read();
theme::resolve_theme_colors(&cfg)
}

Expand All @@ -84,7 +84,7 @@ pub(crate) struct TerminalDisplayConfig {

#[tauri::command]
pub(crate) fn get_terminal_config(state: tauri::State<'_, TauriState>) -> TerminalDisplayConfig {
let cfg = state.config.lock();
let cfg = state.config.read();
let font = cfg.resolved_terminal_font();
let cursor = &cfg.terminal.cursor.style;
let cursor_style = match cursor.shape.to_lowercase().as_str() {
Expand Down Expand Up @@ -122,7 +122,7 @@ pub(crate) struct KeyboardShortcuts {

#[tauri::command]
pub(crate) fn get_keyboard_shortcuts(state: tauri::State<'_, TauriState>) -> KeyboardShortcuts {
let cfg = state.config.lock();
let cfg = state.config.read();
let kb = &cfg.conch.keyboard;
KeyboardShortcuts {
toggle_right_panel: kb.toggle_right_panel.clone(),
Expand Down Expand Up @@ -248,7 +248,7 @@ pub(crate) fn rebuild_menu(
.map(|c| c.conch.keyboard)
.unwrap_or_default();

let plugin_items = plugin_state.lock().menu_items.lock().clone();
let plugin_items = plugin_state.lock().menu_items.read().clone();

// On Windows the custom titlebar handles menus; skip native menu.
if cfg!(target_os = "windows") {
Expand Down
12 changes: 6 additions & 6 deletions crates/conch_tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ use std::collections::HashMap;
use std::sync::Arc;

use conch_core::config::{self, UserConfig};
use parking_lot::Mutex;
use parking_lot::{Mutex, RwLock};
use pty_backend::PtyBackend;
use remote::RemoteState;
use tauri::{Emitter, Manager};
use tauri_plugin_updater::UpdaterExt;

pub(crate) struct TauriState {
ptys: Arc<Mutex<HashMap<String, PtyBackend>>>,
config: Mutex<UserConfig>,
config: RwLock<UserConfig>,
}

/// Launch the Tauri-based UI.
Expand Down Expand Up @@ -89,7 +89,7 @@ pub fn run(config: UserConfig) -> anyhow::Result<()> {
.plugin(tauri_plugin_notification::init())
.manage(TauriState {
ptys: Arc::new(Mutex::new(HashMap::new())),
config: Mutex::new(config),
config: RwLock::new(config),
})
.manage(Arc::clone(&remote_state))
.manage(Arc::clone(&plugin_state))
Expand Down Expand Up @@ -145,7 +145,7 @@ pub fn run(config: UserConfig) -> anyhow::Result<()> {
.name("plugin-menu-rebuild".into())
.spawn(move || {
std::thread::sleep(std::time::Duration::from_millis(500));
let plugin_items = menu_ps.lock().menu_items.lock().clone();
let plugin_items = menu_ps.lock().menu_items.read().clone();
if !plugin_items.is_empty() {
match menu::build_app_menu_with_plugins(
&menu_handle,
Expand Down Expand Up @@ -349,7 +349,7 @@ pub fn run(config: UserConfig) -> anyhow::Result<()> {
// plugin name on the bus is different (e.g., "Form Test").
let real_plugin = ps_guard
.menu_items
.lock()
.read()
.iter()
.find(|i| i.plugin == source_name && i.action == action)
.map(|i| i.plugin.clone());
Expand Down Expand Up @@ -527,7 +527,7 @@ mod tests {
fn tauri_state_default_has_no_pty() {
let state = TauriState {
ptys: Arc::new(Mutex::new(HashMap::new())),
config: Mutex::new(UserConfig::default()),
config: RwLock::new(UserConfig::default()),
};
assert!(state.ptys.lock().is_empty());
}
Expand Down
30 changes: 15 additions & 15 deletions crates/conch_tauri/src/plugins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::sync::Arc;
use conch_plugin::bus::PluginBus;
use conch_plugin::jvm::runtime::JavaPluginManager;
use conch_plugin::lua::runner;
use parking_lot::Mutex;
use parking_lot::{Mutex, RwLock};
use serde::Serialize;
use tauri::Emitter;

Expand Down Expand Up @@ -79,8 +79,8 @@ struct PluginPanelsRemoved {

pub(crate) struct PluginState {
pub bus: Arc<PluginBus>,
pub panels: Arc<Mutex<HashMap<u64, PanelInfo>>>,
pub menu_items: Arc<Mutex<Vec<PluginMenuItem>>>,
pub panels: Arc<RwLock<HashMap<u64, PanelInfo>>>,
pub menu_items: Arc<RwLock<Vec<PluginMenuItem>>>,
pub pending_dialogs: Arc<Mutex<PendingDialogs>>,
pub running_lua: Vec<runner::RunningLuaPlugin>,
pub java_mgr: Option<JavaPluginManager>,
Expand All @@ -91,8 +91,8 @@ impl PluginState {
pub fn new(plugins_config: conch_core::config::PluginsConfig) -> Self {
Self {
bus: Arc::new(PluginBus::new()),
panels: Arc::new(Mutex::new(HashMap::new())),
menu_items: Arc::new(Mutex::new(Vec::new())),
panels: Arc::new(RwLock::new(HashMap::new())),
menu_items: Arc::new(RwLock::new(Vec::new())),
pending_dialogs: Arc::new(Mutex::new(PendingDialogs::new())),
running_lua: Vec::new(),
java_mgr: None,
Expand Down Expand Up @@ -149,7 +149,7 @@ impl PluginState {
fn cleanup_plugin_resources(&self, plugin_name: &str) -> Vec<u64> {
// Collect and remove panels owned by this plugin.
let mut removed_handles = Vec::new();
self.panels.lock().retain(|handle, info| {
self.panels.write().retain(|handle, info| {
if info.plugin_name == plugin_name {
removed_handles.push(*handle);
false
Expand All @@ -160,7 +160,7 @@ impl PluginState {

// Remove menu items registered by this plugin.
self.menu_items
.lock()
.write()
.retain(|item| item.plugin != plugin_name);

// Drop pending dialog channels owned by this plugin.
Expand Down Expand Up @@ -579,7 +579,7 @@ pub(crate) fn dialog_respond_confirm(
pub(crate) fn get_plugin_menu_items(
state: tauri::State<'_, Arc<Mutex<PluginState>>>,
) -> Vec<PluginMenuItem> {
state.lock().menu_items.lock().clone()
state.lock().menu_items.read().clone()
}

/// Trigger a plugin menu action (sends menu_action event to the plugin).
Expand All @@ -602,7 +602,7 @@ pub(crate) fn trigger_plugin_menu_action(
pub(crate) fn get_plugin_panels(
state: tauri::State<'_, Arc<Mutex<PluginState>>>,
) -> Vec<PanelInfo> {
state.lock().panels.lock().values().cloned().collect()
state.lock().panels.read().values().cloned().collect()
}

/// Get the widget JSON for a specific panel.
Expand All @@ -614,7 +614,7 @@ pub(crate) fn get_panel_widgets(
state
.lock()
.panels
.lock()
.read()
.get(&handle)
.map(|p| p.widgets_json.clone())
}
Expand Down Expand Up @@ -662,7 +662,7 @@ mod tests {
#[test]
fn plugin_state_new_is_empty() {
let state = PluginState::new(conch_core::config::PluginsConfig::default());
assert!(state.panels.lock().is_empty());
assert!(state.panels.read().is_empty());
assert!(state.running_lua.is_empty());
}

Expand Down Expand Up @@ -698,7 +698,7 @@ mod tests {

// Insert panels for two different plugins.
{
let mut panels = state.panels.lock();
let mut panels = state.panels.write();
panels.insert(
1,
PanelInfo {
Expand Down Expand Up @@ -741,7 +741,7 @@ mod tests {
assert!(removed.contains(&1));
assert!(removed.contains(&3));

let panels = state.panels.lock();
let panels = state.panels.read();
assert_eq!(panels.len(), 1, "only other-plugin panel should remain");
assert!(panels.contains_key(&2));
}
Expand All @@ -751,7 +751,7 @@ mod tests {
let state = PluginState::new(conch_core::config::PluginsConfig::default());

{
let mut items = state.menu_items.lock();
let mut items = state.menu_items.write();
items.push(PluginMenuItem {
plugin: "my-plugin".into(),
menu: "Tools".into(),
Expand All @@ -777,7 +777,7 @@ mod tests {

state.cleanup_plugin_resources("my-plugin");

let items = state.menu_items.lock();
let items = state.menu_items.read();
assert_eq!(items.len(), 1, "only other-plugin menu item should remain");
assert_eq!(items[0].plugin, "other-plugin");
}
Expand Down
12 changes: 6 additions & 6 deletions crates/conch_tauri/src/plugins/tauri_host_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::sync::atomic::{AtomicU64, Ordering};
use conch_plugin::HostApi;
use conch_plugin::bus::PluginBus;
use conch_plugin_sdk::PanelLocation;
use parking_lot::Mutex;
use parking_lot::{Mutex, RwLock};
use serde::Serialize;
use tauri::Emitter;

Expand All @@ -23,8 +23,8 @@ pub(crate) struct TauriHostApi {
pub name: String,
pub app_handle: tauri::AppHandle,
pub bus: std::sync::Arc<PluginBus>,
pub panels: std::sync::Arc<Mutex<HashMap<u64, PanelInfo>>>,
pub menu_items: std::sync::Arc<Mutex<Vec<PluginMenuItem>>>,
pub panels: std::sync::Arc<RwLock<HashMap<u64, PanelInfo>>>,
pub menu_items: std::sync::Arc<RwLock<Vec<PluginMenuItem>>>,
pub pending_dialogs: std::sync::Arc<Mutex<PendingDialogs>>,
}

Expand Down Expand Up @@ -81,7 +81,7 @@ impl HostApi for TauriHostApi {
_ => "right",
};

self.panels.lock().insert(
self.panels.write().insert(
handle,
PanelInfo {
plugin_name: self.name.clone(),
Expand All @@ -107,7 +107,7 @@ impl HostApi for TauriHostApi {
}

fn set_widgets(&self, handle: u64, widgets_json: &str) {
if let Some(panel) = self.panels.lock().get_mut(&handle) {
if let Some(panel) = self.panels.write().get_mut(&handle) {
panel.widgets_json = widgets_json.to_string();
}

Expand Down Expand Up @@ -265,7 +265,7 @@ impl HostApi for TauriHostApi {
action: action.to_string(),
keybind: keybind.map(String::from),
};
self.menu_items.lock().push(item.clone());
self.menu_items.write().push(item.clone());

// Also emit to frontend for immediate update.
let _ = self.app_handle.emit("plugin-menu-item", &item);
Expand Down
2 changes: 1 addition & 1 deletion crates/conch_tauri/src/pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub(crate) fn spawn_shell(
) -> Result<(), String> {
let window_label = window.label().to_string();
let key = session_key(&window_label, pane_id);
let cfg = state.config.lock();
let cfg = state.config.read();
let (shell, shell_args) = resolved_shell(&cfg.terminal.shell);

let backend = PtyBackend::new(cols, rows, shell, shell_args, &cfg.terminal.env)
Expand Down
6 changes: 3 additions & 3 deletions crates/conch_tauri/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub(crate) struct SaveSettingsResult {

#[tauri::command]
pub(crate) fn get_all_settings(state: tauri::State<'_, TauriState>) -> serde_json::Value {
let cfg = state.config.lock();
let cfg = state.config.read();
serde_json::to_value(&*cfg).unwrap_or_default()
}

Expand Down Expand Up @@ -47,13 +47,13 @@ pub(crate) fn save_settings(
serde_json::from_value(settings).map_err(|e| format!("Invalid settings: {e}"))?;

let restart_required = {
let old_config = state.config.lock();
let old_config = state.config.read();
needs_restart(&old_config, &new_config)
};

// Update in-memory config before disk write.
{
let mut cfg = state.config.lock();
let mut cfg = state.config.write();
*cfg = new_config.clone();
}

Expand Down
Loading