Skip to content

Commit

Permalink
Update to latest libnx and libtesla
Browse files Browse the repository at this point in the history
  • Loading branch information
nedex committed Apr 21, 2020
1 parent f553cc0 commit 4b8bc4e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ include $(DEVKITPRO)/libnx/switch_rules
# NACP building is skipped as well.
#---------------------------------------------------------------------------------
APP_TITLE := QuickNTP
APP_VERSION := 1.0.0
APP_VERSION := 1.1.0

TARGET := $(notdir $(CURDIR))
BUILD := build
Expand Down
2 changes: 1 addition & 1 deletion libs/libtesla
29 changes: 10 additions & 19 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,11 @@
#include "servers.hpp"
#include "tesla-ext.hpp"

char* strdup(const char* s) {
size_t slen = strlen(s);
char* result = (char*)malloc(slen + 1);
if (result == NULL) {
return NULL;
}

memcpy(result, s, slen + 1);
return result;
}

TimeServiceType __nx_time_service_type = TimeServiceType_System;

class NtpGui : public tsl::Gui {
private:
char* Message;
std::string Message;
int currentServer = 0;
bool blockFlag = false;
std::vector<std::string> serverAddresses;
Expand All @@ -33,14 +22,14 @@ class NtpGui : public tsl::Gui {
return &serverAddresses[currentServer][0];
}

void setMessage(const char* fmt, ...) {
void setMessage(const char* fmt = "", ...) {
char buff[200];
va_list va;
va_start(va, fmt);
vsnprintf(buff, sizeof(buff), fmt, va);
va_end(va);

Message = strdup(buff);
Message = buff;
}

bool setNetworkSystemClock(time_t time) {
Expand Down Expand Up @@ -91,13 +80,13 @@ class NtpGui : public tsl::Gui {
}

void serverChanged() {
setMessage("");
setMessage();
}

bool operationBlock(std::function<void()> f) {
if (!blockFlag) {
blockFlag = true;
setMessage("");
setMessage();
f(); // TODO: Call async and set blockFlag to false
blockFlag = false;
}
Expand All @@ -124,11 +113,11 @@ class NtpGui : public tsl::Gui {

public:
NtpGui() : serverAddresses(NTPSERVERS[1].begin(), NTPSERVERS[1].end()) {
setMessage("");
setMessage();
}

virtual tsl::elm::Element* createUI() override {
auto frame = new tsl::elm::OverlayFrame("QuickNTP", "by NedEX - v1.0.0");
auto frame = new tsl::elm::OverlayFrame("QuickNTP", "by NedEX - v1.1.0");

auto list = new tsl::elm::List();

Expand Down Expand Up @@ -170,7 +159,9 @@ class NtpGui : public tsl::Gui {
50);

list->addItem(new tsl::elm::CustomDrawerUnscissored([& message = Message](tsl::gfx::Renderer* renderer, s32 x, s32 y, s32 w, s32 h) {
renderer->drawString(message, false, x + 5, tsl::cfg::FramebufferHeight - 100, 20, renderer->a(tsl::style::color::ColorText));
if (!message.empty()) {
renderer->drawString(message.c_str(), false, x + 5, tsl::cfg::FramebufferHeight - 100, 20, renderer->a(tsl::style::color::ColorText));
}
}));

frame->setContent(list);
Expand Down

0 comments on commit 4b8bc4e

Please sign in to comment.