Skip to content

Commit

Permalink
feat: refactor configs dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
hcavarsan committed Jun 20, 2024
1 parent 3b40358 commit 4880052
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
23 changes: 18 additions & 5 deletions crates/kftray-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,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 @@ -137,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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
faTrash,
} from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { homeDir } from '@tauri-apps/api/path'
import { open } from '@tauri-apps/api/shell'
import { invoke } from '@tauri-apps/api/tauri'

Expand Down Expand Up @@ -202,15 +201,9 @@ const PortForwardRow: React.FC<PortForwardRowProps> = ({

const handleInspectLogs = async () => {
try {
const homePath = await homeDir()
const logFileName = `${config.id}_${config.local_port}.log`

const logFilePath = `${config.id}_${config.local_port}.log`

const fullPath = `${homePath}/.kftray/http_logs/${logFilePath}`

const sanitizedFullPath = fullPath.replace(/\\/g, '/')

await invoke('open_log_file', { logFilePath: sanitizedFullPath })
await invoke('open_log_file', { logFileName: logFileName })
} catch (error) {
console.error('Error opening log file:', error)
const errorMessage =
Expand Down

0 comments on commit 4880052

Please sign in to comment.