feat(ui): add show in file manager button to screenshot view

- Add Tools::open_file_manager helper with Windows and Linux support.
- Ensure screenshot directory is created before scanning.
- Add localization keys for en_US and zh_CN.
This commit is contained in:
2026-08-07 19:49:53 +08:00
parent 4fef8e195a
commit d7cb178c2b
4 changed files with 74 additions and 6 deletions

View File

@@ -0,0 +1,57 @@
#pragma once
#include "Cubed/tools/log.hpp"
#include <filesystem>
#include <string>
#ifdef _WIN32
// clang-format off
#include <windows.h>
#include <shellapi.h>
// clang-format on
#elif __linux__
#include <cstdlib>
#endif
namespace Cubed::Tools {
inline void open_file_manager(const std::filesystem::path& path) {
#ifdef _WIN32
ShellExecuteW(nullptr, L"open", path.wstring().c_str(), nullptr, nullptr,
SW_SHOWNORMAL);
#elif __linux__
constexpr const char* FILE_MANAGERS[] = {"nautilus", "dolphin", "thunar",
"nemo", "pcmanfm"};
auto is_available = [](const char* exe) {
std::string cmd = std::string("command -v ") + exe + " >/dev/null 2>&1";
return std::system(cmd.c_str()) == 0;
};
const std::string QUOTED = "\"" + path.string() + "\"";
for (const char* fm : FILE_MANAGERS) {
if (!is_available(fm)) {
continue;
}
std::string cmd = std::string(fm) + " " + QUOTED + " >/dev/null 2>&1 &";
if (std::system(cmd.c_str()) == 0) {
return;
}
}
// Fallback: let the system choose a handler.
if (is_available("xdg-open")) {
std::string cmd = "xdg-open " + QUOTED + " >/dev/null 2>&1 &";
if (std::system(cmd.c_str()) == 0) {
return;
}
}
Logger::warn("Failed to open file manager for {}", path.string());
#endif
}
} // namespace Cubed::Tools