Skip to content

Commit

Permalink
Eim 113 logs button (#41)
Browse files Browse the repository at this point in the history
* added logs component

* added opening the logs folder on click

* added linux specifiuc d3ependency

* correct path format for dbus-send

* fixed navigation

---------

Co-authored-by: Petr Gadorek <[email protected]>
  • Loading branch information
Hahihula and Petr Gadorek authored Jan 29, 2025
1 parent f8d65fa commit d216ac5
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 13 deletions.
12 changes: 11 additions & 1 deletion src-tauri/Cargo.lock

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

4 changes: 4 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ tauri-plugin-log = "2"
log = "0.4"
tokio = "1.41.0"

# OS-specific dependency
[target.'cfg(target_os = "linux")'.dependencies]
fork = "0.1"

[dependencies.openssl-sys]
version = "0.9"
features = ["vendored"]
92 changes: 91 additions & 1 deletion src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ use std::{
thread,
};
use tauri::{AppHandle, Manager};
use std::process::Command;
use std::fs::metadata;
#[cfg(target_os = "linux")]
use fork::{daemon, Fork}; // dep: fork = "0.1"



// Types and structs
#[derive(Default, Serialize, Deserialize)]
Expand Down Expand Up @@ -229,6 +235,22 @@ fn python_sanity_check(app_handle: AppHandle, python: Option<&str>) -> bool {
all_ok
}

#[tauri::command]
fn get_logs_folder(app_handle: AppHandle) -> PathBuf {
match idf_im_lib::get_log_directory() {
Some(folder) => folder,
None => {
send_message(
&app_handle,
format!("Error getting log folder"),
"error".to_string(),
);
log::error!("Error getting log folder"); //TODO: emit message
PathBuf::new()
}
}}


#[tauri::command]
fn python_install(app_handle: AppHandle) -> bool {
match idf_im_lib::system_dependencies::install_prerequisites(vec!["python".to_string()]) {
Expand Down Expand Up @@ -1107,6 +1129,72 @@ async fn start_simple_setup(app_handle: tauri::AppHandle) {
}
}

#[tauri::command]
fn show_in_folder(path: String) {
#[cfg(target_os = "windows")]
{
match Command::new("explorer")
.args(["/select,", &path]) // The comma after select is not a typo
.spawn() {
Ok(_) => {},
Err(e) => {
error!("Failed to open folder with explorer: {}", e);
}
}

}

#[cfg(target_os = "linux")]
{
let path = if path.contains(",") {
// see https://gitlab.freedesktop.org/dbus/dbus/-/issues/76
match metadata(&path).unwrap().is_dir() {
true => path,
false => {
let mut path2 = PathBuf::from(path);
path2.pop();
path2.into_os_string().into_string().unwrap()
}
}
} else {
path
};

// Try using xdg-open first
if Command::new("xdg-open")
.arg(&path)
.spawn()
.is_err()
{
// Fallback to dbus-send if xdg-open fails
let uri = format!("file://{}", path);
match Command::new("dbus-send")
.args(["--session", "--dest=org.freedesktop.FileManager1", "--type=method_call",
"/org/freedesktop/FileManager1", "org.freedesktop.FileManager1.ShowItems",
format!("array:string:\"{}\"", uri).as_str(), "string:\"\""])
.spawn() {
Ok(_) => {},
Err(e) => {
error!("Failed to open file with dbus-send: {}", e);
}
}
}
}

#[cfg(target_os = "macos")]
{
match Command::new("open")
.args(["-R", &path])
.spawn() {
Ok(_) => {},
Err(e) => {
error!("Failed to open file with open: {}", e);
}
}

}
}

use tauri::Emitter;

#[cfg_attr(mobile, tauri::mobile_entry_point)]
Expand Down Expand Up @@ -1156,7 +1244,9 @@ pub fn run() {
start_installation,
start_simple_setup,
quit_app,
save_config
save_config,
get_logs_folder,
show_in_folder
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
43 changes: 33 additions & 10 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,48 @@
<router-view></router-view>
<!-- Footer -->
<footer class="footer">
ESP-IDF Installation Manager {{ appVersion }}
<div class="footer-content">
<div class="version">ESP-IDF Installation Manager {{ appVersion }}</div>
<div class="log-link">
<LogLink />
</div>
</div>
</footer>
</div>
</template>

<script setup>
<script>
import { NConfigProvider, NLayout, NLayoutHeader, NLayoutContent, useOsTheme } from 'naive-ui'
import { darkTheme } from 'naive-ui'
import { ref, onMounted } from 'vue'
import { attachConsole } from '@tauri-apps/plugin-log'
import { getVersion } from '@tauri-apps/api/app';
import { getVersion } from '@tauri-apps/api/app'
import LogLink from './components/LogLink.vue'
export default {
name: 'App',
components: {
NConfigProvider,
NLayout,
NLayoutHeader,
NLayoutContent,
LogLink
},
setup() {
const osTheme = useOsTheme()
const theme = null // If you want to use computed: const theme = computed(() => (osTheme.value === 'dark' ? darkTheme : null))
const appVersion = ref('')
const osTheme = useOsTheme()
const theme = null // computed(() => (osTheme.value === 'dark' ? darkTheme : null))
const appVersion = ref('');
onMounted(async () => {
const detach = await attachConsole()
appVersion.value = await getVersion()
})
onMounted(async () => {
const detach = await attachConsole();
appVersion.value = await getVersion();
})
return {
osTheme,
theme,
appVersion
}
}
}
</script>
18 changes: 17 additions & 1 deletion src/assets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,27 @@ h2 {

.footer {
padding: 1rem;
text-align: center;
color: #6b7280;
font-size: 0.875rem;
}

.footer-content {
display: flex;
justify-content: center;
align-items: center;
position: relative;
max-width: 100%;
}

.version {
text-align: center;
}

.log-link {
position: absolute;
right: 0;
}

.title {
font-size: 27px;
font-family: 'Trueno-bold', sans-serif;
Expand Down
30 changes: 30 additions & 0 deletions src/components/LogLink.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script>
import { NButton } from 'naive-ui'
import { invoke } from "@tauri-apps/api/core";
export default {
name: 'LogLink',
components: { NButton },
data() {
return {
LogPath: ''
}
},
async created() {
this.LogPath = await invoke("get_logs_folder", {});
},
methods: {
async open_logs(e) {
e.preventDefault();
console.log("Opening logs folder: " + this.LogPath);
invoke("show_in_folder", { path: this.LogPath });
console.log("Logs folder opened.");
}
}
}
</script>
<template>
<p>
<a href="_self" @click="open_logs($event)">Logs folder</a>
</p>
</template>

0 comments on commit d216ac5

Please sign in to comment.