Skip to content

Commit

Permalink
fix: Launch with invalid default profile fails
Browse files Browse the repository at this point in the history
Closes: #274
  • Loading branch information
joshuamegnauth54 authored and jackpot51 committed Aug 13, 2024
1 parent be808b5 commit 397b527
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ pub enum Action {
TabActivate8,
TabClose,
TabNew,
TabNewNoProfile,
TabNext,
TabPrev,
WindowClose,
Expand Down Expand Up @@ -248,6 +249,7 @@ impl Action {
Self::TabActivate8 => Message::TabActivateJump(8),
Self::TabClose => Message::TabClose(entity_opt),
Self::TabNew => Message::TabNew,
Self::TabNewNoProfile => Message::TabNewNoProfile,
Self::TabNext => Message::TabNext,
Self::TabPrev => Message::TabPrev,
Self::WindowClose => Message::WindowClose,
Expand Down Expand Up @@ -335,6 +337,7 @@ pub enum Message {
TabContextAction(segmented_button::Entity, Action),
TabContextMenu(pane_grid::Pane, Option<Point>),
TabNew,
TabNewNoProfile,
TabNext,
TabPrev,
TermEvent(pane_grid::Pane, segmented_button::Entity, TermEvent),
Expand Down Expand Up @@ -1258,6 +1261,28 @@ impl App {
tab_model
.data_set::<Mutex<Terminal>>(entity, Mutex::new(terminal));
}
Err(err) if profile_id_opt.is_some() => {
// Create a tab without a profile if the selected
// profile doesn't work
let name = profile_id_opt
.and_then(|id| self.config.profiles.get(&id))
.map(|profile| profile.name.as_str())
.unwrap_or_default();
log::error!(
"failed to open terminal with profile `{}`: {}",
name,
err
);

// TabClose focuses the nearest tab which would be incorrect
// in this specific case as it would unfocus the new tab
// created by TabNewNoProfile
// TabClose can also cause the terminal app to close if it
// closes the only open tab. This would close cosmic term
// if launched with an invalid profile (issue #274)
tab_model.remove(entity);
return self.update(Message::TabNewNoProfile);
}
Err(err) => {
log::error!("failed to open terminal: {}", err);
// Clean up partially created tab
Expand Down Expand Up @@ -2261,6 +2286,9 @@ impl Application for App {
self.get_default_profile(),
)
}
Message::TabNewNoProfile => {
return self.create_and_focus_new_terminal(self.pane_model.focus, None)
}
Message::TabNext => {
if let Some(tab_model) = self.pane_model.active() {
let len = tab_model.iter().count();
Expand Down

0 comments on commit 397b527

Please sign in to comment.