Skip to content

Commit

Permalink
fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
badcast committed Apr 2, 2024
1 parent e0899a7 commit d224878
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 81 deletions.
25 changes: 20 additions & 5 deletions client-frontend/dragon-tea/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@ pkg_check_modules(libnotify REQUIRED libnotify)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})

file(GLOB_RECURSE DRAGONTEA_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.c"
"${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
file(GLOB_RECURSE DRAGONTEA_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
file(GLOB_RECURSE DRAGONTEA_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/src/teauilib/*.c")

add_executable(dragontea)
list(APPEND DRAGONTEA_SOURCES ${DRAGONTEA_HEADERS})

add_library(dragontea SHARED)
add_executable(exec ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${DRAGONTEA_HEADERS})

set_target_properties(dragontea PROPERTIES OUTPUT_NAME "teauilib")
set_target_properties(exec PROPERTIES OUTPUT_NAME "dragontea")

target_compile_definitions(dragontea PRIVATE TEA_COMPILLING)

# COMPILE BUILTIN SERVERS
set(BUILTIN_TEMPLATE_FILE "${CMAKE_BINARY_DIR}/builtin_template.c")
Expand Down Expand Up @@ -44,18 +53,22 @@ if(EXISTS "${BUILTIN_TEMPLATE_FILE}")
BUILTIN_SERVERS_N=${BF_LENGTH})
endif()

target_sources(dragontea PUBLIC ${DRAGONTEA_SOURCES})
target_sources(dragontea PRIVATE ${DRAGONTEA_SOURCES})

target_include_directories(
dragontea
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/" ${gtk3ui_INCLUDE_DIRS}
${gthread_INCLUDE_DIRS} ${libcurl_INCLUDE_DIRS} ${json_INCLUDE_DIRS}
${libnotify_INCLUDE_DIRS})

target_include_directories(exec PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/)

target_link_libraries(
dragontea ${gtk3ui_LIBRARIES} ${libcurl_LIBRARIES} ${json_LIBRARIES}
${gthread_LIBRARIES} ${libnotify_LIBRARIES})

target_link_libraries(exec dragontea)

target_compile_definitions(dragontea
PUBLIC DRAGON_TEA_VERSION="${DRAGON_TEA_VERSION}")

Expand All @@ -68,5 +81,7 @@ if(UNIX OR LINUX)
DESTINATION "${CMAKE_INSTALL_PREFIX}/share")

install(FILES "${CMAKE_BINARY_DIR}/dragontea"
DESTINATION "${CMAKE_INSTALL_PREFIX}/bin/")
DESTINATION "${CMAKE_INSTALL_PREFIX}/bin/
")

endif()
26 changes: 26 additions & 0 deletions client-frontend/dragon-tea/include/tea_main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

// MSVC/MinGW Compiller
#if _MSC_VER || WIN32
#define API_EXPORT __declspec(dllexport)
#define API_IMPORT __declspec(dllimport)
#elif __linux__ || __unix__
// Linux/Unix GNU Compiller
#if defined(__GNUC__) && __GNUC__ >= 4
#define __GCCAPI__ __attribute__((visibility("default")))
#else
#define __GCCAPI__
#endif

#define API_EXPORT __GCCAPI__
#define API_IMPORT __GCCAPI__

#endif

#ifdef TEA_COMPILLING
#define TEA_API API_EXPORT
#else
#define TEA_API API_IMPORT
#endif

int TEA_API tea_main(int argc, char *argv[]);
77 changes: 3 additions & 74 deletions client-frontend/dragon-tea/src/main.c
Original file line number Diff line number Diff line change
@@ -1,79 +1,8 @@
#include <fcntl.h>
#include <stdio.h>

#include "tea.h"

#define USE_ONCE_LAUNCH 0

#if USE_ONCE_LAUNCH
#include <semaphore.h>
#define TSEM_KNAME "dragon_tea_lock"
#endif
#include "tea_main.h"

int main(int argc, char *argv[])
{
setlocale(LC_ALL, "");

bindtextdomain(DRAGON_TEA_TEXTDOMAIN, DRAGON_TEA_LOCALE_DIR);
textdomain(DRAGON_TEA_TEXTDOMAIN);

// Check runned on Root
#ifdef TEA_OS_LINUX
if(getuid() == 0)
{
printf(_("The program is running as root. These privileges can harm the system, please be aware of this. Closing."));
return EXIT_FAILURE;
}
#endif

// GUI Init
gtk_init(&argc, &argv);

#if USE_ONCE_LAUNCH
// Check is only one copy runs
sem_t *sem;

sem = sem_open(TSEM_KNAME, O_CREAT | O_EXCL, 0644, 1);
if(sem == SEM_FAILED)
{
ui_error("Program already launched.");
return EXIT_FAILURE;
}

if(sem_wait(sem) == -1)
{
perror("sem_wait");
return EXIT_FAILURE;
}
#endif

// Run Dragon Tea Messenger
tea_init();

// Window Looping
gtk_main();

// Free Unused resources DTM
tea_free();

#if USE_ONCE_LAUNCH
// Close launch
if(sem_post(sem) == -1)
{
perror("sem_post");
return EXIT_FAILURE;
}
if(sem_close(sem) == -1)
{
perror("sem_close");
return EXIT_FAILURE;
}

if(sem_unlink(TSEM_KNAME) == -1)
{
perror("sem_unlink");
return EXIT_FAILURE;
}
#endif

return EXIT_SUCCESS;
return tea_main(argc, argv);
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ gboolean on_chat_message_handler_async(gpointer)
if(last_chance_state != CHANCE_TO_LOGOUT)
strcpy(buffer, _("Your network has been restored. "));
else
buffer[0] = NULL;
buffer[0] = '\0';

strcat(buffer, _("You're online."));
tea_ui_chat_status_text(buffer);
Expand Down Expand Up @@ -174,7 +174,7 @@ gboolean on_chat_message_handler_async(gpointer)
{
gnotify = notify_notification_new(
message->sent_user_name, message->message_text, gtk_window_get_icon_name(widgets.main_window));
notify_notification_add_action(gnotify, "custom_action", _("Read message"), notify_action, NULL, NULL);
notify_notification_add_action(gnotify, "custom_action", _("Read message"), (NotifyActionCallback) notify_action, NULL, NULL);

if(!env.old_notify_remove)
notify_notification_set_timeout(gnotify, 0);
Expand Down
File renamed without changes.
81 changes: 81 additions & 0 deletions client-frontend/dragon-tea/src/teauilib/teauilib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include <fcntl.h>

#include "tea_main.h"

#include "tea.h"

#define USE_ONCE_LAUNCH 0

#if USE_ONCE_LAUNCH
#include <semaphore.h>
#define TSEM_KNAME "dragon_tea_lock"
#endif

int TEA_API tea_main(int argc, char *argv[])
{
setlocale(LC_ALL, "");

bindtextdomain(DRAGON_TEA_TEXTDOMAIN, DRAGON_TEA_LOCALE_DIR);
textdomain(DRAGON_TEA_TEXTDOMAIN);

// Check runned on Root
#ifdef TEA_OS_LINUX
if(getuid() == 0)
{
printf(_("The program is running as root. These privileges can harm the system, please be aware of this. Closing."));
return EXIT_FAILURE;
}
#endif

// GUI Init
gtk_init(&argc, &argv);

#if USE_ONCE_LAUNCH
// Check is only one copy runs
sem_t *sem;

sem = sem_open(TSEM_KNAME, O_CREAT | O_EXCL, 0644, 1);
if(sem == SEM_FAILED)
{
ui_error("Program already launched.");
return EXIT_FAILURE;
}

if(sem_wait(sem) == -1)
{
perror("sem_wait");
return EXIT_FAILURE;
}
#endif

// Run Dragon Tea Messenger
tea_init();

// Window Looping
gtk_main();

// Free Unused resources DTM
tea_free();

#if USE_ONCE_LAUNCH
// Close launch
if(sem_post(sem) == -1)
{
perror("sem_post");
return EXIT_FAILURE;
}
if(sem_close(sem) == -1)
{
perror("sem_close");
return EXIT_FAILURE;
}

if(sem_unlink(TSEM_KNAME) == -1)
{
perror("sem_unlink");
return EXIT_FAILURE;
}
#endif

return EXIT_SUCCESS;
}

0 comments on commit d224878

Please sign in to comment.