Skip to content

Commit

Permalink
profile selection, fix setting default profile
Browse files Browse the repository at this point in the history
  • Loading branch information
aprxi committed Aug 18, 2024
1 parent ab39d07 commit e4009ad
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl UserProfileDbHandler {
profile_name: &str,
) -> Result<(), ApplicationError> {
let mut db = self.db.lock().await;

eprintln!("Setting default profile to {}", profile_name);
db.process_queue_with_result(|tx| {
tx.execute(
"UPDATE user_profiles SET is_default = 0 WHERE is_default = 1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ impl ProfileEditModal {
mut db_handler: UserProfileDbHandler,
) -> Result<Self, ApplicationError> {
let profiles = db_handler.get_profile_list().await?;
let profile_list = ProfileList::new(profiles);
let default_profile = db_handler.get_default_profile().await?;
let profile_list = ProfileList::new(profiles, default_profile);

let settings =
if let Some(profile) = profile_list.get_selected_profile() {
db_handler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ pub struct ProfileList {
}

impl ProfileList {
pub fn new(profiles: Vec<String>) -> Self {
pub fn new(profiles: Vec<String>, default_profile: Option<String>) -> Self {
ProfileList {
profiles,
selected_index: 0,
default_profile: None,
default_profile,
}
}

Expand Down Expand Up @@ -94,11 +94,15 @@ impl ProfileList {
self.default_profile = Some(profile.to_string());
}

pub fn is_default_profile(&self, profile: &str) -> bool {
self.default_profile.as_ref().map_or(false, |default| default == profile)
}

pub fn get_profiles(&self) -> Vec<String> {
self.profiles
.iter()
.map(|p| {
if Some(p) == self.default_profile.as_ref() {
if self.is_default_profile(p) {
format!("* {}", p) // Prepend an asterisk to mark the default profile
} else {
p.clone()
Expand Down

0 comments on commit e4009ad

Please sign in to comment.