[ui] Add auto-mount on first launch functionality #52
This commit is contained in:
@@ -216,15 +216,15 @@ void mgmt_app_config::set_auto_start(bool auto_start) {
|
|||||||
if (utils::file::change_to_process_directory()) {
|
if (utils::file::change_to_process_directory()) {
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
if (auto_start) {
|
if (auto_start) {
|
||||||
utils::create_autostart_opts opts{};
|
utils::autostart_cfg cfg{};
|
||||||
opts.app_name = "repertory";
|
cfg.app_name = "repertory";
|
||||||
opts.comment = "Mount utility for AWS S3 and Sia";
|
cfg.comment = "Mount utility for AWS S3 and Sia";
|
||||||
opts.exec_args = {"-ui", "-lo"};
|
cfg.exec_args = {"-ui", "-lo"};
|
||||||
opts.exec_path = utils::path::combine(".", {"repertory"});
|
cfg.exec_path = utils::path::combine(".", {"repertory"});
|
||||||
opts.icon_path = utils::path::combine(".", {"repertory.png"});
|
cfg.icon_path = utils::path::combine(".", {"repertory.png"});
|
||||||
opts.terminal = true;
|
cfg.terminal = true;
|
||||||
|
|
||||||
if (utils::create_autostart_entry(opts, false)) {
|
if (utils::create_autostart_entry(cfg, false)) {
|
||||||
utils::error::handle_info(function_name,
|
utils::error::handle_info(function_name,
|
||||||
"created auto-start entry|name|repertory");
|
"created auto-start entry|name|repertory");
|
||||||
} else {
|
} else {
|
||||||
@@ -244,7 +244,7 @@ void mgmt_app_config::set_auto_start(bool auto_start) {
|
|||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
if (auto_start) {
|
if (auto_start) {
|
||||||
shortcut_cfg cfg{};
|
utils::shortcut_cfg cfg{};
|
||||||
cfg.arguments = {L"-ui", L"-lo"};
|
cfg.arguments = {L"-ui", L"-lo"};
|
||||||
cfg.exe_path = utils::path::combine(L".", {L"repertory"});
|
cfg.exe_path = utils::path::combine(L".", {L"repertory"});
|
||||||
cfg.location = utils::path::absolute(L".");
|
cfg.location = utils::path::absolute(L".");
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
namespace repertory::utils {
|
namespace repertory::utils {
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
struct create_autostart_opts final {
|
struct autostart_cfg final {
|
||||||
std::string app_name;
|
std::string app_name;
|
||||||
std::optional<std::string> comment;
|
std::optional<std::string> comment;
|
||||||
bool enabled{true};
|
bool enabled{true};
|
||||||
@@ -51,7 +51,7 @@ template <typename thread_t>
|
|||||||
#endif // defined(__APPLE__)
|
#endif // defined(__APPLE__)
|
||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
[[nodiscard]] auto create_autostart_entry(create_autostart_opts opts,
|
[[nodiscard]] auto create_autostart_entry(const autostart_cfg &cfg,
|
||||||
bool overwrite_existing = true)
|
bool overwrite_existing = true)
|
||||||
-> bool;
|
-> bool;
|
||||||
#endif // defined(__linux__)
|
#endif // defined(__linux__)
|
||||||
|
@@ -180,11 +180,11 @@ auto convert_to_uint64(const pthread_t &thread) -> std::uint64_t {
|
|||||||
#endif // !defined(__APPLE__)
|
#endif // !defined(__APPLE__)
|
||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
auto create_autostart_entry(create_autostart_opts opts, bool overwrite_existing)
|
auto create_autostart_entry(const autostart_cfg &cfg, bool overwrite_existing)
|
||||||
-> bool {
|
-> bool {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
auto file = desktop_file_path_for(opts.app_name);
|
auto file = desktop_file_path_for(cfg.app_name);
|
||||||
if (utils::file::file{file}.exists() && not overwrite_existing) {
|
if (utils::file::file{file}.exists() && not overwrite_existing) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -198,10 +198,10 @@ auto create_autostart_entry(create_autostart_opts opts, bool overwrite_existing)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto exec_line = opts.exec_path;
|
auto exec_line = cfg.exec_path;
|
||||||
if (not opts.exec_args.empty()) {
|
if (not cfg.exec_args.empty()) {
|
||||||
exec_line += ' ';
|
exec_line += ' ';
|
||||||
exec_line += join_args_for_exec(opts.exec_args);
|
exec_line += join_args_for_exec(cfg.exec_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ofstream out(file, std::ios::binary | std::ios::trunc);
|
std::ofstream out(file, std::ios::binary | std::ios::trunc);
|
||||||
@@ -212,30 +212,30 @@ auto create_autostart_entry(create_autostart_opts opts, bool overwrite_existing)
|
|||||||
out << "[Desktop Entry]\n";
|
out << "[Desktop Entry]\n";
|
||||||
out << "Type=Application\n";
|
out << "Type=Application\n";
|
||||||
out << "Version=1.0\n";
|
out << "Version=1.0\n";
|
||||||
out << "Name=" << opts.app_name << "\n";
|
out << "Name=" << cfg.app_name << "\n";
|
||||||
out << "Exec=" << exec_line << "\n";
|
out << "Exec=" << exec_line << "\n";
|
||||||
out << "Terminal=" << (opts.terminal ? "true" : "false") << "\n";
|
out << "Terminal=" << (cfg.terminal ? "true" : "false") << "\n";
|
||||||
|
|
||||||
if (opts.comment && !opts.comment->empty()) {
|
if (cfg.comment && not cfg.comment->empty()) {
|
||||||
out << "Comment=" << *opts.comment << "\n";
|
out << "Comment=" << *cfg.comment << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.icon_path && !opts.icon_path->empty()) {
|
if (cfg.icon_path && not cfg.icon_path->empty()) {
|
||||||
out << "Icon=" << *opts.icon_path << "\n";
|
out << "Icon=" << *cfg.icon_path << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!opts.only_show_in.empty()) {
|
if (not cfg.only_show_in.empty()) {
|
||||||
out << "OnlyShowIn=";
|
out << "OnlyShowIn=";
|
||||||
for (std::size_t idx = 0U; idx < opts.only_show_in.size(); ++idx) {
|
for (std::size_t idx = 0U; idx < cfg.only_show_in.size(); ++idx) {
|
||||||
if (idx != 0U) {
|
if (idx != 0U) {
|
||||||
out << ';';
|
out << ';';
|
||||||
}
|
}
|
||||||
out << opts.only_show_in[idx];
|
out << cfg.only_show_in[idx];
|
||||||
}
|
}
|
||||||
out << ";\n";
|
out << ";\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (not opts.enabled) {
|
if (not cfg.enabled) {
|
||||||
out << "X-GNOME-Autostart-enabled=false\n";
|
out << "X-GNOME-Autostart-enabled=false\n";
|
||||||
out << "Hidden=true\n";
|
out << "Hidden=true\n";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user