Refakturiert die Anwendung und modernisiert das Build-System

Diese umfangreiche Überarbeitung verbessert die Architektur, den Build-Prozess und die Benutzeroberfläche der Toolbox.

Wesentliche Änderungen:
- **Build-System:** Umfassende Modernisierung des CMake-Builds für verbesserte Stabilität und Wartbarkeit. Die Konfiguration wurde auf zielbasierte Befehle umgestellt, `c_tray` stabilisiert und `saucer-desktop` entfernt.
- **Modulare Architektur:** Die Kernlogik von `ToolboxWindow` wurde in dedizierte Helferklassen ausgelagert, darunter `LuaRunner` für die Skriptausführung, `ToolRegistry` für die Tool-Erkennung, `ResourceLoader` für UI-Ressourcen, `ToolboxJsBridge` für JavaScript-Bindungen und `WindowPlacement` für die Fensterverwaltung. Dies reduziert die Komplexität und fördert die Wiederverwendbarkeit.
- **Benutzeroberfläche (UI):** Die HTML-Templates (`einstellungen_custom.html`, `index.html`) und Stylesheets (`styles.css`) wurden zentralisiert und überarbeitet, um eine kohärentere Benutzeroberfläche mit benutzerdefinierten Fensterdekorationen zu bieten. Neue Funktionen wie das Öffnen der Kommandozeile und eine "Tool hinzufügen"-Karte wurden integriert.
- **Tray-Verwaltung:** Die Tray-Icon-Logik wurde in `TrayController` gekapselt, um eine robustere und zentralisierte Steuerung zu ermöglichen, insbesondere im Umgang mit Explorer-Neustarts.
This commit is contained in:
2026-05-08 15:31:42 +02:00
parent 843f978309
commit 074fa73992
26 changed files with 1676 additions and 701 deletions

28
inc/luaRunner.h Normal file
View File

@@ -0,0 +1,28 @@
#pragma once
#include <atomic>
#include <filesystem>
#include <functional>
#include <memory>
#include <mutex>
#include <unordered_map>
class LuaRunner {
public:
using CompletionCallback = std::function<void()>;
void run(int id, const std::filesystem::path& scriptPath, int timeoutSeconds, CompletionCallback onComplete);
void cancel(int id);
private:
struct LuaTask {
std::shared_ptr<std::atomic_bool> cancel;
};
struct State {
std::mutex tasksMutex;
std::unordered_map<int, LuaTask> tasks;
};
std::shared_ptr<State> m_state = std::make_shared<State>();
};

11
inc/resourceLoader.h Normal file
View File

@@ -0,0 +1,11 @@
#pragma once
#include <string>
#include <saucer/smartview.hpp>
class ResourceLoader {
public:
static bool loadToolboxShell(saucer::smartview& webview);
static bool serveHtml(saucer::smartview& webview, const std::string& htmlPath, bool setDecorations);
};

29
inc/toolRegistry.h Normal file
View File

@@ -0,0 +1,29 @@
#pragma once
#include <filesystem>
#include <string>
#include <vector>
struct ToolboxItem {
std::string id;
std::string name;
std::string path;
std::string icon;
std::string lua_script_path_string;
std::string description;
std::string category;
std::string version;
std::string author;
std::string url;
std::string license;
};
class ToolRegistry {
public:
static std::filesystem::path toolboxDirectory(const std::filesystem::path& userPath);
static bool ensureToolboxDirectory(const std::filesystem::path& userPath);
static std::vector<ToolboxItem> loadTools(const std::filesystem::path& userPath);
private:
static void encodeIcon(const std::filesystem::path& imagePath, ToolboxItem& item);
};

28
inc/toolboxJsBridge.h Normal file
View File

@@ -0,0 +1,28 @@
#pragma once
#include <functional>
#include <string>
#include <saucer/smartview.hpp>
class ToolboxJsBridge {
public:
struct Bindings {
std::function<std::string()> getToolboxItems;
std::function<void(int)> runLua;
std::function<void(int)> cancelLua;
std::function<void()> debugPrint;
std::function<void()> openFileSystem;
std::function<void()> openCommandPrompt;
std::function<void(int)> openSettings;
std::function<void()> openIndex;
std::function<void()> getNewContent;
std::function<int()> getLuaTimeoutSeconds;
std::function<void(int)> setLuaTimeoutSeconds;
std::function<std::string()> getActiveToolName;
std::function<std::string()> getToolConfigIni;
std::function<void(const std::string&)> setToolConfigIni;
};
static void registerBindings(saucer::smartview& webview, Bindings bindings);
};

View File

@@ -2,14 +2,15 @@
#include <saucer/smartview.hpp>
#include "modules/hwnd_module.h"
#include <saucer/embedded/all.hpp>
#include <sol/sol.hpp>
#include <saucer/webview.hpp>
#include <unordered_map>
#include <mutex>
#include <chrono>
#include "luaRunner.h"
#include "optionWindow.h"
#include "resourceLoader.h"
#include "toolConfig.h"
#include "toolboxJsBridge.h"
#include "toolRegistry.h"
#include "windowPlacement.h"
class ToolboxWindow {
public:
@@ -30,20 +31,6 @@ public:
std::atomic_bool isIndex = true;
struct ToolboxItem{
std::string id;
std::string name;
std::string path;
std::string icon;
std::string lua_script_path_string;
std::string description;
std::string category;
std::string version;
std::string author;
std::string url;
std::string license;
};
std::vector<ToolboxItem> m_toolboxItems;
saucer::smartview m_webview;
@@ -60,8 +47,6 @@ private:
std::string jsonString;
int size_x,size_y;
#ifdef _WIN32
std::filesystem::path userPath = std::getenv("USERPROFILE"); // Windows
#else
@@ -75,7 +60,6 @@ private:
void configureWindow();
void moveWindowTo(int x, int y);
void loadResources();
void runLuaScript();
void ExposeToJs();
@@ -92,6 +76,8 @@ private:
void open_file_system();
void open_cmd();
void SetJsonItems();
void openEinst();
@@ -107,14 +93,8 @@ private:
void setLuaTimeoutSeconds(int seconds);
std::string getActiveToolName();
struct LuaTask {
std::shared_ptr<std::atomic_bool> cancel;
};
std::mutex m_luaTasksMutex;
std::unordered_map<int, LuaTask> m_luaTasks;
int m_activeToolId = -1;
LuaRunner m_luaRunner;
ToolConfigStore m_configStore;
std::filesystem::path getToolConfigPath(int id) const;

21
inc/trayController.h Normal file
View File

@@ -0,0 +1,21 @@
#pragma once
#include <memory>
class ToolboxWindow;
class TrayController {
public:
explicit TrayController(ToolboxWindow& window);
~TrayController();
TrayController(const TrayController&) = delete;
TrayController& operator=(const TrayController&) = delete;
bool initialize();
void shutdown();
private:
struct Impl;
std::unique_ptr<Impl> m_impl;
};

14
inc/windowPlacement.h Normal file
View File

@@ -0,0 +1,14 @@
#pragma once
#include <Windows.h>
#include <saucer/smartview.hpp>
class WindowPlacement {
public:
static void configureToolbox(saucer::smartview& webview, HWND hwnd);
static void moveTo(HWND hwnd, int x, int y);
static void center(HWND hwnd);
static void resize(saucer::smartview& webview, int width, int height);
static void resizePercent(saucer::smartview& webview, double widthPercent, double heightPercent);
};