mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-02 01:13:19 +00:00
Update dependencies and adapt code
This commit is contained in:
parent
f11f4bf1c9
commit
a80515ff90
9 changed files with 72 additions and 29 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -7,3 +7,6 @@
|
|||
[submodule "external/selenite"]
|
||||
path = external/selenite
|
||||
url = https://codeberg.org/vyn/selenite.git
|
||||
[submodule "external/evalyte-cpp-common"]
|
||||
path = external/evalyte-cpp-common
|
||||
url = https://codeberg.org/vyn/evalyte-cpp-common.git
|
||||
|
|
|
@ -6,7 +6,6 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|||
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
|
||||
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
|
||||
|
||||
add_subdirectory(external/slint)
|
||||
# -- Slint setup
|
||||
#find_package(Slint QUIET)
|
||||
#if (NOT Slint_FOUND)
|
||||
|
@ -24,28 +23,32 @@ add_subdirectory(external/slint)
|
|||
#endif (NOT Slint_FOUND)
|
||||
# -- End of Slint setup
|
||||
|
||||
add_subdirectory(external/slint)
|
||||
add_subdirectory(external/selenite/cpp)
|
||||
add_subdirectory(external/mirai-core)
|
||||
|
||||
add_executable(mirai
|
||||
src/main.cpp
|
||||
src/UiState.cpp
|
||||
src/AppWindowBackend.cpp
|
||||
src/Utils.cpp
|
||||
)
|
||||
|
||||
|
||||
target_include_directories(mirai PRIVATE "external/mirai-core/include")
|
||||
target_include_directories(mirai PRIVATE "external/selenite/cpp/include")
|
||||
target_include_directories(mirai PRIVATE "external/evalyte-cpp-common/include")
|
||||
|
||||
set_property(TARGET mirai PROPERTY SLINT_EMBED_RESOURCES embed-files)
|
||||
|
||||
target_link_libraries(mirai PRIVATE Slint::Slint)
|
||||
target_link_libraries(mirai PRIVATE selenite)
|
||||
|
||||
target_include_directories(mirai PRIVATE "external")
|
||||
target_link_libraries(mirai PRIVATE mirai-core)
|
||||
|
||||
slint_target_sources(
|
||||
mirai ui/appwindow.slint
|
||||
mirai ui/AppWindow.slint
|
||||
NAMESPACE ui
|
||||
LIBRARY_PATHS selenite=${CMAKE_CURRENT_SOURCE_DIR}/external/selenite/index.slint
|
||||
LIBRARY_PATHS selenite=${CMAKE_CURRENT_SOURCE_DIR}/external/selenite/components/index.slint
|
||||
)
|
||||
|
||||
# On Windows, copy the Slint DLL next to the application binary so that it's found.
|
||||
|
|
1
external/evalyte-cpp-common
vendored
Submodule
1
external/evalyte-cpp-common
vendored
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit b154a3351b89a5962a2bed2feae683b3a8009857
|
2
external/selenite
vendored
2
external/selenite
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 65e2a75a09df205a86a09d9dd4f1ca916bb115a3
|
||||
Subproject commit cbab9dabe784bd3c799d23ead5d2b4d942ec4081
|
|
@ -4,35 +4,33 @@
|
|||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "UiState.h"
|
||||
#include "AppWindowBackend.h"
|
||||
#include "SeleniteSetup.h"
|
||||
#include "Utils.h"
|
||||
#include "appwindow.h"
|
||||
#include "mirai-core/DataProvider.h"
|
||||
#include "mirai-core/Day.h"
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include "slint.h"
|
||||
#include "slint_sharedvector.h"
|
||||
#include "slint_string.h"
|
||||
#include <algorithm>
|
||||
#include <bits/chrono.h>
|
||||
#include <cassert>
|
||||
#include <charconv>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <format>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <ostream>
|
||||
#include <ranges>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
UiState::UiState(mirai::Mirai *miraiInstance) : miraiInstance_(miraiInstance), view_(miraiInstance)
|
||||
AppWindowBackend::AppWindowBackend(mirai::Mirai *miraiInstance)
|
||||
: miraiInstance_(miraiInstance), view_(miraiInstance)
|
||||
{
|
||||
sources_ = std::make_shared<slint::VectorModel<ui::Source>>();
|
||||
days_ = std::make_shared<slint::VectorModel<ui::Day>>();
|
||||
|
@ -45,6 +43,13 @@ UiState::UiState(mirai::Mirai *miraiInstance) : miraiInstance_(miraiInstance), v
|
|||
}
|
||||
);
|
||||
|
||||
const auto palette =
|
||||
selenite::parseJson(std::string(getenv("HOME")) + "/.config/evalyte/theme.json");
|
||||
if (palette.has_value()) {
|
||||
std::cerr << "Warning, no evalyte/theme.json found" << std::endl;
|
||||
setSelenitePalette(mainWindow_, palette.value());
|
||||
}
|
||||
|
||||
mainWindow_->global<ui::Backend>().set_sources(sourcesNames);
|
||||
|
||||
view_.setAllSources();
|
||||
|
@ -77,7 +82,7 @@ std::optional<ui::Date> stringToDate(const std::string &dateStr)
|
|||
return ui::Date{.year = year, .month = month, .day = day};
|
||||
}
|
||||
|
||||
void UiState::setupUtilsCallbacks()
|
||||
void AppWindowBackend::setupUtilsCallbacks()
|
||||
{
|
||||
mainWindow_->global<ui::Backend>().on_format_date([&](const ui::Date &date) {
|
||||
std::chrono::year_month_day chronoDate{
|
||||
|
@ -89,7 +94,7 @@ void UiState::setupUtilsCallbacks()
|
|||
});
|
||||
}
|
||||
|
||||
void UiState::setupCallbacks()
|
||||
void AppWindowBackend::setupCallbacks()
|
||||
{
|
||||
mainWindow_->global<ui::Backend>().on_task_clicked([&](int sourceId, int taskId) {
|
||||
auto source = miraiInstance_->getSourceById(sourceId);
|
||||
|
@ -243,7 +248,7 @@ stdToSlintStringVector(const std::vector<std::string> &stdVector)
|
|||
return slintVector;
|
||||
}
|
||||
|
||||
void UiState::reloadTasks()
|
||||
void AppWindowBackend::reloadTasks()
|
||||
{
|
||||
days_->clear();
|
||||
if (miraiInstance_->getSources().size() == 0) {
|
||||
|
@ -323,7 +328,7 @@ void UiState::reloadTasks()
|
|||
mainWindow_->global<ui::Backend>().set_unscheduled_tasks(unscheduledTasks_);
|
||||
}
|
||||
|
||||
void UiState::reloadSources()
|
||||
void AppWindowBackend::reloadSources()
|
||||
{
|
||||
sources_->clear();
|
||||
bool noSourceSelected = miraiInstance_->getSources().size() == view_.activeSourceCount();
|
||||
|
@ -337,7 +342,7 @@ void UiState::reloadSources()
|
|||
mainWindow_->global<ui::Backend>().set_no_source_selected(noSourceSelected);
|
||||
}
|
||||
|
||||
void UiState::run()
|
||||
void AppWindowBackend::run()
|
||||
{
|
||||
mainWindow_->run();
|
||||
}
|
|
@ -11,11 +11,11 @@
|
|||
#include "mirai-core/View.h"
|
||||
#include "slint.h"
|
||||
|
||||
class UiState
|
||||
class AppWindowBackend
|
||||
{
|
||||
|
||||
public:
|
||||
UiState(mirai::Mirai *mirai);
|
||||
AppWindowBackend(mirai::Mirai *mirai);
|
||||
|
||||
void run();
|
||||
|
30
src/SeleniteSetup.h
Normal file
30
src/SeleniteSetup.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "appwindow.h"
|
||||
#include "selenite/palette.h"
|
||||
#include "slint_color.h"
|
||||
|
||||
slint::Color seleniteColorToSlint(const selenite::Color &color)
|
||||
{
|
||||
return slint::Color::from_rgb_uint8(color.r, color.g, color.b);
|
||||
}
|
||||
|
||||
void setSelenitePalette(slint::ComponentHandle<ui::AppWindow> ui, const selenite::Palette &palette)
|
||||
{
|
||||
auto &uiPalette = ui->global<ui::Palette>();
|
||||
|
||||
uiPalette.set_background(seleniteColorToSlint(palette.background));
|
||||
uiPalette.set_pane(seleniteColorToSlint(palette.pane));
|
||||
uiPalette.set_foreground(seleniteColorToSlint(palette.foreground));
|
||||
uiPalette.set_foreground_hint(seleniteColorToSlint(palette.foregroundHint));
|
||||
uiPalette.set_control_background(seleniteColorToSlint(palette.background3));
|
||||
uiPalette.set_control_foreground(seleniteColorToSlint(palette.foreground));
|
||||
uiPalette.set_card_background(seleniteColorToSlint(palette.background2));
|
||||
uiPalette.set_accent(seleniteColorToSlint(palette.primary));
|
||||
}
|
12
src/main.cpp
12
src/main.cpp
|
@ -4,30 +4,30 @@
|
|||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "UiState.h"
|
||||
#include "AppWindowBackend.h"
|
||||
#include "evalyte-cpp-common/config.h"
|
||||
#include "mirai-core/Config.h"
|
||||
#include "mirai-core/DataProvider.h"
|
||||
#include "mirai-core/MarkdownDataProvider.h"
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
mirai::Config config(std::string(getenv("HOME")) + "/.config/mirai/config.json");
|
||||
|
||||
mirai::Mirai mirai;
|
||||
|
||||
const auto configFilePath = evalyte::createConfigDirectoryPath("mirai") + "/config.json";
|
||||
mirai::Config config(configFilePath);
|
||||
for (const auto &sourceFilePath : config.sources()) {
|
||||
std::unique_ptr<mirai::DataProvider> file =
|
||||
std::make_unique<mirai::MarkdownDataProvider>(sourceFilePath);
|
||||
mirai.loadSource(std::move(file));
|
||||
}
|
||||
|
||||
UiState uiState{&mirai};
|
||||
uiState.run();
|
||||
AppWindowBackend appWindow{&mirai};
|
||||
appWindow.run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { Backend } from "Backend.slint";
|
||||
import { Button, VerticalBox, CheckBox, Palette } from "std-widgets.slint";
|
||||
import { Button, VerticalBox, CheckBox } from "std-widgets.slint";
|
||||
import { SideBar } from "./components/SideBar.slint";
|
||||
import { MainView } from "MainView.slint";
|
||||
import { Palette } from "@selenite";
|
||||
|
||||
export component AppWindow inherits Window {
|
||||
|
||||
|
@ -21,4 +22,4 @@ export component AppWindow inherits Window {
|
|||
|
||||
}
|
||||
|
||||
export { Backend } // Export to make it visible to the C++ backend
|
||||
export { Backend, Palette } // Export to make it visible to the C++ backend
|
Loading…
Add table
Add a link
Reference in a new issue