Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): implement discovery page #24

Merged
merged 63 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
5c96ec7
feat(ui): complete main layout, add carousel.
aurora0x27 Aug 14, 2024
f4d7bf6
feat(ui): add layout to "current activity"
aurora0x27 Aug 14, 2024
7740ae3
Merge branch 'dev' into feat/ui/discovery-page
aurora0x27 Aug 15, 2024
dca6cc3
feat(executor): different modes of `asyncExecute` using a timer
Mairon1206 Aug 15, 2024
eecbbbf
feat(executor): add execution strategy
Serein207 Aug 17, 2024
efac2b6
feat: add view data to `ViewManager` (#17)
cEvolve05 Aug 17, 2024
8983911
feat(net): github api (#28)
afkdsghk211331 Aug 17, 2024
fb94893
docs(executor): optimize flag description
Serein207 Aug 17, 2024
1818aa0
feat(net): evento api (#26)
schoolbag123 Aug 17, 2024
c9c3483
feat(ui): add scrollview to layout
aurora0x27 Aug 18, 2024
ec92da0
feat/ui/discovery-page: add scarousel to scroollview
aurora0x27 Aug 21, 2024
95392dc
feat/ui/DiscoveryPage: accomplish dynamic grid
aurora0x27 Aug 23, 2024
6f0933b
feat(ui): ui core multiple update (#31)
cEvolve05 Aug 20, 2024
8dc144f
feat: set default slint style to material
Serein207 Aug 20, 2024
11a807c
fix(ui): fix toast and login shadow (#33)
cEvolve05 Aug 20, 2024
96fa8b1
feat: slint experimental feature
Serein207 Aug 20, 2024
8ddbc5c
feat(ui): initialize sur-ui default theme
Serein207 Aug 20, 2024
110b916
fix: crash showing message when another message on screen
cEvolve05 Aug 20, 2024
a79adeb
feat(ui): optimize menu overlay
Serein207 Aug 20, 2024
fa74438
fix: open url failed on macos
Serein207 Aug 20, 2024
df13a4c
build(deps): bump 3rdpart/sast-link-cxx-sdk from `9e2e743` to `2f6263…
dependabot[bot] Aug 20, 2024
2207323
fix: make `openBrowser` inline, added dev shortcut
cEvolve05 Aug 21, 2024
6f1876e
fix: menu expand animation lost
Serein207 Aug 21, 2024
1e23014
chore(cmake): remove useless variable
Serein207 Aug 21, 2024
30e1d9a
build(deps): bump 3rdpart/sast-link-cxx-sdk from `9e2e743` to `2f6263…
dependabot[bot] Aug 22, 2024
3e71080
feat(ui): finish setting page (#21)
DTPA101 Aug 22, 2024
75e2a8d
feat(ui): `LoadingButton` component (#37)
cEvolve05 Aug 26, 2024
6d2a222
refactor!: drop icon color auto switch function (#42)
cEvolve05 Aug 26, 2024
a592469
feat(ui): event card (#38)
Mairon1206 Aug 26, 2024
af7de0d
feat(ui): improve view data logic
Mairon1206 Aug 27, 2024
ad25987
feat(assets): remove useless images
Serein207 Aug 28, 2024
554d7c5
feat(card): optimize animation
Serein207 Aug 28, 2024
b86c1b6
feat(card): optimize event card
Serein207 Aug 28, 2024
cf61329
feat(font): increase font size
Serein207 Aug 28, 2024
dde490b
feat(ui)!: add md3 button (#46)
cEvolve05 Aug 29, 2024
ab37583
feat(ui): complete main layout, add carousel.
aurora0x27 Aug 14, 2024
2b0344c
feat(ui): add scrollview to layout
aurora0x27 Aug 18, 2024
011b709
feat/ui/DiscoveryPage: accomplish dynamic grid
aurora0x27 Aug 23, 2024
b2c6169
feat/ui/discovery-page: use component eventcardgroup
aurora0x27 Aug 29, 2024
405d3d0
feat/ui/discovery-page: pull before push to remote
aurora0x27 Aug 29, 2024
da63605
feat(ui): fix compile error and conflicts
aurora0x27 Aug 29, 2024
6581295
feat/ui/discovery-page: modify component height
aurora0x27 Sep 1, 2024
3c79592
feat/ui/discovery-page: finish page display
aurora0x27 Sep 1, 2024
f1f0136
feat/ui/discovery-page: seperate current and newest event
aurora0x27 Sep 1, 2024
76f4e51
feat/ui/discovery-page: delete dead code
aurora0x27 Sep 1, 2024
0ece482
fix: correct about page link color
cEvolve05 Sep 17, 2024
c79d0a0
refactor: new login overlay
cEvolve05 Sep 17, 2024
db4cdec
docs(readme): change to english
Serein207 Sep 17, 2024
d3505a0
feat(cache): clear disk cache
Serein207 Sep 17, 2024
bf9005a
fix(net)!: potential lifetime problem & modify api
Serein207 Sep 18, 2024
3da0ec0
perf(net): change buffer to local variable
Serein207 Sep 18, 2024
8197ab7
fix(ui): load image logic
Serein207 Sep 18, 2024
05e3f8b
feat(ui): clean up code
Mairon1206 Sep 18, 2024
c5e4f6d
Merge branch 'dev' into feat/ui/discovery-page
Mairon1206 Sep 18, 2024
9d932bd
fix
Mairon1206 Sep 18, 2024
ff29100
ci: limit thread number of build
Serein207 Sep 19, 2024
f98b38b
build: replace platform macro
Serein207 Sep 19, 2024
ca2a8d3
Merge branch 'dev' into feat/ui/discovery-page
Serein207 Sep 19, 2024
7ea27b4
fix: remove redundant code due to merge
Serein207 Sep 19, 2024
c422df4
Merge branch 'dev' into feat/ui/discovery-page
Serein207 Sep 19, 2024
3635261
feat: controller logic
Mairon1206 Sep 19, 2024
833e64b
fix: miss header
Serein207 Sep 19, 2024
c393f26
perf: condition render info text
Serein207 Sep 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .vscode/c_cpp_properties.json
Mairon1206 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "linux-clang-x64",
"compileCommands": "${workspaceFolder}/out/build/Unix-Makefiles-Default/compile_commands.json"
}
],
"version": 4
}
12 changes: 12 additions & 0 deletions .vscode/launch.json
Mairon1206 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"configurations": [
{
"type": "cmake",
"request": "launch",
"name": "Debug portfile(s)",
"cmakeDebugType": "external",
"pipeName": "/tmp/vcpkg_ext_portfile_dbg",
"preLaunchTask": "Debug vcpkg commands"
}
]
}
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ if (POLICY CMP0167)
endif()

project(sast-evento VERSION ${VERSION_SEMANTIC} LANGUAGES CXX)
option(EVENTO_EMBED_RESOURCES "ON to request slint embed resources")

option(EVENTO_EMBED_RESOURCES OFF "Request slint embed resources")
set(SLINT_STYLE "material" CACHE STRING "Slint style" FORCE)

if(APPLE)
set(MACOSX_BUNDLE_GUI_IDENTIFIER ${IDENTIFIER})
Expand Down
23 changes: 23 additions & 0 deletions CMakePresets.json
Serein207 marked this conversation as resolved.
Show resolved Hide resolved
Mairon1206 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,29 @@
"value": "arm64",
"strategy": "external"
}
},
{
"name": "Clang-Default",
"hidden": true,
"displayName": "Clang 17.0.6 x86_64-pc-linux-gnu",
"description": "使用编译器: C = /usr/bin/clang, CXX = /usr/bin/clang++",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"cacheVariables": {
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"CMAKE_C_COMPILER": "/usr/bin/clang",
"CMAKE_CXX_COMPILER": "/usr/bin/clang++",
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "Unix-Makefiles-Default",
"description": "Config with Unix Makefile",
"displayName": "Unix-Makefiles-Default",
"inherits": [
"Clang-Default"
],
"generator": "Unix Makefiles",
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
],
"buildPresets": [
Expand Down
120 changes: 76 additions & 44 deletions src/Controller/AsyncExecutor.hh
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#pragma once

#include <bitset>
#include <boost/asio/awaitable.hpp>
#include <boost/asio/co_spawn.hpp>
#include <boost/asio/experimental/awaitable_operators.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/signal_set.hpp>
#include <boost/asio/static_thread_pool.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/system/detail/error_code.hpp>
#include <chrono>
#include <memory>
#include <slint.h>
#include <spdlog/spdlog.h>
#include <thread>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace boost::asio::experimental::awaitable_operators;

Expand All @@ -30,12 +30,21 @@ public:
AsyncExecutor(const AsyncExecutor&) = delete;
AsyncExecutor& operator=(const AsyncExecutor&) = delete;

enum TimerFlag {
Immediate = 1,
Delay = 1 << 1,
Once = 1 << 2,
Periodic = 1 << 3,
};

/**
* @param task: return value of a coroutine,
* @brief execute a coroutine and call the callback when it's done
*
* @param task return value of a coroutine,
* an awaitable object wrapping a T type value
*
* @param callback: callback function, called in the main thread when coroutine is done
* parameter: any based on T except T&&
* @param callback callback function, called in the main thread when coroutine is done
* parameter: any based on T(awaitable object wrapped type) except T&&
*/
template<typename T, BOOST_ASIO_COMPLETION_TOKEN_FOR(void(T&)) CompletionCallback>
void asyncExecute(Task<T> task, CompletionCallback&& callback) {
Expand All @@ -59,10 +68,12 @@ public:
}

/**
* @param task: return value of a coroutine,
* @brief execute a coroutine and call the callback when it's done
*
* @param task return value of a coroutine,
* an awaitable object wrapping a T type value
*
* @param callback: callback function, called in the main thread when coroutine is done
* @param callback callback function, called in the main thread when coroutine is done
* parameter: void
*
* Specialization for "void"
Expand All @@ -85,23 +96,46 @@ public:
}

/**
* @param func: coroutine function pointer
* @brief execute a coroutine and call the callback when it's done at specific intervals using a timer
*
* @param func coroutine function pointer
*
* @param callback: callback function, called in the main thread when coroutine is done periodically
* parameters: any based on T(awaitable object wrapped type) except T&&
* @param callback callback function, called in the main thread when coroutine is done periodically
* parameter: any based on T(awaitable object wrapped type) except T&&
*
* @param interval: interval between each coroutine call
* @param interval interval between each coroutine call
*
* @param flag the strategy of the timer, MUST use `|` to combine two enum values below:
* * Immediate: execute the coroutine immediately
* * Delay: execute the coroutine after the interval
* * Once: execute the coroutine once
* * Periodic: execute the coroutine every interval periodically
*
* FORBIDDEN combinations:
* * Immediate and Delay
* * Periodic and Once
*/
template<typename TaskFunc, typename CompletionCallback>
void asyncExecute(TaskFunc&& func,
CompletionCallback&& callback,
std::chrono::steady_clock::duration interval) {
asyncExecute(func(), callback);
asyncExecuteByTimer(std::forward<TaskFunc>(func),
std::forward<CompletionCallback>(callback),
interval);
std::chrono::steady_clock::duration interval,
int flag = TimerFlag::Periodic | TimerFlag::Immediate) {
assert(std::bitset<32>(flag).count() == 2);
assert(!(flag & TimerFlag::Immediate && flag & TimerFlag::Delay));
assert(!(flag & TimerFlag::Periodic && flag & TimerFlag::Once));

if (flag & TimerFlag::Immediate)
asyncExecute(func(), callback);

if (flag & TimerFlag::Periodic || flag & TimerFlag::Delay)
asyncExecuteByTimer(std::forward<TaskFunc>(func),
std::forward<CompletionCallback>(callback),
interval,
flag);
}

net::io_context& getIoContext() { return _ioc; }

~AsyncExecutor() {
_ioc.stop();
if (_iocThread.joinable()) {
Expand All @@ -125,26 +159,19 @@ private:
}

template<typename TaskFunc, typename CompletionCallback>
requires std::is_invocable_v<CompletionCallback>
void asyncExecuteByTimer(TaskFunc&& func,
CompletionCallback&& callback,
std::chrono::steady_clock::duration interval) {
_periodicTasks[_taskId] = interval;
std::chrono::steady_clock::duration interval,
int flag) {
auto timer = std::make_shared<net::steady_timer>(_ioc, interval);
_timers.push_back(timer);
asyncExecuteByTimerHelper(std::forward<TaskFunc>(func),
std::forward<CompletionCallback>(callback),
_taskId);
++_taskId;
}

template<typename TaskFunc, typename CompletionCallback>
requires std::is_invocable_v<CompletionCallback>
void asyncExecuteByTimerHelper(TaskFunc&& func, CompletionCallback&& callback, int taskId) {
_timers[taskId]->async_wait([=,
func = std::forward<TaskFunc>(func),
callback = std::forward<CompletionCallback>(callback),
this](const boost::system::error_code& ec) {
timer->async_wait([=,
func = std::forward<TaskFunc>(func),
callback = std::forward<CompletionCallback>(callback),
this](const boost::system::error_code& ec) {
if (!ec) {
// ensure timer is captured
timer.get();
net::co_spawn(_ioc, func(), [callback](std::exception_ptr e) {
if (!e) {
slint::invoke_from_event_loop(callback);
Expand All @@ -156,8 +183,9 @@ private:
spdlog::error(ex.what());
}
});
_timers[taskId]->expires_after(_periodicTasks[taskId]);
asyncExecuteByTimerHelper(std::move(func), std::move(callback), taskId);
if (flag & TimerFlag::Periodic) {
asyncExecuteByTimer(std::move(func), std::move(callback), interval, flag);
}
} else {
spdlog::error(ec.what());
}
Expand All @@ -166,12 +194,18 @@ private:

template<typename TaskFunc, typename CompletionCallback>
requires(!std::is_same_v<net::awaitable<void>, std::invoke_result_t<TaskFunc>>)
void asyncExecuteByTimerHelper(TaskFunc&& func, CompletionCallback&& callback, int taskId) {
_timers[taskId]->async_wait([=,
func = std::forward<TaskFunc>(func),
callback = std::forward<CompletionCallback>(callback),
this](const boost::system::error_code& ec) {
void asyncExecuteByTimer(TaskFunc&& func,
CompletionCallback&& callback,
std::chrono::steady_clock::duration interval,
int flag) {
auto timer = std::make_shared<net::steady_timer>(_ioc, interval);
timer->async_wait([=,
func = std::forward<TaskFunc>(func),
callback = std::forward<CompletionCallback>(callback),
this](const boost::system::error_code& ec) {
if (!ec) {
// ensure timer is captured
timer.get();
net::co_spawn(_ioc, func(), [callback](std::exception_ptr e, auto value) {
if (!e) {
slint::invoke_from_event_loop(
Expand All @@ -186,8 +220,9 @@ private:
spdlog::error(ex.what());
}
});
_timers[taskId]->expires_after(_periodicTasks[taskId]);
asyncExecuteByTimerHelper(std::move(func), std::move(callback), taskId);
if (flag & TimerFlag::Periodic) {
asyncExecuteByTimer(std::move(func), std::move(callback), interval, flag);
}
} else {
spdlog::error(ec.what());
}
Expand All @@ -197,9 +232,6 @@ private:
private:
net::io_context _ioc;
std::thread _iocThread;
std::vector<std::shared_ptr<net::steady_timer>> _timers;
std::unordered_map<int, std::chrono::steady_clock::duration> _periodicTasks;
int _taskId = 0;

friend AsyncExecutor* executor();
};
Expand Down
Loading