🚧 update

This commit is contained in:
Vladislav Nepogodin 2021-09-22 03:44:34 +04:00
parent 6d8baa8b30
commit 48b5fdf98f
No known key found for this signature in database
GPG Key ID: B62C3D10C54D5DA9
6 changed files with 89 additions and 6 deletions

View File

@ -17,6 +17,7 @@ message(STATUS "BUILD: ${CMAKE_BUILD_TYPE}")
## ##
## INCLUDE ## INCLUDE
## ##
include(GNUInstallDirs)
include(CompilerWarnings) include(CompilerWarnings)
include(EnableCcache) include(EnableCcache)
include(ClangTidy) include(ClangTidy)
@ -70,3 +71,30 @@ link_directories(${GTK3_LIBRARY_DIRS})
add_definitions(${GTK3_CFLAGS_OTHER}) add_definitions(${GTK3_CFLAGS_OTHER})
target_link_libraries(${PROJECT_NAME} ${GTK3_LIBRARIES} fmt::fmt) target_link_libraries(${PROJECT_NAME} ${GTK3_LIBRARIES} fmt::fmt)
install(
TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(
FILES ${CMAKE_SOURCE_DIR}/cachyos-hello.desktop
DESTINATION ${CMAKE_INSTALL_DATADIR}/applications
)
install(
DIRECTORY ${CMAKE_SOURCE_DIR}/data
DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}
)
install(
DIRECTORY ${CMAKE_SOURCE_DIR}/ui
DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}
)
# uninstall
add_custom_target(uninstall
COMMAND cat ${PROJECT_BINARY_DIR}/install_manifest.txt | xargs rm
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

View File

@ -68,6 +68,13 @@ executable(
include_directories: [include_directories('src')], include_directories: [include_directories('src')],
install: true) install: true)
install_data (
meson.project_name () + '.desktop',
install_dir: join_paths(get_option('datadir'), 'applications')
)
meson.add_install_script('postinstall.sh')
summary( summary(
{ {
'Build type': get_option('buildtype'), 'Build type': get_option('buildtype'),

12
postinstall.sh Executable file
View File

@ -0,0 +1,12 @@
#!/bin/sh
mkdir -p "${DESTDIR}/${MESON_INSTALL_PREFIX}/share/cachyos-hello/"
cp -r "${MESON_SOURCE_ROOT}/data" "${DESTDIR}/${MESON_INSTALL_PREFIX}/share/cachyos-hello/"
cp -r "${MESON_SOURCE_ROOT}/ui" "${DESTDIR}/${MESON_INSTALL_PREFIX}/share/cachyos-hello/"
cd "${MESON_SOURCE_ROOT}/po"
for lang in $(ls *.po); do
lang=${lang::-3}
mkdir -p ${DESTDIR}/usr/share/locale/${lang//_/-}/LC_MESSAGES
msgfmt -c -o ${DESTDIR}/usr/share/locale/${lang//_/-}/LC_MESSAGES/cachyos-hello.mo $lang.po
done

View File

@ -7,6 +7,7 @@
#include <filesystem> #include <filesystem>
#include <iostream> #include <iostream>
#include <iterator> #include <iterator>
#include <stdexcept>
#include <unordered_map> #include <unordered_map>
#include <fmt/core.h> #include <fmt/core.h>
@ -25,8 +26,12 @@ std::string fix_path(std::string&& path) noexcept {
} }
nlohmann::json read_json(const std::string_view& path) { nlohmann::json read_json(const std::string_view& path) {
const auto& buf = fix_path(path.data());
if (!fs::exists(buf)) {
throw std::runtime_error(fmt::format("File does not exist: \"{}\"", buf));
}
// read a JSON file // read a JSON file
std::ifstream i(fix_path(path.data())); std::ifstream i(buf);
nlohmann::json j; nlohmann::json j;
i >> j; i >> j;
@ -63,6 +68,22 @@ std::array<std::string, 2> get_lsb_infos() {
return {lsb["ID"], lsb["RELEASE"]}; return {lsb["ID"], lsb["RELEASE"]};
} }
void child_watch_cb(GPid pid, gint status, gpointer /*user_data*/) {
#if !defined(NDEBUG)
g_message("Child %" G_PID_FORMAT " exited %s", pid,
g_spawn_check_wait_status(status, nullptr) ? "normally" : "abnormally");
#endif
// Free any resources associated with the child here, such as I/O channels
// on its stdout and stderr FDs. If you have no code to put in the
// child_watch_cb() callback, you can remove it and the g_child_watch_add()
// call, but you must also remove the G_SPAWN_DO_NOT_REAP_CHILD flag,
// otherwise the child process will stay around as a zombie until this
// process exits.
g_spawn_close_pid(pid);
}
void quick_message(Gtk::Window* parent, const std::string& message) { void quick_message(Gtk::Window* parent, const std::string& message) {
// Create the widgets // Create the widgets
const auto& flags = static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT); const auto& flags = static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT);
@ -82,12 +103,27 @@ void quick_message(Gtk::Window* parent, const std::string& message) {
gtk_widget_show_all(dialog); gtk_widget_show_all(dialog);
int result = gtk_dialog_run(GTK_DIALOG(dialog)); int result = gtk_dialog_run(GTK_DIALOG(dialog));
std::vector<std::string> argv{};
if (result == GTK_RESPONSE_NO) { if (result == GTK_RESPONSE_NO) {
fmt::print("Offline\n"); argv = {fix_path("~/.local/bin/calamares-offline.sh")};
} else { } else {
fmt::print("Online\n"); argv = {fix_path("~/.local/bin/calamares-online.sh")};
} }
int child_stdout{};
int child_stderr{};
Glib::Pid child_pid;
// Spawn child process.
try {
Glib::spawn_async_with_pipes(".", argv, Glib::SpawnFlags::SPAWN_DO_NOT_REAP_CHILD, Glib::SlotSpawnChildSetup(), &child_pid, nullptr, &child_stdout, &child_stderr);
} catch (Glib::Error& error) {
g_critical("%s", error.what().c_str());
}
// Add a child watch function which will be called when the child process
// exits.
g_child_watch_add(child_pid, child_watch_cb, nullptr);
gtk_widget_destroy(dialog); gtk_widget_destroy(dialog);
} }
} // namespace } // namespace
@ -221,7 +257,7 @@ Hello::Hello(int argc, char** argv) {
languages->set_active_id(get_best_locale()); languages->set_active_id(get_best_locale());
// Set autostart switcher state // Set autostart switcher state
m_autostart = fs::is_regular_file(fix_path(m_preferences["autostart_path"])); m_autostart = fs::exists(fix_path(m_preferences["autostart_path"]));
Gtk::Switch* autostart_switch; Gtk::Switch* autostart_switch;
m_builder->get_widget("autostart", autostart_switch); m_builder->get_widget("autostart", autostart_switch);
autostart_switch->set_active(m_autostart); autostart_switch->set_active(m_autostart);
@ -269,11 +305,13 @@ auto Hello::get_best_locale() const noexcept -> std::string {
/// Sets locale of ui and pages. /// Sets locale of ui and pages.
void Hello::set_locale(const std::string_view& use_locale) noexcept { void Hello::set_locale(const std::string_view& use_locale) noexcept {
#if !defined(NDEBUG)
fmt::print( fmt::print(
"┌{0:─^{2}}┐\n" "┌{0:─^{2}}┐\n"
"│{1: ^{2}}│\n" "│{1: ^{2}}│\n"
"└{0:─^{2}}┘\n", "└{0:─^{2}}┘\n",
"", fmt::format("Locale changed to {}", use_locale), 40); "", fmt::format("Locale changed to {}", use_locale), 40);
#endif
textdomain(m_app); textdomain(m_app);
Glib::setenv("LANGUAGE", use_locale.data()); Glib::setenv("LANGUAGE", use_locale.data());

View File

@ -6,8 +6,6 @@
#include <string_view> #include <string_view>
#include <utility> #include <utility>
#include <gtk/gtk.h>
inline std::pair<std::string, std::string> tokenize(std::string& str, const std::string_view& delim) { inline std::pair<std::string, std::string> tokenize(std::string& str, const std::string_view& delim) {
std::size_t start{}; std::size_t start{};
std::size_t end = str.find(delim.data()); std::size_t end = str.find(delim.data());