Skip to content

Commit

Permalink
Add option to use DOCKER_HOST variable for server uri
Browse files Browse the repository at this point in the history
Closes: #61
  • Loading branch information
vv9k committed Dec 7, 2021
1 parent c479b59 commit bf1ae9b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 0.3.0
- Add an option to respect `DOCKER_HOST` variable to the settings. If the checkbox is checked and the variable is present it will be used as the host uri.

# 0.2.0
- Explicitly sort sidepanel images/containers by newest
- Persist settings as YAML file in appropriate OS config directory
Expand Down
14 changes: 11 additions & 3 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,13 +758,21 @@ impl App {
self.add_error(e);
} else {
self.send_event_notify(EventRequest::DockerUriChange {
uri: self.settings_window.settings.docker_addr.clone(),
uri: self.docker_uri(),
});
}
}

pub fn docker_uri(&self) -> &str {
&self.settings_window.settings.docker_addr
pub fn docker_uri(&self) -> String {
if self.settings_window.settings.use_docker_host_env {
match std::env::var("DOCKER_HOST") {
Ok(uri) => return uri,
Err(e) => {
log::error!("failed to read DOCKER_HOST environment variable: {}", e);
}
}
}
self.settings_window.settings.docker_addr.clone()
}

fn handle_popups(&mut self) {
Expand Down
8 changes: 8 additions & 0 deletions src/app/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ pub fn dir() -> Option<PathBuf> {
pub struct Settings {
pub docker_addr: String,
pub fonts: FontSizes,
pub use_docker_host_env: bool,
}

impl Default for Settings {
fn default() -> Self {
Self {
docker_addr: crate::DEFAULT_DOCKER_ADDR.to_string(),
fonts: FontSizes::default(),
use_docker_host_env: false,
}
}
}
Expand Down Expand Up @@ -109,6 +111,12 @@ impl SettingsWindow {
);
ui.end_row();

ui.checkbox(
&mut self.settings.use_docker_host_env,
"Use DOCKER_HOST env var",
);
ui.end_row();

self.fonts_ui(ui);
ui.end_row();

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn main() -> Result<()> {
initial_window_size: Some((1280., 720.).into()),
..Default::default()
};
let uri = app.docker_uri().to_string();
let uri = app.docker_uri();

DockerWorker::spawn(rt, uri, rx_req, tx_rsp);

Expand Down

0 comments on commit bf1ae9b

Please sign in to comment.