Skip to content

Commit

Permalink
feat: system tray
Browse files Browse the repository at this point in the history
  • Loading branch information
Mairon1206 committed Aug 6, 2024
1 parent 15238ee commit c3ac160
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "3rdpart/keychain"]
path = 3rdpart/keychain
url = https://github.com/hrantzsch/keychain.git
[submodule "3rdpart/traypp"]
path = 3rdpart/traypp
url = https://github.com/Soundux/traypp.git
1 change: 1 addition & 0 deletions 3rdpart/traypp
Submodule traypp added at 698db7
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ endif()
add_subdirectory(src)
# sast-link-sdk
add_subdirectory(3rdpart/sast-link-cxx-sdk)
# traypp
add_subdirectory(3rdpart/traypp EXCLUDE_FROM_ALL)

# credential storage
set(BUILD_SHARED_LIBS OFF)
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ target_link_libraries(${PROJECT_NAME}
keychain
Slint::Slint
version::version
tray
)

# On Windows, copy the Slint DLL next to the application binary so that it's found.
Expand Down
44 changes: 44 additions & 0 deletions src/Infrastructure/Tray/SystemTray.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

#include <app.h>
#include <slint.h>
#include <spdlog/spdlog.h>
#include <thread>
#include <tray.hpp>

namespace evento {

class SystemTray {
public:
SystemTray(slint::ComponentWeakHandle<App> uiWeak)
: _tray("Evento Tray", "./app.ico") {
std::thread trayThread([&] {
_tray.addEntry(Tray::Button("显示", [&] {
auto ui = *uiWeak.lock();
ui->show();
}));
_tray.addEntry(Tray::Button("关于", [&] {
//TODO: switch to about page
}));
_tray.addEntry(Tray::Button("退出", [&] {
spdlog::info("exiting SAST Evento...");
_tray.exit();
slint::quit_event_loop();
_isRunning = false;
}));
_tray.run();
});
trayThread.detach();
}
~SystemTray() {
if (_isRunning) {
_tray.exit();
}
}

private:
Tray::Tray _tray;
bool _isRunning = true;
};

} // namespace evento
8 changes: 6 additions & 2 deletions src/main.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include <Infrastructure/Network/network.h>
#include <Infrastructure/Tray/SystemTray.h>
#include <Infrastructure/Utils/Config.h>
#include <Infrastructure/Utils/Logger.h>
#include <Version.h>
#include <app.h>
#include <filesystem>
#include <slint.h>
#include <spdlog/spdlog.h>

int main(int argc, char** argv) {
Expand All @@ -15,6 +17,8 @@ int main(int argc, char** argv) {
auto uiEntry = App::create();
uiEntry->global<LoginOverlayBridge>().on_link_login(start_sast_link);
uiEntry->global<LoginOverlayBridge>().set_version("v" VERSION_FULL);
uiEntry->run();
uiEntry->show();
evento::SystemTray tray(uiEntry);
slint::run_event_loop(slint::EventLoopMode::RunUntilQuit);
evento::saveConfig();
}
}

0 comments on commit c3ac160

Please sign in to comment.