Skip to content

Commit

Permalink
Fixed bug where the screen wouldn't update when a button is pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmmaTech committed Jul 24, 2021
1 parent 2d16472 commit 3a7047a
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ CXXFLAGS := $(CFLAGS) -std=c++17 -O2 -Wno-volatile
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)

LIBS := -lnx
LIBS := -lnx -lcurl

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
Expand Down
11 changes: 11 additions & 0 deletions include/constants.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#define CALCULATOR_NX_PATH "/switch/Calculator_NX"

#define CONFIG_PATH "/config/Calculator_NX"
#define DOWNLOAD_PATH "/config/Calculator_NX/download"

#define TAGS_API_LINK "https://api.github.com/repos/EmreTech/Calculator_NX/tags"
#define LATEST_RELEASE_API_LINK "https://api.github.com/repos/EmreTech/Calculator_NX/releases/latest"

#define BASE_DOWNLOAD_URL "https://github.com/EmreTech/Calculator_NX/releases/download/{}/Calculator_NX.nro"
15 changes: 15 additions & 0 deletions include/download.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <curl/curl.h>

#include <iostream>
#include <fstream>
#include <string>
#include <cstdio>

#define API_AGENT "EmreTech"

CURLcode downloadFile(const std::string &url, const std::string &filename);

std::string getLatestTag(bool nightly);
std::string getLatestDownload(bool nightly);
7 changes: 7 additions & 0 deletions resources/i18n/en-US/text.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"title": "Calculator_NX Rewrite",
"update_title": "Calculator_NX Updater",

"tabs": {
"calculator": "Calculator",
Expand All @@ -14,5 +15,11 @@
"about": {
"appname": "Calculator_NX",
"developer": "Developed by EmreTech"
},

"updater": {
"starting_update": "Starting update...",
"downloading_update": "Downloading the latest version...",
"restarting_to_finish": "About to restart to finish the update."
}
}
7 changes: 7 additions & 0 deletions resources/xml/activity/updater.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<brls:AppletFrame
title="@i18n/text/update_title"
icon="@res/icon/Calculator_NX_Icon_Alt.jpg">

<UpdaterTab />

</brls:AppletFrame>
14 changes: 14 additions & 0 deletions resources/xml/tabs/updater.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<brls:Box
width="auto"
height="auto"
alignItems="center"
justifyContent="center">

<brls:Label
width="auto"
height="auto"
horizontalAlign="center"
fontSize="35"
text="@i18n/text/updater/starting_update"/>

</brls:Box>
1 change: 1 addition & 0 deletions source/calculatorTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,5 @@ void CalculatorTab::updateScreenBufferFromExpStr()
screenBuffer = expressionStr;
if (expressionStr.length() >= 30)
screenBuffer = expressionStr.substr(29);
updateScreen();
}
80 changes: 80 additions & 0 deletions source/download.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include <download.hpp>

#include <nlohmann/json.hpp>
#include <fmt/core.h>

#include <constants.hpp>

size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream)
{
size_t written = fwrite(ptr, size, nmemb, stream);
return written;
}
CURLcode downloadFile(const std::string &url, const std::string &filename)
{
CURL *curl;
FILE *fp;
CURLcode res;

curl = curl_easy_init();
if (curl)
{
fp = fopen(filename.c_str(), "wb");

curl_easy_setopt(curl, CURLOPT_URL, url.c_str());

curl_easy_setopt(curl, CURLOPT_USERAGENT, API_AGENT);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);

curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);

res = curl_easy_perform(curl);
curl_easy_cleanup(curl);

fclose(fp);
}

return res;
}

std::string getLatestTag(bool nightly)
{
downloadFile(
(nightly ? TAGS_API_LINK : LATEST_RELEASE_API_LINK), DOWNLOAD_PATH + std::string("/github_api.json")
);

nlohmann::json api_data;
std::ifstream api_file(DOWNLOAD_PATH + std::string("/github_api.json"));

api_file >> api_data;
api_file.close();

if (nightly)
return api_data[0]["name"].get<std::string>();

return api_data["tag_name"];
}

std::string getLatestDownload(bool nightly)
{
if (nightly)
{
std::string latestTag = getLatestTag(nightly);
return fmt::format(BASE_DOWNLOAD_URL, latestTag);
}

downloadFile(
LATEST_RELEASE_API_LINK, DOWNLOAD_PATH + std::string("/github_api_two.json")
);

nlohmann::json api_data;
std::ifstream api_file(DOWNLOAD_PATH + std::string("/github_api_two.json"));

api_file >> api_data;
api_file.close();

return api_data["assets"][12/*"browser_download_url"*/];
}
1 change: 0 additions & 1 deletion source/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <borealis.hpp>
#include <nlohmann/json.hpp>

#include <calculatorTab.hpp>
#include <aboutTab.hpp>
Expand Down

0 comments on commit 3a7047a

Please sign in to comment.