Skip to content

Commit

Permalink
feat: refactor configs dirs (#265)
Browse files Browse the repository at this point in the history
* feat: refactor configs dirs

* feat: refactor configs dirs

* feat: refactor configs dirs

* feat: refactor configs dirs

* feat: refactor configs dirs

* feat: refactor configs dirs

* feat: refactor configs dirs
  • Loading branch information
hcavarsan authored Jun 21, 2024
1 parent c272223 commit 3f336af
Show file tree
Hide file tree
Showing 21 changed files with 645 additions and 209 deletions.
101 changes: 94 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@

<h2> Download latest release </h2>
<div align="left">
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.12.0_universal.dmg">
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.12.1_universal.dmg">
<img src="https://img.shields.io/badge/-macOS (Universal)-grey.svg?style=for-the-badge&logo=apple" alt="Download for macOS" />
</a>
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.12.0_arm64-setup.exe">
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.12.1_arm64-setup.exe">
<img src="https://img.shields.io/badge/-Windows (ARM64)-grey.svg?style=for-the-badge&logo=windows" alt="Download for Windows ARM64" />
</a>
<br />
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.12.0_x64-setup.exe">
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.12.1_x64-setup.exe">
<img src="https://img.shields.io/badge/-Windows (x64)-grey.svg?style=for-the-badge&logo=windows" alt="Download for Windows x64" />
</a>
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.12.0_x86-setup.exe">
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.12.1_x86-setup.exe">
<img src="https://img.shields.io/badge/-Windows (x86)-grey.svg?style=for-the-badge&logo=windows" alt="Download for Windows x86" />
</a>
<br />
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.12.0_amd64.AppImage">
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.12.1_amd64.AppImage">
<img src="https://img.shields.io/badge/-Linux (x64)-grey.svg?style=for-the-badge&logo=linux" alt="Download for Linux AMD64" />
</a>
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.12.0_aarch64.AppImage">
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.12.1_aarch64.AppImage">
<img src="https://img.shields.io/badge/-Linux (ARM64)-grey.svg?style=for-the-badge&logo=linux" alt="Download for Linux AARCH64" />
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion crates/kftray-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kftray-server"
version = "0.12.0"
version = "0.12.1"
description = "KFtray Server is a Rust application that relays UDP/TCP traffic to an upstream server"
authors = [
"Henrique Cavarsan <[email protected]>",
Expand Down
5 changes: 3 additions & 2 deletions crates/kftray-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kftray"
version = "0.12.0"
version = "0.12.1"
description = "A cross-platform system tray app for Kubernetes port-forward management"
authors = ["Henrique Cavarsan <[email protected]>"]
license = "MIT"
Expand Down Expand Up @@ -64,6 +64,7 @@ uuid = { version = "1.8.0", features = ["v4"] }
bytes = "1.6.0"
tracing-subscriber = "0.3.18"
dashmap = "5.5.3"
native-dialog = "0.7.0"

[dev-dependencies]
tempfile = "3.9"
Expand All @@ -75,4 +76,4 @@ tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
default = ["custom-protocol"]
# this feature is used used for production builds where `devPath` points to the filesystem
# DO NOT remove this
custom-protocol = ["tauri/custom-protocol"]
custom-protocol = ["tauri/custom-protocol"]
40 changes: 21 additions & 19 deletions crates/kftray-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use reqwest::header::{
};
use tauri::State;

use crate::utils::config_dir::get_log_folder_path;
use crate::{
config::{
import_configs,
Expand Down Expand Up @@ -110,21 +111,34 @@ pub async fn import_configs_from_github(
}

#[tauri::command]
pub async fn open_log_file(log_file_path: String) -> Result<(), String> {
pub async fn open_log_file(log_file_name: String) -> Result<(), String> {
use std::env;
use std::fs;

use open::that_in_background;

println!("Opening log file: {}", log_file_path);
let log_folder_path = get_log_folder_path()?;
let log_file_path = log_folder_path.join(log_file_name);

if !log_file_path.exists() {
return Err(format!(
"Log file does not exist: {}",
log_file_path.display()
));
}

println!("Opening log file: {}", log_file_path.display());

if fs::metadata(&log_file_path).is_err() {
return Err(format!("Log file does not exist: {}", log_file_path));
return Err(format!(
"Log file does not exist: {}",
log_file_path.display()
));
}

let editor = env::var("EDITOR").unwrap_or_else(|_| default_editor());

match try_open_with_editor(&log_file_path, &editor) {
match try_open_with_editor(log_file_path.to_str().unwrap(), &editor) {
Ok(_) => Ok(()),
Err(err) => {
println!(
Expand All @@ -136,7 +150,7 @@ pub async fn open_log_file(log_file_path: String) -> Result<(), String> {
Ok(Ok(_)) => Ok(()),
Ok(Err(err)) => {
println!("Error opening log file with default method: {}. Trying fallback methods...", err);
fallback_methods(&log_file_path)
fallback_methods(log_file_path.to_str().unwrap())
}
Err(err) => Err(format!("Failed to join thread: {:?}", err)),
}
Expand Down Expand Up @@ -202,12 +216,6 @@ pub async fn clear_http_logs() -> Result<(), String> {
use std::fs;
use std::path::PathBuf;

fn get_log_folder_path() -> PathBuf {
let mut path = dirs::home_dir().unwrap();
path.push(".kftray/http_logs");
path
}

fn delete_files_in_folder(path: &PathBuf) -> Result<(), String> {
if path.is_dir() {
for entry in
Expand All @@ -226,7 +234,7 @@ pub async fn clear_http_logs() -> Result<(), String> {
Ok(())
}

let log_folder_path = get_log_folder_path();
let log_folder_path = get_log_folder_path()?;

if !log_folder_path.exists() {
return Err(format!(
Expand All @@ -243,12 +251,6 @@ pub async fn get_http_log_size() -> Result<u64, String> {
use std::fs;
use std::path::PathBuf;

fn get_log_folder_path() -> PathBuf {
let mut path = dirs::home_dir().unwrap();
path.push(".kftray/http_logs");
path
}

fn calculate_folder_size(path: &PathBuf) -> Result<u64, String> {
let mut size = 0;

Expand All @@ -273,7 +275,7 @@ pub async fn get_http_log_size() -> Result<u64, String> {
Ok(size)
}

let log_folder_path = get_log_folder_path();
let log_folder_path = get_log_folder_path()?;

if !log_folder_path.exists() {
return Err(format!(
Expand Down
Loading

0 comments on commit 3f336af

Please sign in to comment.