Skip to content

Commit a4bb45a

Browse files
committed
Made config writing blocking
1 parent c87ceab commit a4bb45a

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

src/config.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub fn config_path() -> PathBuf {
1717
parent.join(CONFIG_FILE_NAME)
1818
}
1919

20+
/// Reads the [`ClientConfig`] from the config file if one is present
2021
pub fn read_config_file() -> Option<ClientConfig> {
2122
let file_path = config_path();
2223
if !file_path.exists() {
@@ -44,7 +45,9 @@ pub fn read_config_file() -> Option<ClientConfig> {
4445
Some(config)
4546
}
4647

47-
pub async fn write_config_file(config: ClientConfig) {
48+
/// Writes the provided `config` to the config file, this will create a new
49+
/// file if one is not present
50+
pub fn write_config_file(config: ClientConfig) {
4851
let file_path = config_path();
4952
let bytes = match serde_json::to_vec(&config) {
5053
Ok(value) => value,
@@ -54,7 +57,7 @@ pub async fn write_config_file(config: ClientConfig) {
5457
}
5558
};
5659
debug!("Writing config file");
57-
if let Err(err) = tokio::fs::write(file_path, bytes).await {
60+
if let Err(err) = std::fs::write(file_path, bytes) {
5861
show_error("Failed to save client config", &err.to_string());
5962
}
6063
}

src/ui/iced.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ enum AppMessage {
5656
LookupState(LookupState),
5757
/// The remember checkbox button has changed
5858
RememberChanged(bool),
59-
/// Message that doesn't do anything
60-
Noop,
6159
}
6260

6361
/// Different states that lookup process can be in
@@ -139,8 +137,6 @@ impl Application for App {
139137

140138
// Lookup result changed
141139
AppMessage::LookupState(value) => {
142-
let mut command = Command::none();
143-
144140
if let LookupState::Success(value) = &value {
145141
// Start all the servers
146142
start_all_servers(self.http_client.clone(), value.url.clone());
@@ -149,20 +145,15 @@ impl Application for App {
149145
if self.remember {
150146
let connection_url = value.url.to_string();
151147

152-
command = Command::perform(
153-
write_config_file(ClientConfig { connection_url }),
154-
|_| AppMessage::Noop,
155-
)
148+
write_config_file(ClientConfig { connection_url });
156149
}
157150
}
158151

159152
self.lookup_result = value;
160-
return command;
161153
}
162154

163155
// Remember value changed
164156
AppMessage::RememberChanged(value) => self.remember = value,
165-
AppMessage::Noop => {}
166157
}
167158
Command::none()
168159
}

src/ui/native.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,8 @@ impl App {
139139
// Save the connection URL
140140
if remember {
141141
let connection_url = result.url.to_string();
142-
tokio::spawn(async move {
143-
write_config_file(ClientConfig { connection_url }).await;
144-
});
142+
143+
write_config_file(ClientConfig { connection_url });
145144
}
146145

147146
let text = format!(

0 commit comments

Comments
 (0)