Implement window hiding and tray icon functionality
Added methods to hide and show the Toolbox window and integrated a system tray icon with menu options, including window toggle and application quit functionality. Moved Lua script execution to occur after successful script loading. Introduced resource inclusion in the project files to support icon loading.
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef RESOURCE_H
|
||||||
|
#define RESOURCE_H
|
||||||
|
|
||||||
|
#define IDI_ICON1 101 // ID für das Icon
|
||||||
|
|
||||||
|
#endif // RESOURCE_H
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "tray.h"
|
||||||
|
#include "toolboxWindow.h"
|
||||||
|
|
||||||
|
class toolboxTray {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
+11
-2
@@ -10,10 +10,13 @@ class ToolboxWindow {
|
|||||||
public:
|
public:
|
||||||
// Konstruktor erhält das Application-Objekt als Parameter
|
// Konstruktor erhält das Application-Objekt als Parameter
|
||||||
explicit ToolboxWindow(std::shared_ptr<saucer::application>& app);
|
explicit ToolboxWindow(std::shared_ptr<saucer::application>& app);
|
||||||
|
~ToolboxWindow();
|
||||||
|
|
||||||
|
bool m_bShow = false;
|
||||||
|
|
||||||
// Methode zum Anzeigen des Fensters
|
// Methode zum Anzeigen des Fensters
|
||||||
void show();
|
void show();
|
||||||
|
void hide();
|
||||||
// Für die Fensterinitialisierung
|
// Für die Fensterinitialisierung
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|
||||||
@@ -35,9 +38,13 @@ public:
|
|||||||
|
|
||||||
std::vector<ToolboxItem> m_toolboxItems;
|
std::vector<ToolboxItem> m_toolboxItems;
|
||||||
|
|
||||||
|
saucer::smartview<saucer::default_serializer, hwnd_module> m_webview;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<saucer::application> m_app;
|
std::shared_ptr<saucer::application> m_app;
|
||||||
saucer::smartview<saucer::default_serializer, hwnd_module> m_webview;
|
std::thread m_threadMonitor;
|
||||||
|
std::atomic<bool> m_runningMonitor = true;
|
||||||
|
|
||||||
void configureWindow();
|
void configureWindow();
|
||||||
void loadResources();
|
void loadResources();
|
||||||
void runLuaScript();
|
void runLuaScript();
|
||||||
@@ -51,4 +58,6 @@ private:
|
|||||||
void debug_print();
|
void debug_print();
|
||||||
|
|
||||||
void run_lua(int id);
|
void run_lua(int id);
|
||||||
|
|
||||||
|
void monitor_focus();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,21 +1,67 @@
|
|||||||
#include "toolboxWindow.h"
|
|
||||||
#include <saucer/app.hpp>
|
#include <saucer/app.hpp>
|
||||||
|
#include "toolboxWindow.h"
|
||||||
|
#include "tray.h"
|
||||||
|
#include "resource.h"
|
||||||
|
|
||||||
|
ToolboxWindow* g_toolboxWindow = nullptr;
|
||||||
|
|
||||||
|
void on_toggle(struct tray_menu *item) {
|
||||||
|
item->checked = !item->checked;
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_quit(struct tray_menu *item) {
|
||||||
|
tray_exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_click(struct tray_menu *item) {
|
||||||
|
if (g_toolboxWindow->m_bShow)
|
||||||
|
g_toolboxWindow->hide();
|
||||||
|
else
|
||||||
|
g_toolboxWindow->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
// Initialisiere die Saucer-Anwendung
|
|
||||||
auto app = saucer::application::acquire({
|
|
||||||
.id = "toolbox",
|
|
||||||
});
|
|
||||||
|
|
||||||
// Erstelle und initialisiere das Toolbox-Fenster
|
// Neue Anwendung erstellen
|
||||||
|
auto app = saucer::application::acquire({
|
||||||
|
.id = "toolbox",
|
||||||
|
});
|
||||||
|
|
||||||
|
// Toolbox-Fenster erstellen und initialisieren
|
||||||
ToolboxWindow toolboxWindow(app);
|
ToolboxWindow toolboxWindow(app);
|
||||||
toolboxWindow.initialize();
|
toolboxWindow.initialize();
|
||||||
|
|
||||||
// Zeige das Fenster an
|
g_toolboxWindow = &toolboxWindow;
|
||||||
toolboxWindow.show();
|
toolboxWindow.show();
|
||||||
|
|
||||||
// Starte die Saucer-Anwendung
|
HICON hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));
|
||||||
|
|
||||||
|
struct tray_menu tray_menu_items[] = {
|
||||||
|
{"Öffnen", 0, 0, NULL, on_click, 0},
|
||||||
|
{"Option umschalten", 0, 0, NULL, on_toggle, 0},
|
||||||
|
{"-", 0, 0, NULL, nullptr, 0},
|
||||||
|
{"Beenden", 0, 0, NULL, on_quit, 0},
|
||||||
|
{nullptr, 0, 0, NULL, nullptr, 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct tray tray = {
|
||||||
|
.icon = (char*)"toolbox.ico",
|
||||||
|
.menu = tray_menu_items
|
||||||
|
};
|
||||||
|
|
||||||
|
if (tray_init(&tray) != 0) {
|
||||||
|
fprintf(stderr, "Fehler beim Initialisieren des Tray-Icons\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//toolboxWindow.show();
|
||||||
|
|
||||||
|
/* while (tray_loop(1) == 0) {
|
||||||
|
}*/
|
||||||
|
|
||||||
|
// Anwendung ausführen
|
||||||
app->run();
|
app->run();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
#include "toolboxTray.h"
|
||||||
+27
-4
@@ -15,6 +15,14 @@ void ToolboxWindow::initialize() {
|
|||||||
loadResources();
|
loadResources();
|
||||||
ExposeToJs();
|
ExposeToJs();
|
||||||
m_webview.set_dev_tools(true);
|
m_webview.set_dev_tools(true);
|
||||||
|
//m_webview.set_decorations(false);
|
||||||
|
//m_webview.set_always_on_top(true);
|
||||||
|
|
||||||
|
m_threadMonitor = std::thread([&]() {
|
||||||
|
monitor_focus();
|
||||||
|
});
|
||||||
|
|
||||||
|
m_threadMonitor.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolboxWindow::configureWindow() {
|
void ToolboxWindow::configureWindow() {
|
||||||
@@ -71,9 +79,13 @@ void ToolboxWindow::runLuaScript() {
|
|||||||
|
|
||||||
void ToolboxWindow::show() {
|
void ToolboxWindow::show() {
|
||||||
m_webview.show();
|
m_webview.show();
|
||||||
runLuaScript();
|
m_bShow = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ToolboxWindow::hide() {
|
||||||
|
m_webview.hide();
|
||||||
|
m_bShow = false;
|
||||||
|
}
|
||||||
|
|
||||||
void ToolboxWindow::ExposeToJs() {
|
void ToolboxWindow::ExposeToJs() {
|
||||||
// Konvertierung des Vektors in JSON
|
// Konvertierung des Vektors in JSON
|
||||||
@@ -228,9 +240,6 @@ void ToolboxWindow::fillToolboxMenu() {
|
|||||||
|
|
||||||
void ToolboxWindow::run_lua(int id) {
|
void ToolboxWindow::run_lua(int id) {
|
||||||
|
|
||||||
m_webview.execute("enableButtonByToolId({})",saucer::make_args(id));
|
|
||||||
m_webview.reload();
|
|
||||||
|
|
||||||
// Lambda-Funktion, um das Lua-Skript auszuführen
|
// Lambda-Funktion, um das Lua-Skript auszuführen
|
||||||
auto lua_task = [this, id]() {
|
auto lua_task = [this, id]() {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
@@ -239,6 +248,8 @@ void ToolboxWindow::run_lua(int id) {
|
|||||||
try {
|
try {
|
||||||
std::string scriptPath = m_toolboxItems[id].lua_script;
|
std::string scriptPath = m_toolboxItems[id].lua_script;
|
||||||
lua.script_file(scriptPath);
|
lua.script_file(scriptPath);
|
||||||
|
m_webview.execute("enableButtonByToolId({})",saucer::make_args(id));
|
||||||
|
m_webview.reload();
|
||||||
} catch (const sol::error& e) {
|
} catch (const sol::error& e) {
|
||||||
std::cerr << "Lua error: " << e.what() << std::endl;
|
std::cerr << "Lua error: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
@@ -256,3 +267,15 @@ void ToolboxWindow::run_lua(int id) {
|
|||||||
void ToolboxWindow::debug_print() {
|
void ToolboxWindow::debug_print() {
|
||||||
std::cout << "ToolboxWindow::debug_print()" << std::endl;
|
std::cout << "ToolboxWindow::debug_print()" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ToolboxWindow::~ToolboxWindow() {
|
||||||
|
m_runningMonitor = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ToolboxWindow::monitor_focus() {
|
||||||
|
while(m_runningMonitor){
|
||||||
|
if(m_bShow && !m_webview.focused()) {
|
||||||
|
this->hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+3
-1
@@ -1 +1,3 @@
|
|||||||
IDI_ICON1 ICON "res/ico/toolbox.ico"
|
#include "resource.h"
|
||||||
|
|
||||||
|
IDI_ICON1 ICON "res/ico/toolbox.ico"
|
||||||
|
|||||||
Reference in New Issue
Block a user