Skip to content

Commit

Permalink
refactor: clean up gui file argument parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
f0e committed Dec 2, 2024
1 parent aa68839 commit 1769390
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
14 changes: 1 addition & 13 deletions src/gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,7 @@ int app_main(int argc, char* argv[]) { // NOLINT

std::vector<std::string> arguments(argv + 1, argv + argc);

// redundant since add_files checks paths too so i could just pass arguments to it, but id rather keep the logic
// here for the clarity
std::vector<std::string> passed_file_paths;
for (const auto& file_path_str : arguments) {
std::filesystem::path file_path(file_path_str);

if (!file_path.empty() && std::filesystem::exists(file_path))
passed_file_paths.push_back(file_path_str);
}

std::thread(tasks::run).detach();

tasks::add_files(passed_file_paths);
std::thread(tasks::run, arguments).detach();

gui::run();

Expand Down
6 changes: 4 additions & 2 deletions src/gui/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "gui/renderer.h"
#include "gui/ui/ui.h"

void tasks::run() {
void tasks::run(const std::vector<std::string>& arguments) {
blur.initialise(false, true);

rendering.set_progress_callback([] {
Expand Down Expand Up @@ -36,14 +36,16 @@ void tasks::run() {
gui::renderer::on_render_finished(render, success);
});

add_files(arguments); // todo: mac packaged app support (& linux? does it work?)

while (true) {
rendering.render_videos();
}
}

void tasks::add_files(const std::vector<std::string>& files) {
for (const std::string& path_str : files) {
std::filesystem::path path(path_str);
std::filesystem::path path = std::filesystem::canonical(path_str);
if (path.empty() || !std::filesystem::exists(path))
continue;

Expand Down
4 changes: 1 addition & 3 deletions src/gui/tasks.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#pragma once

#include "common/config.h"

namespace tasks {
void run();
void run(const std::vector<std::string>& arguments);

void add_files(const std::vector<std::string>& files);
}

0 comments on commit 1769390

Please sign in to comment.