diff --git a/CMakeLists.txt b/CMakeLists.txt index bc250c3..8e58252 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.3 FATAL_ERROR) project(slack++ VERSION 0.1 LANGUAGES CXX C) -#set(CMAKE_BUILD_TYPE Release) +set(CMAKE_BUILD_TYPE Debug) set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") include_directories(include src) diff --git a/TODO.md b/TODO.md index 4b1e2ff..e78dbf5 100644 --- a/TODO.md +++ b/TODO.md @@ -1,8 +1,6 @@ TODO: -- [x] enhance mouse support (wheel on roster, left click on roster select it, right click mute it) -- [ ] cleanup code...private things/fix includes -- [ ] switch to signalfd instead of ppoll? +- [x] switch to signalfd instead of ppoll? - [ ] fix all issues from valgrind... LONGTERM AIMS: diff --git a/include/SlackUI.hpp b/include/SlackUI.hpp index 61af4e3..6d07e9b 100644 --- a/include/SlackUI.hpp +++ b/include/SlackUI.hpp @@ -3,7 +3,11 @@ #include #include #include -#include "signal.h" + +#ifdef __linux__ +#include +#include +#endif #ifdef LIBNOTIFY_FOUND #include diff --git a/include/WebsocketClient.hpp b/include/WebsocketClient.hpp index 3b3a85f..6592e4b 100644 --- a/include/WebsocketClient.hpp +++ b/include/WebsocketClient.hpp @@ -39,21 +39,20 @@ class WebsocketClient { CURLcode res = curl_easy_perform(curl); if (res == CURLE_OK) { - long s; - curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &s); - socket = s; - - std::string data; - - for (const auto& h: headers) { - data += h + "\r\n"; + res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &socket); + if (res == CURLE_OK) { + std::string data; + + for (const auto& h: headers) { + data += h + "\r\n"; + } + + data += "\r\n"; + + _send(data); + ping_pong(); + return true; } - - data += "\r\n"; - - _send(data); - ping_pong(); - return true; } Log::d() << "An error occurred during connection." << std::endl; return false; @@ -122,7 +121,7 @@ class WebsocketClient { int offset = 0; while (data.size() > offset && data.size() > 3) { - auto buff = std::string(data.begin()+offset, data.end()); + auto buff = std::string(data.begin() + offset, data.end()); if (buff.size() < 3) break; int length = buff[1] & 127; @@ -152,9 +151,9 @@ class WebsocketClient { } - std::string event(buff.begin()+index, buff.begin()+index+length); + std::string event(buff.begin() + index, buff.begin() + index + length); events.push_back(event); - offset = index+length; + offset += index + length; } } diff --git a/main.cpp b/main.cpp index 85889f3..6dc1d16 100644 --- a/main.cpp +++ b/main.cpp @@ -4,13 +4,11 @@ #include #include -static void check_cmdline(int, char **); - -static std::string TOKEN_NAME; +static void check_cmdline(int, char **, std::string&); int main(int argc, char* argv[]) { - - check_cmdline(argc, argv); + std::string TOKEN_NAME; + check_cmdline(argc, argv, TOKEN_NAME); auto token = std::getenv(TOKEN_NAME.c_str()); if (!token) { @@ -32,9 +30,10 @@ int main(int argc, char* argv[]) { c.set_token(token); ui.show(); + return 0; } -static void check_cmdline(int argc, char *argv[]) { +static void check_cmdline(int argc, char *argv[], std::string& TOKEN_NAME) { if (argc == 2) { if (strcmp(argv[1], "--help") == 0) { diff --git a/src/SlackClient.cpp b/src/SlackClient.cpp index 69f8966..ecfa6d2 100644 --- a/src/SlackClient.cpp +++ b/src/SlackClient.cpp @@ -192,29 +192,31 @@ Json::Value SlackClient::call(const std::string &api, const std::vector 0; i++) { if (main_p[i].revents & POLLIN) { switch (i) { case NCURSES_EVT: - // ncurses event + // ncurses event c = active_win->wait(get_session()); switch (c) { case KEY_TAB: @@ -111,17 +121,21 @@ void SlackUI::main_ui_cycle() { } break; case SOCKET_EVT: - // socket event + // socket event client->receive(); break; +#ifdef __linux__ + case SIGNAL_EVT: + // signal event on linux + sig_handler(main_p[SIGNAL_EVT].fd); + break; +#endif } ret--; } } } - close(main_p[0].fd); - close(main_p[1].fd); // before leaving, make sure we updated current chat's mark // only if a chat had been selected (ie the user did not leave slack++ immediately) update_mark(get_session(), @@ -189,8 +203,8 @@ Session& SlackUI::get_session() { } SlackUI::~SlackUI() { - endwin(); delwin(stdscr); + endwin(); } void SlackUI::setup_ncurses() {